From 900b7dc5acc3bb34b2f5333912f25071c4e21b54 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Sun, 15 Mar 2026 19:43:44 +0100 Subject: [PATCH] Test that the compile-time and run-time entropy source counts match Signed-off-by: Gilles Peskine --- tests/suites/test_suite_entropy.data | 3 +++ tests/suites/test_suite_entropy.function | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tests/suites/test_suite_entropy.data b/tests/suites/test_suite_entropy.data index 514fced49e..eff261401d 100644 --- a/tests/suites/test_suite_entropy.data +++ b/tests/suites/test_suite_entropy.data @@ -4,6 +4,9 @@ entropy_init_free:0 Entropy init-free-init-free entropy_init_free:1 +Entropy: count default sources +entropy_count_sources: + Create NV seed_file nv_seed_file_create: diff --git a/tests/suites/test_suite_entropy.function b/tests/suites/test_suite_entropy.function index a4f3b1bd7c..0e719f6f06 100644 --- a/tests/suites/test_suite_entropy.function +++ b/tests/suites/test_suite_entropy.function @@ -171,6 +171,29 @@ void entropy_init_free(int reinit) } /* END_CASE */ +/* BEGIN_CASE */ +void entropy_count_sources() +{ + mbedtls_entropy_context ctx; + mbedtls_entropy_init(&ctx); + +#if defined(MBEDTLS_ENTROPY_HAVE_SOURCES) + TEST_EQUAL(MBEDTLS_ENTROPY_HAVE_SOURCES, ctx.source_count); +#else + TEST_EQUAL(0, ctx.source_count); +#endif + +#if defined(MBEDTLS_ENTROPY_NV_SEED) + TEST_EQUAL(MBEDTLS_ENTROPY_TRUE_SOURCES + 1, ctx.source_count); +#else + TEST_EQUAL(MBEDTLS_ENTROPY_TRUE_SOURCES, ctx.source_count); +#endif + +exit: + mbedtls_entropy_free(&ctx); +} +/* END_CASE */ + /* BEGIN_CASE depends_on:MBEDTLS_ENTROPY_NV_SEED:MBEDTLS_FS_IO */ void entropy_seed_file(char *path, int ret) {