diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-05-08 10:30:38 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-05-08 10:30:38 +0000 |
commit | 691538eb399e9a0ca1e8ed86699c58e3022d6fd5 (patch) | |
tree | 800f8949f27d84d45e38201a6aeb62612cfea68a /test | |
parent | dd0dcbb957c69dd08ab2d4b4eb1b7543e4c6aad8 (diff) | |
download | ChibiOS-691538eb399e9a0ca1e8ed86699c58e3022d6fd5.tar.gz ChibiOS-691538eb399e9a0ca1e8ed86699c58e3022d6fd5.tar.bz2 ChibiOS-691538eb399e9a0ca1e8ed86699c58e3022d6fd5.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1909 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
-rw-r--r-- | test/testdyn.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/test/testdyn.c b/test/testdyn.c index dcd2d951e..345076828 100644 --- a/test/testdyn.c +++ b/test/testdyn.c @@ -53,6 +53,12 @@ */
#if CH_USE_DYNAMIC
+#if CH_USE_HEAP
+static MemoryHeap heap1;
+#endif
+#if CH_USE_MEMPOOLS
+static MemoryPool mp1;
+#endif
/**
* @page test_dynamic_001 Threads creation from Memory Heap
@@ -72,9 +78,6 @@ 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";
@@ -138,8 +141,6 @@ const struct testcase testdyn1 = { * one to fail.
*/
-static MemoryPool mp1;
-
static char *dyn2_gettest(void) {
return "Dynamic APIs, threads creation from memory pool";
@@ -190,7 +191,7 @@ const struct testcase testdyn2 = { };
#endif /* CH_USE_MEMPOOLS */
-#if CH_USE_HEAP
+#if CH_USE_HEAP && CH_USE_REGISTRY
/**
* @page test_dynamic_003 Registry and References test
*
@@ -223,6 +224,7 @@ static void dyn3_setup(void) { static void dyn3_execute(void) {
unsigned n1, n2, n3;
+ Thread *tp;
tprio_t prio = chThdGetPriority();
/* Current number of threads in the system, two times just in case some
@@ -231,23 +233,22 @@ static void dyn3_execute(void) { n1 = regscan();
/* Testing references increase/decrease and final detach.*/
- threads[0] = chThdCreateFromHeap(&heap1, THD_WA_SIZE(THREADS_STACK_SIZE),
- prio-1, thread, "A");
- test_assert(1, threads[0]->p_refs == 1, "wrong initial reference counter");
- chThdAddRef(threads[0]);
- test_assert(2, threads[0]->p_refs == 2, "references increase failure");
- chThdRelease(threads[0]);
- test_assert(3, threads[0]->p_refs == 1, "references decrease failure");
+ tp = chThdCreateFromHeap(&heap1, WA_SIZE, prio-1, thread, "A");
+ test_assert(1, tp->p_refs == 1, "wrong initial reference counter");
+ chThdAddRef(tp);
+ test_assert(2, tp->p_refs == 2, "references increase failure");
+ chThdRelease(tp);
+ test_assert(3, tp->p_refs == 1, "references decrease failure");
/* Verify the new threads count.*/
n2 = regscan();
test_assert(4, n1 == n2 - 1, "unexpected threads count");
/* Detach and let the thread execute and terminate.*/
- chThdRelease(threads[0]);
- test_assert(5, threads[0]->p_refs == 0, "detach failure");
+ chThdRelease(tp);
+ test_assert(5, tp->p_refs == 0, "detach failure");
chThdSleepMilliseconds(50); /* The thread just terminates. */
- test_assert(6, threads[0]->p_state == THD_STATE_FINAL, "invalid state");
+ test_assert(6, tp->p_state == THD_STATE_FINAL, "invalid state");
/* Clearing the zombie by scanning the registry.*/
n3 = regscan();
@@ -260,7 +261,7 @@ const struct testcase testdyn3 = { NULL,
dyn3_execute
};
-#endif /* CH_USE_HEAP */
+#endif /* CH_USE_HEAP && CH_USE_REGISTRY */
#endif /* CH_USE_DYNAMIC */
/**
@@ -274,7 +275,7 @@ const struct testcase * const patterndyn[] = { #if CH_USE_MEMPOOLS
&testdyn2,
#endif
-#if CH_USE_HEAP
+#if CH_USE_HEAP && CH_USE_REGISTRY
&testdyn3,
#endif
#endif
|