diff --git a/core/Makefile b/core/Makefile index 7c1ca0e8cd..cb386a0248 100644 --- a/core/Makefile +++ b/core/Makefile @@ -38,6 +38,15 @@ FIRMWARE_MAXSIZE = 1703936 GITREV=$(shell git describe --always --dirty | tr '-' '_') CFLAGS += -DGITREV=$(GITREV) +EMU = $(CURDIR)/emu.py +EMU_TEST_ARGS = --disable-animation --headless --quiet --temporary-profile +EMU_TEST = $(EMU) $(EMU_TEST_ARGS) -c + +TESTPATH = $(CURDIR)/../tests +JUNIT_XML ?= $(TESTPATH)/junit.xml +PYTEST = pytest --junitxml=$(JUNIT_XML) +TREZOR_FIDO2_UDP_PORT = 21326 + ## help commands: help: ## show this help @@ -57,7 +66,7 @@ run: ## run unix port cd src ; ../$(UNIX_BUILD_DIR)/micropython emu: ## run emulator - ./emu.sh + $(EMU) ## test commands: @@ -65,25 +74,27 @@ test: ## run unit tests cd tests ; ./run_tests.sh $(TESTOPTS) test_emu: ## run selected device tests from python-trezor - cd tests ; ./run_tests_device_emu.sh $(TESTOPTS) + $(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests $(TESTOPTS) test_emu_monero: ## run selected monero device tests from monero-agent cd tests ; ./run_tests_device_emu_monero.sh $(TESTOPTS) test_emu_u2f: ## run selected u2f device tests from u2f-tests-hid - cd tests ; ./run_tests_device_emu_u2f.sh $(TESTOPTS) + $(EMU_TEST) --slip0014 $(TESTPATH)/fido_tests/u2f-tests-hid/HIDTest $(TREZOR_FIDO2_UDP_PORT) $(TESTOPTS) + $(EMU_TEST) --slip0014 $(TESTPATH)/fido_tests/u2f-tests-hid/U2FTest $(TREZOR_FIDO2_UDP_PORT) $(TESTOPTS) test_emu_fido2: ## run fido2 device tests - cd tests ; ./run_tests_device_emu_fido2.sh $(TESTOPTS) + cd $(TESTPATH)/fido_tests/fido2 ; \ + $(EMU_TEST) $(PYTEST) --sim tests/standard/ --vendor trezor $(TESTOPTS) test_emu_click: ## run click tests - cd tests ; ./run_tests_click_emu.sh $(TESTOPTS) + $(EMU_TEST) $(PYTEST) $(TESTPATH)/click_tests $(TESTOPTS) test_emu_ui: ## run ui integration tests - cd tests ; ./run_tests_device_emu.sh --ui=test -m "not skip_ui" $(TESTOPTS) + $(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests --ui=test -m "not skip_ui" $(TESTOPTS) test_emu_ui_record: ## record and hash screens for ui integration tests - cd tests ; ./run_tests_device_emu.sh --ui=record -m "not skip_ui" $(TESTOPTS) + $(EMU_TEST) $(PYTEST) $(TESTPATH)/device_tests --ui=record -m "not skip_ui" $(TESTOPTS) pylint: ## run pylint on application sources and tests pylint -E $(shell find src tests -name *.py) diff --git a/core/tests/run_tests_device_emu.sh b/core/tests/run_tests_device_emu.sh deleted file mode 100755 index b823bbc43c..0000000000 --- a/core/tests/run_tests_device_emu.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -: "${RUN_TEST_EMU:=1}" - -CORE_DIR="$(SHELL_SESSION_FILE='' && cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )" -MICROPYTHON="${MICROPYTHON:-$CORE_DIR/build/unix/micropython}" -TREZOR_SRC="${CORE_DIR}/src" - -PYOPT="${PYOPT:-0}" -upy_pid="" - -# run emulator if RUN_TEST_EMU -if [[ $RUN_TEST_EMU > 0 ]]; then - source ../trezor_cmd.sh - - # remove flash and sdcard files before run to prevent inconsistent states - mv "${TREZOR_PROFILE_DIR}/trezor.flash" "${TREZOR_PROFILE_DIR}/trezor.flash.bkp" 2>/dev/null - mv "${TREZOR_PROFILE_DIR}/trezor.sdcard" "${TREZOR_PROFILE_DIR}/trezor.sdcard.bkp" 2>/dev/null - - cd "${TREZOR_SRC}" - echo "Starting emulator: $MICROPYTHON $ARGS ${MAIN}" - - TREZOR_TEST=1 \ - TREZOR_DISABLE_ANIMATION=1 \ - $MICROPYTHON $ARGS "${MAIN}" &> "${TREZOR_LOGFILE}" & - upy_pid=$! - cd - - sleep 30 -fi - -# run tests -error=0 -if ! pytest --junitxml=../../tests/junit.xml ../../tests/device_tests "$@"; then - error=1 -fi -kill $upy_pid -exit $error diff --git a/core/tests/run_tests_device_emu_fido2.sh b/core/tests/run_tests_device_emu_fido2.sh deleted file mode 100755 index bcbedbdd9f..0000000000 --- a/core/tests/run_tests_device_emu_fido2.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -: "${RUN_TEST_EMU:=1}" - -CORE_DIR="$(SHELL_SESSION_FILE='' && cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )" -MICROPYTHON="${MICROPYTHON:-$CORE_DIR/build/unix/micropython}" -TREZOR_SRC="${CORE_DIR}/src" - -DISABLE_ANIMATION=1 -PYOPT="${PYOPT:-0}" -upy_pid="" - -# run emulator if RUN_TEST_EMU -if [[ $RUN_TEST_EMU > 0 ]]; then - source ../trezor_cmd.sh - - # remove flash and sdcard files before run to prevent inconsistent states - mv "${TREZOR_PROFILE_DIR}/trezor.flash" "${TREZOR_PROFILE_DIR}/trezor.flash.bkp" 2>/dev/null - mv "${TREZOR_PROFILE_DIR}/trezor.sdcard" "${TREZOR_PROFILE_DIR}/trezor.sdcard.bkp" 2>/dev/null - - cd "${TREZOR_SRC}" - echo "Starting emulator: $MICROPYTHON $ARGS ${MAIN}" - - TREZOR_TEST=1 \ - TREZOR_DISABLE_ANIMATION=$DISABLE_ANIMATION \ - $MICROPYTHON $ARGS "${MAIN}" &> "${TREZOR_LOGFILE}" & - upy_pid=$! - cd - - sleep 30 -fi - -cd ../../tests/fido_tests/fido2 -# run tests -error=0 -export TREZOR_FIDO2_UDP_PORT=21326 -if ! pytest --junitxml=../../tests/junit.xml --sim tests/standard/ --vendor trezor "$@"; then - error=1 -fi -kill $upy_pid -exit $error diff --git a/core/tests/run_tests_device_emu_u2f.sh b/core/tests/run_tests_device_emu_u2f.sh deleted file mode 100755 index 93c58fadb9..0000000000 --- a/core/tests/run_tests_device_emu_u2f.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash - -: "${RUN_TEST_EMU:=1}" - -CORE_DIR="$(SHELL_SESSION_FILE='' && cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )" -MICROPYTHON="${MICROPYTHON:-$CORE_DIR/build/unix/micropython}" -TREZOR_SRC="${CORE_DIR}/src" - -DISABLE_ANIMATION=1 -PYOPT="${PYOPT:-0}" -upy_pid="" - -# run emulator if RUN_TEST_EMU -if [[ $RUN_TEST_EMU > 0 ]]; then - source ../trezor_cmd.sh - - # remove flash and sdcard files before run to prevent inconsistent states - mv "${TREZOR_PROFILE_DIR}/trezor.flash" "${TREZOR_PROFILE_DIR}/trezor.flash.bkp" 2>/dev/null - mv "${TREZOR_PROFILE_DIR}/trezor.sdcard" "${TREZOR_PROFILE_DIR}/trezor.sdcard.bkp" 2>/dev/null - - cd "${TREZOR_SRC}" - echo "Starting emulator: $MICROPYTHON $ARGS ${MAIN}" - - TREZOR_TEST=1 \ - TREZOR_DISABLE_ANIMATION=$DISABLE_ANIMATION \ - $MICROPYTHON $ARGS "${MAIN}" &> "${TREZOR_LOGFILE}" & - upy_pid=$! - cd - - sleep 30 -fi - -# run tests -error=0 -TREZOR_FIDO2_UDP_PORT=21326 -# missuse loaddevice test to initialize the device -if ! pytest ../../tests/device_tests -k "test_msg_loaddevice" "$@"; then - error=1 -fi -if ! ../../tests/fido_tests/u2f-tests-hid/HIDTest "${TREZOR_FIDO2_UDP_PORT}" "$@"; then - error=1 -fi -if ! ../../tests/fido_tests/u2f-tests-hid/U2FTest "${TREZOR_FIDO2_UDP_PORT}" "$@"; then - error=1 -fi -kill $upy_pid -exit $error