From cd442d4c29789100518394a055d52261e4cbd36f Mon Sep 17 00:00:00 2001 From: batt Date: Wed, 23 Dec 2009 16:50:13 +0000 Subject: [PATCH] Add a simple heap test. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3128 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/struct/heap_test.c | 91 +++++++++++++++++++++++++++++++++++++++ test/run_tests.sh | 1 + 2 files changed, 92 insertions(+) create mode 100644 bertos/struct/heap_test.c diff --git a/bertos/struct/heap_test.c b/bertos/struct/heap_test.c new file mode 100644 index 00000000..6aee0042 --- /dev/null +++ b/bertos/struct/heap_test.c @@ -0,0 +1,91 @@ +/** + * \file + * + * + * \brief Heap test. + * + * \author Francesco Sacchi + */ + + +#include +#include + +#include +#include +#include + +#define TEST_LEN 31 +#define ALLOC_SIZE 113 + +HEAP_DEFINE_BUF(heap_buf, 4027); +STATIC_ASSERT(sizeof(heap_buf) % sizeof(heap_buf_t) == 0); + +Heap h; + +int heap_testSetup(void) +{ + kdbg_init(); + heap_init(&h, heap_buf, sizeof(heap_buf)); + return 0; +} + +int heap_testRun(void) +{ + //Simple test + uint8_t *a[TEST_LEN]; + for (int i = 0; i < TEST_LEN; i++) + { + a[i] = heap_allocmem(&h, ALLOC_SIZE); + ASSERT(a[i]); + for (int j = 0; j < ALLOC_SIZE; j++) + a[i][j] = i; + } + + for (int i = 0; i < TEST_LEN; i++) + { + for (int j = 0; j < ALLOC_SIZE; j++) + { + kprintf("a[%d][%d] = %d\n", i, j, a[i][j]); + ASSERT(a[i][j] == i); + } + heap_freemem(&h, a[i], ALLOC_SIZE); + } + + return 0; +} + +int heap_testTearDown(void) +{ + return 0; +} + +TEST_MAIN(heap); diff --git a/test/run_tests.sh b/test/run_tests.sh index 8ffa6650..ed6ee007 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -47,6 +47,7 @@ SRC_LIST=" bertos/mware/sprintf.c bertos/os/hptime.c bertos/struct/kfile_fifo.c + bertos/struct/heap.c bertos/fs/fatfs/ff.c bertos/emul/diskio_emul.c bertos/fs/fat.c -- 2.25.1