Skip to content

Commit 216e653

Browse files
committed
Merge branch 'bugfix/increase_leak_threshold_for_wpa_supplicant_dpp_test' into 'master'
fix(wpa_supplicant): add crypto init calls to address memory leak issue in tests Closes IDFCI-2409 See merge request espressif/esp-idf!33731
2 parents 87c01b3 + c89c316 commit 216e653

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

components/wpa_supplicant/test_apps/main/test_wpa_supplicant_main.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#include "unity.h"
88
#include "unity_test_runner.h"
99
#include "esp_heap_caps.h"
10+
#include "mbedtls/aes.h"
11+
#include "sdkconfig.h"
12+
#include "soc/soc_caps.h"
13+
#if SOC_SHA_SUPPORT_PARALLEL_ENG
14+
#include "sha/sha_parallel_engine.h"
15+
#elif SOC_SHA_SUPPORT_DMA
16+
#include "sha/sha_dma.h"
17+
#else
18+
#include "sha/sha_block.h"
19+
#endif
1020

1121
#define TEST_MEMORY_LEAK_THRESHOLD_DEFAULT 0
1222
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)
2535
TEST_ASSERT_MESSAGE(delta > leak_threshold, "memory leak");
2636
}
2737

38+
#if SOC_SHA_SUPPORT_SHA512
39+
#define SHA_TYPE SHA2_512
40+
#else
41+
#define SHA_TYPE SHA2_256
42+
#endif //SOC_SHA_SUPPORT_SHA512
43+
2844
void setUp(void)
2945
{
46+
#if CONFIG_MBEDTLS_HARDWARE_SHA
47+
// Execute esp_sha operation to allocate internal SHA semaphore (in case of ESP32)
48+
// and initial DMA setup memory which is considered as leaked otherwise
49+
const uint8_t input_buffer[64] = {0};
50+
uint8_t output_buffer[64];
51+
esp_sha(SHA_TYPE, input_buffer, sizeof(input_buffer), output_buffer);
52+
#endif // SOC_SHA_SUPPORTED
53+
54+
#if CONFIG_MBEDTLS_HARDWARE_AES
55+
// Execute mbedtls_aes_init operation to allocate AES interrupt
56+
// allocation memory which is considered as leak otherwise
57+
const uint8_t plaintext[16] = {0};
58+
uint8_t ciphertext[16];
59+
const uint8_t key[16] = { 0 };
60+
mbedtls_aes_context ctx;
61+
mbedtls_aes_init(&ctx);
62+
mbedtls_aes_setkey_enc(&ctx, key, 128);
63+
mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, plaintext, ciphertext);
64+
mbedtls_aes_free(&ctx);
65+
#endif // SOC_AES_SUPPORTED
66+
3067
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT);
3168
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT);
3269
}

0 commit comments

Comments
 (0)