From aef6d7e5f21ac6e47bef20290cc2be26a95ec3c2 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 21 May 2020 02:20:02 +0200 Subject: [PATCH 1/3] Detect and use system Lua. Makefile. Cmake todo --- client/Makefile | 114 +++++++++++++++++++----------- doc/md/Development/Maintainers.md | 1 + 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/client/Makefile b/client/Makefile index 71d6a6d88..363ff0089 100644 --- a/client/Makefile +++ b/client/Makefile @@ -36,74 +36,63 @@ endif # local libraries LUALIBPATH = ./deps/liblua +LUALIBINC = -I$(LUALIBPATH) LUALIB = $(LUALIBPATH)/liblua.a JANSSONLIBPATH = ./deps/jansson +JANSSONLIBINC = -I$(JANSSONLIBPATH) JANSSONLIB = $(JANSSONLIBPATH)/libjansson.a CBORLIBPATH = ./deps/tinycbor +CBORLIBINC = -I$(CBORLIBPATH) CBORLIB = $(CBORLIBPATH)/tinycbor.a REVENGLIBPATH = ./deps/reveng +REVENGLIBINC = -I$(REVENGLIBPATH) REVENGLIB = $(REVENGLIBPATH)/libreveng.a AMIIBOLIBPATH = ./deps/amiitool +AMIIBOLIBINC = -I$(AMIIBOLIBPATH) AMIIBOLIB = $(AMIIBOLIBPATH)/libamiibo.a HARDNESTEDLIBPATH = ./deps/hardnested +HARDNESTEDLIBINC = -I$(HARDNESTEDLIBPATH) HARDNESTEDLIB = $(HARDNESTEDLIBPATH)/libhardnested.a CLIPARSERLIBPATH = ./deps/cliparser +CLIPARSERLIBINC = -I$(CLIPARSERLIBPATH) CLIPARSERLIB = $(CLIPARSERLIBPATH)/libcliparser.a WAILIBPATH = ./deps/whereami +WAILIBINC = -I$(WAILIBPATH) WAILIB = $(WAILIBPATH)/libwhereami.a +LUAPLATFORM = generic +ifneq (,$(findstring MINGW,$(platform))) + LUAPLATFORM = mingw +else + ifeq ($(platform),Darwin) + LUAPLATFORM = macosx + else + LUALIB += -ldl + LUAPLATFORM = linux + endif +endif + # common libraries MBEDTLSLIBPATH = ../common/mbedtls MBEDTLSLIB = $(OBJDIR)/libmbedtls.a ZLIBPATH = ../common/zlib ZLIB = $(OBJDIR)/libz.a -LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGLIBPATH) -I$(AMIIBOLIBPATH) -I$(HARDNESTEDLIBPATH) -I$(CLIPARSERLIBPATH) -I$(WAILIBPATH) -INCLUDES_CLIENT += -I./src -I../include -I../common -I../common_fpga $(LIBS) -CFLAGS ?= $(DEFCFLAGS) - -# We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: -PM3CFLAGS = $(CFLAGS) $(INCLUDES_CLIENT) -# WIP Testing -#PM3CFLAGS = $(CFLAGS) -std=c11 -pedantic $(INCLUDES_CLIENT) -PREFIX ?= /usr/local -ifneq (,$(findstring MINGW,$(platform))) - # Mingw uses by default Microsoft printf, we want the GNU printf (e.g. for %z) - # and setting _ISOC99_SOURCE sets internally __USE_MINGW_ANSI_STDIO=1 - # FTR __USE_MINGW_ANSI_STDIO seems deprecated in Mingw32 - # but not Mingw64 https://fr.osdn.net/projects/mingw/lists/archive/users/2019-January/000199.html - PM3CFLAGS += -D_ISOC99_SOURCE - PM3CFLAGS += -mno-ms-bitfields -fexec-charset=cp850 -endif -CXXFLAGS ?= -Wall -Werror -O3 -PM3CXXFLAGS = $(CXXFLAGS) -I../include - -LUAPLATFORM = generic -ifneq (,$(findstring MINGW,$(platform))) - LUAPLATFORM = mingw -else - ifeq ($(platform),Darwin) - LUAPLATFORM = macosx - OBJCSRCS = util_darwin.m - LDFLAGS += -framework Foundation -framework AppKit - LDLIBS := -L/usr/local/opt/readline/lib $(LDLIBS) - LIBS := -I/usr/local/opt/readline/include $(LIBS) - # cf brew info qt: qt not symlinked anymore - PKG_CONFIG_ENV := PKG_CONFIG_PATH=/usr/local/opt/qt/lib/pkgconfig -else - LUALIB += -ldl - LUAPLATFORM = linux -endif +# system libraries +ifneq ($(SKIPLUASYSTEM),1) + LUAINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags lua5.2 2>/dev/null) + LUALDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs lua5.2 2>/dev/null) + ifneq ($(LUAINCLUDES),) + LUALIB = $(LUALDLIBS) + LUALIBINC = $(LUAINCLUDES) + LUASYSTEM = 1 + endif endif ifneq ($(SKIPBT),1) BTLDLIBS = $(shell $(PKG_CONFIG_ENV) pkg-config --libs bluez 2>/dev/null) endif -ifneq ($(BTLDLIBS),) - PM3CFLAGS += -DHAVE_BLUEZ -endif - ifneq ($(SKIPQT),1) # Check for correctly configured Qt5 QTINCLUDES = $(shell $(PKG_CONFIG_ENV) pkg-config --cflags Qt5Core Qt5Widgets 2>/dev/null) @@ -118,7 +107,7 @@ ifneq ($(SKIPQT),1) UIC = $(shell $(PKG_CONFIG_ENV) pkg-config --variable=uic_location QtCore) else # On OSX Qt5 is claiming for a C++11 compiler (gnu++14 works too, but if nothing it fails) - PM3CXXFLAGS += -fPIC -std=c++11 + QT5FOUND = 1 endif ifeq ($(QTINCLUDES), ) # if both pkg-config commands failed, search in common places @@ -128,7 +117,7 @@ ifneq ($(SKIPQT),1) ifneq ($(wildcard $(QTDIR)/include/QtWidgets),) QTINCLUDES += -I$(QTDIR)/include/QtWidgets QTLDLIBS = -L$(QTDIR)/lib -lQt5Widgets -lQt5Gui -lQt5Core - PM3CXXFLAGS += -fPIC -std=c++11 + QT5FOUND = 1 endif MOC = $(QTDIR)/bin/moc UIC = $(QTDIR)/bin/uic @@ -136,11 +125,47 @@ ifneq ($(SKIPQT),1) endif endif +LIBS = $(LUALIBINC) $(MBEDTLSLIBINC) $(JANSSONLIBINC) $(CBORLIBINC) $(ZLIBINC) $(REVENGLIBINC) $(AMIIBOLIBINC) $(HARDNESTEDLIBINC) $(CLIPARSERLIBINC) $(WAILIBINC) +INCLUDES_CLIENT += -I./src -I../include -I../common -I../common_fpga $(LIBS) +CFLAGS ?= $(DEFCFLAGS) + +# We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env: +PM3CFLAGS = $(CFLAGS) $(INCLUDES_CLIENT) +# WIP Testing +#PM3CFLAGS = $(CFLAGS) -std=c11 -pedantic $(INCLUDES_CLIENT) +PREFIX ?= /usr/local +ifneq (,$(findstring MINGW,$(platform))) + # Mingw uses by default Microsoft printf, we want the GNU printf (e.g. for %z) + # and setting _ISOC99_SOURCE sets internally __USE_MINGW_ANSI_STDIO=1 + # FTR __USE_MINGW_ANSI_STDIO seems deprecated in Mingw32 + # but not Mingw64 https://fr.osdn.net/projects/mingw/lists/archive/users/2019-January/000199.html + PM3CFLAGS += -D_ISOC99_SOURCE + PM3CFLAGS += -mno-ms-bitfields -fexec-charset=cp850 +endif +ifeq ($(platform),Darwin) + OBJCSRCS = util_darwin.m + LDFLAGS += -framework Foundation -framework AppKit + LDLIBS := -L/usr/local/opt/readline/lib $(LDLIBS) + LIBS := -I/usr/local/opt/readline/include $(LIBS) + # cf brew info qt: qt not symlinked anymore + PKG_CONFIG_ENV := PKG_CONFIG_PATH=/usr/local/opt/qt/lib/pkgconfig +endif + +CXXFLAGS ?= -Wall -Werror -O3 +PM3CXXFLAGS = $(CXXFLAGS) -I../include + +ifneq ($(BTLDLIBS),) + PM3CFLAGS += -DHAVE_BLUEZ +endif + ifneq ($(QTLDLIBS),) QTGUISRCS = proxgui.cpp proxguiqt.cpp proxguiqt.moc.cpp QTGUIOBJS = $(OBJDIR)/proxgui.o $(OBJDIR)/proxguiqt.o $(OBJDIR)/proxguiqt.moc.o PM3CFLAGS += -DHAVE_GUI PM3CXXFLAGS += -DQT_NO_DEBUG + ifeq ($(QT5FOUND),1) + PM3CXXFLAGS += -fPIC -std=c++11 + endif else QTGUISRCS = guidummy.cpp QTGUIOBJS = $(OBJDIR)/guidummy.o @@ -162,6 +187,9 @@ $(info native BT support: Bluez found, enabled) else $(info native BT support: Bluez not found, disabled) endif +ifeq ($(LUASYSTEM),1) +$(info system LUA: Lua5.2 found) +endif $(info compiler version: $(shell $(CC) --version|head -n 1)) $(info ===================================================================) @@ -385,8 +413,10 @@ tarbin: $(BINS) # local libraries: liblua: +ifneq ($(LUASYSTEM),1) $(info [*] MAKE $@ for $(LUAPLATFORM)) $(Q)$(MAKE) --no-print-directory -C $(LUALIBPATH) $(LUAPLATFORM) +endif jansson: $(info [*] MAKE $@) diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index 2a49343fd..c3d0e4e29 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -61,6 +61,7 @@ It's also possible to skip parts even if libraries are present in the compilatio * `make client SKIPQT=1` to skip GUI even if Qt is present * `make client SKIPBT=1` to skip native Bluetooth support even if libbluetooth is present +* `make client SKIPLUASYSTEM=1` to skip system Lua lib even if liblua5.2 is present, use embedded Lua lib instead If you're cross-compiling, these ones might be useful: From 278db15f5aa62d30ef09aa900c70a2c2a57c6264 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 22 May 2020 17:47:30 +0200 Subject: [PATCH 2/3] Move tests to tools/pm3_tests.sh and add "make check" to call it --- .travis.yml | 4 +- Makefile | 41 ++++++- Makefile.defs | 1 + covbuild.sh | 2 +- pm3test.sh | 167 --------------------------- tools/pm3_tests.sh | 276 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 317 insertions(+), 174 deletions(-) delete mode 100755 pm3test.sh create mode 100755 tools/pm3_tests.sh diff --git a/.travis.yml b/.travis.yml index f8cf8228f..ad23bf6f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,9 +54,9 @@ install: script: - if [ "$TO_TEST" = "MAKEFILE" ]; then make clean && make V=1 "$MAKE_PARAMS"; - ./pm3test.sh; + make check; fi - if [ "$TO_TEST" = "CMAKE" ]; then mkdir -p client/build && ( cd client/build && cmake .. && make VERBOSE=1 ); - PM3BIN=./client/build/proxmark3 ./pm3test.sh client; + make client/check CHECKARGS="--clientbin ./client/build/proxmark3"; fi diff --git a/Makefile b/Makefile index 958fe65a2..d111d01fc 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ ifneq (,$(DESTDIR)) endif endif -all clean install uninstall: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% mf_nonce_brute/% fpga_compress/% +all clean install uninstall check: %: client/% bootrom/% armsrc/% recovery/% mfkey/% nonce2key/% mf_nonce_brute/% fpga_compress/% INSTALLTOOLS=pm3_eml2lower.sh pm3_eml2upper.sh pm3_mfdread.py pm3_mfd2eml.py pm3_eml2mfd.py findbits.py rfidtest.pl xorcheck.py INSTALLSIMFW=sim011.bin sim011.sha512.txt @@ -78,6 +78,37 @@ ifeq ($(platform),Linux) endif $(Q)$(RMDIR_SOFT) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLSHARERELPATH) +# tests +mfkey/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +nonce2key/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +mf_nonce_brute/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +fpga_compress/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +bootrom/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +armsrc/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +client/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +recovery/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +common/check: FORCE + $(info [*] CHECK $(patsubst %/check,%,$@)) + $(Q)$(BASH) tools/pm3_tests.sh $(CHECKARGS) $(patsubst %/check,%,$@) +check: common/check + $(info [*] ALL CHECKS DONE) + mfkey/%: FORCE $(info [*] MAKE $@) $(Q)$(MAKE) --no-print-directory -C tools/mfkey $(patsubst mfkey/%,%,$@) DESTDIR=$(MYDESTDIR) @@ -106,7 +137,7 @@ recovery/%: FORCE cleanifplatformchanged $(Q)$(MAKE) --no-print-directory -C recovery $(patsubst recovery/%,%,$@) DESTDIR=$(MYDESTDIR) FORCE: # Dummy target to force remake in the subdirectories, even if files exist (this Makefile doesn't know about the prerequisites) -.PHONY: all clean install uninstall help _test bootrom fullimage recovery client mfkey nonce2key mf_nonce_brute style checks FORCE udev accessrights cleanifplatformchanged +.PHONY: all clean install uninstall help _test bootrom fullimage recovery client mfkey nonce2key mf_nonce_brute style miscchecks release FORCE udev accessrights cleanifplatformchanged help: @echo "Multi-OS Makefile" @@ -129,7 +160,9 @@ help: @echo "+ fpga_compress - Make tools/fpga_compress" @echo @echo "+ style - Apply some automated source code formatting rules" - @echo "+ checks - Detect various encoding issues in source code" + @echo "+ check - Run offline tests. Set CHECKARGS to pass arguments to the test script" + @echo "+ .../check - Run offline tests against specific target. See above." + @echo "+ miscchecks - Detect various encoding issues in source code" @echo @echo "Possible platforms: try \"make PLATFORM=\" for more info, default is PM3RDV4" @echo "To activate verbose mode, use make V=1" @@ -217,7 +250,7 @@ style: --align-pointer=name {} \; # Detecting weird codepages and tabs. -checks: +miscchecks: # Make sure recode is installed @which recode >/dev/null || ( echo "Please install 'recode' package first" ; exit 1 ) @echo "Files with suspicious chars:" diff --git a/Makefile.defs b/Makefile.defs index d206611d3..fb8a7a45b 100644 --- a/Makefile.defs +++ b/Makefile.defs @@ -25,6 +25,7 @@ CC = gcc CXX = g++ LD = g++ SH = sh +BASH = bash PERL = perl PATHSEP=/ diff --git a/covbuild.sh b/covbuild.sh index 2e18e677f..73c9a4441 100755 --- a/covbuild.sh +++ b/covbuild.sh @@ -32,7 +32,7 @@ cov-build --dir "$COVDIR" --c-coverage=gcov --no-network-coverage --no-generate- ######################################### # Run tests # ######################################### -cov-build --dir "$COVDIR" --c-coverage=gcov --no-network-coverage --test-capture ./pm3test.sh long +cov-build --dir "$COVDIR" --c-coverage=gcov --no-network-coverage --test-capture tools/pm3_tests.sh --long #cov-manage-emit --dir "$COVDIR" list-coverage-known ######################################### diff --git a/pm3test.sh b/pm3test.sh deleted file mode 100755 index 3bd7ae3a8..000000000 --- a/pm3test.sh +++ /dev/null @@ -1,167 +0,0 @@ -#!/usr/bin/env bash - -PM3PATH=$(dirname "$0") -cd "$PM3PATH" || exit 1 - -if [ "$1" == "client" ]; then - shift - TESTDEVICE=false - TESTTOOLS=false -else - TESTDEVICE=true - TESTTOOLS=true -fi -if [ "$1" == "long" ]; then - shift - SLOWTESTS=true -else - SLOWTESTS=false -fi - -C_RED='\033[0;31m' -C_GREEN='\033[0;32m' -C_YELLOW='\033[0;33m' -C_BLUE='\033[0;34m' -C_NC='\033[0m' # No Color - -# title, file name or file wildcard to check -function CheckFileExist() { - - if [ -f "$2" ]; then - echo -e "$1 ${C_GREEN}[OK]${C_NC}" - return 0 - fi - - if ls "$2" 1> /dev/null 2>&1; then - echo -e "$1 ${C_GREEN}[OK]${C_NC}" - return 0 - fi - - echo -e "$1 ${C_RED}[Fail]${C_NC}" - return 1 -} - -# title, command line, check result, repeat several times if failed, ignore if fail -function CheckExecute() { - - if [ "$4" ]; then - local RETRY="1 2 3 e" - else - local RETRY="e" - fi - - for I in $RETRY - do - RES=$(eval "$2") - if echo "$RES" | grep -q "$3"; then - echo -e "$1 ${C_GREEN}[OK]${C_NC}" - return 0 - fi - if [ ! $I == "e" ]; then echo "retry $I"; fi - done - - - if [ "$5" ]; then - echo -e "$1 ${C_YELLOW}[Ignored]${C_NC}" - return 0 - fi - - echo -e "$1 ${C_RED}[Fail]${C_NC}" - echo -e "Execution trace:\n$RES" - return 1 -} - -echo -e "\n${C_BLUE}RRG/Iceman Proxmark3 test tool ${C_NC}\n" - -echo -n "work directory: " -pwd -echo "client ${PM3BIN:="./client/proxmark3"}" - -if [ "$TRAVIS_COMMIT" ]; then - if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - echo "Travis branch: $TRAVIS_BRANCH slug: $TRAVIS_REPO_SLUG commit: $TRAVIS_COMMIT" - else - echo "Travis pull request: $TRAVIS_PULL_REQUEST branch: $TRAVIS_BRANCH slug: $TRAVIS_PULL_REQUEST_SLUG commit: $TRAVIS_COMMIT" - fi -fi - -echo -n "git branch: " -git describe --all -echo -n "git sha: " -git rev-parse HEAD -echo "" - -while true; do - echo -e "\n${C_BLUE}Testing files:${C_NC}" - if ! CheckFileExist "proxmark3 exists" "$PM3BIN"; then break; fi - if ! CheckFileExist "hardnested tables exists" "./client/resources/hardnested_tables/bitflip_0_001_states.bin.z"; then break; fi - if ! CheckFileExist "simmodule fw file exists" "./tools/simmodule/sim011.bin"; then break; fi - - if $TESTDEVICE; then - if ! CheckFileExist "arm image exists" "./armsrc/obj/fullimage.elf"; then break; fi - if ! CheckFileExist "bootrom exists" "./bootrom/obj/bootrom.elf"; then break; fi - fi - - echo -e "\n${C_BLUE}Testing basic help:${C_NC}" - if ! CheckExecute "proxmark help" "$PM3BIN -h" "wait"; then break; fi - if ! CheckExecute "proxmark help text ISO7816" "$PM3BIN -t 2>&1" "ISO7816"; then break; fi - if ! CheckExecute "proxmark help text hardnested" "$PM3BIN -t 2>&1" "hardnested"; then break; fi - - echo -e "\n${C_BLUE}Testing data manipulation:${C_NC}" - if ! CheckExecute "reveng readline test" "$PM3BIN -c 'reveng -h;reveng -D'" "CRC-64/GO-ISO"; then break; fi - if ! CheckExecute "reveng -g test" "$PM3BIN -c 'reveng -g abda202c'" "CRC-16/ISO-IEC-14443-3-A"; then break; fi - if ! CheckExecute "reveng -w test" "$PM3BIN -c 'reveng -w 8 -s 01020304e3 010204039d'" "CRC-8/SMBUS"; then break; fi - if ! CheckExecute "mfu pwdgen test" "$PM3BIN -c 'hf mfu pwdgen t'" "Selftest OK"; then break; fi - if ! CheckExecute "trace load/list 14a" "$PM3BIN -c 'trace load traces/hf_mfu.trace; trace list 1;'" "READBLOCK(8)"; then break; fi - if ! CheckExecute "trace load/list x" "$PM3BIN -c 'trace load traces/hf_mfu.trace; trace list x 1;'" "0.0101840425"; then break; fi - - echo -e "\n${C_BLUE}Testing LF:${C_NC}" - if ! CheckExecute "lf EM4x05 test" "$PM3BIN -c 'data load traces/em4x05.pm3;lf search 1'" "FDX-B ID found"; then break; fi - if ! CheckExecute "lf EM410x test" "$PM3BIN -c 'data load traces/EM4102-1.pm3;lf search 1'" "EM410x ID found"; then break; fi - if ! CheckExecute "lf VISA2000 test" "$PM3BIN -c 'data load traces/visa2000.pm3;lf search 1'" "Visa2000 ID found"; then break; fi - if ! CheckExecute "lf AWID test" "$PM3BIN -c 'data load traces/AWID-15-259.pm3;lf search 1'" "AWID ID found"; then break; fi - if ! CheckExecute "lf SECURAKEY test" "$PM3BIN -c 'data load traces/securakey-64169.pm3;lf search 1 '" "Securakey ID found"; then break; fi - if ! CheckExecute "lf NEXWATCH test" "$PM3BIN -c 'data load traces/quadrakey-521512301.pm3;lf search 1 '" "NexWatch ID found"; then break; fi - if ! CheckExecute "lf KERI test" "$PM3BIN -c 'data load traces/keri.pm3;lf search 1'" "Pyramid ID found"; then break; fi - if ! CheckExecute "lf HID Prox test" "$PM3BIN -c 'data load traces/hid-proxCardII-05512-11432784-1.pm3;lf search 1'" "HID Prox ID found"; then break; fi - if ! CheckExecute "lf PARADOX test" "$PM3BIN -c 'data load traces/Paradox-96_40426-APJN08.pm3;lf search 1'" "Paradox ID found"; then break; fi - if ! CheckExecute "lf PAC test" "$PM3BIN -c 'data load traces/pac-8E4C058E.pm3;lf search 1'" "PAC/Stanley ID found"; then break; fi - if ! CheckExecute "lf VIKING test" "$PM3BIN -c 'data load traces/Transit999-best.pm3;lf search 1'" "Viking ID found"; then break; fi - if ! CheckExecute "lf FDX-B test" "$PM3BIN -c 'data load traces/homeagain1600.pm3;lf search 1'" "FDX-B ID found"; then break; fi - if ! CheckExecute "lf INDALA test" "$PM3BIN -c 'data load traces/indala-504278295.pm3;lf search 1'" "Indala ID found"; then break; fi - if ! CheckExecute "lf FDX/BioThermo test" "$PM3BIN -c 'data load traces/lf_fdx_biothermo.pm3; lf fdx demo'" "95.2 F / 35.1 C"; then break; fi - - - echo -e "\n${C_BLUE}Testing HF:${C_NC}" - if ! CheckExecute "hf mf offline text" "$PM3BIN -c 'hf mf'" "at_enc"; then break; fi - if $SLOWTESTS; then - if ! CheckExecute "hf mf hardnested test" "$PM3BIN -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi - if ! CheckExecute "hf iclass test" "$PM3BIN -c 'hf iclass loclass t l'" "verified ok"; then break; fi - if ! CheckExecute "emv test" "$PM3BIN -c 'emv test -l'" "Test(s) \[ OK"; then break; fi - else - if ! CheckExecute "hf iclass test" "$PM3BIN -c 'hf iclass loclass t'" "key diversification (ok)"; then break; fi - if ! CheckExecute "emv test" "$PM3BIN -c 'emv test'" "Test(s) \[ OK"; then break; fi - fi - - if $TESTTOOLS; then - echo -e "\n${C_BLUE}Testing tools:${C_NC}" - # Need a decent example for mfkey32... - if ! CheckExecute "mfkey32v2 test" "tools/mfkey/mfkey32v2 12345678 1AD8DF2B 1D316024 620EF048 30D6CB07 C52077E2 837AC61A" "Found Key: \[a0a1a2a3a4a5\]"; then break; fi - if ! CheckExecute "mfkey64 test" "tools/mfkey/mfkey64 9c599b32 82a4166c a1e458ce 6eea41e0 5cadf439" "Found Key: \[ffffffffffff\]"; then break; fi - if ! CheckExecute "mfkey64 long trace test" "tools/mfkey/./mfkey64 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea" "Found Key: \[091e639cb715\]"; then break; fi - if ! CheckExecute "nonce2key test" "tools/nonce2key/nonce2key e9cadd9c a8bf4a12 a020a8285858b090 050f010607060e07 5693be6c00000000" "key recovered: fc00018778f7"; then break; fi - if ! CheckExecute "xorcheck test" "tools/xorcheck.py 04 00 80 64 ba" "final LRC XOR byte value: 5A"; then break; fi - if ! CheckExecute "findbits test" "tools/findbits.py 73 0110010101110011" "Match at bit 9: 011001010"; then break; fi - if ! CheckExecute "findbits_test test" "tools/findbits_test.py 2>&1" "OK"; then break; fi - if ! CheckExecute "pm3_eml_mfd test" "tools/pm3_eml_mfd_test.py 2>&1" "OK"; then break; fi - if $SLOWTESTS; then - if ! CheckExecute "mf_nonce_brute test" "tools/mf_nonce_brute/mf_nonce_brute 9c599b32 5a920d85 1011 98d76b77 d6c6e870 0000 ca7e0b63 0111 3e709c8a" "Key.*: \[ffffffffffff\]"; then break; fi - fi - fi - - echo -e "\n${C_GREEN}Tests [OK]${C_NC}\n" - exit 0 -done - -echo -e "\n${C_RED}Tests [FAIL]${C_NC}\n" -exit 1 diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh new file mode 100755 index 000000000..8aaf82d58 --- /dev/null +++ b/tools/pm3_tests.sh @@ -0,0 +1,276 @@ +#!/usr/bin/env bash + +PM3PATH="$(dirname "$0")/.." +cd "$PM3PATH" || exit 1 + +SLOWTESTS=false +TESTALL=true +TESTMFKEY=false +TESTNONCE2KEY=false +TESTMFNONCEBRUTE=false +TESTFPGACOMPRESS=false +TESTBOOTROM=false +TESTARMSRC=false +TESTCLIENT=false +TESTRECOVERY=false +TESTCOMMON=false + +# https://medium.com/@Drew_Stokes/bash-argument-parsing-54f3b81a6a8f +PARAMS="" +while (( "$#" )); do + case "$1" in + -h|--help) + echo """ +Usage: $0 [--long] [--clientbin /path/to/proxmark3] [mfkey|nonce2key|mf_nonce_brute|fpga_compress|bootrom|armsrc|client|recovery|common] + --long: Enable slow tests + --clientbin ...: Specify path to proxmark3 binary to test + If no target given, all targets will be tested +""" + exit 0 + ;; + -l|--long) + SLOWTESTS=true + shift + ;; + --clientbin) + if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then + CLIENTBIN=$2 + shift 2 + else + echo "Error: Argument for $1 is missing" >&2 + exit 1 + fi + ;; + mfkey) + TESTALL=false + TESTMFKEY=true + shift + ;; + nonce2key) + TESTALL=false + TESTNONCE2KEY=true + shift + ;; + mf_nonce_brute) + TESTALL=false + TESTMFNONCEBRUTE=true + shift + ;; + fpga_compress) + TESTALL=false + TESTFPGACOMPRESS=true + shift + ;; + bootrom) + TESTALL=false + TESTBOOTROM=true + shift + ;; + armsrc) + TESTALL=false + TESTARMSRC=true + shift + ;; + client) + TESTALL=false + TESTCLIENT=true + shift + ;; + recovery) + TESTALL=false + TESTRECOVERY=true + shift + ;; + common) + TESTALL=false + TESTCOMMON=true + shift + ;; + -*|--*=) # unsupported flags + echo "Error: Unsupported flag $1" >&2 + exit 1 + ;; + *) # preserve positional arguments + PARAMS="$PARAMS $1" + shift + ;; + esac +done +# set positional arguments in their proper place +eval set -- "$PARAMS" + +C_RED='\033[0;31m' +C_GREEN='\033[0;32m' +C_YELLOW='\033[0;33m' +C_BLUE='\033[0;34m' +C_NC='\033[0m' # No Color + +# title, file name or file wildcard to check +function CheckFileExist() { + + if [ -f "$2" ]; then + echo -e "$1 ${C_GREEN}[OK]${C_NC}" + return 0 + fi + + if ls "$2" 1> /dev/null 2>&1; then + echo -e "$1 ${C_GREEN}[OK]${C_NC}" + return 0 + fi + + echo -e "$1 ${C_RED}[Fail]${C_NC}" + return 1 +} + +# title, command line, check result, repeat several times if failed, ignore if fail +function CheckExecute() { + if [ "$1" == "slow" ]; then + SLOWTEST=true + shift + else + SLOWTEST=false + fi + if [ "$4" ]; then + local RETRY="1 2 3 e" + else + local RETRY="e" + fi + + if $SLOWTEST && ! $SLOWTESTS; then + echo -e "$1 ${C_YELLOW}[SKIPPED]${C_NC} (slow)\n" + return 0 + fi + + for I in $RETRY + do + RES=$(eval "$2") + if echo "$RES" | grep -q "$3"; then + echo -e "$1 ${C_GREEN}[OK]${C_NC}" + return 0 + fi + if [ ! $I == "e" ]; then echo "retry $I"; fi + done + + if [ "$5" ]; then + echo -e "$1 ${C_YELLOW}[Ignored]${C_NC}" + return 0 + fi + + echo -e "$1 ${C_RED}[Fail]${C_NC}" + echo -e "Execution trace:\n$RES" + return 1 +} + +echo -e "\n${C_BLUE}RRG/Iceman Proxmark3 test tool ${C_NC}\n" + +echo -n "work directory: " +pwd + +if [ "$TRAVIS_COMMIT" ]; then + if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + echo "Travis branch: $TRAVIS_BRANCH slug: $TRAVIS_REPO_SLUG commit: $TRAVIS_COMMIT" + else + echo "Travis pull request: $TRAVIS_PULL_REQUEST branch: $TRAVIS_BRANCH slug: $TRAVIS_PULL_REQUEST_SLUG commit: $TRAVIS_COMMIT" + fi +fi + +echo -n "git branch: " +git describe --all +echo -n "git sha: " +git rev-parse HEAD +echo "" + +while true; do + if $TESTALL || $TESTCOMMON; then + echo -e "\n${C_BLUE}Testing common:${C_NC}" + if ! CheckFileExist "hardnested tables exists" "./client/resources/hardnested_tables/bitflip_0_001_states.bin.z"; then break; fi + if ! CheckFileExist "simmodule fw file exists" "./tools/simmodule/sim011.bin"; then break; fi + echo -e "\n${C_BLUE}Testing tools:${C_NC}" + if ! CheckExecute "xorcheck test" "tools/xorcheck.py 04 00 80 64 ba" "final LRC XOR byte value: 5A"; then break; fi + if ! CheckExecute "findbits test" "tools/findbits.py 73 0110010101110011" "Match at bit 9: 011001010"; then break; fi + if ! CheckExecute "findbits_test test" "tools/findbits_test.py 2>&1" "OK"; then break; fi + if ! CheckExecute "pm3_eml_mfd test" "tools/pm3_eml_mfd_test.py 2>&1" "OK"; then break; fi + fi + if $TESTALL || $TESTBOOTROM; then + echo -e "\n${C_BLUE}Testing bootrom:${C_NC}" + if ! CheckFileExist "bootrom exists" "./bootrom/obj/bootrom.elf"; then break; fi + fi + if $TESTALL || $TESTARMSRC; then + echo -e "\n${C_BLUE}Testing armsrc:${C_NC}" + if ! CheckFileExist "arm image exists" "./armsrc/obj/fullimage.elf"; then break; fi + fi + if $TESTALL || $TESTRECOVERY; then + echo -e "\n${C_BLUE}Testing recovery:${C_NC}" + if ! CheckFileExist "recovery image exists" "./recovery/proxmark3_recovery.bin"; then break; fi + + fi + if $TESTALL || $TESTFPGACOMPRESS; then + echo -e "\n${C_BLUE}Testing fpgacompress:${C_NC} ${FPGACPMPRESSBIN:=./tools/fpga_compress/fpga_compress}" + if ! CheckFileExist "fpgacompress exists" "$FPGACPMPRESSBIN"; then break; fi + fi + if $TESTALL || $TESTMFKEY; then + echo -e "\n${C_BLUE}Testing mfkey:${C_NC} ${MFKEY32V2BIN:=./tools/mfkey/mfkey32v2} ${MFKEY64BIN:=./tools/mfkey/mfkey64}" + if ! CheckFileExist "mfkey32v2 exists" "$MFKEY32V2BIN"; then break; fi + if ! CheckFileExist "mfkey64 exists" "$MFKEY64BIN"; then break; fi + # Need a decent example for mfkey32... + if ! CheckExecute "mfkey32v2 test" "$MFKEY32V2BIN 12345678 1AD8DF2B 1D316024 620EF048 30D6CB07 C52077E2 837AC61A" "Found Key: \[a0a1a2a3a4a5\]"; then break; fi + if ! CheckExecute "mfkey64 test" "$MFKEY64BIN 9c599b32 82a4166c a1e458ce 6eea41e0 5cadf439" "Found Key: \[ffffffffffff\]"; then break; fi + if ! CheckExecute "mfkey64 long trace test" "$MFKEY64BIN 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea" "Found Key: \[091e639cb715\]"; then break; fi + fi + if $TESTALL || $TESTNONCE2KEY; then + echo -e "\n${C_BLUE}Testing nonce2key:${C_NC} ${NONCE2KEYBIN:=./tools/nonce2key/nonce2key}" + if ! CheckFileExist "nonce2key exists" "$NONCE2KEYBIN"; then break; fi + if ! CheckExecute "nonce2key test" "$NONCE2KEYBIN e9cadd9c a8bf4a12 a020a8285858b090 050f010607060e07 5693be6c00000000" "key recovered: fc00018778f7"; then break; fi + fi + if $TESTALL || $TESTMFNONCEBRUTE; then + echo -e "\n${C_BLUE}Testing mf_nonce_brute:${C_NC} ${MFNONCEBRUTEBIN:=./tools/mf_nonce_brute/mf_nonce_brute}" + if ! CheckFileExist "mf_nonce_brute exists" "$MFNONCEBRUTEBIN"; then break; fi + if ! CheckExecute slow "mf_nonce_brute test" "$MFNONCEBRUTEBIN 9c599b32 5a920d85 1011 98d76b77 d6c6e870 0000 ca7e0b63 0111 3e709c8a" "Key.*: \[ffffffffffff\]"; then break; fi + fi + if $TESTALL || $TESTCLIENT; then + echo -e "\n${C_BLUE}Testing client:${C_NC} ${CLIENTBIN:=./client/proxmark3}" + if ! CheckFileExist "proxmark3 exists" "$CLIENTBIN"; then break; fi + echo -e "\n${C_BLUE}Testing basic help:${C_NC}" + if ! CheckExecute "proxmark help" "$CLIENTBIN -h" "wait"; then break; fi + if ! CheckExecute "proxmark help text ISO7816" "$CLIENTBIN -t 2>&1" "ISO7816"; then break; fi + if ! CheckExecute "proxmark help text hardnested" "$CLIENTBIN -t 2>&1" "hardnested"; then break; fi + + echo -e "\n${C_BLUE}Testing data manipulation:${C_NC}" + if ! CheckExecute "reveng readline test" "$CLIENTBIN -c 'reveng -h;reveng -D'" "CRC-64/GO-ISO"; then break; fi + if ! CheckExecute "reveng -g test" "$CLIENTBIN -c 'reveng -g abda202c'" "CRC-16/ISO-IEC-14443-3-A"; then break; fi + if ! CheckExecute "reveng -w test" "$CLIENTBIN -c 'reveng -w 8 -s 01020304e3 010204039d'" "CRC-8/SMBUS"; then break; fi + if ! CheckExecute "mfu pwdgen test" "$CLIENTBIN -c 'hf mfu pwdgen t'" "Selftest OK"; then break; fi + if ! CheckExecute "trace load/list 14a" "$CLIENTBIN -c 'trace load traces/hf_mfu.trace; trace list 1;'" "READBLOCK(8)"; then break; fi + if ! CheckExecute "trace load/list x" "$CLIENTBIN -c 'trace load traces/hf_mfu.trace; trace list x 1;'" "0.0101840425"; then break; fi + + echo -e "\n${C_BLUE}Testing LF:${C_NC}" + if ! CheckExecute "lf EM4x05 test" "$CLIENTBIN -c 'data load traces/em4x05.pm3;lf search 1'" "FDX-B ID found"; then break; fi + if ! CheckExecute "lf EM410x test" "$CLIENTBIN -c 'data load traces/EM4102-1.pm3;lf search 1'" "EM410x ID found"; then break; fi + if ! CheckExecute "lf VISA2000 test" "$CLIENTBIN -c 'data load traces/visa2000.pm3;lf search 1'" "Visa2000 ID found"; then break; fi + if ! CheckExecute "lf AWID test" "$CLIENTBIN -c 'data load traces/AWID-15-259.pm3;lf search 1'" "AWID ID found"; then break; fi + if ! CheckExecute "lf SECURAKEY test" "$CLIENTBIN -c 'data load traces/securakey-64169.pm3;lf search 1 '" "Securakey ID found"; then break; fi + if ! CheckExecute "lf NEXWATCH test" "$CLIENTBIN -c 'data load traces/quadrakey-521512301.pm3;lf search 1 '" "NexWatch ID found"; then break; fi + if ! CheckExecute "lf KERI test" "$CLIENTBIN -c 'data load traces/keri.pm3;lf search 1'" "Pyramid ID found"; then break; fi + if ! CheckExecute "lf HID Prox test" "$CLIENTBIN -c 'data load traces/hid-proxCardII-05512-11432784-1.pm3;lf search 1'" "HID Prox ID found"; then break; fi + if ! CheckExecute "lf PARADOX test" "$CLIENTBIN -c 'data load traces/Paradox-96_40426-APJN08.pm3;lf search 1'" "Paradox ID found"; then break; fi + if ! CheckExecute "lf PAC test" "$CLIENTBIN -c 'data load traces/pac-8E4C058E.pm3;lf search 1'" "PAC/Stanley ID found"; then break; fi + if ! CheckExecute "lf VIKING test" "$CLIENTBIN -c 'data load traces/Transit999-best.pm3;lf search 1'" "Viking ID found"; then break; fi + if ! CheckExecute "lf FDX-B test" "$CLIENTBIN -c 'data load traces/homeagain1600.pm3;lf search 1'" "FDX-B ID found"; then break; fi + if ! CheckExecute "lf INDALA test" "$CLIENTBIN -c 'data load traces/indala-504278295.pm3;lf search 1'" "Indala ID found"; then break; fi + if ! CheckExecute "lf FDX/BioThermo test" "$CLIENTBIN -c 'data load traces/lf_fdx_biothermo.pm3; lf fdx demo'" "95.2 F / 35.1 C"; then break; fi + + echo -e "\n${C_BLUE}Testing HF:${C_NC}" + if ! CheckExecute "hf mf offline text" "$CLIENTBIN -c 'hf mf'" "at_enc"; then break; fi + if ! CheckExecute slow "hf mf hardnested long test" "$CLIENTBIN -c 'hf mf hardnested t 1 000000000000'" "found:" "repeat" "ignore"; then break; fi + if ! CheckExecute slow "hf iclass long test" "$CLIENTBIN -c 'hf iclass loclass t l'" "verified ok"; then break; fi + if ! CheckExecute slow "emv long test" "$CLIENTBIN -c 'emv test -l'" "Test(s) \[ OK"; then break; fi + if ! $SLOWTESTS; then + if ! CheckExecute "hf iclass test" "$CLIENTBIN -c 'hf iclass loclass t'" "key diversification (ok)"; then break; fi + if ! CheckExecute "emv test" "$CLIENTBIN -c 'emv test'" "Test(s) \[ OK"; then break; fi + fi + fi + echo -e "\n${C_GREEN}Tests [OK]${C_NC}\n" + exit 0 +done +echo -e "\n${C_RED}Tests [FAIL]${C_NC}\n" +exit 1 From bcb0e5db4d0a80de456289a33df0287c3f46fb66 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 22 May 2020 18:40:12 +0200 Subject: [PATCH 3/3] document make check --- doc/md/Development/Maintainers.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/md/Development/Maintainers.md b/doc/md/Development/Maintainers.md index c3d0e4e29..af36dbbe2 100644 --- a/doc/md/Development/Maintainers.md +++ b/doc/md/Development/Maintainers.md @@ -72,6 +72,8 @@ On some architectures, pthread library is not present: * `make client SKIPPTHREAD=1` to skip `-lpthread` at linker stage. +Some unittests are available via `make check`, which is actually triggering individual targets as for `make install`. + `make install` is actually triggering the following individual targets which can be accessed individually: * `make client/install` @@ -89,4 +91,4 @@ On some architectures, pthread library is not present: * SIM firmware * udev rule on Linux -Same logic for `make all`, `make clean`, `make uninstall` +Same logic for `make all`, `make clean`, `make uninstall` and `make check`.