From 4eebe42a1115c1a884612af0b24f5b294fa33f2f Mon Sep 17 00:00:00 2001 From: Valerio Setti Date: Wed, 14 Jan 2026 23:05:02 +0100 Subject: [PATCH] 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 --- tests/include/test/pk_helpers.h | 4 +++- tests/src/pk_helpers.c | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/include/test/pk_helpers.h b/tests/include/test/pk_helpers.h index 71a0d20fd..5241693e3 100644 --- a/tests/include/test/pk_helpers.h +++ b/tests/include/test/pk_helpers.h @@ -74,7 +74,9 @@ mbedtls_svc_key_id_t mbedtls_pk_helpers_make_psa_key_from_predefined(psa_key_typ * \param method The desired method for populating the PK context. See * "pk_context_populate_method_t" for available options. * - * \return 0 on success; an error code otherwise. + * \return 0 on success. + * In case of failure -1 is returned and the test case is marked + * as failed. */ int mbedtls_pk_helpers_populate_context(mbedtls_pk_context *pk, mbedtls_svc_key_id_t key_id, pk_context_populate_method_t method); diff --git a/tests/src/pk_helpers.c b/tests/src/pk_helpers.c index f313919a9..e2e224292 100644 --- a/tests/src/pk_helpers.c +++ b/tests/src/pk_helpers.c @@ -109,23 +109,23 @@ exit: int mbedtls_pk_helpers_populate_context(mbedtls_pk_context *pk, mbedtls_svc_key_id_t key_id, pk_context_populate_method_t method) { - int ret; + int ret = -1; switch (method) { case TEST_PK_WRAP_PSA: - ret = mbedtls_pk_wrap_psa(pk, key_id); + TEST_EQUAL(mbedtls_pk_wrap_psa(pk, key_id), 0); break; case TEST_PK_COPY_FROM_PSA: - ret = mbedtls_pk_copy_from_psa(key_id, pk); + TEST_EQUAL(mbedtls_pk_copy_from_psa(key_id, pk), 0); break; case TEST_PK_COPY_PUBLIC_FROM_PSA: - ret = mbedtls_pk_copy_public_from_psa(key_id, pk); + TEST_EQUAL(mbedtls_pk_copy_public_from_psa(key_id, pk), 0); break; default: - ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA; + TEST_FAIL("Unknown population method"); } - TEST_EQUAL(ret, 0); + ret = 0; exit: return ret;