diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-10-16 17:45:19 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-10-16 17:45:19 +0000 |
commit | 2c46df1916a25b7880416aee974a518cc607717a (patch) | |
tree | 87cac3a4daccc11dcfa281e2f59fa866ae257bc1 /test | |
parent | 8da7f367eeb3dc4dd71a10f7e7f18efe785c554f (diff) | |
download | ChibiOS-2c46df1916a25b7880416aee974a518cc607717a.tar.gz ChibiOS-2c46df1916a25b7880416aee974a518cc607717a.tar.bz2 ChibiOS-2c46df1916a25b7880416aee974a518cc607717a.zip |
New heap manager.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1221 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
-rw-r--r-- | test/test.c | 8 | ||||
-rw-r--r-- | test/test.h | 17 | ||||
-rw-r--r-- | test/testdyn.c | 66 | ||||
-rw-r--r-- | test/testheap.c | 119 | ||||
-rw-r--r-- | test/testmbox.c | 4 | ||||
-rw-r--r-- | test/testqueues.c | 4 |
6 files changed, 114 insertions, 104 deletions
diff --git a/test/test.c b/test/test.c index 434ef1b8c..bbeb9adc4 100644 --- a/test/test.c +++ b/test/test.c @@ -59,11 +59,7 @@ static char *tokp; * Static working areas, the following areas can be used for threads or
* used as temporary buffers. */
-WORKING_AREA(waT0, THREADS_STACK_SIZE);
-WORKING_AREA(waT1, THREADS_STACK_SIZE);
-WORKING_AREA(waT2, THREADS_STACK_SIZE);
-WORKING_AREA(waT3, THREADS_STACK_SIZE);
-WORKING_AREA(waT4, THREADS_STACK_SIZE);
+union test_buffers test;
/*
* Pointers to the spawned threads. @@ -73,7 +69,7 @@ Thread *threads[MAX_THREADS]; /*
* Pointers to the working areas. */
-void * const wa[5] = {waT0, waT1, waT2, waT3, waT4};
+void * const wa[5] = {test.waT0, test.waT1, test.waT2, test.waT3, test.waT4};
/*
* Console output.
diff --git a/test/test.h b/test/test.h index fca9da8b1..7b261b553 100644 --- a/test/test.h +++ b/test/test.h @@ -47,6 +47,17 @@ struct testcase { void (*execute)(void);
};
+union test_buffers {
+ struct {
+ WORKING_AREA(waT0, THREADS_STACK_SIZE);
+ WORKING_AREA(waT1, THREADS_STACK_SIZE);
+ WORKING_AREA(waT2, THREADS_STACK_SIZE);
+ WORKING_AREA(waT3, THREADS_STACK_SIZE);
+ WORKING_AREA(waT4, THREADS_STACK_SIZE);
+ };
+ uint8_t buffer[WA_SIZE * 5];
+};
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -94,11 +105,7 @@ extern "C" { }
extern Thread *threads[MAX_THREADS];
-extern WORKING_AREA(waT0, THREADS_STACK_SIZE);
-extern WORKING_AREA(waT1, THREADS_STACK_SIZE);
-extern WORKING_AREA(waT2, THREADS_STACK_SIZE);
-extern WORKING_AREA(waT3, THREADS_STACK_SIZE);
-extern WORKING_AREA(waT4, THREADS_STACK_SIZE);
+extern union test_buffers test;
extern void * const wa[];
extern bool_t test_timer_done;
diff --git a/test/testdyn.c b/test/testdyn.c index 44e6ffaa4..07c3f92a0 100644 --- a/test/testdyn.c +++ b/test/testdyn.c @@ -70,50 +70,56 @@ static msg_t thread(void *p) { }
#if CH_USE_HEAP
+
+static MemoryHeap heap1;
+
static char *dyn1_gettest(void) {
return "Dynamic APIs, threads creation from heap";
}
+static void dyn1_setup(void) {
+
+ chHeapInit(&heap1, test.buffer, sizeof(union test_buffers));
+}
+
static void dyn1_execute(void) {
size_t n, sz;
void *p1;
tprio_t prio = chThdGetPriority();
- /* Test skipped if the heap is already fragmented. */
- if ((n = chHeapStatus(&sz)) == 1) {
- /* Starting threads from the heap. */
- threads[0] = chThdCreateFromHeap(THD_WA_SIZE(THREADS_STACK_SIZE),
- prio-1, thread, "A");
- threads[1] = chThdCreateFromHeap(THD_WA_SIZE(THREADS_STACK_SIZE),
- prio-2, thread, "B");
- /* Allocating the whole heap in order to make the thread creation fail.*/
- (void)chHeapStatus(&n);
- p1 = chHeapAlloc(n);
- threads[2] = chThdCreateFromHeap(THD_WA_SIZE(THREADS_STACK_SIZE),
- prio-3, thread, "C");
- chHeapFree(p1);
-
- test_assert(1, (threads[0] != NULL) &&
- (threads[1] != NULL) &&
- (threads[2] == NULL) &&
- (threads[3] == NULL) &&
- (threads[4] == NULL),
- "thread creation failed");
-
- /* Claiming the memory from terminated threads. */
- test_wait_threads();
- test_assert_sequence(2, "AB");
-
- /* Heap status checked again.*/
- test_assert(3, chHeapStatus(&n) == 1, "heap fragmented");
- test_assert(4, n == sz, "heap size changed");
- }
+ (void)chHeapStatus(&heap1, &sz);
+ /* Starting threads from the heap. */
+ threads[0] = chThdCreateFromHeap(&heap1, THD_WA_SIZE(THREADS_STACK_SIZE),
+ prio-1, thread, "A");
+ threads[1] = chThdCreateFromHeap(&heap1, THD_WA_SIZE(THREADS_STACK_SIZE),
+ prio-2, thread, "B");
+ /* Allocating the whole heap in order to make the thread creation fail.*/
+ (void)chHeapStatus(&heap1, &n);
+ p1 = chHeapAlloc(&heap1, n);
+ threads[2] = chThdCreateFromHeap(&heap1, THD_WA_SIZE(THREADS_STACK_SIZE),
+ prio-3, thread, "C");
+ chHeapFree(p1);
+
+ test_assert(1, (threads[0] != NULL) &&
+ (threads[1] != NULL) &&
+ (threads[2] == NULL) &&
+ (threads[3] == NULL) &&
+ (threads[4] == NULL),
+ "thread creation failed");
+
+ /* Claiming the memory from terminated threads. */
+ test_wait_threads();
+ test_assert_sequence(2, "AB");
+
+ /* Heap status checked again.*/
+ test_assert(3, chHeapStatus(&heap1, &n) == 1, "heap fragmented");
+ test_assert(4, n == sz, "heap size changed");
}
const struct testcase testdyn1 = {
dyn1_gettest,
- NULL,
+ dyn1_setup,
NULL,
dyn1_execute
};
diff --git a/test/testheap.c b/test/testheap.c index 6e68c11be..6545893ce 100644 --- a/test/testheap.c +++ b/test/testheap.c @@ -50,6 +50,8 @@ #define SIZE 16
+static MemoryHeap test_heap;
+
/**
* @page test_heap_001 Allocation and fragmentation test
*
@@ -66,74 +68,73 @@ static char *heap1_gettest(void) { return "Heap, allocation and fragmentation test";
}
+static void heap1_setup(void) {
+
+ chHeapInit(&test_heap, test.buffer, sizeof(union test_buffers));
+}
+
static void heap1_execute(void) {
void *p1, *p2, *p3;
size_t n, sz;
/* Test skipped if the heap is already fragmented. */
- if ((n = chHeapStatus(&sz)) == 1) {
- test_print("--- Size : ");
- test_printn(sz);
- test_println(" bytes, not fragmented");
-
- /* Same order */
- p1 = chHeapAlloc(SIZE);
- p2 = chHeapAlloc(SIZE);
- p3 = chHeapAlloc(SIZE);
- chHeapFree(p1); /* Does not merge */
- chHeapFree(p2); /* Merges backward */
- chHeapFree(p3); /* Merges both sides */
- test_assert(1, chHeapStatus(&n) == 1, "heap fragmented");
-
- /* Reverse order */
- p1 = chHeapAlloc(SIZE);
- p2 = chHeapAlloc(SIZE);
- p3 = chHeapAlloc(SIZE);
- chHeapFree(p3); /* Merges forward */
- chHeapFree(p2); /* Merges forward */
- chHeapFree(p1); /* Merges forward */
- test_assert(2, chHeapStatus(&n) == 1, "heap fragmented");
-
- /* Small fragments handling */
- p1 = chHeapAlloc(SIZE + 1);
- p2 = chHeapAlloc(SIZE);
- chHeapFree(p1);
- test_assert(3, chHeapStatus(&n) == 2, "invalid state");
- p1 = chHeapAlloc(SIZE);
- test_assert(4, chHeapStatus(&n) == 1, "heap fragmented");
- chHeapFree(p2);
- chHeapFree(p1);
- test_assert(5, chHeapStatus(&n) == 1, "heap fragmented");
-
- /* Skip fragment handling */
- p1 = chHeapAlloc(SIZE);
- p2 = chHeapAlloc(SIZE);
- chHeapFree(p1);
- test_assert(6, chHeapStatus(&n) == 2, "invalid state");
- p1 = chHeapAlloc(SIZE * 2); /* Skips first fragment */
- chHeapFree(p1);
- chHeapFree(p2);
- test_assert(7, chHeapStatus(&n) == 1, "heap fragmented");
-
- /* Allocate all handling */
- (void)chHeapStatus(&n);
- p1 = chHeapAlloc(n);
- test_assert(8, chHeapStatus(&n) == 0, "not empty");
- chHeapFree(p1);
-
- test_assert(9, chHeapStatus(&n) == 1, "heap fragmented");
- test_assert(10, n == sz, "size changed");
- }
- else {
- test_print("--- Size : ");
- test_printn(sz);
- test_println(" bytes, fragmented, test skipped");
- }
+ (void)chHeapStatus(&test_heap, &sz);
+ test_print("--- Size : ");
+ test_printn(sz);
+ test_println(" bytes");
+
+ /* Same order */
+ p1 = chHeapAlloc(&test_heap, SIZE);
+ p2 = chHeapAlloc(&test_heap, SIZE);
+ p3 = chHeapAlloc(&test_heap, SIZE);
+ chHeapFree(p1); /* Does not merge */
+ chHeapFree(p2); /* Merges backward */
+ chHeapFree(p3); /* Merges both sides */
+ test_assert(1, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+
+ /* Reverse order */
+ p1 = chHeapAlloc(&test_heap, SIZE);
+ p2 = chHeapAlloc(&test_heap, SIZE);
+ p3 = chHeapAlloc(&test_heap, SIZE);
+ chHeapFree(p3); /* Merges forward */
+ chHeapFree(p2); /* Merges forward */
+ chHeapFree(p1); /* Merges forward */
+ test_assert(2, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+
+ /* Small fragments handling */
+ p1 = chHeapAlloc(&test_heap, SIZE + 1);
+ p2 = chHeapAlloc(&test_heap, SIZE);
+ chHeapFree(p1);
+ test_assert(3, chHeapStatus(&test_heap, &n) == 2, "invalid state");
+ p1 = chHeapAlloc(&test_heap, SIZE);
+ test_assert(4, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+ chHeapFree(p2);
+ chHeapFree(p1);
+ test_assert(5, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+
+ /* Skip fragment handling */
+ p1 = chHeapAlloc(&test_heap, SIZE);
+ p2 = chHeapAlloc(&test_heap, SIZE);
+ chHeapFree(p1);
+ test_assert(6, chHeapStatus(&test_heap, &n) == 2, "invalid state");
+ p1 = chHeapAlloc(&test_heap, SIZE * 2); /* Skips first fragment */
+ chHeapFree(p1);
+ chHeapFree(p2);
+ test_assert(7, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+
+ /* Allocate all handling */
+ (void)chHeapStatus(&test_heap, &n);
+ p1 = chHeapAlloc(&test_heap, n);
+ test_assert(8, chHeapStatus(&test_heap, &n) == 0, "not empty");
+ chHeapFree(p1);
+
+ test_assert(9, chHeapStatus(&test_heap, &n) == 1, "heap fragmented");
+ test_assert(10, n == sz, "size changed");
}
const struct testcase testheap1 = {
heap1_gettest,
- NULL,
+ heap1_setup,
NULL,
heap1_execute
};
diff --git a/test/testmbox.c b/test/testmbox.c index 96cf543ce..3c23cf937 100644 --- a/test/testmbox.c +++ b/test/testmbox.c @@ -59,7 +59,7 @@ * variables are explicitly initialized in each test case. It is done in order
* to test the macros.
*/
-static MAILBOX_DECL(mb1, waT0, MB_SIZE);
+static MAILBOX_DECL(mb1, test.waT0, MB_SIZE);
/**
* @page test_mbox_001 Queuing and timeouts
@@ -77,7 +77,7 @@ static char *mbox1_gettest(void) { static void mbox1_setup(void) {
- chMBInit(&mb1, (msg_t *)waT0, MB_SIZE);
+ chMBInit(&mb1, (msg_t *)test.waT0, MB_SIZE);
}
static void mbox1_execute(void) {
diff --git a/test/testqueues.c b/test/testqueues.c index aff42334c..e5e3a4c0b 100644 --- a/test/testqueues.c +++ b/test/testqueues.c @@ -63,8 +63,8 @@ static void notify(void) {} * variables are explicitly initialized in each test case. It is done in order
* to test the macros.
*/
-static INPUTQUEUE_DECL(iq, waT0, TEST_QUEUES_SIZE, notify);
-static OUTPUTQUEUE_DECL(oq, waT0, TEST_QUEUES_SIZE, notify);
+static INPUTQUEUE_DECL(iq, test.waT0, TEST_QUEUES_SIZE, notify);
+static OUTPUTQUEUE_DECL(oq, test.waT1, TEST_QUEUES_SIZE, notify);
/**
* @page test_queues_001 Input Queues functionality and APIs
|