2021-03-08 07:18:51 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-08 21:05:02 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include "tc_comm.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is an example for heap malloc
|
|
|
|
*/
|
|
|
|
|
|
|
|
static rt_bool_t mem_check(rt_uint8_t *ptr, rt_uint8_t value, rt_uint32_t len)
|
|
|
|
{
|
2013-12-21 11:56:33 +08:00
|
|
|
while (len)
|
|
|
|
{
|
|
|
|
if (*ptr != value)
|
2013-12-18 23:04:18 +08:00
|
|
|
return RT_FALSE;
|
2013-12-21 11:56:33 +08:00
|
|
|
ptr ++;
|
|
|
|
len --;
|
|
|
|
}
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
return RT_TRUE;
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void heap_malloc_init()
|
|
|
|
{
|
2013-12-21 11:56:33 +08:00
|
|
|
rt_uint8_t res = TC_STAT_PASSED;
|
|
|
|
rt_uint8_t *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
ptr1 = rt_malloc(1);
|
|
|
|
ptr2 = rt_malloc(13);
|
|
|
|
ptr3 = rt_malloc(31);
|
|
|
|
ptr4 = rt_malloc(127);
|
|
|
|
ptr5 = rt_malloc(0);
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
memset(ptr1, 1, 1);
|
|
|
|
memset(ptr2, 2, 13);
|
|
|
|
memset(ptr3, 3, 31);
|
|
|
|
memset(ptr4, 4, 127);
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
if (mem_check(ptr1, 1, 1) == RT_FALSE)
|
2013-12-18 23:04:18 +08:00
|
|
|
res = TC_STAT_FAILED;
|
2013-12-21 11:56:33 +08:00
|
|
|
if (mem_check(ptr2, 2, 13) == RT_FALSE)
|
2013-12-18 23:04:18 +08:00
|
|
|
res = TC_STAT_FAILED;
|
2013-12-21 11:56:33 +08:00
|
|
|
if (mem_check(ptr3, 3, 31) == RT_FALSE)
|
2013-12-18 23:04:18 +08:00
|
|
|
res = TC_STAT_FAILED;
|
2013-12-21 11:56:33 +08:00
|
|
|
if (mem_check(ptr4, 4, 127) == RT_FALSE)
|
2013-12-18 23:04:18 +08:00
|
|
|
res = TC_STAT_FAILED;
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
rt_free(ptr4);
|
|
|
|
rt_free(ptr3);
|
|
|
|
rt_free(ptr2);
|
|
|
|
rt_free(ptr1);
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
if (ptr5 != RT_NULL)
|
|
|
|
{
|
|
|
|
rt_free(ptr5);
|
|
|
|
}
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
tc_done(res);
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RT_USING_TC
|
|
|
|
int _tc_heap_malloc()
|
|
|
|
{
|
2013-12-21 11:56:33 +08:00
|
|
|
heap_malloc_init();
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
return 0;
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
FINSH_FUNCTION_EXPORT(_tc_heap_malloc, a heap malloc test);
|
|
|
|
#else
|
|
|
|
int rt_application_init()
|
|
|
|
{
|
2013-12-21 11:56:33 +08:00
|
|
|
heap_malloc_init();
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2013-12-21 11:56:33 +08:00
|
|
|
return 0;
|
2013-01-08 21:05:02 +08:00
|
|
|
}
|
|
|
|
#endif
|