Skip to content

Commit 6061ab6

Browse files
committed
Fix heap memory check in TestChipCryptoPAL
Wipe all key slots during each test case SetUp to avoid reusing slot previously used by other tests. This affects heap memory usage calculation as when the slot is reused it frees the memory. Signed-off-by: Adrian Gielniewski <[email protected]>
1 parent 4eb0de5 commit 6061ab6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/crypto/tests/TestChipCryptoPAL.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373

7474
#if CHIP_CRYPTO_PSA
7575
#include <psa/crypto.h>
76+
extern "C" {
77+
psa_status_t psa_initialize_key_slots(void);
78+
void psa_wipe_all_key_slots(void);
79+
}
7680
#endif
7781

7882
using namespace chip;
@@ -289,14 +293,17 @@ static void TestAES_CTR_128_Decrypt(const AesCtrTestEntry * vector)
289293

290294
struct TestChipCryptoPAL : public ::testing::Test
291295
{
292-
static void SetUpTestSuite()
296+
static void SetUpTestSuite() { ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR); }
297+
static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
298+
299+
void SetUp() override
293300
{
294-
ASSERT_EQ(chip::Platform::MemoryInit(), CHIP_NO_ERROR);
295301
#if CHIP_CRYPTO_PSA
296302
psa_crypto_init();
303+
psa_wipe_all_key_slots();
304+
psa_initialize_key_slots();
297305
#endif
298306
}
299-
static void TearDownTestSuite() { chip::Platform::MemoryShutdown(); }
300307
};
301308

302309
TEST_F(TestChipCryptoPAL, TestAES_CTR_128CryptTestVectors)

0 commit comments

Comments
 (0)