You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.7 KiB
106 lines
2.7 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
|
|
* Description: testcode1
|
|
* Author: SmartMedia_BSP
|
|
* Create: 2020-06-04
|
|
*/
|
|
|
|
#include <malloc.h>
|
|
#include <stdio.h>
|
|
#include <trace.h>
|
|
|
|
void dump_stack_test(void)
|
|
{
|
|
printf("%s,%d\n", __FUNCTION__, __LINE__);
|
|
fbl_backtrace();
|
|
}
|
|
|
|
#define MALLOC_MAX_ARRAY_SIZE 200
|
|
void malloc_test(void)
|
|
{
|
|
printf("\nmalloc test\n");
|
|
unsigned int i;
|
|
void *p[MALLOC_MAX_ARRAY_SIZE];
|
|
printf("-------1--------\n");
|
|
show_memnode(0);
|
|
printf("-------2--------\n");
|
|
for (i = 0; i < 100; i++) { /* 100 times */
|
|
p[i] = malloc(i);
|
|
}
|
|
show_memnode(0);
|
|
for (i = 0; i < 100; i++) { /* 100 times */
|
|
free(p[i]);
|
|
}
|
|
show_memnode(0);
|
|
printf("-------3--------\n");
|
|
for (i = 0; i < 100; i++) { /* 100 times */
|
|
p[i] = malloc(2 * i); /* 2: double i */
|
|
}
|
|
for (i = 0; i < 100; i += 2) { /* 100:max value,step 2 */
|
|
free(p[i]);
|
|
}
|
|
for (i = 1; i < 100; i += 2) { /* 100:max value,step 2 */
|
|
free(p[i]);
|
|
}
|
|
show_memnode(0);
|
|
printf("-------4--------\n");
|
|
for (i = 0; i < 100; i++) { /* 100 times */
|
|
p[i] = malloc(16 * i); /* 16 times of i */
|
|
}
|
|
for (i = 0; i < 100; i += 2) { /* 100:max value,step 2 */
|
|
free(p[i]);
|
|
p[i] = NULL;
|
|
}
|
|
show_memnode(20); /* 20: show list size */
|
|
for (i = 0; i < 100; i += 2) { /* 100:max value,step 2 */
|
|
p[i] = malloc(4 * i); /* 4 times of i */
|
|
show_memnode(10); /* 10: show list size */
|
|
}
|
|
for (i = 0; i < 100; i++) { /* 100 times */
|
|
free(p[i]);
|
|
}
|
|
printf("malloc test done\n");
|
|
}
|
|
|
|
void mem_align_test(void)
|
|
{
|
|
int i;
|
|
void *p[MALLOC_MAX_ARRAY_SIZE];
|
|
printf("\nmem_align test\n");
|
|
for (i = 0; i < 5; i++) { /* 5 times */
|
|
p[i] = memalign(8, 7); /* align 8 bytes, 7 bytes */
|
|
printf("0x%x\n", p[i]);
|
|
}
|
|
for (i = 5; i < 10; i++) { /* from 5 to 10 */
|
|
p[i] = memalign(8, 8); /* align 8 bytes, 8 bytes */
|
|
printf("0x%x\n", p[i]);
|
|
}
|
|
for (i = 0; i < 10; i++) { /* 10 times */
|
|
free(p[i]);
|
|
}
|
|
show_memnode(0);
|
|
printf("mem_align test done\n");
|
|
}
|
|
void exception_test(void)
|
|
{
|
|
printf("\nexception test start\n");
|
|
/* undefined instruction */
|
|
asm("test1:\n\r"
|
|
" .word 0xFF123456\n\r");
|
|
/* data abort */
|
|
asm("ldr r1, =0x3\r\n"
|
|
"ldr r2, [r1]\r\n");
|
|
/* prefetch abort */
|
|
asm("ldr pc, =0xFFFF0000\r\n");
|
|
/* software interrupt */
|
|
asm("swi #0xb");
|
|
}
|
|
|
|
void do_testcase(void)
|
|
{
|
|
dump_stack_test();
|
|
malloc_test();
|
|
mem_align_test();
|
|
exception_test();
|
|
}
|