aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test.c2
-rw-r--r--test/test.mk4
-rw-r--r--test/testcond.c4
-rw-r--r--test/testdyn.c12
-rw-r--r--test/testevt.c16
-rw-r--r--test/testheap.c6
-rw-r--r--test/testmbox.c101
-rw-r--r--test/testmbox.h25
-rw-r--r--test/testmtx.c2
-rw-r--r--test/testpools.c4
-rw-r--r--test/testsem.c4
11 files changed, 154 insertions, 26 deletions
diff --git a/test/test.c b/test/test.c
index ed9b04b91..15e23e79c 100644
--- a/test/test.c
+++ b/test/test.c
@@ -25,6 +25,7 @@
#include "testmtx.h"
#include "testcond.h"
#include "testmsg.h"
+#include "testmbox.h"
#include "testevt.h"
#include "testheap.h"
#include "testpools.h"
@@ -40,6 +41,7 @@ static const struct testcase **patterns[] = {
patternmtx,
patterncond,
patternmsg,
+ patternmbox,
patternevt,
patternheap,
patternpools,
diff --git a/test/test.mk b/test/test.mk
index 100b3d0ed..6cce48f2a 100644
--- a/test/test.mk
+++ b/test/test.mk
@@ -1,8 +1,8 @@
# List of all the ChibiOS/RT test files.
TESTSRC = ../../test/test.c ../../test/testrdy.c ../../test/testsem.c \
../../test/testmtx.c ../../test/testcond.c ../../test/testmsg.c \
- ../../test/testevt.c ../../test/testheap.c ../../test/testpools.c \
- ../../test/testdyn.c ../../test/testbmk.c
+ ../../test/testmbox.c ../../test/testevt.c ../../test/testheap.c \
+ ../../test/testpools.c ../../test/testdyn.c ../../test/testbmk.c
# Required include directories
TESTINC = ../../test
diff --git a/test/testcond.c b/test/testcond.c
index 2771b5202..692ec88d2 100644
--- a/test/testcond.c
+++ b/test/testcond.c
@@ -55,7 +55,7 @@ static void cond1_execute(void) {
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, prio+3, thread1, "C");
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, prio+4, thread1, "B");
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread1, "A");
- test_assert(prio == chThdGetPriority(), "priority return failure");
+ test_assert(prio == chThdGetPriority(), "#1"); /* Priority return failure.*/
chCondSignal(&c1);
chCondSignal(&c1);
chCondSignal(&c1);
@@ -86,7 +86,7 @@ static void cond2_execute(void) {
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, prio+3, thread1, "C");
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, prio+4, thread1, "B");
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread1, "A");
- test_assert(prio == chThdGetPriority(), "priority return failure");
+ test_assert(prio == chThdGetPriority(), "#1"); /* Priority return failure.*/
chCondBroadcast(&c1);
test_wait_threads();
test_assert_sequence("ABCDE");
diff --git a/test/testdyn.c b/test/testdyn.c
index 07b07594c..775e3c795 100644
--- a/test/testdyn.c
+++ b/test/testdyn.c
@@ -52,15 +52,15 @@ static void dyn1_execute(void) {
(threads[2] == NULL) &&
(threads[3] == NULL) &&
(threads[4] == NULL),
- "thread creation failed");
+ "#1"); /* Thread creation failed.*/
/* Claiming the memory from terminated threads. */
test_wait_threads();
test_assert_sequence("AB");
/* Heap status checked again.*/
- test_assert(chHeapStatus(&n) == 1, "heap fragmented");
- test_assert(n == sz, "heap size changed");
+ test_assert(chHeapStatus(&n) == 1, "#2"); /* Heap fragmented.*/
+ test_assert(n == sz, "#3"); /* Heap size changed.*/
}
}
@@ -105,7 +105,7 @@ static void dyn2_execute(void) {
(threads[2] != NULL) &&
(threads[3] != NULL) &&
(threads[4] != NULL),
- "thread creation failed");
+ "#1"); /* Thread creation failed.*/
/* Claiming the memory from terminated threads. */
test_wait_threads();
@@ -113,8 +113,8 @@ static void dyn2_execute(void) {
/* Now the pool must be full again. */
for (i = 0; i < 5; i++)
- test_assert(chPoolAlloc(&mp1) != NULL, "pool list empty");
- test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty");
+ test_assert(chPoolAlloc(&mp1) != NULL, "#2"); /* Pool list empty.*/
+ test_assert(chPoolAlloc(&mp1) == NULL, "#3"); /* Pool list not empty.*/
}
const struct testcase testdyn2 = {
diff --git a/test/testevt.c b/test/testevt.c
index 89c5cf114..7af8b7b73 100644
--- a/test/testevt.c
+++ b/test/testevt.c
@@ -55,20 +55,20 @@ static void evt1_execute(void) {
*/
chEvtPend(5);
m = chEvtWaitOne(ALL_EVENTS);
- test_assert(m == 1, "chEvtWaitOne() error");
+ test_assert(m == 1, "#1"); /* Single bit error.*/
m = chEvtWaitOne(ALL_EVENTS);
- test_assert(m == 4, "chEvtWaitOne() error");
+ test_assert(m == 4, "#2"); /* Single bit error.*/
m = chEvtClear(0);
- test_assert(m == 0, "stuck event");
+ test_assert(m == 0, "#3"); /* Stuck event.*/
/*
* Test on chEvtWaitAny().
*/
chEvtPend(5);
m = chEvtWaitAny(ALL_EVENTS);
- test_assert(m == 5, "chEvtWaitAny() error");
+ test_assert(m == 5, "#4"); /* Unexpected pending.*/
m = chEvtClear(0);
- test_assert(m == 0, "stuck event");
+ test_assert(m == 0, "#5"); /* Stuck event.*/
/*
* Test on chEvtWaitAll(), chEvtRegisterMask() and chEvtUnregister().
@@ -82,13 +82,13 @@ static void evt1_execute(void) {
m = chEvtWaitAll(5);
test_assert_time_window(target_time, target_time + ALLOWED_DELAY);
m = chEvtClear(0);
- test_assert(m == 0, "stuck event");
+ test_assert(m == 0, "#6"); /* Stuck event.*/
test_wait_threads();
chEvtUnregister(&es1, &el1);
chEvtUnregister(&es2, &el2);
- test_assert(!chEvtIsListening(&es1), "stuck listener");
- test_assert(!chEvtIsListening(&es2), "stuck listener");
+ test_assert(!chEvtIsListening(&es1), "#7"); /* Stuck listener.*/
+ test_assert(!chEvtIsListening(&es2), "#8"); /* Stuck listener.*/
}
const struct testcase testevt1 = {
diff --git a/test/testheap.c b/test/testheap.c
index 841c084e8..0a84b7b33 100644
--- a/test/testheap.c
+++ b/test/testheap.c
@@ -47,7 +47,7 @@ static void heap1_execute(void) {
chHeapFree(p1); /* Does not merge */
chHeapFree(p2); /* Merges backward */
chHeapFree(p3); /* Merges both sides */
- test_assert(chHeapStatus(&n) == 1, "heap fragmented #1");
+ test_assert(chHeapStatus(&n) == 1, "#1"); /* Heap fragmented.*/
/* Reverse order */
p1 = chHeapAlloc(SIZE);
@@ -56,9 +56,9 @@ static void heap1_execute(void) {
chHeapFree(p3); /* Merges forward */
chHeapFree(p2); /* Merges forward */
chHeapFree(p1); /* Merges forward */
- test_assert(chHeapStatus(&n) == 1, "heap fragmented #2");
+ test_assert(chHeapStatus(&n) == 1, "#2"); /* Heap fragmented.*/
- test_assert(n == sz, "heap size changed");
+ test_assert(n == sz, "#3"); /* Heap size changed.*/
}
else {
test_print("--- Size : ");
diff --git a/test/testmbox.c b/test/testmbox.c
new file mode 100644
index 000000000..7ab3f6126
--- /dev/null
+++ b/test/testmbox.c
@@ -0,0 +1,101 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <ch.h>
+
+#include "test.h"
+
+#if CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT
+
+#define ALLOWED_DELAY MS2ST(5)
+#define MB_SIZE 5
+
+static msg_t mb1_buf[MB_SIZE];
+static Mailbox mb1;
+
+static char *mbox1_gettest(void) {
+
+ return "Mailboxes, queuing and timeouts";
+}
+
+static void mbox1_setup(void) {
+
+ chMBInit(&mb1, mb1_buf, MB_SIZE);
+}
+
+static void mbox1_execute(void) {
+ msg_t msg1, msg2;
+ unsigned i;
+
+ /* Testing initial space.*/
+ test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#1");
+
+ /* Testing enqueuing.*/
+ for (i = 0; i < MB_SIZE - 1; i++) {
+ msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE);
+ test_assert(msg1 == RDY_OK, "#2");
+ }
+ msg1 = chMBPostAhead(&mb1, 'A', TIME_INFINITE);
+ test_assert(msg1 == RDY_OK, "#3");
+
+ /* Testing post timeout.*/
+ msg1 = chMBPost(&mb1, 'X', 1);
+ test_assert(msg1 == RDY_TIMEOUT, "#4");
+
+ /* Testing final conditions.*/
+ test_assert(chMBGetEmpty(&mb1) == 0, "#5");
+ test_assert(chMBGetFull(&mb1) == MB_SIZE, "#6");
+ test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#7");
+
+ /* Testing dequeuing.*/
+ for (i = 0; i < MB_SIZE; i++) {
+ msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE);
+ test_assert(msg1 == RDY_OK, "#8");
+ test_emit_token(msg2);
+ }
+ test_assert_sequence("ABCDE");
+
+ /* Testing fetch timeout.*/
+ msg1 = chMBFetch(&mb1, &msg2, 1);
+ test_assert(msg1 == RDY_TIMEOUT, "#9");
+
+ /* Testing final conditions.*/
+ test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#10");
+ test_assert(chMBGetFull(&mb1) == 0, "#11");
+ test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#12");
+}
+
+const struct testcase testmbox1 = {
+ mbox1_gettest,
+ mbox1_setup,
+ NULL,
+ mbox1_execute
+};
+
+#endif /* CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT */
+
+/*
+ * Test sequence for mailboxes pattern.
+ */
+const struct testcase *patternmbox[] = {
+#if CH_USE_MAILBOXES && CH_USE_SEMAPHORES_TIMEOUT
+ &testmbox1,
+#endif
+ NULL
+};
diff --git a/test/testmbox.h b/test/testmbox.h
new file mode 100644
index 000000000..52cb7ee18
--- /dev/null
+++ b/test/testmbox.h
@@ -0,0 +1,25 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _TESTMBOX_H_
+#define _TESTMBOX_H_
+
+extern const struct testcase *patternmbox[];
+
+#endif /* _TESTMBOX_H_ */
diff --git a/test/testmtx.c b/test/testmtx.c
index 6bef57041..685361bba 100644
--- a/test/testmtx.c
+++ b/test/testmtx.c
@@ -56,7 +56,7 @@ static void mtx1_execute(void) {
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread1, "A");
chMtxUnlock();
test_wait_threads();
- test_assert(prio == chThdGetPriority(), "priority return failure");
+ test_assert(prio == chThdGetPriority(), "#1"); /* Priority return failure.*/
test_assert_sequence("ABCDE");
}
diff --git a/test/testpools.c b/test/testpools.c
index fae7402c3..759a28c44 100644
--- a/test/testpools.c
+++ b/test/testpools.c
@@ -44,10 +44,10 @@ static void pools1_execute(void) {
/* Empting the pool again. */
for (i = 0; i < MAX_THREADS; i++)
- test_assert(chPoolAlloc(&mp1) != NULL, "pool list empty");
+ test_assert(chPoolAlloc(&mp1) != NULL, "#1"); /* Pool list empty.*/
/* Now must be empty. */
- test_assert(chPoolAlloc(&mp1) == NULL, "pool list not empty");
+ test_assert(chPoolAlloc(&mp1) == NULL, "#2"); /* Pool list not empty.*/
}
const struct testcase testpools1 = {
diff --git a/test/testsem.c b/test/testsem.c
index c582d9531..35e37d965 100644
--- a/test/testsem.c
+++ b/test/testsem.c
@@ -86,8 +86,8 @@ static void sem2_execute(void) {
for (i = 0; i < 5; i++) {
test_emit_token('A' + i);
chSemWaitTimeout(&sem1, MS2ST(500));
- test_assert(isempty(&sem1.s_queue), "queue not empty");
- test_assert(&sem1.s_cnt != 0, "counter not zero");
+ test_assert(isempty(&sem1.s_queue), "#1"); /* Queue not empty */
+ test_assert(&sem1.s_cnt != 0, "#2"); /* Counter not zero */
}
test_assert_sequence("ABCDE");
test_assert_time_window(target_time, target_time + ALLOWED_DELAY);