Changes to the test suite in order to save RAM on AVR targets.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@917 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
gdisirio 2009-04-25 11:12:10 +00:00
parent c031b80726
commit a2a8822648
12 changed files with 181 additions and 170 deletions

View File

@ -96,6 +96,8 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
- CHANGE: Removed the chMsgSendWithEvent() function. It is rarely used and - CHANGE: Removed the chMsgSendWithEvent() function. It is rarely used and
the functionality can be re-created with a compound atomic operation. Also the functionality can be re-created with a compound atomic operation. Also
removed the CH_USE_MESSAGES_EVENT configuration option. removed the CH_USE_MESSAGES_EVENT configuration option.
- CHANGE: Modified the test suite assertions in order to save RAM on the AVR
targets. The test suit now uses much less string space.
*** 1.2.0 *** *** 1.2.0 ***
- Added license exception text to the 1.2.0 branch. - Added license exception text to the 1.2.0 branch.

View File

@ -49,7 +49,7 @@ static const struct testcase **patterns[] = {
}; };
static bool_t local_fail, global_fail; static bool_t local_fail, global_fail;
static char *failmsg; static unsigned failpoint;
static char tokens_buffer[MAX_TOKENS]; static char tokens_buffer[MAX_TOKENS];
static char *tokp; static char *tokp;
static WORKING_AREA(waT0, THREADS_STACK_SIZE); static WORKING_AREA(waT0, THREADS_STACK_SIZE);
@ -118,35 +118,35 @@ void test_emit_token(char token) {
/* /*
* Assertions. * Assertions.
*/ */
bool_t _test_fail(char * msg) { bool_t _test_fail(unsigned point) {
local_fail = TRUE; local_fail = TRUE;
global_fail = TRUE; global_fail = TRUE;
failmsg = msg; failpoint = point;
return TRUE; return TRUE;
} }
bool_t _test_assert(bool_t condition, char * msg) { bool_t _test_assert(unsigned point, bool_t condition) {
if (!condition) if (!condition)
return _test_fail(msg); return _test_fail(point);
return FALSE; return FALSE;
} }
bool_t _test_assert_sequence(char *expected) { bool_t _test_assert_sequence(unsigned point, char *expected) {
char *cp = tokens_buffer; char *cp = tokens_buffer;
while (cp < tokp) { while (cp < tokp) {
if (*cp++ != *expected++) if (*cp++ != *expected++)
return _test_fail(NULL); return _test_fail(point);
} }
if (*expected) if (*expected)
return _test_fail(NULL); return _test_fail(point);
return FALSE; return FALSE;
} }
bool_t _test_assert_time_window(systime_t start, systime_t end) { bool_t _test_assert_time_window(unsigned point, systime_t start, systime_t end) {
return _test_assert(chTimeIsWithin(start, end), "time window error"); return _test_assert(point, chTimeIsWithin(start, end));
} }
/* /*
@ -256,14 +256,11 @@ msg_t TestThread(void *p) {
test_println(")"); test_println(")");
execute_test(patterns[i][j]); execute_test(patterns[i][j]);
if (local_fail) { if (local_fail) {
test_print("--- Result: FAIL ("); test_print("--- Result: FAIL (#");
if (failmsg) test_printn(failpoint);
test_print(failmsg); test_print(" [");
else { print_tokens();
test_print("sequence error: "); test_println("])");
print_tokens();
}
test_println(")");
} }
else else
test_println("--- Result: SUCCESS"); test_println("--- Result: SUCCESS");

View File

@ -55,10 +55,10 @@ extern "C" {
void test_print(char *msgp); void test_print(char *msgp);
void test_println(char *msgp); void test_println(char *msgp);
void test_emit_token(char token); void test_emit_token(char token);
bool_t _test_fail(char * msg); bool_t _test_fail(unsigned point);
bool_t _test_assert(bool_t condition, char * msg); bool_t _test_assert(unsigned point, bool_t condition);
bool_t _test_assert_sequence(char *expected); bool_t _test_assert_sequence(unsigned point, char *expected);
bool_t _test_assert_time_window(systime_t start, systime_t end); bool_t _test_assert_time_window(unsigned point, systime_t start, systime_t end);
void test_terminate_threads(void); void test_terminate_threads(void);
void test_wait_threads(void); void test_wait_threads(void);
systime_t test_wait_tick(void); systime_t test_wait_tick(void);
@ -71,23 +71,23 @@ extern "C" {
} }
#endif #endif
#define test_fail(msg) { \ #define test_fail(point) { \
test_fail(msg); \ test_fail(point); \
return; \ return; \
} }
#define test_assert(condition, msg) { \ #define test_assert(point, condition, msg) { \
if (_test_assert(condition, msg)) \ if (_test_assert(point, condition)) \
return; \ return; \
} }
#define test_assert_sequence(expected) { \ #define test_assert_sequence(point, expected) { \
if (_test_assert_sequence(expected)) \ if (_test_assert_sequence(point, expected)) \
return; \ return; \
} }
#define test_assert_time_window(start, end) { \ #define test_assert_time_window(point, start, end) { \
if (_test_assert_time_window(start, end)) \ if (_test_assert_time_window(point, start, end)) \
return; \ return; \
} }

View File

@ -49,20 +49,20 @@ static void dyn1_execute(void) {
threads[2] = chThdCreateFromHeap(THD_WA_SIZE(0x10000000), threads[2] = chThdCreateFromHeap(THD_WA_SIZE(0x10000000),
prio-3, thread, "C"); prio-3, thread, "C");
test_assert((threads[0] != NULL) && test_assert(1, (threads[0] != NULL) &&
(threads[1] != NULL) && (threads[1] != NULL) &&
(threads[2] == NULL) && (threads[2] == NULL) &&
(threads[3] == NULL) && (threads[3] == NULL) &&
(threads[4] == NULL), (threads[4] == NULL),
"#1"); /* Thread creation failed.*/ "thread creation failed");
/* Claiming the memory from terminated threads. */ /* Claiming the memory from terminated threads. */
test_wait_threads(); test_wait_threads();
test_assert_sequence("AB"); test_assert_sequence(2, "AB");
/* Heap status checked again.*/ /* Heap status checked again.*/
test_assert(chHeapStatus(&n) == 1, "#2"); /* Heap fragmented.*/ test_assert(3, chHeapStatus(&n) == 1, "heap fragmented");
test_assert(n == sz, "#3"); /* Heap size changed.*/ test_assert(4, n == sz, "heap size changed");
} }
} }
@ -102,21 +102,21 @@ static void dyn2_execute(void) {
threads[3] = chThdCreateFromMemoryPool(&mp1, prio-4, thread, "D"); threads[3] = chThdCreateFromMemoryPool(&mp1, prio-4, thread, "D");
threads[4] = chThdCreateFromMemoryPool(&mp1, prio-5, thread, "E"); threads[4] = chThdCreateFromMemoryPool(&mp1, prio-5, thread, "E");
test_assert((threads[0] != NULL) && test_assert(1, (threads[0] != NULL) &&
(threads[1] != NULL) && (threads[1] != NULL) &&
(threads[2] != NULL) && (threads[2] != NULL) &&
(threads[3] != NULL) && (threads[3] != NULL) &&
(threads[4] == NULL), (threads[4] == NULL),
"#1"); /* Thread creation failed.*/ "thread creation failed");
/* Claiming the memory from terminated threads. */ /* Claiming the memory from terminated threads. */
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABCD"); test_assert_sequence(2, "ABCD");
/* Now the pool must be full again. */ /* Now the pool must be full again. */
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "#2"); /* Pool list empty.*/ test_assert(3, chPoolAlloc(&mp1) != NULL, "pool list empty");
test_assert(chPoolAlloc(&mp1) == NULL, "#3"); /* Pool list not empty.*/ test_assert(4, chPoolAlloc(&mp1) == NULL, "pool list not empty");
} }
const struct testcase testdyn2 = { const struct testcase testdyn2 = {

View File

@ -51,17 +51,17 @@ static void evt1_execute(void) {
chEvtInit(&es1); chEvtInit(&es1);
chEvtRegisterMask(&es1, &el1, 1); chEvtRegisterMask(&es1, &el1, 1);
chEvtRegisterMask(&es1, &el2, 2); chEvtRegisterMask(&es1, &el2, 2);
test_assert(chEvtIsListening(&es1), "#1"); /* Must not be empty */ test_assert(1, chEvtIsListening(&es1), "no listener");
chEvtUnregister(&es1, &el1); chEvtUnregister(&es1, &el1);
test_assert(chEvtIsListening(&es1), "#2"); /* Must not be empty */ test_assert(2, chEvtIsListening(&es1), "no listener");
chEvtUnregister(&es1, &el2); chEvtUnregister(&es1, &el2);
test_assert(!chEvtIsListening(&es1), "#3"); /* Stuck listener.*/ test_assert(3, !chEvtIsListening(&es1), "stuck listener");
/* /*
* Testing chEvtDispatch(). * Testing chEvtDispatch().
*/ */
chEvtDispatch(evhndl, 7); chEvtDispatch(evhndl, 7);
test_assert_sequence("ABC"); test_assert_sequence(4, "ABC");
} }
const struct testcase testevt1 = { const struct testcase testevt1 = {
@ -106,11 +106,11 @@ static void evt2_execute(void) {
*/ */
chEvtPend(5); chEvtPend(5);
m = chEvtWaitOne(ALL_EVENTS); m = chEvtWaitOne(ALL_EVENTS);
test_assert(m == 1, "#1"); /* Single bit error.*/ test_assert(1, m == 1, "single event error");
m = chEvtWaitOne(ALL_EVENTS); m = chEvtWaitOne(ALL_EVENTS);
test_assert(m == 4, "#2"); /* Single bit error.*/ test_assert(2, m == 4, "single event error");
m = chEvtClear(0); m = chEvtClear(0);
test_assert(m == 0, "#3"); /* Stuck bit.*/ test_assert(3, m == 0, "stuck event");
/* /*
* Test on chEvtWaitOne() with wait. * Test on chEvtWaitOne() with wait.
@ -120,10 +120,10 @@ static void evt2_execute(void) {
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() - 1, threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() - 1,
thread1, chThdSelf()); thread1, chThdSelf());
m = chEvtWaitOne(ALL_EVENTS); m = chEvtWaitOne(ALL_EVENTS);
test_assert_time_window(target_time, target_time + ALLOWED_DELAY); test_assert_time_window(4, target_time, target_time + ALLOWED_DELAY);
test_assert(m == 1, "#5"); /* Single bit error.*/ test_assert(5, m == 1, "single event error");
m = chEvtClear(0); m = chEvtClear(0);
test_assert(m == 0, "#6"); /* Stuck bit.*/ test_assert(6, m == 0, "stuck event");
test_wait_threads(); test_wait_threads();
/* /*
@ -131,9 +131,9 @@ static void evt2_execute(void) {
*/ */
chEvtPend(5); chEvtPend(5);
m = chEvtWaitAny(ALL_EVENTS); m = chEvtWaitAny(ALL_EVENTS);
test_assert(m == 5, "#7"); /* Unexpected pending bit.*/ test_assert(7, m == 5, "unexpected pending bit");
m = chEvtClear(0); m = chEvtClear(0);
test_assert(m == 0, "#8"); /* Stuck bit.*/ test_assert(8, m == 0, "stuck event");
/* /*
* Test on chEvtWaitAny() with wait. * Test on chEvtWaitAny() with wait.
@ -143,10 +143,10 @@ static void evt2_execute(void) {
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() - 1, threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() - 1,
thread1, chThdSelf()); thread1, chThdSelf());
m = chEvtWaitAny(ALL_EVENTS); m = chEvtWaitAny(ALL_EVENTS);
test_assert_time_window(target_time, target_time + ALLOWED_DELAY); test_assert_time_window(9, target_time, target_time + ALLOWED_DELAY);
test_assert(m == 1, "#9"); /* Single bit error.*/ test_assert(10, m == 1, "single event error");
m = chEvtClear(0); m = chEvtClear(0);
test_assert(m == 0, "#10"); /* Stuck bit.*/ test_assert(11, m == 0, "stuck event");
test_wait_threads(); test_wait_threads();
/* /*
@ -161,14 +161,14 @@ static void evt2_execute(void) {
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() - 1, threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() - 1,
thread2, "A"); thread2, "A");
m = chEvtWaitAll(5); m = chEvtWaitAll(5);
test_assert_time_window(target_time, target_time + ALLOWED_DELAY); test_assert_time_window(12, target_time, target_time + ALLOWED_DELAY);
m = chEvtClear(0); m = chEvtClear(0);
test_assert(m == 0, "#11"); /* Stuck event.*/ test_assert(13, m == 0, "stuck event");
test_wait_threads(); test_wait_threads();
chEvtUnregister(&es1, &el1); chEvtUnregister(&es1, &el1);
chEvtUnregister(&es2, &el2); chEvtUnregister(&es2, &el2);
test_assert(!chEvtIsListening(&es1), "#12"); /* Stuck listener.*/ test_assert(14, !chEvtIsListening(&es1), "stuck listener");
test_assert(!chEvtIsListening(&es2), "#13"); /* Stuck listener.*/ test_assert(15, !chEvtIsListening(&es2), "stuck listener");
} }
const struct testcase testevt2 = { const struct testcase testevt2 = {
@ -196,17 +196,17 @@ static void evt3_execute(void) {
* Tests various timeout situations. * Tests various timeout situations.
*/ */
m = chEvtWaitOneTimeout(ALL_EVENTS, TIME_IMMEDIATE); m = chEvtWaitOneTimeout(ALL_EVENTS, TIME_IMMEDIATE);
test_assert(m == 0, "#1"); test_assert(1, m == 0, "spurious event");
m = chEvtWaitAnyTimeout(ALL_EVENTS, TIME_IMMEDIATE); m = chEvtWaitAnyTimeout(ALL_EVENTS, TIME_IMMEDIATE);
test_assert(m == 0, "#2"); test_assert(2, m == 0, "spurious event");
m = chEvtWaitAllTimeout(ALL_EVENTS, TIME_IMMEDIATE); m = chEvtWaitAllTimeout(ALL_EVENTS, TIME_IMMEDIATE);
test_assert(m == 0, "#3"); test_assert(3, m == 0, "spurious event");
m = chEvtWaitOneTimeout(ALL_EVENTS, 10); m = chEvtWaitOneTimeout(ALL_EVENTS, 10);
test_assert(m == 0, "#4"); test_assert(4, m == 0, "spurious event");
m = chEvtWaitAnyTimeout(ALL_EVENTS, 10); m = chEvtWaitAnyTimeout(ALL_EVENTS, 10);
test_assert(m == 0, "#5"); test_assert(5, m == 0, "spurious event");
m = chEvtWaitAllTimeout(ALL_EVENTS, 10); m = chEvtWaitAllTimeout(ALL_EVENTS, 10);
test_assert(m == 0, "#6"); test_assert(6, m == 0, "spurious event");
#endif #endif
} }

View File

@ -47,7 +47,7 @@ static void heap1_execute(void) {
chHeapFree(p1); /* Does not merge */ chHeapFree(p1); /* Does not merge */
chHeapFree(p2); /* Merges backward */ chHeapFree(p2); /* Merges backward */
chHeapFree(p3); /* Merges both sides */ chHeapFree(p3); /* Merges both sides */
test_assert(chHeapStatus(&n) == 1, "#1"); /* Heap fragmented.*/ test_assert(1, chHeapStatus(&n) == 1, "heap fragmented");
/* Reverse order */ /* Reverse order */
p1 = chHeapAlloc(SIZE); p1 = chHeapAlloc(SIZE);
@ -56,26 +56,26 @@ static void heap1_execute(void) {
chHeapFree(p3); /* Merges forward */ chHeapFree(p3); /* Merges forward */
chHeapFree(p2); /* Merges forward */ chHeapFree(p2); /* Merges forward */
chHeapFree(p1); /* Merges forward */ chHeapFree(p1); /* Merges forward */
test_assert(chHeapStatus(&n) == 1, "#2"); /* Heap fragmented.*/ test_assert(2, chHeapStatus(&n) == 1, "heap fragmented");
/* Small fragments handling */ /* Small fragments handling */
p1 = chHeapAlloc(SIZE + 1); p1 = chHeapAlloc(SIZE + 1);
p2 = chHeapAlloc(SIZE); p2 = chHeapAlloc(SIZE);
chHeapFree(p1); chHeapFree(p1);
test_assert(chHeapStatus(&n) == 2, "#3"); /* Heap must contain 2 blocks.*/ test_assert(3, chHeapStatus(&n) == 2, "invalid state");
p1 = chHeapAlloc(SIZE); p1 = chHeapAlloc(SIZE);
test_assert(chHeapStatus(&n) == 1, "#4"); /* Heap fragmented.*/ test_assert(4, chHeapStatus(&n) == 1, "heap fragmented");
chHeapFree(p2); chHeapFree(p2);
chHeapFree(p1); chHeapFree(p1);
/* Allocate all handling */ /* Allocate all handling */
(void)chHeapStatus(&n); (void)chHeapStatus(&n);
p1 = chHeapAlloc(n); p1 = chHeapAlloc(n);
test_assert(chHeapStatus(&n) == 0, "#5"); /* Heap must be empty.*/ test_assert(5, chHeapStatus(&n) == 0, "not empty");
chHeapFree(p1); chHeapFree(p1);
test_assert(chHeapStatus(&n) == 1, "#6"); /* Heap fragmented.*/ test_assert(6, chHeapStatus(&n) == 1, "heap fragmented");
test_assert(n == sz, "#7"); /* Heap size changed.*/ test_assert(7, n == sz, "size changed");
} }
else { else {
test_print("--- Size : "); test_print("--- Size : ");

View File

@ -46,63 +46,63 @@ static void mbox1_execute(void) {
/* /*
* Testing initial space. * Testing initial space.
*/ */
test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#1"); test_assert(1, chMBGetEmpty(&mb1) == MB_SIZE, "wrong size");
/* /*
* Testing enqueuing and backward circularity. * Testing enqueuing and backward circularity.
*/ */
for (i = 0; i < MB_SIZE - 1; i++) { for (i = 0; i < MB_SIZE - 1; i++) {
msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#2"); test_assert(2, msg1 == RDY_OK, "wrong wake-up message");
} }
msg1 = chMBPostAhead(&mb1, 'A', TIME_INFINITE); msg1 = chMBPostAhead(&mb1, 'A', TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#3"); test_assert(3, msg1 == RDY_OK, "wrong wake-up message");
/* /*
* Testing post timeout. * Testing post timeout.
*/ */
msg1 = chMBPost(&mb1, 'X', 1); msg1 = chMBPost(&mb1, 'X', 1);
test_assert(msg1 == RDY_TIMEOUT, "#4"); test_assert(4, msg1 == RDY_TIMEOUT, "wrong wake-up message");
/* /*
* Testing final conditions. * Testing final conditions.
*/ */
test_assert(chMBGetEmpty(&mb1) == 0, "#5"); test_assert(5, chMBGetEmpty(&mb1) == 0, "still empty");
test_assert(chMBGetFull(&mb1) == MB_SIZE, "#6"); test_assert(6, chMBGetFull(&mb1) == MB_SIZE, "not full");
test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#7"); test_assert(7, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
/* /*
* Testing dequeuing. * Testing dequeuing.
*/ */
for (i = 0; i < MB_SIZE; i++) { for (i = 0; i < MB_SIZE; i++) {
msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE); msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#8"); test_assert(8, msg1 == RDY_OK, "wrong wake-up message");
test_emit_token(msg2); test_emit_token(msg2);
} }
test_assert_sequence("ABCDE"); test_assert_sequence(9, "ABCDE");
/* /*
* Testing buffer circularity. * Testing buffer circularity.
*/ */
msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE); msg1 = chMBPost(&mb1, 'B' + i, TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#9"); test_assert(10, msg1 == RDY_OK, "wrong wake-up message");
msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE); msg1 = chMBFetch(&mb1, &msg2, TIME_INFINITE);
test_assert(msg1 == RDY_OK, "#10"); test_assert(11, msg1 == RDY_OK, "wrong wake-up message");
test_assert(mb1.mb_buffer == mb1.mb_wrptr, "#11"); test_assert(12, mb1.mb_buffer == mb1.mb_wrptr, "write pointer not aligned to base");
test_assert(mb1.mb_buffer == mb1.mb_rdptr, "#12"); test_assert(13, mb1.mb_buffer == mb1.mb_rdptr, "read pointer not aligned to base");
/* /*
* Testing fetch timeout. * Testing fetch timeout.
*/ */
msg1 = chMBFetch(&mb1, &msg2, 1); msg1 = chMBFetch(&mb1, &msg2, 1);
test_assert(msg1 == RDY_TIMEOUT, "#13"); test_assert(14, msg1 == RDY_TIMEOUT, "wrong wake-up message");
/* /*
* Testing final conditions. * Testing final conditions.
*/ */
test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#14"); test_assert(15, chMBGetEmpty(&mb1) == MB_SIZE, "not empty");
test_assert(chMBGetFull(&mb1) == 0, "#15"); test_assert(16, chMBGetFull(&mb1) == 0, "still full");
test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#16"); test_assert(17, mb1.mb_rdptr == mb1.mb_wrptr, "pointers not aligned");
/* /*
* Testing reset. * Testing reset.
@ -112,10 +112,10 @@ static void mbox1_execute(void) {
/* /*
* Re-testing final conditions. * Re-testing final conditions.
*/ */
test_assert(chMBGetEmpty(&mb1) == MB_SIZE, "#17"); test_assert(18, chMBGetEmpty(&mb1) == MB_SIZE, "not empty");
test_assert(chMBGetFull(&mb1) == 0, "#18"); test_assert(19, chMBGetFull(&mb1) == 0, "still full");
test_assert(mb1.mb_rdptr == mb1.mb_wrptr, "#19"); test_assert(20, mb1.mb_buffer == mb1.mb_wrptr, "write pointer not aligned to base");
test_assert(mb1.mb_buffer == mb1.mb_wrptr, "#20"); test_assert(21, mb1.mb_buffer == mb1.mb_rdptr, "read pointer not aligned to base");
} }
const struct testcase testmbox1 = { const struct testcase testmbox1 = {

View File

@ -51,7 +51,7 @@ static void msg1_execute(void) {
test_emit_token(msg); test_emit_token(msg);
chMsgRelease(msg = chMsgWait()); chMsgRelease(msg = chMsgWait());
test_emit_token(msg); test_emit_token(msg);
test_assert_sequence("ABC"); test_assert_sequence(1, "ABC");
/* /*
* Testing message fetch using chMsgGet(). * Testing message fetch using chMsgGet().
@ -59,15 +59,15 @@ static void msg1_execute(void) {
* the receiver. * the receiver.
*/ */
msg = chMsgGet(); msg = chMsgGet();
test_assert(msg != 0, "#1"); test_assert(1, msg != 0, "no message");
chMsgRelease(0); chMsgRelease(0);
test_assert(msg == 'D', "#2"); test_assert(2, msg == 'D', "wrong message");
/* /*
* Must not have pending messages. * Must not have pending messages.
*/ */
msg = chMsgGet(); msg = chMsgGet();
test_assert(msg == 0, "#3"); test_assert(3, msg == 0, "unknown message");
} }
const struct testcase testmsg1 = { const struct testcase testmsg1 = {

View File

@ -57,8 +57,8 @@ static void mtx1_execute(void) {
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread1, "A"); threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread1, "A");
chMtxUnlock(); chMtxUnlock();
test_wait_threads(); test_wait_threads();
test_assert(prio == chThdGetPriority(), "#1"); /* Priority return failure.*/ test_assert(1, prio == chThdGetPriority(), "wrong priority level");
test_assert_sequence("ABCDE"); test_assert_sequence(2, "ABCDE");
} }
const struct testcase testmtx1 = { const struct testcase testmtx1 = {
@ -116,7 +116,7 @@ static void mtx2_execute(void) {
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-3, thread3, "C"); threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriority()-3, thread3, "C");
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-2, thread4, "B"); threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-2, thread4, "B");
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABC"); test_assert_sequence(1, "ABC");
} }
const struct testcase testmtx2 = { const struct testcase testmtx2 = {
@ -204,7 +204,7 @@ static void mtx3_execute(void) {
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread8, "B"); threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread8, "B");
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread9, "A"); threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread9, "A");
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABCDE"); test_assert_sequence(1, "ABCDE");
} }
const struct testcase testmtx3 = { const struct testcase testmtx3 = {
@ -250,40 +250,40 @@ static void mtx4_execute(void) {
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, p1, thread13, "B"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, p1, thread13, "B");
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, p2, thread14, "A"); threads[1] = chThdCreateStatic(wa[1], WA_SIZE, p2, thread14, "A");
chMtxLock(&m2); chMtxLock(&m2);
test_assert(chThdGetPriority() == p, "#1"); test_assert(1, chThdGetPriority() == p, "wrong priority level");
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p1, "#2"); test_assert(2, chThdGetPriority() == p1, "wrong priority level");
chMtxLock(&m1); chMtxLock(&m1);
test_assert(chThdGetPriority() == p1, "#3"); test_assert(3, chThdGetPriority() == p1, "wrong priority level");
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p2, "#4"); test_assert(4, chThdGetPriority() == p2, "wrong priority level");
chMtxUnlock(); chMtxUnlock();
test_assert(chThdGetPriority() == p1, "#5"); test_assert(5, chThdGetPriority() == p1, "wrong priority level");
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p1, "#6"); test_assert(6, chThdGetPriority() == p1, "wrong priority level");
chMtxUnlockAll(); chMtxUnlockAll();
test_assert(chThdGetPriority() == p, "#7"); test_assert(7, chThdGetPriority() == p, "wrong priority level");
test_wait_threads(); test_wait_threads();
/* Test repeated in order to cover chMtxUnlockS().*/ /* Test repeated in order to cover chMtxUnlockS().*/
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, p1, thread13, "D"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, p1, thread13, "D");
threads[1] = chThdCreateStatic(wa[1], WA_SIZE, p2, thread14, "C"); threads[1] = chThdCreateStatic(wa[1], WA_SIZE, p2, thread14, "C");
chMtxLock(&m2); chMtxLock(&m2);
test_assert(chThdGetPriority() == p, "#8"); test_assert(8, chThdGetPriority() == p, "wrong priority level");
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p1, "#9"); test_assert(9, chThdGetPriority() == p1, "wrong priority level");
chMtxLock(&m1); chMtxLock(&m1);
test_assert(chThdGetPriority() == p1, "#10"); test_assert(10, chThdGetPriority() == p1, "wrong priority level");
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p2, "#11"); test_assert(11, chThdGetPriority() == p2, "wrong priority level");
chSysLock(); chSysLock();
chMtxUnlockS(); chMtxUnlockS();
chSysUnlock(); chSysUnlock();
test_assert(chThdGetPriority() == p1, "#12"); test_assert(12, chThdGetPriority() == p1, "wrong priority level");
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
test_assert(chThdGetPriority() == p1, "#13"); test_assert(13, chThdGetPriority() == p1, "wrong priority level");
chMtxUnlockAll(); chMtxUnlockAll();
test_assert(chThdGetPriority() == p, "#14"); test_assert(14, chThdGetPriority() == p, "wrong priority level");
test_wait_threads(); test_wait_threads();
} }
@ -311,18 +311,18 @@ static void mtx5_execute(void) {
prio = chThdGetPriority(); prio = chThdGetPriority();
b = chMtxTryLock(&m1); b = chMtxTryLock(&m1);
test_assert(b, "#1"); test_assert(1, b, "already locked");
b = chMtxTryLock(&m1); b = chMtxTryLock(&m1);
test_assert(!b, "#2"); test_assert(2, !b, "not locked");
chSysLock(); chSysLock();
chMtxUnlockS(); chMtxUnlockS();
chSysUnlock(); chSysUnlock();
test_assert(isempty(&m1.m_queue), "#3"); /* Queue not empty */ test_assert(3, isempty(&m1.m_queue), "queue not empty");
test_assert(m1.m_owner == NULL, "#4"); /* Owned */ test_assert(4, m1.m_owner == NULL, "still owned");
test_assert(chThdGetPriority() == prio, "#5"); test_assert(5, chThdGetPriority() == prio, "wrong priority level");
} }
const struct testcase testmtx5 = { const struct testcase testmtx5 = {
@ -370,7 +370,7 @@ static void mtx6_execute(void) {
chSchRescheduleS(); chSchRescheduleS();
chSysUnlock(); chSysUnlock();
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABCDE"); test_assert_sequence(1, "ABCDE");
} }
const struct testcase testmtx6 = { const struct testcase testmtx6 = {
@ -402,7 +402,7 @@ static void mtx7_execute(void) {
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread10, "A"); threads[4] = chThdCreateStatic(wa[4], WA_SIZE, prio+5, thread10, "A");
chCondBroadcast(&c1); chCondBroadcast(&c1);
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABCDE"); test_assert_sequence(1, "ABCDE");
} }
const struct testcase testmtx7 = { const struct testcase testmtx7 = {
@ -452,7 +452,7 @@ static void mtx8_execute(void) {
chCondSignal(&c1); chCondSignal(&c1);
chCondSignal(&c1); chCondSignal(&c1);
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABC"); test_assert_sequence(1, "ABC");
} }
const struct testcase testmtx8 = { const struct testcase testmtx8 = {

View File

@ -44,10 +44,10 @@ static void pools1_execute(void) {
/* Empting the pool again. */ /* Empting the pool again. */
for (i = 0; i < MAX_THREADS; i++) for (i = 0; i < MAX_THREADS; i++)
test_assert(chPoolAlloc(&mp1) != NULL, "#1"); /* Pool list empty.*/ test_assert(1, chPoolAlloc(&mp1) != NULL, "list empty");
/* Now must be empty. */ /* Now must be empty. */
test_assert(chPoolAlloc(&mp1) == NULL, "#2"); /* Pool list not empty.*/ test_assert(2, chPoolAlloc(&mp1) == NULL, "list not empty");
} }
const struct testcase testpools1 = { const struct testcase testpools1 = {

View File

@ -58,9 +58,9 @@ static void sem1_execute(void) {
chSemSignal(&sem1); chSemSignal(&sem1);
test_wait_threads(); test_wait_threads();
#if CH_USE_SEMAPHORES_PRIORITY #if CH_USE_SEMAPHORES_PRIORITY
test_assert_sequence("ADCEB"); test_assert_sequence(1, "ADCEB");
#else #else
test_assert_sequence("ABCDE"); test_assert_sequence(1, "ABCDE");
#endif #endif
} }
@ -101,19 +101,20 @@ static void sem2_execute(void) {
* Testing special case TIME_IMMEDIATE. * Testing special case TIME_IMMEDIATE.
*/ */
msg = chSemWaitTimeout(&sem1, TIME_IMMEDIATE); msg = chSemWaitTimeout(&sem1, TIME_IMMEDIATE);
test_assert(msg == RDY_TIMEOUT, "#1"); test_assert(1, msg == RDY_TIMEOUT, "wrong wake-up message");
test_assert(isempty(&sem1.s_queue), "#2"); /* Queue not empty */ test_assert(2, isempty(&sem1.s_queue), "queue not empty");
test_assert(sem1.s_cnt == 0, "#3"); /* Counter not zero */ test_assert(3, sem1.s_cnt == 0, "counter not zero");
/* /*
* Testing not timeout condition. * Testing not timeout condition.
*/ */
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()-1, thread2, "A"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() - 1,
thread2, "A");
msg = chSemWaitTimeout(&sem1, MS2ST(500)); msg = chSemWaitTimeout(&sem1, MS2ST(500));
test_wait_threads(); test_wait_threads();
test_assert(msg == RDY_OK, "#4"); test_assert(4, msg == RDY_OK, "wrong wake-up message");
test_assert(isempty(&sem1.s_queue), "#5"); /* Queue not empty */ test_assert(5, isempty(&sem1.s_queue), "queue not empty");
test_assert(sem1.s_cnt == 0, "#6"); /* Counter not zero */ test_assert(6, sem1.s_cnt == 0, "counter not zero");
/* /*
* Testing timeout condition. * Testing timeout condition.
@ -123,12 +124,12 @@ static void sem2_execute(void) {
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
test_emit_token('A' + i); test_emit_token('A' + i);
msg = chSemWaitTimeout(&sem1, MS2ST(500)); msg = chSemWaitTimeout(&sem1, MS2ST(500));
test_assert(msg == RDY_TIMEOUT, "#7"); test_assert(7, msg == RDY_TIMEOUT, "wrong wake-up message");
test_assert(isempty(&sem1.s_queue), "#8"); /* Queue not empty */ test_assert(8, isempty(&sem1.s_queue), "queue not empty");
test_assert(sem1.s_cnt == 0, "#9"); /* Counter not zero */ test_assert(9, sem1.s_cnt == 0, "counter not zero");
} }
test_assert_sequence("ABCDE"); test_assert_sequence(10, "ABCDE");
test_assert_time_window(target_time, target_time + ALLOWED_DELAY); test_assert_time_window(11, target_time, target_time + ALLOWED_DELAY);
} }
const struct testcase testsem2 = { const struct testcase testsem2 = {
@ -161,12 +162,12 @@ static void sem3_execute(void) {
threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread3, "A"); threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority()+1, thread3, "A");
chSemSignalWait(&sem1, &sem1); chSemSignalWait(&sem1, &sem1);
test_assert(isempty(&sem1.s_queue), "#1"); /* Queue not empty */ test_assert(1, isempty(&sem1.s_queue), "queue not empty");
test_assert(sem1.s_cnt == 0, "#2"); /* Counter not zero */ test_assert(2, sem1.s_cnt == 0, "counter not zero");
chSemSignalWait(&sem1, &sem1); chSemSignalWait(&sem1, &sem1);
test_assert(isempty(&sem1.s_queue), "#3"); /* Queue not empty */ test_assert(3, isempty(&sem1.s_queue), "queue not empty");
test_assert(sem1.s_cnt == 0, "#4"); /* Counter not zero */ test_assert(4, sem1.s_cnt == 0, "counter not zero");
} }
const struct testcase testsem3 = { const struct testcase testsem3 = {

View File

@ -40,7 +40,7 @@ static void thd1_execute(void) {
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B"); threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B");
threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A"); threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriority()-1, thread, "A");
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABCDE"); test_assert_sequence(1, "ABCDE");
} }
const struct testcase testthd1 = { const struct testcase testthd1 = {
@ -63,7 +63,7 @@ static void thd2_execute(void) {
threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B"); threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriority()-2, thread, "B");
threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C"); threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriority()-3, thread, "C");
test_wait_threads(); test_wait_threads();
test_assert_sequence("ABCDE"); test_assert_sequence(1, "ABCDE");
} }
const struct testcase testthd2 = { const struct testcase testthd2 = {
@ -83,30 +83,41 @@ static void thd3_execute(void) {
prio = chThdGetPriority(); prio = chThdGetPriority();
p1 = chThdSetPriority(prio + 1); p1 = chThdSetPriority(prio + 1);
test_assert(p1 == prio, "#1"); test_assert(1, p1 == prio,
test_assert(chThdGetPriority() == prio + 1, "#2"); "unexpected returned priority level");
test_assert(2, chThdGetPriority() == prio + 1,
"unexpected priority level");
p1 = chThdSetPriority(p1); p1 = chThdSetPriority(p1);
test_assert(p1 == prio + 1, "#3"); test_assert(3, p1 == prio + 1,
test_assert(chThdGetPriority() == prio, "#4"); "unexpected returned priority level");
test_assert(4, chThdGetPriority() == prio,
"unexpected priority level");
#if CH_USE_MUTEXES #if CH_USE_MUTEXES
/* Simulates a priority boost situation (p_prio > p_realprio).*/ /* Simulates a priority boost situation (p_prio > p_realprio).*/
chSysLock(); chSysLock();
chThdSelf()->p_prio += 2; chThdSelf()->p_prio += 2;
chSysUnlock(); chSysUnlock();
test_assert(chThdGetPriority() == prio + 2, "#5"); test_assert(5, chThdGetPriority() == prio + 2,
"unexpected priority level");
/* Tries to raise but below the boost level. */ /* Tries to raise but below the boost level. */
p1 = chThdSetPriority(prio + 1); p1 = chThdSetPriority(prio + 1);
test_assert(p1 == prio, "#6"); test_assert(6, p1 == prio,
test_assert(chThdSelf()->p_prio == prio + 2, "#7"); "unexpected returned priority level");
test_assert(chThdSelf()->p_realprio == prio + 1, "#8"); test_assert(7, chThdSelf()->p_prio == prio + 2,
"unexpected priority level");
test_assert(8, chThdSelf()->p_realprio == prio + 1,
"unexpected returned real priority level");
/* Tries to raise above the boost level. */ /* Tries to raise above the boost level. */
p1 = chThdSetPriority(prio + 3); p1 = chThdSetPriority(prio + 3);
test_assert(p1 == prio + 1, "#9"); test_assert(9, p1 == prio + 1,
test_assert(chThdSelf()->p_prio == prio + 3, "#10"); "unexpected returned priority level");
test_assert(chThdSelf()->p_realprio == prio + 3, "#11"); test_assert(10, chThdSelf()->p_prio == prio + 3,
"unexpected priority level");
test_assert(11, chThdSelf()->p_realprio == prio + 3,
"unexpected real priority level");
chSysLock(); chSysLock();
chThdSelf()->p_prio = prio; chThdSelf()->p_prio = prio;
@ -135,22 +146,22 @@ static void thd4_execute(void) {
/* Timeouts in microseconds.*/ /* Timeouts in microseconds.*/
time = chTimeNow(); time = chTimeNow();
chThdSleepMicroseconds(100000); chThdSleepMicroseconds(100000);
test_assert_time_window(time + US2ST(100000), time + US2ST(100000) + 1); test_assert_time_window(1, time + US2ST(100000), time + US2ST(100000) + 1);
/* Timeouts in milliseconds.*/ /* Timeouts in milliseconds.*/
time = chTimeNow(); time = chTimeNow();
chThdSleepMilliseconds(100); chThdSleepMilliseconds(100);
test_assert_time_window(time + MS2ST(100), time + MS2ST(100) + 1); test_assert_time_window(2, time + MS2ST(100), time + MS2ST(100) + 1);
/* Timeouts in seconds.*/ /* Timeouts in seconds.*/
time = chTimeNow(); time = chTimeNow();
chThdSleepSeconds(1); chThdSleepSeconds(1);
test_assert_time_window(time + S2ST(1), time + S2ST(1) + 1); test_assert_time_window(3, time + S2ST(1), time + S2ST(1) + 1);
/* Absolute timelines.*/ /* Absolute timelines.*/
time = chTimeNow() + MS2ST(100); time = chTimeNow() + MS2ST(100);
chThdSleepUntil(time); chThdSleepUntil(time);
test_assert_time_window(time, time + 1); test_assert_time_window(4, time, time + 1);
} }
const struct testcase testthd4 = { const struct testcase testthd4 = {