File
Blob: scripts/test_crypto_profile.py
| 1 | """Check opt-in native profiling without altering the crypto implementation.""" |
| 2 | from pathlib import Path |
| 3 | import shutil |
| 4 | import subprocess |
| 5 | import tempfile |
| 6 | import unittest |
| 7 | |
| 8 | ROOT = Path(__file__).resolve().parents[1] |
| 9 | |
| 10 | |
| 11 | class CryptoProfileTests(unittest.TestCase): |
| 12 | def test_native_calls_are_forwarded_and_allocations_are_task_scoped(self): |
| 13 | compiler = shutil.which("cc") |
| 14 | self.assertIsNotNone(compiler, "A host C compiler is required for native adapter tests") |
| 15 | platform = ROOT / "firmware/platform" |
| 16 | fixtures = platform / "tests/crypto_profile" |
| 17 | with tempfile.TemporaryDirectory() as directory: |
| 18 | executable = Path(directory) / "crypto-profile-test" |
| 19 | compiled = subprocess.run( |
| 20 | [ |
| 21 | compiler, "-std=c11", "-Wall", "-Wextra", "-Werror", |
| 22 | "-I", str(fixtures), "-I", str(platform / "include"), |
| 23 | str(platform / "crypto_profile.c"), str(fixtures / "profile_test.c"), |
| 24 | str(fixtures / "native.c"), |
| 25 | "-Wl,--wrap=radio_crypto_hmac", "-Wl,--wrap=radio_crypto_aes_ctr", |
| 26 | "-Wl,--wrap=radio_crypto_aes_gcm", "-Wl,--wrap=esp_mbedtls_mem_calloc", |
| 27 | "-o", str(executable), |
| 28 | ], |
| 29 | capture_output=True, text=True, |
| 30 | ) |
| 31 | self.assertEqual(compiled.returncode, 0, compiled.stdout + compiled.stderr) |
| 32 | result = subprocess.run([str(executable)], capture_output=True, text=True) |
| 33 | self.assertEqual(result.returncode, 0, result.stdout + result.stderr) |
| 34 | |
| 35 | |
| 36 | if __name__ == "__main__": |
| 37 | unittest.main() |