summaryrefslogtreecommitdiff
path: root/examples/kernel/heap_realloc.c
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2013-12-18 18:05:31 -0800
committerBernard Xiong <[email protected]>2013-12-18 18:05:31 -0800
commit0e8b23ff954fe2164ea5aedc4efc334982158b62 (patch)
tree09043f8117d205b3be4c308004948d357e6851c7 /examples/kernel/heap_realloc.c
parentcb347f5af05be87d673ec7c53662eb5e61ed681d (diff)
parenta51b5799f73c7fb6df3d53d540b94fa85fb283c1 (diff)
Merge pull request #212 from grissiom/fix-tc
Fix tc
Diffstat (limited to 'examples/kernel/heap_realloc.c')
-rw-r--r--examples/kernel/heap_realloc.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/examples/kernel/heap_realloc.c b/examples/kernel/heap_realloc.c
index a4974d5bf3..c77a60f7d9 100644
--- a/examples/kernel/heap_realloc.c
+++ b/examples/kernel/heap_realloc.c
@@ -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_realloc_init()
{
+ rt_uint8_t res = TC_STAT_PASSED;
rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
ptr1 = rt_malloc(1);
@@ -33,36 +34,54 @@ 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);
ptr3 = rt_realloc(ptr3, 127);
ptr4 = rt_realloc(ptr4, 1);
ptr5 = rt_realloc(ptr5, 0);
+ if (ptr5)
+ {
+ rt_kprintf("realloc(ptr, 0) should return NULL\n");
+ 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);
- if (ptr5 != RT_NULL)
- {
- rt_free(ptr5);
- }
-
- tc_done(TC_STAT_PASSED);
-
-_failed:
- tc_done(TC_STAT_FAILED);
+ tc_done(res);
}
#ifdef RT_USING_TC