diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-08-12 11:10:19 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-08-12 11:10:19 +0000 |
commit | 43752ee8d132fc57028a9ff15156c5bfcd81c013 (patch) | |
tree | eb4a8eafaaac4084e1c0c307850a8ce17939e58f /test | |
parent | e0309ba9738efc707f8c43de43e04d2c62a32e8c (diff) | |
download | ChibiOS-43752ee8d132fc57028a9ff15156c5bfcd81c013.tar.gz ChibiOS-43752ee8d132fc57028a9ff15156c5bfcd81c013.tar.bz2 ChibiOS-43752ee8d132fc57028a9ff15156c5bfcd81c013.zip |
Extended state check to all kernel I-class and s-class APIs, corrected some test cases where call protocol rules were not strictly observerd. No the whole test suite pass with the state checker enabled.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3223 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
-rw-r--r-- | test/test.h | 16 | ||||
-rw-r--r-- | test/testbmk.c | 2 | ||||
-rw-r--r-- | test/testmbox.c | 34 | ||||
-rw-r--r-- | test/testqueues.c | 52 | ||||
-rw-r--r-- | test/testsem.c | 2 |
5 files changed, 78 insertions, 28 deletions
diff --git a/test/test.h b/test/test.h index 31806fddb..b1fd311e6 100644 --- a/test/test.h +++ b/test/test.h @@ -127,6 +127,22 @@ extern "C" { }
/**
+ * @brief Test assertion with lock.
+ *
+ * @param[in] point numeric assertion identifier
+ * @param[in] condition a boolean expression that must be verified to be true
+ * @param[in] msg failure message
+ */
+#define test_assert_lock(point, condition, msg) { \
+ chSysLock(); \
+ if (_test_assert(point, condition)) { \
+ chSysUnlock(); \
+ return; \
+ } \
+ chSysUnlock(); \
+}
+
+/**
* @brief Test sequence assertion.
*
* @param[in] point numeric assertion identifier
diff --git a/test/testbmk.c b/test/testbmk.c index 54da81fd8..4958ddf8b 100644 --- a/test/testbmk.c +++ b/test/testbmk.c @@ -465,10 +465,12 @@ static void bmk9_execute(void) { test_wait_tick();
test_start_timer(1000);
do {
+ chSysLock();
chIQPutI(&iq, 0);
chIQPutI(&iq, 1);
chIQPutI(&iq, 2);
chIQPutI(&iq, 3);
+ chSysUnlock();
(void)chIQGet(&iq);
(void)chIQGet(&iq);
(void)chIQGet(&iq);
diff --git a/test/testmbox.c b/test/testmbox.c index 8797536c6..86b9febb4 100644 --- a/test/testmbox.c +++ b/test/testmbox.c @@ -101,19 +101,23 @@ static void mbox1_execute(void) { */
msg1 = chMBPost(&mb1, 'X', 1);
test_assert(4, msg1 == RDY_TIMEOUT, "wrong wake-up message");
+ chSysLock();
msg1 = chMBPostI(&mb1, 'X');
+ chSysUnlock();
test_assert(5, msg1 == RDY_TIMEOUT, "wrong wake-up message");
msg1 = chMBPostAhead(&mb1, 'X', 1);
test_assert(6, msg1 == RDY_TIMEOUT, "wrong wake-up message");
+ chSysLock();
msg1 = chMBPostAheadI(&mb1, 'X');
+ chSysUnlock();
test_assert(7, msg1 == RDY_TIMEOUT, "wrong wake-up message");
/*
* Testing final conditions.
*/
- test_assert(8, chMBGetFreeCountI(&mb1) == 0, "still empty");
- test_assert(9, chMBGetUsedCountI(&mb1) == MB_SIZE, "not full");
- test_assert(10, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
+ test_assert_lock(8, chMBGetFreeCountI(&mb1) == 0, "still empty");
+ test_assert_lock(9, chMBGetUsedCountI(&mb1) == MB_SIZE, "not full");
+ test_assert_lock(10, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
/*
* Testing dequeuing.
@@ -140,19 +144,22 @@ static void mbox1_execute(void) { */
msg1 = chMBFetch(&mb1, &msg2, 1);
test_assert(17, msg1 == RDY_TIMEOUT, "wrong wake-up message");
+ chSysLock();
msg1 = chMBFetchI(&mb1, &msg2);
+ chSysUnlock();
test_assert(18, msg1 == RDY_TIMEOUT, "wrong wake-up message");
/*
* Testing final conditions.
*/
- test_assert(19, chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
- test_assert(20, chMBGetUsedCountI(&mb1) == 0, "still full");
- test_assert(21, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
+ test_assert_lock(19, chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
+ test_assert_lock(20, chMBGetUsedCountI(&mb1) == 0, "still full");
+ test_assert_lock(21, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
/*
* Testing I-Class.
*/
+ chSysLock()
msg1 = chMBPostI(&mb1, 'A');
test_assert(22, msg1 == RDY_OK, "wrong wake-up message");
msg1 = chMBPostI(&mb1, 'B');
@@ -162,16 +169,20 @@ static void mbox1_execute(void) { msg1 = chMBPostI(&mb1, 'D');
test_assert(25, msg1 == RDY_OK, "wrong wake-up message");
msg1 = chMBPostI(&mb1, 'E');
+ chSysUnlock()
test_assert(26, msg1 == RDY_OK, "wrong wake-up message");
test_assert(27, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
for (i = 0; i < MB_SIZE; i++) {
+ chSysLock();
msg1 = chMBFetchI(&mb1, &msg2);
+ chSysUnlock();
test_assert(28, msg1 == RDY_OK, "wrong wake-up message");
test_emit_token(msg2);
}
test_assert_sequence(29, "ABCDE");
test_assert(30, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
+ chSysLock();
msg1 = chMBPostAheadI(&mb1, 'E');
test_assert(31, msg1 == RDY_OK, "wrong wake-up message");
msg1 = chMBPostAheadI(&mb1, 'D');
@@ -181,10 +192,13 @@ static void mbox1_execute(void) { msg1 = chMBPostAheadI(&mb1, 'B');
test_assert(34, msg1 == RDY_OK, "wrong wake-up message");
msg1 = chMBPostAheadI(&mb1, 'A');
+ chSysUnlock();
test_assert(35, msg1 == RDY_OK, "wrong wake-up message");
test_assert(36, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
for (i = 0; i < MB_SIZE; i++) {
+ chSysLock();
msg1 = chMBFetchI(&mb1, &msg2);
+ chSysUnlock();
test_assert(37, msg1 == RDY_OK, "wrong wake-up message");
test_emit_token(msg2);
}
@@ -199,10 +213,10 @@ static void mbox1_execute(void) { /*
* Re-testing final conditions.
*/
- test_assert(40, chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
- test_assert(41, chMBGetUsedCountI(&mb1) == 0, "still full");
- test_assert(42, mb1.mb_buffer == mb1.mb_wrptr, "write pointer not aligned to base");
- test_assert(43, mb1.mb_buffer == mb1.mb_rdptr, "read pointer not aligned to base");
+ test_assert_lock(40, chMBGetFreeCountI(&mb1) == MB_SIZE, "not empty");
+ test_assert_lock(41, chMBGetUsedCountI(&mb1) == 0, "still full");
+ test_assert_lock(42, mb1.mb_buffer == mb1.mb_wrptr, "write pointer not aligned to base");
+ test_assert_lock(43, mb1.mb_buffer == mb1.mb_rdptr, "read pointer not aligned to base");
}
ROMCONST struct testcase testmbox1 = {
diff --git a/test/testqueues.c b/test/testqueues.c index 55945761d..456598fa4 100644 --- a/test/testqueues.c +++ b/test/testqueues.c @@ -96,46 +96,54 @@ static void queues1_execute(void) { size_t n;
/* Initial empty state */
- test_assert(1, chIQIsEmptyI(&iq), "not empty");
+ test_assert_lock(1, chIQIsEmptyI(&iq), "not empty");
/* Queue filling */
+ chSysLock();
for (i = 0; i < TEST_QUEUES_SIZE; i++)
chIQPutI(&iq, 'A' + i);
- test_assert(2, chIQIsFullI(&iq), "still has space");
- test_assert(3, chIQPutI(&iq, 0) == Q_FULL, "failed to report Q_FULL");
+ chSysUnlock();
+ test_assert_lock(2, chIQIsFullI(&iq), "still has space");
+ test_assert_lock(3, chIQPutI(&iq, 0) == Q_FULL, "failed to report Q_FULL");
/* Queue emptying */
for (i = 0; i < TEST_QUEUES_SIZE; i++)
test_emit_token(chIQGet(&iq));
- test_assert(4, chIQIsEmptyI(&iq), "still full");
+ test_assert_lock(4, chIQIsEmptyI(&iq), "still full");
test_assert_sequence(5, "ABCD");
/* Queue filling again */
+ chSysLock();
for (i = 0; i < TEST_QUEUES_SIZE; i++)
chIQPutI(&iq, 'A' + i);
+ chSysUnlock();
/* Reading the whole thing */
n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE);
test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size");
- test_assert(7, chIQIsEmptyI(&iq), "still full");
+ test_assert_lock(7, chIQIsEmptyI(&iq), "still full");
/* Queue filling again */
+ chSysLock();
for (i = 0; i < TEST_QUEUES_SIZE; i++)
chIQPutI(&iq, 'A' + i);
+ chSysUnlock();
/* Partial reads */
n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
test_assert(8, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
n = chIQReadTimeout(&iq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
test_assert(9, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
- test_assert(10, chIQIsEmptyI(&iq), "still full");
+ test_assert_lock(10, chIQIsEmptyI(&iq), "still full");
/* Testing reset */
+ chSysLock();
chIQPutI(&iq, 0);
chIQResetI(&iq);
- test_assert(11, chIQGetFullI(&iq) == 0, "still full");
+ chSysUnlock();
+ test_assert_lock(11, chIQGetFullI(&iq) == 0, "still full");
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread1, NULL);
- test_assert(12, chIQGetFullI(&iq) == 0, "not empty");
+ test_assert_lock(12, chIQGetFullI(&iq) == 0, "not empty");
test_wait_threads();
/* Timeout */
@@ -175,38 +183,46 @@ static void queues2_execute(void) { size_t n;
/* Initial empty state */
- test_assert(1, chOQIsEmptyI(&oq), "not empty");
+ test_assert_lock(1, chOQIsEmptyI(&oq), "not empty");
/* Queue filling */
for (i = 0; i < TEST_QUEUES_SIZE; i++)
chOQPut(&oq, 'A' + i);
- test_assert(2, chOQIsFullI(&oq), "still has space");
+ test_assert_lock(2, chOQIsFullI(&oq), "still has space");
/* Queue emptying */
- for (i = 0; i < TEST_QUEUES_SIZE; i++)
- test_emit_token(chOQGetI(&oq));
- test_assert(3, chOQIsEmptyI(&oq), "still full");
+ for (i = 0; i < TEST_QUEUES_SIZE; i++) {
+ char c;
+
+ chSysLock();
+ c = chOQGetI(&oq);
+ chSysUnlock();
+ test_emit_token(c);
+ }
+ test_assert_lock(3, chOQIsEmptyI(&oq), "still full");
test_assert_sequence(4, "ABCD");
- test_assert(5, chOQGetI(&oq) == Q_EMPTY, "failed to report Q_EMPTY");
+ test_assert_lock(5, chOQGetI(&oq) == Q_EMPTY, "failed to report Q_EMPTY");
/* Writing the whole thing */
n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE * 2, TIME_IMMEDIATE);
test_assert(6, n == TEST_QUEUES_SIZE, "wrong returned size");
- test_assert(7, chOQIsFullI(&oq), "not full");
+ test_assert_lock(7, chOQIsFullI(&oq), "not full");
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread2, NULL);
- test_assert(8, chOQGetFullI(&oq) == TEST_QUEUES_SIZE, "not empty");
+ test_assert_lock(8, chOQGetFullI(&oq) == TEST_QUEUES_SIZE, "not empty");
test_wait_threads();
/* Testing reset */
+ chSysLock();
chOQResetI(&oq);
- test_assert(9, chOQGetFullI(&oq) == 0, "still full");
+ chSysUnlock();
+ test_assert_lock(9, chOQGetFullI(&oq) == 0, "still full");
/* Partial writes */
n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
test_assert(10, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
n = chOQWriteTimeout(&oq, wa[1], TEST_QUEUES_SIZE / 2, TIME_IMMEDIATE);
test_assert(11, n == TEST_QUEUES_SIZE / 2, "wrong returned size");
- test_assert(12, chOQIsFullI(&oq), "not full");
+ test_assert_lock(12, chOQIsFullI(&oq), "not full");
/* Timeout */
test_assert(13, chOQPutTimeout(&oq, 0, 10) == Q_TIMEOUT, "wrong timeout return");
diff --git a/test/testsem.c b/test/testsem.c index 6a6a622ef..d5c9072a7 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -104,7 +104,9 @@ static void sem1_execute(void) { test_assert_sequence(1, "ABCDE");
#endif
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+5, thread1, "A");
+ chSysLock();
chSemAddCounterI(&sem1, 2);
+ chSysUnlock();
test_wait_threads();
test_assert(2, chSemGetCounterI(&sem1) == 1, "invalid counter");
}
|