Page MenuHomePhabricator

Testing Mbed TLS on Mbed OS
Updated 1,131 Days AgoPublic

Running Mbed TLS tests on Mbed OS

Unit tests

Mbed TLS 2.13 through 2.27 allowed running the Mbed TLS unit tests on Mbed OS. This possibility has been discontinued in 2.28/3.1. We plan to bring it back in the future.

Prerequisites

  • Mbed OS ≥5.5.1
  • Mbed TLS 2.13–2.27 (this doesn't have to be the version in your copy of Mbed OS)
  • The Mbed OS development tools (pip install --user mbed-tools), including Greentea (mbed-gt)

Some test suites may not work on platforms with too little space for code, stack or heap.

Building the tests

  • Check out mbed-os
  • cd mbed-os/features/mbedtls/importer/TARGET_IGNORE
  • Optional: check out mbedtls) — you can work in your working Mbed TLS branch
  • cd mbedtls/tests
  • make generate-target-tests
  • mkdir TESTS/host_tests
  • cp scripts/mbedtls_test.py TESTS/host_tests
  • copy the TESTS directory in mbed-os/features/mbedtls/
  • cd back to mbed-os/
  • mbed test --compile -m K64F -t GCC_ARM -n features-mbedtls-tests-mbedtls* (adapt -m to your platform and -t to your compiler)

You should now see mbedtls tests with the command mbedgt -V -l

Running the tests

To run the AES tests, for example:

mbedgt -V -n features-mbedtls-tests-mbedtls-test_suite_aes*

Debugging the on-target tests

To debug the tests, you will need to use a pyocd-gdbserver.

In order to debug the tests, you will need:

  1. Burn the test image on the target
  2. Run pyocd-gdbserver: pyocd-gdbserver
  3. Run your gdb client
  4. Run mbedhtrun with --skipflash and --skip reset. For example:
sudo mbedhtrun -m NRF52840_DK -p /dev/ttyACM0:9600 -f "BUILD/tests/NRF52840_DK/GCC_ARM-DEBUG/features/mbedtls/TESTS/mbedtls/test_suite_psa_crypto/test_suite_psa_crypto" -e "features/mbedtls/TESTS/host_tests" -d /media/roneld01/DAPLINK1 -C 6 -c default -t 1102000044203120414a4e39313031313730303797969903 -r default --sync 5 --skip-flash --skip-reset

Note: when running the mbedgt for the test with -V parameter, you will see the mbedhtrun command that it runs. Just copy this line, and add the --skip-reset and --skip-flash parameters

Note: The tests are generated with lines that start with #line. The debugger doesn't neccessary recognize these lines, and might not interpret the test files. You sould delete the lines that start with "#line" and recompile. (There may be a way to have the debugger point to the origin of the files - target_test.function and helpers.function but I didn't check this)

Last Author
gilles-peskine-arm
Last Edited
Nov 16 2021, 10:35 AM

Event Timeline

gilles-peskine-arm edited the content of this document. (Show Details)Nov 16 2021, 10:35 AM