diff --git a/CMakeLists.txt b/CMakeLists.txt index 3045800a..0050d705 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ link_libraries(ssl crypto dl blst) add_subdirectory(src) if (BUILD_TESTING) - add_subdirectory(tests/syscalls) + add_subdirectory(tests/c/) endif() add_custom_target( diff --git a/tests/c/CMakeLists.txt b/tests/c/CMakeLists.txt new file mode 100644 index 00000000..ace683c3 --- /dev/null +++ b/tests/c/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(syscalls) diff --git a/tests/syscalls/CMakeLists.txt b/tests/c/syscalls/CMakeLists.txt similarity index 100% rename from tests/syscalls/CMakeLists.txt rename to tests/c/syscalls/CMakeLists.txt diff --git a/tests/syscalls/cavp/blake2b_kat.data b/tests/c/syscalls/cavp/blake2b_kat.data similarity index 100% rename from tests/syscalls/cavp/blake2b_kat.data rename to tests/c/syscalls/cavp/blake2b_kat.data diff --git a/tests/syscalls/cavp/groestl_224_long_msg.data b/tests/c/syscalls/cavp/groestl_224_long_msg.data similarity index 100% rename from tests/syscalls/cavp/groestl_224_long_msg.data rename to tests/c/syscalls/cavp/groestl_224_long_msg.data diff --git a/tests/syscalls/cavp/groestl_224_short_msg.data b/tests/c/syscalls/cavp/groestl_224_short_msg.data similarity index 100% rename from tests/syscalls/cavp/groestl_224_short_msg.data rename to tests/c/syscalls/cavp/groestl_224_short_msg.data diff --git a/tests/syscalls/cavp/groestl_256_long_msg.data b/tests/c/syscalls/cavp/groestl_256_long_msg.data similarity index 100% rename from tests/syscalls/cavp/groestl_256_long_msg.data rename to tests/c/syscalls/cavp/groestl_256_long_msg.data diff --git a/tests/syscalls/cavp/groestl_256_short_msg.data b/tests/c/syscalls/cavp/groestl_256_short_msg.data similarity index 100% rename from tests/syscalls/cavp/groestl_256_short_msg.data rename to tests/c/syscalls/cavp/groestl_256_short_msg.data diff --git a/tests/syscalls/cavp/groestl_384_long_msg.data b/tests/c/syscalls/cavp/groestl_384_long_msg.data similarity index 100% rename from tests/syscalls/cavp/groestl_384_long_msg.data rename to tests/c/syscalls/cavp/groestl_384_long_msg.data diff --git a/tests/syscalls/cavp/groestl_384_short_msg.data b/tests/c/syscalls/cavp/groestl_384_short_msg.data similarity index 100% rename from tests/syscalls/cavp/groestl_384_short_msg.data rename to tests/c/syscalls/cavp/groestl_384_short_msg.data diff --git a/tests/syscalls/cavp/groestl_512_long_msg.data b/tests/c/syscalls/cavp/groestl_512_long_msg.data similarity index 100% rename from tests/syscalls/cavp/groestl_512_long_msg.data rename to tests/c/syscalls/cavp/groestl_512_long_msg.data diff --git a/tests/syscalls/cavp/groestl_512_short_msg.data b/tests/c/syscalls/cavp/groestl_512_short_msg.data similarity index 100% rename from tests/syscalls/cavp/groestl_512_short_msg.data rename to tests/c/syscalls/cavp/groestl_512_short_msg.data diff --git a/tests/syscalls/cavp/hmac.data b/tests/c/syscalls/cavp/hmac.data similarity index 100% rename from tests/syscalls/cavp/hmac.data rename to tests/c/syscalls/cavp/hmac.data diff --git a/tests/syscalls/cavp/keccak_224_long_msg.data b/tests/c/syscalls/cavp/keccak_224_long_msg.data similarity index 100% rename from tests/syscalls/cavp/keccak_224_long_msg.data rename to tests/c/syscalls/cavp/keccak_224_long_msg.data diff --git a/tests/syscalls/cavp/keccak_224_short_msg.data b/tests/c/syscalls/cavp/keccak_224_short_msg.data similarity index 100% rename from tests/syscalls/cavp/keccak_224_short_msg.data rename to tests/c/syscalls/cavp/keccak_224_short_msg.data diff --git a/tests/syscalls/cavp/keccak_256_long_msg.data b/tests/c/syscalls/cavp/keccak_256_long_msg.data similarity index 100% rename from tests/syscalls/cavp/keccak_256_long_msg.data rename to tests/c/syscalls/cavp/keccak_256_long_msg.data diff --git a/tests/syscalls/cavp/keccak_256_short_msg.data b/tests/c/syscalls/cavp/keccak_256_short_msg.data similarity index 100% rename from tests/syscalls/cavp/keccak_256_short_msg.data rename to tests/c/syscalls/cavp/keccak_256_short_msg.data diff --git a/tests/syscalls/cavp/keccak_384_long_msg.data b/tests/c/syscalls/cavp/keccak_384_long_msg.data similarity index 100% rename from tests/syscalls/cavp/keccak_384_long_msg.data rename to tests/c/syscalls/cavp/keccak_384_long_msg.data diff --git a/tests/syscalls/cavp/keccak_384_short_msg.data b/tests/c/syscalls/cavp/keccak_384_short_msg.data similarity index 100% rename from tests/syscalls/cavp/keccak_384_short_msg.data rename to tests/c/syscalls/cavp/keccak_384_short_msg.data diff --git a/tests/syscalls/cavp/keccak_512_long_msg.data b/tests/c/syscalls/cavp/keccak_512_long_msg.data similarity index 100% rename from tests/syscalls/cavp/keccak_512_long_msg.data rename to tests/c/syscalls/cavp/keccak_512_long_msg.data diff --git a/tests/syscalls/cavp/keccak_512_short_msg.data b/tests/c/syscalls/cavp/keccak_512_short_msg.data similarity index 100% rename from tests/syscalls/cavp/keccak_512_short_msg.data rename to tests/c/syscalls/cavp/keccak_512_short_msg.data diff --git a/tests/syscalls/cavp/sha224_long_msg.data b/tests/c/syscalls/cavp/sha224_long_msg.data similarity index 100% rename from tests/syscalls/cavp/sha224_long_msg.data rename to tests/c/syscalls/cavp/sha224_long_msg.data diff --git a/tests/syscalls/cavp/sha224_short_msg.data b/tests/c/syscalls/cavp/sha224_short_msg.data similarity index 100% rename from tests/syscalls/cavp/sha224_short_msg.data rename to tests/c/syscalls/cavp/sha224_short_msg.data diff --git a/tests/syscalls/cavp/sha256_long_msg.data b/tests/c/syscalls/cavp/sha256_long_msg.data similarity index 100% rename from tests/syscalls/cavp/sha256_long_msg.data rename to tests/c/syscalls/cavp/sha256_long_msg.data diff --git a/tests/syscalls/cavp/sha256_short_msg.data b/tests/c/syscalls/cavp/sha256_short_msg.data similarity index 100% rename from tests/syscalls/cavp/sha256_short_msg.data rename to tests/c/syscalls/cavp/sha256_short_msg.data diff --git a/tests/syscalls/cavp/sha384_long_msg.data b/tests/c/syscalls/cavp/sha384_long_msg.data similarity index 100% rename from tests/syscalls/cavp/sha384_long_msg.data rename to tests/c/syscalls/cavp/sha384_long_msg.data diff --git a/tests/syscalls/cavp/sha384_short_msg.data b/tests/c/syscalls/cavp/sha384_short_msg.data similarity index 100% rename from tests/syscalls/cavp/sha384_short_msg.data rename to tests/c/syscalls/cavp/sha384_short_msg.data diff --git a/tests/syscalls/cavp/sha3_224_long_msg.data b/tests/c/syscalls/cavp/sha3_224_long_msg.data similarity index 100% rename from tests/syscalls/cavp/sha3_224_long_msg.data rename to tests/c/syscalls/cavp/sha3_224_long_msg.data diff --git a/tests/syscalls/cavp/sha3_224_short_msg.data b/tests/c/syscalls/cavp/sha3_224_short_msg.data similarity index 100% rename from tests/syscalls/cavp/sha3_224_short_msg.data rename to tests/c/syscalls/cavp/sha3_224_short_msg.data diff --git a/tests/syscalls/cavp/sha3_256_long_msg.data b/tests/c/syscalls/cavp/sha3_256_long_msg.data similarity index 100% rename from tests/syscalls/cavp/sha3_256_long_msg.data rename to tests/c/syscalls/cavp/sha3_256_long_msg.data diff --git a/tests/syscalls/cavp/sha3_256_short_msg.data b/tests/c/syscalls/cavp/sha3_256_short_msg.data similarity index 100% rename from tests/syscalls/cavp/sha3_256_short_msg.data rename to tests/c/syscalls/cavp/sha3_256_short_msg.data diff --git a/tests/syscalls/cavp/sha3_384_long_msg.data b/tests/c/syscalls/cavp/sha3_384_long_msg.data similarity index 100% rename from tests/syscalls/cavp/sha3_384_long_msg.data rename to tests/c/syscalls/cavp/sha3_384_long_msg.data diff --git a/tests/syscalls/cavp/sha3_384_short_msg.data b/tests/c/syscalls/cavp/sha3_384_short_msg.data similarity index 100% rename from tests/syscalls/cavp/sha3_384_short_msg.data rename to tests/c/syscalls/cavp/sha3_384_short_msg.data diff --git a/tests/syscalls/cavp/sha3_512_long_msg.data b/tests/c/syscalls/cavp/sha3_512_long_msg.data similarity index 100% rename from tests/syscalls/cavp/sha3_512_long_msg.data rename to tests/c/syscalls/cavp/sha3_512_long_msg.data diff --git a/tests/syscalls/cavp/sha3_512_short_msg.data b/tests/c/syscalls/cavp/sha3_512_short_msg.data similarity index 100% rename from tests/syscalls/cavp/sha3_512_short_msg.data rename to tests/c/syscalls/cavp/sha3_512_short_msg.data diff --git a/tests/syscalls/cavp/sha512_long_msg.data b/tests/c/syscalls/cavp/sha512_long_msg.data similarity index 100% rename from tests/syscalls/cavp/sha512_long_msg.data rename to tests/c/syscalls/cavp/sha512_long_msg.data diff --git a/tests/syscalls/cavp/sha512_short_msg.data b/tests/c/syscalls/cavp/sha512_short_msg.data similarity index 100% rename from tests/syscalls/cavp/sha512_short_msg.data rename to tests/c/syscalls/cavp/sha512_short_msg.data diff --git a/tests/syscalls/cavp/shake128_long_msg.data b/tests/c/syscalls/cavp/shake128_long_msg.data similarity index 100% rename from tests/syscalls/cavp/shake128_long_msg.data rename to tests/c/syscalls/cavp/shake128_long_msg.data diff --git a/tests/syscalls/cavp/shake128_short_msg.data b/tests/c/syscalls/cavp/shake128_short_msg.data similarity index 100% rename from tests/syscalls/cavp/shake128_short_msg.data rename to tests/c/syscalls/cavp/shake128_short_msg.data diff --git a/tests/syscalls/cavp/shake128_variable_output.data b/tests/c/syscalls/cavp/shake128_variable_output.data similarity index 100% rename from tests/syscalls/cavp/shake128_variable_output.data rename to tests/c/syscalls/cavp/shake128_variable_output.data diff --git a/tests/syscalls/cavp/shake256_long_msg.data b/tests/c/syscalls/cavp/shake256_long_msg.data similarity index 100% rename from tests/syscalls/cavp/shake256_long_msg.data rename to tests/c/syscalls/cavp/shake256_long_msg.data diff --git a/tests/syscalls/cavp/shake256_short_msg.data b/tests/c/syscalls/cavp/shake256_short_msg.data similarity index 100% rename from tests/syscalls/cavp/shake256_short_msg.data rename to tests/c/syscalls/cavp/shake256_short_msg.data diff --git a/tests/syscalls/cavp/shake256_variable_output.data b/tests/c/syscalls/cavp/shake256_variable_output.data similarity index 100% rename from tests/syscalls/cavp/shake256_variable_output.data rename to tests/c/syscalls/cavp/shake256_variable_output.data diff --git a/tests/syscalls/hello.c b/tests/c/syscalls/hello.c similarity index 100% rename from tests/syscalls/hello.c rename to tests/c/syscalls/hello.c diff --git a/tests/syscalls/nist_cavp.c b/tests/c/syscalls/nist_cavp.c similarity index 100% rename from tests/syscalls/nist_cavp.c rename to tests/c/syscalls/nist_cavp.c diff --git a/tests/syscalls/nist_cavp.h b/tests/c/syscalls/nist_cavp.h similarity index 100% rename from tests/syscalls/nist_cavp.h rename to tests/c/syscalls/nist_cavp.h diff --git a/tests/syscalls/test_aes.c b/tests/c/syscalls/test_aes.c similarity index 100% rename from tests/syscalls/test_aes.c rename to tests/c/syscalls/test_aes.c diff --git a/tests/syscalls/test_bip32.c b/tests/c/syscalls/test_bip32.c similarity index 100% rename from tests/syscalls/test_bip32.c rename to tests/c/syscalls/test_bip32.c diff --git a/tests/syscalls/test_blake2.c b/tests/c/syscalls/test_blake2.c similarity index 100% rename from tests/syscalls/test_blake2.c rename to tests/c/syscalls/test_blake2.c diff --git a/tests/syscalls/test_bls.c b/tests/c/syscalls/test_bls.c similarity index 100% rename from tests/syscalls/test_bls.c rename to tests/c/syscalls/test_bls.c diff --git a/tests/syscalls/test_bn.c b/tests/c/syscalls/test_bn.c similarity index 100% rename from tests/syscalls/test_bn.c rename to tests/c/syscalls/test_bn.c diff --git a/tests/syscalls/test_crc16.c b/tests/c/syscalls/test_crc16.c similarity index 100% rename from tests/syscalls/test_crc16.c rename to tests/c/syscalls/test_crc16.c diff --git a/tests/syscalls/test_ec.c b/tests/c/syscalls/test_ec.c similarity index 100% rename from tests/syscalls/test_ec.c rename to tests/c/syscalls/test_ec.c diff --git a/tests/syscalls/test_ecdh.c b/tests/c/syscalls/test_ecdh.c similarity index 100% rename from tests/syscalls/test_ecdh.c rename to tests/c/syscalls/test_ecdh.c diff --git a/tests/syscalls/test_ecdsa.c b/tests/c/syscalls/test_ecdsa.c similarity index 100% rename from tests/syscalls/test_ecdsa.c rename to tests/c/syscalls/test_ecdsa.c diff --git a/tests/syscalls/test_ecpoint.c b/tests/c/syscalls/test_ecpoint.c similarity index 100% rename from tests/syscalls/test_ecpoint.c rename to tests/c/syscalls/test_ecpoint.c diff --git a/tests/syscalls/test_eddsa.c b/tests/c/syscalls/test_eddsa.c similarity index 100% rename from tests/syscalls/test_eddsa.c rename to tests/c/syscalls/test_eddsa.c diff --git a/tests/syscalls/test_eip2333.c b/tests/c/syscalls/test_eip2333.c similarity index 100% rename from tests/syscalls/test_eip2333.c rename to tests/c/syscalls/test_eip2333.c diff --git a/tests/syscalls/test_endorsement.c b/tests/c/syscalls/test_endorsement.c similarity index 100% rename from tests/syscalls/test_endorsement.c rename to tests/c/syscalls/test_endorsement.c diff --git a/tests/syscalls/test_hmac.c b/tests/c/syscalls/test_hmac.c similarity index 100% rename from tests/syscalls/test_hmac.c rename to tests/c/syscalls/test_hmac.c diff --git a/tests/syscalls/test_math.c b/tests/c/syscalls/test_math.c similarity index 100% rename from tests/syscalls/test_math.c rename to tests/c/syscalls/test_math.c diff --git a/tests/syscalls/test_mpi_rng.c b/tests/c/syscalls/test_mpi_rng.c similarity index 100% rename from tests/syscalls/test_mpi_rng.c rename to tests/c/syscalls/test_mpi_rng.c diff --git a/tests/syscalls/test_os_global_pin_is_validated.c b/tests/c/syscalls/test_os_global_pin_is_validated.c similarity index 100% rename from tests/syscalls/test_os_global_pin_is_validated.c rename to tests/c/syscalls/test_os_global_pin_is_validated.c diff --git a/tests/syscalls/test_rfc6979.c b/tests/c/syscalls/test_rfc6979.c similarity index 100% rename from tests/syscalls/test_rfc6979.c rename to tests/c/syscalls/test_rfc6979.c diff --git a/tests/syscalls/test_ripemd.c b/tests/c/syscalls/test_ripemd.c similarity index 100% rename from tests/syscalls/test_ripemd.c rename to tests/c/syscalls/test_ripemd.c diff --git a/tests/syscalls/test_sha2.c b/tests/c/syscalls/test_sha2.c similarity index 100% rename from tests/syscalls/test_sha2.c rename to tests/c/syscalls/test_sha2.c diff --git a/tests/syscalls/test_sha3.c b/tests/c/syscalls/test_sha3.c similarity index 100% rename from tests/syscalls/test_sha3.c rename to tests/c/syscalls/test_sha3.c diff --git a/tests/syscalls/test_slip21.c b/tests/c/syscalls/test_slip21.c similarity index 100% rename from tests/syscalls/test_slip21.c rename to tests/c/syscalls/test_slip21.c diff --git a/tests/syscalls/utils.c b/tests/c/syscalls/utils.c similarity index 100% rename from tests/syscalls/utils.c rename to tests/c/syscalls/utils.c diff --git a/tests/syscalls/utils.h b/tests/c/syscalls/utils.h similarity index 80% rename from tests/syscalls/utils.h rename to tests/c/syscalls/utils.h index 39ebde09..6209d0e4 100644 --- a/tests/syscalls/utils.h +++ b/tests/c/syscalls/utils.h @@ -3,7 +3,7 @@ #include #include -#define TESTS_PATH "../../../tests/syscalls/" +#define TESTS_PATH "../../../../tests/c/syscalls/" #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) int hex2num(char c); diff --git a/tests/syscalls/wycheproof/X25519.data b/tests/c/syscalls/wycheproof/X25519.data similarity index 100% rename from tests/syscalls/wycheproof/X25519.data rename to tests/c/syscalls/wycheproof/X25519.data diff --git a/tests/syscalls/wycheproof/X448.data b/tests/c/syscalls/wycheproof/X448.data similarity index 100% rename from tests/syscalls/wycheproof/X448.data rename to tests/c/syscalls/wycheproof/X448.data diff --git a/tests/syscalls/wycheproof/ecdh_secp256k1.data b/tests/c/syscalls/wycheproof/ecdh_secp256k1.data similarity index 100% rename from tests/syscalls/wycheproof/ecdh_secp256k1.data rename to tests/c/syscalls/wycheproof/ecdh_secp256k1.data diff --git a/tests/syscalls/wycheproof/eddsa.data b/tests/c/syscalls/wycheproof/eddsa.data similarity index 100% rename from tests/syscalls/wycheproof/eddsa.data rename to tests/c/syscalls/wycheproof/eddsa.data diff --git a/tests/__init__.py b/tests/python/__init__.py similarity index 100% rename from tests/__init__.py rename to tests/python/__init__.py diff --git a/tests/api/resources/automation.json b/tests/python/api/resources/automation.json similarity index 100% rename from tests/api/resources/automation.json rename to tests/python/api/resources/automation.json diff --git a/tests/api/test_api.py b/tests/python/api/test_api.py similarity index 89% rename from tests/api/test_api.py rename to tests/python/api/test_api.py index a43b3667..1e3fb2a3 100644 --- a/tests/api/test_api.py +++ b/tests/python/api/test_api.py @@ -9,27 +9,9 @@ from speculos.client import SpeculosClient -AppInfo = namedtuple("AppInfo", ["filepath", "device", "name", "version", "hash"]) - -SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) API_URL = "http://127.0.0.1:5000" -@pytest.fixture(scope="class") -def client(request): - """Run the API tests on the default btc.elf app.""" - - app_dir = os.path.join(SCRIPT_DIR, os.pardir, os.pardir, "apps") - filepath = os.path.realpath(os.path.join(app_dir, "btc.elf")) - info = [filepath] + os.path.basename(filepath).split("#") - info = AppInfo(*info) - - args = ["--model", info.device, "--sdk", info.version] - - with SpeculosClient(app=filepath, args=args) as _client: - yield _client - - @pytest.mark.usefixtures("client") class TestApi: @staticmethod @@ -109,7 +91,7 @@ def get_current_screen_content(session): assert re.match(text, event["text"]) texts = [("About",), ("Version", ".*"), ("Bitcoin", "is ready")] - for i in range(0, 3): + for i in range(len(texts)): TestApi.press_button("left") for text in texts[i]: event = get_next_event(stream) diff --git a/tests/apps/__init__.py b/tests/python/apps/__init__.py similarity index 100% rename from tests/apps/__init__.py rename to tests/python/apps/__init__.py diff --git a/tests/apps/resources/__init__.py b/tests/python/apps/resources/__init__.py similarity index 100% rename from tests/apps/resources/__init__.py rename to tests/python/apps/resources/__init__.py diff --git a/tests/apps/resources/btc_getpubkey_blue.json b/tests/python/apps/resources/btc_getpubkey_blue.json similarity index 100% rename from tests/apps/resources/btc_getpubkey_blue.json rename to tests/python/apps/resources/btc_getpubkey_blue.json diff --git a/tests/apps/resources/btc_getpubkey_blue.png b/tests/python/apps/resources/btc_getpubkey_blue.png similarity index 100% rename from tests/apps/resources/btc_getpubkey_blue.png rename to tests/python/apps/resources/btc_getpubkey_blue.png diff --git a/tests/apps/resources/btc_getpubkey_nanos.json b/tests/python/apps/resources/btc_getpubkey_nanos.json similarity index 100% rename from tests/apps/resources/btc_getpubkey_nanos.json rename to tests/python/apps/resources/btc_getpubkey_nanos.json diff --git a/tests/apps/resources/btc_getpubkey_nanos.png b/tests/python/apps/resources/btc_getpubkey_nanos.png similarity index 100% rename from tests/apps/resources/btc_getpubkey_nanos.png rename to tests/python/apps/resources/btc_getpubkey_nanos.png diff --git a/tests/apps/resources/btc_getpubkey_nanosp.json b/tests/python/apps/resources/btc_getpubkey_nanosp.json similarity index 100% rename from tests/apps/resources/btc_getpubkey_nanosp.json rename to tests/python/apps/resources/btc_getpubkey_nanosp.json diff --git a/tests/apps/resources/btc_getpubkey_nanosp.png b/tests/python/apps/resources/btc_getpubkey_nanosp.png similarity index 100% rename from tests/apps/resources/btc_getpubkey_nanosp.png rename to tests/python/apps/resources/btc_getpubkey_nanosp.png diff --git a/tests/apps/resources/btc_getpubkey_nanox.json b/tests/python/apps/resources/btc_getpubkey_nanox.json similarity index 100% rename from tests/apps/resources/btc_getpubkey_nanox.json rename to tests/python/apps/resources/btc_getpubkey_nanox.json diff --git a/tests/apps/resources/btc_getpubkey_nanox.png b/tests/python/apps/resources/btc_getpubkey_nanox.png similarity index 100% rename from tests/apps/resources/btc_getpubkey_nanox.png rename to tests/python/apps/resources/btc_getpubkey_nanox.png diff --git a/tests/apps/test_btc.py b/tests/python/apps/test_btc.py similarity index 100% rename from tests/apps/test_btc.py rename to tests/python/apps/test_btc.py diff --git a/tests/apps/test_btc_testnet.py b/tests/python/apps/test_btc_testnet.py similarity index 100% rename from tests/apps/test_btc_testnet.py rename to tests/python/apps/test_btc_testnet.py diff --git a/tests/apps/test_ram_page.py b/tests/python/apps/test_ram_page.py similarity index 100% rename from tests/apps/test_ram_page.py rename to tests/python/apps/test_ram_page.py diff --git a/tests/apps/test_vnc.py b/tests/python/apps/test_vnc.py similarity index 100% rename from tests/apps/test_vnc.py rename to tests/python/apps/test_vnc.py diff --git a/tests/apps/conftest.py b/tests/python/conftest.py similarity index 67% rename from tests/apps/conftest.py rename to tests/python/conftest.py index 196321e7..0c308da5 100644 --- a/tests/apps/conftest.py +++ b/tests/python/conftest.py @@ -2,20 +2,21 @@ import os import re from collections import namedtuple +from pathlib import Path from typing import List from speculos.client import SpeculosClient -SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) +# going back from...(conftest.py \ python \ tests \ git root) / 'apps' +APP_DIR = Path(__file__).resolve().parent. parent. parent / "apps" AppInfo = namedtuple("AppInfo", ["filepath", "model", "name", "sdk", "hash"]) -def app_info_from_path(path) -> AppInfo: +def app_info_from_path(path: Path) -> AppInfo: # name example: nanos#btc#1.5#5b6693b8.elf app_regexp = re.compile(r"^(nanos|nanox|blue|nanosp)#([^#]+)#([^#][\d\w\-.]+)#([a-f0-9]*)\.elf$") - filename = os.path.basename(path) - matching = re.match(app_regexp, filename) + matching = re.match(app_regexp, path.name) if not matching: return None assert len(matching.groups()) == 4 @@ -23,7 +24,7 @@ def app_info_from_path(path) -> AppInfo: hash=matching.group(4)) -def list_apps_to_test(app_dir) -> List[AppInfo]: +def list_apps_to_test() -> List[AppInfo]: """ List apps matching the pattern: @@ -37,11 +38,10 @@ def list_apps_to_test(app_dir) -> List[AppInfo]: 'apps/nanos#btc#1.5#5b6693b8.elf' """ all_apps = [] - for filename in os.listdir(app_dir): - if "#" not in filename: + for appfile in APP_DIR.iterdir(): + if "#" not in appfile.name: continue - path = os.path.join(app_dir, filename) - info = app_info_from_path(path) + info = app_info_from_path(appfile) if not info: pytest.fail( f"An unexpected file was found in apps/, with a # but not matching the pattern: {filename!r}" @@ -53,25 +53,21 @@ def list_apps_to_test(app_dir) -> List[AppInfo]: @pytest.fixture(scope="function") def app(request, client): - return app_info_from_path(client.app) + return app_info_from_path(Path(client.app)) -def get_apps(name): - """Retrieve the list of apps in the ../apps directory.""" - app_dir = os.path.join(SCRIPT_DIR, os.pardir, os.pardir, "apps") - apps = list_apps_to_test(app_dir) - apps = [app for app in apps if app.name == name] - return apps +def get_apps(name: str) -> List[AppInfo]: + """Retrieve the list of apps in the ../../apps directory.""" + return [app for app in list_apps_to_test() if app.name == name] -def default_btc_app(): - app_dir = os.path.join(SCRIPT_DIR, os.pardir, os.pardir, "apps") - filepath = os.path.realpath(os.path.join(app_dir, "btc.elf")) +def default_btc_app() -> List[AppInfo]: + filepath = (APP_DIR / "btc.elf").resolve() apps = get_apps("btc") - return [app for app in apps if os.path.realpath(app.filepath) == filepath] + return [app for app in apps if app.filepath == filepath] -def idfn(app): +def idfn(app: Path) -> str: """ Set the test ID to the app file name for each test running on a set of apps. @@ -80,14 +76,14 @@ def idfn(app): These IDs can be used with -k to select specific cases to run, and they will also identify the specific case when one is failing. """ - return os.path.basename(app.filepath) + return app.filepath def client_instance(app, additional_args=None): args = ["--model", app.model, "--sdk", app.sdk] if additional_args is not None: args += additional_args - return SpeculosClient(app.filepath, args=args) + return SpeculosClient(str(app.filepath), args=args) @pytest.fixture(scope="module", params=get_apps("btc"), ids=idfn) @@ -99,9 +95,9 @@ def client_btc(request): @pytest.fixture(scope="module", params=get_apps("btc-test"), ids=idfn) def client_btc_testnet(request): app = request.param - btc_app = app.filepath.replace("btc-test", "btc") - assert os.path.exists(btc_app) - args = ["-l", "Bitcoin:%s" % btc_app] + btc_app = app.filepath.parent / app.filepath.name.replace("btc-test", "btc") + assert btc_app.is_file() + args = ["-l", "Bitcoin:%s" % str(btc_app)] with client_instance(request.param, additional_args=args) as _client: yield _client @@ -123,3 +119,13 @@ def client_vnc(request): args = list(get_closest_marker("additional_args").args) with client_instance(request.param, args) as _client: yield _client + + +@pytest.fixture(scope="class") +def client(request): + """Run the API tests on the default btc.elf app.""" + + info = app_info_from_path((APP_DIR / "btc.elf").resolve()) + args = ["--model", info.model, "--sdk", info.sdk] + with SpeculosClient(app=str(info.filepath), args=args) as _client: + yield _client diff --git a/tests/mcu/resources/automation_invalid_action_args.json b/tests/python/mcu/resources/automation_invalid_action_args.json similarity index 100% rename from tests/mcu/resources/automation_invalid_action_args.json rename to tests/python/mcu/resources/automation_invalid_action_args.json diff --git a/tests/mcu/resources/automation_invalid_action_name.json b/tests/python/mcu/resources/automation_invalid_action_name.json similarity index 100% rename from tests/mcu/resources/automation_invalid_action_name.json rename to tests/python/mcu/resources/automation_invalid_action_name.json diff --git a/tests/mcu/resources/automation_invalid_rule_key.json b/tests/python/mcu/resources/automation_invalid_rule_key.json similarity index 100% rename from tests/mcu/resources/automation_invalid_rule_key.json rename to tests/python/mcu/resources/automation_invalid_rule_key.json diff --git a/tests/mcu/resources/automation_valid.json b/tests/python/mcu/resources/automation_valid.json similarity index 100% rename from tests/mcu/resources/automation_valid.json rename to tests/python/mcu/resources/automation_valid.json diff --git a/tests/mcu/test_automation.py b/tests/python/mcu/test_automation.py similarity index 100% rename from tests/mcu/test_automation.py rename to tests/python/mcu/test_automation.py diff --git a/tests/pytest.ini b/tests/python/pytest.ini similarity index 100% rename from tests/pytest.ini rename to tests/python/pytest.ini diff --git a/tests/unit/__init__.py b/tests/python/unit/__init__.py similarity index 100% rename from tests/unit/__init__.py rename to tests/python/unit/__init__.py diff --git a/tests/unit/test_client_Api.py b/tests/python/unit/test_client_Api.py similarity index 100% rename from tests/unit/test_client_Api.py rename to tests/python/unit/test_client_Api.py diff --git a/tests/unit/test_client_SpeculosClient.py b/tests/python/unit/test_client_SpeculosClient.py similarity index 100% rename from tests/unit/test_client_SpeculosClient.py rename to tests/python/unit/test_client_SpeculosClient.py