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/testdyn.c | |
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/testdyn.c')
-rw-r--r-- | test/testdyn.c | 66 |
1 files changed, 36 insertions, 30 deletions
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
};
|