aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-04-19 09:23:49 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-04-19 09:23:49 +0000
commitc031b80726d1472098bb6e352eba561e3ab2e766 (patch)
treec4aea2cf7f50ff1227239843b788cf3f4d716b57
parent8a83ae1bb9db8b0e25d6b1cc899fec54bfe8fbf8 (diff)
downloadChibiOS-c031b80726d1472098bb6e352eba561e3ab2e766.tar.gz
ChibiOS-c031b80726d1472098bb6e352eba561e3ab2e766.tar.bz2
ChibiOS-c031b80726d1472098bb6e352eba561e3ab2e766.zip
100% code coverage for mailboxes.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@916 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--test/testmbox.c61
1 files changed, 49 insertions, 12 deletions
diff --git a/test/testmbox.c b/test/testmbox.c
index 4a548105c..14e594b29 100644
--- a/test/testmbox.c
+++ b/test/testmbox.c
@@ -43,10 +43,14 @@ static void mbox1_execute(void) {
msg_t msg1, msg2;
unsigned i;
- /* Testing initial space.*/
+ /*
+ * Testing initial space.
+ */
test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#1");
- /* Testing enqueuing.*/
+ /*
+ * Testing enqueuing and backward circularity.
+ */
for (i = 0; i < MB_SIZE - 1; i++) {
msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#2");
@@ -54,16 +58,22 @@ static void mbox1_execute(void) {
msg1 = chMBPostAhead(&mb1, 'A', TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#3");
- /* Testing post timeout.*/
+ /*
+ * Testing post timeout.
+ */
msg1 = chMBPost(&mb1, 'X', 1);
test_assert(msg1 == RDY_TIMEOUT, "#4");
- /* Testing final conditions.*/
+ /*
+ * 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.*/
+ /*
+ * Testing dequeuing.
+ */
for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#8");
@@ -71,14 +81,41 @@ static void mbox1_execute(void) {
}
test_assert_sequence("ABCDE");
- /* Testing fetch timeout.*/
- msg1 = chMBFetch(&mb1, &msg2, 1);
- test_assert(msg1 == RDY_TIMEOUT, "#9");
+ /*
+ * Testing buffer circularity.
+ */
+ msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE);
+ test_assert(msg1 == RDY_OK, "#9");
+ msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE);
+ test_assert(msg1 == RDY_OK, "#10");
+ test_assert(mb1.mb_buffer == mb1.mb_wrptr, "#11");
+ test_assert(mb1.mb_buffer == mb1.mb_rdptr, "#12");
- /* 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");
+ /*
+ * Testing fetch timeout.
+ */
+ msg1 = chMBFetch(&mb1, &msg2, 1);
+ test_assert(msg1 == RDY_TIMEOUT, "#13");
+
+ /*
+ * Testing final conditions.
+ */
+ test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#14");
+ test_assert(chMBGetFull(&mb1) == 0, "#15");
+ test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#16");
+
+ /*
+ * Testing reset.
+ */
+ chMBReset(&mb1);
+
+ /*
+ * Re-testing final conditions.
+ */
+ test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#17");
+ test_assert(chMBGetFull(&mb1) == 0, "#18");
+ test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#19");
+ test_assert(mb1.mb_buffer == mb1.mb_wrptr, "#20");
}
const struct testcase testmbox1 = {