Commit Graph

493 Commits

Author SHA1 Message Date
Gilles Peskine a5b6f6f778 Explain why the child calls _exit() and not exit()
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-23 19:24:18 +01:00
Gilles Peskine a2083218c7 Keep exposing the library common.h in test/macros.h
Partially revert "Give test code access to internal macros of the library".
I think that it would be better not to require every user of `test/macros.h`
to have access to the library source, but it's out of scope here.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-16 17:47:22 +01:00
Gilles Peskine 0384a5929a Give test code access to internal macros of the library
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-16 15:53:57 +01:00
Gilles Peskine dbfd1a6fa9 New test helper mbedtls_test_fork_run_child()
Run some code in a child process. Propagate output from the child if the
test succeeds, and propagate the test result information otherwise.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-16 15:53:57 +01:00
Gilles Peskine 25c1750beb Sort out inclusions of <test/build_info.h> vs "test_common.h"
Include `"test_common.h"` as the first thing in C files, and
`<test/build_info.h>` as the first thing in header files.

This requires moving `<test/test_common.h>` to its intended location
`"test_common.h"`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-11 20:11:47 +01:00
Gilles Peskine 30d9a6210b Split <test/build_info.h> out of test_common.h
The header `test_common.h` contains two kinds of things:

* Things to do at the beginning of individual C files. Specifically,
  defining macros that notify system headers about what we want from them.
  Keep those in `test_common.h`, which will subsequently be moved out of
  the include directory.
* Things to do at the beginning of every header. In particular, read the
  library configuration. Move them to a new header `build_info.h`,
  which is the only one intended to be included from headers.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-11 20:11:47 +01:00
Gilles Peskine 6d5987a954 Include <test/test_common.h> first in test code
This lets us define things that we want to have everywhere in test code. In
particular, this lets us define platform-specific symbols that influence
what system headers declare. This also takes care of including the library
configuration.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-20 21:46:11 +01:00
Gilles Peskine f41a9f6056 New macro TEST_ASSERT_ERRNO
Show errno if a test assertion fails.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-17 17:21:20 +01:00
Gilles Peskine 2ffd883d80 Driver entry point test code: add XOF support
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-02-09 21:16:28 +01:00
Valerio Setti c32c5064c0 tests: pk_helpers: fix code style
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-15 10:11:37 +01:00
Valerio Setti 73c4f2e5d6 tests: pk_helpers: improve documentation of pk_context_populate_method_t
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-14 23:33:50 +01:00
Valerio Setti 4eebe42a11 tests: pk_helpers: optimize failure reporting in mbedtls_pk_helpers_populate_context
Keep TEST_EQUAL() on the function that might fail so that if a failure
happen the message will report the actual function that failed.

Documentation of the helper function is also updated.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-14 23:09:35 +01:00
Valerio Setti 43e4dc061d tests: pk_helpers: update documentation
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-14 12:54:10 +01:00
Valerio Setti 2b3cc12c01 tests: pk_helpers: let all helper function return an error code
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-14 12:53:25 +01:00
Valerio Setti fa298be91a tests: src: pk_helpers: style fix in code and documentation
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-08 09:28:34 +01:00
Valerio Setti e28511869c tests: src: pk_helpers: select predefined keys using PSA key type and bits
A new look-up table is created, "predefined_keys_psa", to list all the
predefined keys together with the corresponding PSA key type and bits.
A new look-up table was created in order not to conflict with the already
existing "predefined_keys" one.

"mbedtls_pk_helpers_get_predefined_key_data" is modified in order to
use the new look-up table.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-08 09:16:21 +01:00
Valerio Setti 88e0eb729e tests: src: pk_helpers: add documentation and proper functions prefix
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-07 18:25:07 +01:00
Valerio Setti 0a3c8c4fdd tests: src: move PK helpers out of tf-psa-crypto to this repo
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-01-07 12:24:32 +01:00
Ronald Cron 17750d1f3a test_driver.py: Fix/Improve some comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-12-11 14:40:46 +01:00
Ronald Cron c806e683f8 test_driver.py: Get rid of one subdirectory in include/ limitation
Get rid of one subdirectory in include/ limitation.
Prefix all file basename instead of changing the
name of `include/mbedtls` to `include/libtestdriver1`.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-12-09 11:04:50 +01:00
Ronald Cron 9d7330c411 tests: drivers: Factorize internal header inclusion pre-processor logic
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-12-09 01:04:19 +01:00
Ronald Cron ca68ad8377 Move "libtestdriver1_" aliases to test_driver_common.h
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-12-05 14:45:32 +01:00
Ronald Cron 275f8dd5c7 Remove MBEDTLS_PLATFORM_GET_ENTROPY_ALT
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2025-09-09 08:27:45 +02:00
Gilles Peskine 8ef6acd627 Define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA for TF-PSA-Crypto
In Mbed TLS 3.6, this error was used in the library as well as the test
framework, but since TF-PSA-Crypto 1.0, it has been removed from the
library.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-09-02 00:16:32 +02:00
Anton Matkin af60653c4c Changed the private header preprocessor condition, so that the old (non-private) path is only taken in case of mbedtls 3.6
Signed-off-by: Anton Matkin <anton.matkin@arm.com>
2025-08-21 12:12:14 +02:00
Anton Matkin 39b328e60b Add preprocessor code, for compatibility with older mbedtls version, namely, now the inclusioin of header files in the private/ folder is conditional
Signed-off-by: Anton Matkin <anton.matkin@arm.com>
2025-08-21 12:12:14 +02:00
Anton Matkin cfd4b2cc53 Fix erroneous include change
Signed-off-by: Anton Matkin <anton.matkin@arm.com>
2025-08-21 12:12:14 +02:00
Anton Matkin 2b5dbf46c0 Modifications done by executing the script for each private header (in the tf-psa-crypto section)
Signed-off-by: Anton Matkin <anton.matkin@arm.com>
2025-08-21 12:12:14 +02:00
Bence Szépkúti 6177e44e9c Simplify version detection
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-07-29 10:28:53 +02:00
Bence Szépkúti a556abfaf8 Adapt to the renaming of common.h
common.h has been renamed to tf_psa_crypto_common.h in the standalone
TF PSA Crypto library used in Mbed TLS 4.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2025-07-29 10:20:11 +02:00
Gilles Peskine 91c400a884 Provide the new entropy callback
Provide the new interface for `mbedtls_platform_get_entropy()` requested
in https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/307 when
`MBEDTLS_PSA_DRIVER_GET_ENTROPY` is enabled. Keep providing the old
interface when `MBEDTLS_PLATFORM_GET_ENTROPY_ALT` is enabled.

For now, the new interface is identical to the old one. Subsequent commits
will change the interface.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-07-08 16:06:43 +02:00
Ben Taylor 7457034c5d Conditionally include private pk.h
Signed-off-by: Ben Taylor <ben.taylor@linaro.org>
2025-07-03 14:10:30 +01:00
Gilles Peskine 3e6db65fce Pacify code style check
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-07 17:22:50 +02:00
Gilles Peskine 97de10533d Complain about bad initialization of operation structures
In every existing test driver entry point that is the setup for a multipart
operation, check that the driver operation structure is all-bits-zero on
entry, as guaranteed by the driver specification.

There is a risk that this isn't the case, mostly, on platforms where
initializing a union to `{0}` initializes only the default member and not
all members.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-05-07 17:22:50 +02:00
Valerio Setti c612667e75 test: fake_external_rng_for_test: add more functionalities to mbedtls_platform_get_entropy()
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-04-28 17:09:28 +02:00
Gilles Peskine bb8e457dbc Merge pull request #161 from valeriosetti/issue9618-framework
[framework] MBEDTLS_PLATFORM_GET_ENTROPY_ALT in 4.0
2025-04-23 18:39:44 +02:00
Gilles Peskine 767b6f5913 Merge remote-tracking branch 'main' into union-initialization-gcc15-framework-preliminaries 2025-04-23 10:25:09 +02:00
Valerio Setti 6f0b670d3a tests: rename mbedtls_platform_get_entropy_alt()
Since mbedtls_platform_get_entropy_alt() is being renamed to
mbedtls_platform_get_entropy() on the tf-psa-crypto repo, this commit
adapts to testing support.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-04-17 16:49:09 +02:00
Valerio Setti 566659e20e tests: add functions to force behavior of mbedtls_platform_get_entropy_alt()
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-04-16 11:24:11 +02:00
Gilles Peskine 92f2203e7e Add common header for test drivers
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-06 18:28:14 +01:00
Gilles Peskine 468acda2d0 New helper function mbedtls_test_buffer_is_all_zero()
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-06 18:28:14 +01:00
Gilles Peskine bdccf4178f Short initializers for multipart operation structures
For each multipart or interruptible operation, define an initializer
function that simulates the minimum that `my_op_t op = {0}` guarantees in C.
That is, initialize most fields to 0, but set the fields that are unions to
a nonzero value. This simulates platforms where initializing a union to
`{0}` only initializes the first member, and thus reading from another
member can yield a nonzero value. In our operation structures, the union's
first member is an unused `dummy`, and the other members are
driver-specific, so we just make the whole union nonzero and this has to be
good enough for the setup functions in the core to cope.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-06 18:28:14 +01:00
Gilles Peskine 9ae1988c07 mbedtls_test_psa_raw_key_agreement_with_self: update documentation
Fix various obsolete or copy-pasted things, and document what test
assertions this function makes.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-01-22 12:33:40 +01:00
Ronald Cron 50d074d09d Move *config_test_driver* headers back to mbedtls
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2024-11-20 12:37:26 +01:00
David Horstmann de5f965ebe Port psa_exercise_key changes
These changes to psa_exercise_key were added while the files were being
moved to the framework. Port them to the framework now.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-11-18 15:52:42 +00:00
David Horstmann a2b59be722 Always include psa/crypto.h
Previously this was not included when in 3.6 and PSA_CRYPTO_CLIENT was
defined.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-11-14 12:26:34 +00:00
David Horstmann dfd518f976 Move test helpers into the framework
Move everything in tests/src and tests/include except for TLS-only
things, the alt-dummy headers and the generated PSA test wrappers.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-11-14 12:11:06 +00:00
Waleed Elmelegy a2891a9ac9 Add PSA interuptable key agreement APIs
Signed-off-by: Waleed Elmelegy <waleed.elmelegy@arm.com>
2024-11-06 16:03:46 +00:00
Manuel Pégourié-Gonnard 69868299a8 Merge pull request #9430 from davidhorstmann-arm/align-development-3.6-test-helpers
Align development test helpers with 3.6
2024-10-30 09:09:34 +00:00
David Horstmann fd38fdf501 Disentangle 3.6/4.0 *_PSA_INIT/DONE variants
Since PSA is always on in 4.x, *_PSA_INIT() and *_PSA_DONE() can be
simply aliased to PSA_INIT() and PSA_DONE() until such a time as we
remove them.

Simplify the login of these PSA_INIT/DONE variants by aliasing them in
4.x and keeping the more complex 3.6 logic entirely separate.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-10-25 15:13:00 +01:00