diff --git a/examples/kernel/heap_malloc.c b/examples/kernel/heap_malloc.c index 0a6b46cc951fc369c52ba1c33b90ef1b5b3ff348..558c5403a94884170c9b7d945e99f404acf87f4a 100644 --- a/examples/kernel/heap_malloc.c +++ b/examples/kernel/heap_malloc.c @@ -9,8 +9,8 @@ static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len) { while (len) { - if (*ptr != value) return RT_FALSE; - + if (*ptr != value) + return RT_FALSE; ptr ++; len --; } @@ -20,6 +20,7 @@ static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len) static void heap_malloc_init() { + rt_uint8_t res = TC_STAT_PASSED; rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5; ptr1 = rt_malloc(1); @@ -33,14 +34,18 @@ static void heap_malloc_init() memset(ptr3, 3, 31); memset(ptr4, 4, 127); - if (mem_check(ptr1, 1, 1) != RT_FALSE) goto _failed; - if (mem_check(ptr2, 2, 13) != RT_FALSE) goto _failed; - if (mem_check(ptr3, 3, 31) != RT_FALSE) goto _failed; - if (mem_check(ptr4, 4, 127) != RT_FALSE) goto _failed; + if (mem_check(ptr1, 1, 1) == RT_FALSE) + res = TC_STAT_FAILED; + if (mem_check(ptr2, 2, 13) == RT_FALSE) + res = TC_STAT_FAILED; + if (mem_check(ptr3, 3, 31) == RT_FALSE) + res = TC_STAT_FAILED; + if (mem_check(ptr4, 4, 127) == RT_FALSE) + res = TC_STAT_FAILED; rt_free(ptr4); rt_free(ptr3); - rt_free(ptr3); + rt_free(ptr2); rt_free(ptr1); if (ptr5 != RT_NULL) @@ -48,10 +53,7 @@ static void heap_malloc_init() rt_free(ptr5); } - tc_done(TC_STAT_PASSED); - -_failed: - tc_done(TC_STAT_FAILED); + tc_done(res); } #ifdef RT_USING_TC diff --git a/examples/kernel/heap_realloc.c b/examples/kernel/heap_realloc.c index 0f3ec95916a330d4a85b923d04e253ac96456d1a..c77a60f7d91dfc2943ff6ae3d0318a253adc26e9 100644 --- a/examples/kernel/heap_realloc.c +++ b/examples/kernel/heap_realloc.c @@ -34,10 +34,26 @@ static void heap_realloc_init() memset(ptr3, 3, 31); memset(ptr4, 4, 127); - if (mem_check(ptr1, 1, 1) != RT_FALSE) goto _failed; - if (mem_check(ptr2, 2, 13) != RT_FALSE) goto _failed; - if (mem_check(ptr3, 3, 31) != RT_FALSE) goto _failed; - if (mem_check(ptr4, 4, 127) != RT_FALSE) goto _failed; + if (mem_check(ptr1, 1, 1) == RT_FALSE) + { + res = TC_STAT_FAILED; + goto _free; + } + if (mem_check(ptr2, 2, 13) == RT_FALSE) + { + res = TC_STAT_FAILED; + goto _free; + } + if (mem_check(ptr3, 3, 31) == RT_FALSE) + { + res = TC_STAT_FAILED; + goto _free; + } + if (mem_check(ptr4, 4, 127) == RT_FALSE) + { + res = TC_STAT_FAILED; + goto _free; + } ptr1 = rt_realloc(ptr1, 13); ptr2 = rt_realloc(ptr2, 31); @@ -50,14 +66,19 @@ static void heap_realloc_init() res = TC_STAT_FAILED; } - if (mem_check(ptr1, 1, 1) != RT_FALSE) goto _failed; - if (mem_check(ptr2, 2, 13) != RT_FALSE) goto _failed; - if (mem_check(ptr3, 3, 31) != RT_FALSE) goto _failed; - if (mem_check(ptr4, 4, 1) != RT_FALSE) goto _failed; + if (mem_check(ptr1, 1, 1) == RT_FALSE) + res = TC_STAT_FAILED; + if (mem_check(ptr2, 2, 13) == RT_FALSE) + res = TC_STAT_FAILED; + if (mem_check(ptr3, 3, 31) == RT_FALSE) + res = TC_STAT_FAILED; + if (mem_check(ptr4, 4, 1) == RT_FALSE) + res = TC_STAT_FAILED; +_free: rt_free(ptr4); rt_free(ptr3); - rt_free(ptr3); + rt_free(ptr2); rt_free(ptr1); tc_done(res);