git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@489 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2008-11-01 17:49:53 +00:00
parent 69d06df416
commit a701fdfd14
3 changed files with 36 additions and 13 deletions

View File

@ -135,32 +135,35 @@ void test_emit_token(char token) {
/* /*
* Assertions. * Assertions.
*/ */
void test_fail(char * msg) { bool_t _test_fail(char * msg) {
local_fail = TRUE; local_fail = TRUE;
global_fail = TRUE; global_fail = TRUE;
failmsg = msg; failmsg = msg;
return TRUE;
} }
void test_assert(bool_t condition, char * msg) { bool_t _test_assert(bool_t condition, char * msg) {
if (!condition) if (!condition)
test_fail(msg); return _test_fail(msg);
return FALSE;
} }
void test_assert_sequence(char *expected) { bool_t _test_assert_sequence(char *expected) {
char *cp = tokens_buffer; char *cp = tokens_buffer;
while (cp < tokp) { while (cp < tokp) {
if (*cp++ != *expected++) if (*cp++ != *expected++)
test_fail(NULL); return _test_fail(NULL);
} }
if (*expected) if (*expected)
test_fail(NULL); return _test_fail(NULL);
return FALSE;
} }
void test_assert_time_window(systime_t start, systime_t end) { bool_t _test_assert_time_window(systime_t start, systime_t end) {
test_assert(chSysInTimeWindow(start, end), "time window error"); return _test_assert(chSysInTimeWindow(start, end), "time window error");
} }
/* /*

View File

@ -46,10 +46,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);
void test_fail(char * msg); bool_t _test_fail(char * msg);
void test_assert(bool_t condition, char * msg); bool_t _test_assert(bool_t condition, char * msg);
void test_assert_sequence(char *expected); bool_t _test_assert_sequence(char *expected);
void test_assert_time_window(systime_t start, systime_t end); bool_t _test_assert_time_window(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);
@ -62,6 +62,26 @@ extern "C" {
} }
#endif #endif
#define test_fail(msg) { \
test_fail(msg); \
return; \
}
#define test_assert(condition, msg) { \
if (_test_assert(condition, msg)) \
return; \
}
#define test_assert_sequence(expected) { \
if (_test_assert_sequence(expected)) \
return; \
}
#define test_assert_time_window(start, end) { \
if (_test_assert_time_window(start, end)) \
return; \
}
extern Thread *threads[MAX_THREADS]; extern Thread *threads[MAX_THREADS];
extern void *wa[MAX_THREADS]; extern void *wa[MAX_THREADS];
extern bool_t test_timer_done; extern bool_t test_timer_done;

View File

@ -58,8 +58,8 @@ static void mtx1_execute(void) {
threads[3] = chThdCreateStatic(wa[3], STKSIZE, prio+4, thread1, "B"); threads[3] = chThdCreateStatic(wa[3], STKSIZE, prio+4, thread1, "B");
threads[4] = chThdCreateStatic(wa[4], STKSIZE, prio+5, thread1, "A"); threads[4] = chThdCreateStatic(wa[4], STKSIZE, prio+5, thread1, "A");
chMtxUnlock(); chMtxUnlock();
test_assert(prio == chThdGetPriority(), "priority return failure");
test_wait_threads(); test_wait_threads();
test_assert(prio == chThdGetPriority(), "priority return failure");
test_assert_sequence("ABCDE"); test_assert_sequence("ABCDE");
} }