summaryrefslogtreecommitdiff
path: root/examples/kernel/heap_malloc.c
diff options
context:
space:
mode:
authorbernard <[email protected]>2013-12-29 22:31:05 +0800
committerbernard <[email protected]>2013-12-29 22:31:05 +0800
commita93251ae2b61e7a48c2168e08e81dc15f42a92e2 (patch)
treedde4cf4909c61c3c0308194aa2c08efe56e16073 /examples/kernel/heap_malloc.c
parent42ae1c634d9e102091b82bc61ebfe05cccd7fcea (diff)
parent939176d13adf7a5a38673f1c836f85fa68cd30be (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
Diffstat (limited to 'examples/kernel/heap_malloc.c')
-rw-r--r--examples/kernel/heap_malloc.c78
1 files changed, 40 insertions, 38 deletions
diff --git a/examples/kernel/heap_malloc.c b/examples/kernel/heap_malloc.c
index 0a6b46cc95..271202ad8f 100644
--- a/examples/kernel/heap_malloc.c
+++ b/examples/kernel/heap_malloc.c
@@ -7,66 +7,68 @@
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;
+ while (len)
+ {
+ if (*ptr != value)
+ return RT_FALSE;
+ ptr ++;
+ len --;
+ }
- ptr ++;
- len --;
- }
-
- return RT_TRUE;
+ return RT_TRUE;
}
static void heap_malloc_init()
{
- rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
-
- ptr1 = rt_malloc(1);
- ptr2 = rt_malloc(13);
- ptr3 = rt_malloc(31);
- ptr4 = rt_malloc(127);
- ptr5 = rt_malloc(0);
+ rt_uint8_t res = TC_STAT_PASSED;
+ rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
- memset(ptr1, 1, 1);
- memset(ptr2, 2, 13);
- memset(ptr3, 3, 31);
- memset(ptr4, 4, 127);
+ ptr1 = rt_malloc(1);
+ ptr2 = rt_malloc(13);
+ ptr3 = rt_malloc(31);
+ ptr4 = rt_malloc(127);
+ ptr5 = rt_malloc(0);
- 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;
+ memset(ptr1, 1, 1);
+ memset(ptr2, 2, 13);
+ memset(ptr3, 3, 31);
+ memset(ptr4, 4, 127);
- rt_free(ptr4);
- rt_free(ptr3);
- rt_free(ptr3);
- rt_free(ptr1);
+ 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;
- if (ptr5 != RT_NULL)
- {
- rt_free(ptr5);
- }
+ rt_free(ptr4);
+ rt_free(ptr3);
+ rt_free(ptr2);
+ rt_free(ptr1);
- tc_done(TC_STAT_PASSED);
+ if (ptr5 != RT_NULL)
+ {
+ rt_free(ptr5);
+ }
-_failed:
- tc_done(TC_STAT_FAILED);
+ tc_done(res);
}
#ifdef RT_USING_TC
int _tc_heap_malloc()
{
- heap_malloc_init();
+ heap_malloc_init();
- return 0;
+ return 0;
}
FINSH_FUNCTION_EXPORT(_tc_heap_malloc, a heap malloc test);
#else
int rt_application_init()
{
- heap_malloc_init();
+ heap_malloc_init();
- return 0;
+ return 0;
}
#endif