| 1 | /* |
|---|
| 2 | OSHeapTest.c |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | #include "DHL_OSAL.h" |
|---|
| 6 | |
|---|
| 7 | /* |
|---|
| 8 | ¸Þ¸ð¸® ÇÒ´çÀ» À§ÇÑ º¯¼ö¸¦ ¼±¾ðÇϰí |
|---|
| 9 | ¸Þ¸ð¸® ÇÒ´ç ÀüÈÄÀÇ ÁÖ¼Ò È®ÀÎ |
|---|
| 10 | ¸Þ¸ð¸® ¹Ýȯ ÈÄÀÇ ÁÖ¼Ò È®ÀÎ |
|---|
| 11 | |
|---|
| 12 | °á°ú : pMemÀÇ ÁÖ¼Ò°¡ 0x0 -> 0xXXXXXXXX -> 0x0 ¼ø¼·Î Ãâ·ÂµÇ¸é Á¤»ó |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | #define TEST_MALLOC_SIZE 1024 |
|---|
| 16 | |
|---|
| 17 | UINT32 size_heap; // size of entire heap |
|---|
| 18 | |
|---|
| 19 | UINT32 num_alloc_chunk; // number of alloc chunk |
|---|
| 20 | UINT32 size_alloc; // total byte size alloc chunk |
|---|
| 21 | |
|---|
| 22 | UINT32 num_free_chunk; // number of free chunk |
|---|
| 23 | UINT32 size_free; // total byte size free chunk |
|---|
| 24 | |
|---|
| 25 | static void print_heap_status(void) |
|---|
| 26 | { |
|---|
| 27 | DHL_OS_HEAP_STATUS status; |
|---|
| 28 | |
|---|
| 29 | DHL_OS_GetHeapStatus(&status); |
|---|
| 30 | DHL_OS_Printf("size_heap = %x, num_alloc_chunk = %x, size_alloc = %x num_free_chunk=%x, size_free=%x \n", |
|---|
| 31 | status.size_heap, status.num_alloc_chunk, |
|---|
| 32 | status.size_alloc, status.num_free_chunk, status.size_free); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | void OS_HeapTest(void) |
|---|
| 36 | { |
|---|
| 37 | int* pMem = 0; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | DHL_OS_Printf( "\r\n----OS Heap Test----\r\n\r\n"); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | DHL_OS_Printf( "The value of \'pMem\' before malloc is 0x%x\r\n", pMem); |
|---|
| 44 | |
|---|
| 45 | print_heap_status(); |
|---|
| 46 | pMem = DHL_OS_Malloc(TEST_MALLOC_SIZE); |
|---|
| 47 | |
|---|
| 48 | DHL_OS_Printf( "The value of \'pMem\' after malloc is 0x%x\r\n", pMem); |
|---|
| 49 | |
|---|
| 50 | if (pMem == 0) |
|---|
| 51 | DHL_OS_Printf( "Malloc is failed..\r\n"); |
|---|
| 52 | |
|---|
| 53 | print_heap_status(); |
|---|
| 54 | DHL_OS_Free((void**)&pMem); |
|---|
| 55 | |
|---|
| 56 | DHL_OS_Printf("The value of \'pMem\' after free.. 0x%x\r\n", pMem); |
|---|
| 57 | print_heap_status(); |
|---|
| 58 | } |
|---|
| 59 | |
|---|