25
25
*/
26
26
27
27
#include " mbed.h"
28
+ #include " mbed_stats.h"
28
29
#include " cfstore_config.h"
29
30
#include " cfstore_debug.h"
30
31
#include " cfstore_test.h"
@@ -507,11 +508,10 @@ control_t cfstore_create_test_04_end(const size_t call_count)
507
508
*
508
509
* Create enough KV's to consume the whole of available memory
509
510
*/
510
- int32_t cfstore_create_test_05_core (const size_t call_count, uint32_t * bytes_stored_ex )
511
+ int32_t cfstore_create_test_05_core (const size_t call_count)
511
512
{
512
513
int32_t ret = ARM_DRIVER_ERROR;
513
514
uint32_t i = 0 ;
514
- uint32_t bytes_stored = 0 ;
515
515
const uint32_t max_num_kvs_create = 200 ;
516
516
const size_t kv_name_tag_len = 3 ;
517
517
const size_t kv_name_min_len = 10 ;
@@ -535,9 +535,6 @@ int32_t cfstore_create_test_05_core(const size_t call_count, uint32_t* bytes_sto
535
535
memset (value_buf, 0 , max_value_buf_size);
536
536
snprintf (kv_name_tag_buf, kv_name_tag_len+1 , " %0d" , (int ) i);
537
537
ret = cfstore_create_kv_create (kv_name_min_len, kv_name_tag_buf, value_buf, kv_value_min_len/64 * (i+1 ));
538
- bytes_stored += kv_name_min_len + i + strlen (kv_name_tag_buf); /* kv_name */
539
- bytes_stored += kv_value_min_len/64 * (i+1 ); /* kv value blob */
540
- bytes_stored += 8 ; /* kv overhead */
541
538
if (ret == ARM_CFSTORE_DRIVER_ERROR_OUT_OF_MEMORY){
542
539
CFSTORE_ERRLOG (" Out of memory on %d-th KV, trying to allocate memory totalling %d.\n " , (int ) i, (int ) bytes_stored);
543
540
break ;
@@ -551,9 +548,6 @@ int32_t cfstore_create_test_05_core(const size_t call_count, uint32_t* bytes_sto
551
548
free (value_buf);
552
549
CFSTORE_TEST_UTEST_MESSAGE (cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, " %s:Error: Uninitialize() call failed.\n " , __func__);
553
550
TEST_ASSERT_MESSAGE (drv->Uninitialize () >= ARM_DRIVER_OK, cfstore_create_utest_msg_g);
554
- if (bytes_stored_ex){
555
- *bytes_stored_ex = bytes_stored;
556
- }
557
551
return ret;
558
552
}
559
553
@@ -576,22 +570,25 @@ control_t cfstore_create_test_05(const size_t call_count)
576
570
{
577
571
uint32_t i = 0 ;
578
572
int32_t ret = ARM_DRIVER_ERROR;
579
- uint32_t bytes_stored = 0 ;
580
- uint32_t bytes_stored_prev = 0 ;
581
573
const uint32_t max_loops = 50 ;
574
+ mbed_stats_heap_t stats_before;
575
+ mbed_stats_heap_t stats_after;
576
+
577
+ mbed_stats_heap_get (&stats_before);
582
578
583
579
CFSTORE_FENTRYLOG (" %s:entered\n " , __func__);
584
580
for (i = 0 ; i < max_loops; i++) {
585
- ret = cfstore_create_test_05_core (call_count, &bytes_stored );
581
+ ret = cfstore_create_test_05_core (call_count);
586
582
CFSTORE_TEST_UTEST_MESSAGE (cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, " %s:Error: cfstore_create_test_05_core() failed (ret = %d.\n " , __func__, (int ) ret);
587
583
TEST_ASSERT_MESSAGE (ret >= ARM_DRIVER_OK, cfstore_create_utest_msg_g);
588
584
585
+ mbed_stats_heap_get (&stats_after);
589
586
if (i > 1 ) {
590
- CFSTORE_TEST_UTEST_MESSAGE (cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, " %s:Error: memory leak: stored %d bytes on loop %d, but %d bytes on loop %d .\n " , __func__, (int ) bytes_stored , (int ) i, (int ) bytes_stored_prev , (int ) i-1 );
591
- TEST_ASSERT_MESSAGE (bytes_stored == bytes_stored_prev , cfstore_create_utest_msg_g);
592
-
587
+ CFSTORE_TEST_UTEST_MESSAGE (cfstore_create_utest_msg_g, CFSTORE_UTEST_MSG_BUF_SIZE, " %s:Error: memory leak: stored %d bytes on loop %d, but %d bytes on loop %d .\n " , __func__, (int ) stats_after. current_size , (int ) i, (int ) stats_before. current_size , (int ) i-1 );
588
+ TEST_ASSERT_MESSAGE (stats_after. current_size == stats_before. current_size , cfstore_create_utest_msg_g);
589
+ TEST_ASSERT (stats_after. alloc_fail_cnt > stats_before. alloc_fail_cnt );
593
590
}
594
- bytes_stored_prev = bytes_stored ;
591
+ stats_before = stats_after ;
595
592
}
596
593
return CaseNext;
597
594
}
@@ -828,7 +825,9 @@ Case cases[] = {
828
825
Case (" CREATE_test_03_end" , cfstore_create_test_03_end),
829
826
Case (" CREATE_test_04_start" , cfstore_utest_default_start),
830
827
Case (" CREATE_test_04_end" , cfstore_create_test_04_end),
828
+ #if defined(MBED_HEAP_STATS_ENABLED) && MBED_HEAP_STATS_ENABLED && !defined(__ICCARM__)
831
829
Case (" CREATE_test_05" , cfstore_create_test_05),
830
+ #endif
832
831
Case (" CREATE_test_06_start" , cfstore_utest_default_start),
833
832
Case (" CREATE_test_06_end" , cfstore_create_test_06_end),
834
833
Case (" CREATE_test_07_start" , cfstore_utest_default_start),
0 commit comments