diff --git a/components/mbedtls/test_apps/persistent_storage_format/main/app_main.c b/components/mbedtls/test_apps/persistent_storage_format/main/app_main.c index 42463fd9382..75e933aec9f 100644 --- a/components/mbedtls/test_apps/persistent_storage_format/main/app_main.c +++ b/components/mbedtls/test_apps/persistent_storage_format/main/app_main.c @@ -10,10 +10,28 @@ #include "esp_newlib.h" #include "memory_checks.h" #include "nvs_flash.h" +#include "psa/crypto.h" #include "unity.h" +#include "test_persistent_format.h" + +/* First ITS access caches the NVS psa_its namespace (and related one-shot + * PSA storage state). Prime it before leak accounting so consume tests are + * not charged ~1.2 KB against the 1200-byte critical threshold — the same + * pattern mbedtls_ut uses for AES interrupt allocation. */ +static void prime_psa_its(psa_key_id_t id) +{ + psa_key_attributes_t attr = PSA_KEY_ATTRIBUTES_INIT; + (void)psa_get_key_attributes(id, &attr); + psa_reset_key_attributes(&attr); + (void)psa_purge_key(id); +} void setUp(void) { + prime_psa_its(ESP_PERSISTENT_FIXTURE_DS_KEY_ID); + prime_psa_its(ESP_PERSISTENT_FIXTURE_HMAC_KEY_ID); + prime_psa_its(ESP_PERSISTENT_FIXTURE_ECDSA_KEY_ID); + test_utils_record_free_mem(); test_utils_set_leak_level(CONFIG_UNITY_CRITICAL_LEAK_LEVEL_GENERAL, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL);