fix(wpa_supplicant): add crypto init calls to address memory leak issue in tests

- C61 does not feature MPI hardware and hence the other tests were
  getting executed first
- Memory leak threshold should be independent of target crypto
  peripherals and hence added to crypto init to test `setUp` call
This commit is contained in:
Mahavir Jain 2024-09-24 14:13:22 +05:30
parent 7752c1b051
commit c89c316922
No known key found for this signature in database
GPG Key ID: 99324EF4A00734E0

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -7,6 +7,16 @@
#include "unity.h" #include "unity.h"
#include "unity_test_runner.h" #include "unity_test_runner.h"
#include "esp_heap_caps.h" #include "esp_heap_caps.h"
#include "mbedtls/aes.h"
#include "sdkconfig.h"
#include "soc/soc_caps.h"
#if SOC_SHA_SUPPORT_PARALLEL_ENG
#include "sha/sha_parallel_engine.h"
#elif SOC_SHA_SUPPORT_DMA
#include "sha/sha_dma.h"
#else
#include "sha/sha_block.h"
#endif
#define TEST_MEMORY_LEAK_THRESHOLD_DEFAULT 0 #define TEST_MEMORY_LEAK_THRESHOLD_DEFAULT 0
static int leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT; static int leak_threshold = TEST_MEMORY_LEAK_THRESHOLD_DEFAULT;
@ -25,8 +35,35 @@ static void check_leak(size_t before_free, size_t after_free, const char *type)
TEST_ASSERT_MESSAGE(delta > leak_threshold, "memory leak"); TEST_ASSERT_MESSAGE(delta > leak_threshold, "memory leak");
} }
#if SOC_SHA_SUPPORT_SHA512
#define SHA_TYPE SHA2_512
#else
#define SHA_TYPE SHA2_256
#endif //SOC_SHA_SUPPORT_SHA512
void setUp(void) void setUp(void)
{ {
#if CONFIG_MBEDTLS_HARDWARE_SHA
// Execute esp_sha operation to allocate internal SHA semaphore (in case of ESP32)
// and initial DMA setup memory which is considered as leaked otherwise
const uint8_t input_buffer[64] = {0};
uint8_t output_buffer[64];
esp_sha(SHA_TYPE, input_buffer, sizeof(input_buffer), output_buffer);
#endif // SOC_SHA_SUPPORTED
#if CONFIG_MBEDTLS_HARDWARE_AES
// Execute mbedtls_aes_init operation to allocate AES interrupt
// allocation memory which is considered as leak otherwise
const uint8_t plaintext[16] = {0};
uint8_t ciphertext[16];
const uint8_t key[16] = { 0 };
mbedtls_aes_context ctx;
mbedtls_aes_init(&ctx);
mbedtls_aes_setkey_enc(&ctx, key, 128);
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, plaintext, ciphertext);
mbedtls_aes_free(&ctx);
#endif // SOC_AES_SUPPORTED
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
} }