2007-10-03 17:14:03 +00:00
|
|
|
/*
|
|
|
|
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>
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
#include "test.h"
|
|
|
|
#include "testrdy.h"
|
|
|
|
#include "testsem.h"
|
|
|
|
#include "testmtx.h"
|
|
|
|
#include "testmsg.h"
|
2009-02-18 12:58:35 +00:00
|
|
|
#include "testmbox.h"
|
2008-11-09 09:31:17 +00:00
|
|
|
#include "testevt.h"
|
2008-08-28 15:10:54 +00:00
|
|
|
#include "testheap.h"
|
2008-08-26 14:43:09 +00:00
|
|
|
#include "testpools.h"
|
2008-09-23 15:04:14 +00:00
|
|
|
#include "testdyn.h"
|
2008-06-26 13:36:25 +00:00
|
|
|
#include "testbmk.h"
|
2007-11-14 16:32:41 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
/*
|
2009-02-16 18:22:49 +00:00
|
|
|
* Array of all the test patterns.
|
2008-06-26 10:54:55 +00:00
|
|
|
*/
|
2009-02-16 18:22:49 +00:00
|
|
|
static const struct testcase **patterns[] = {
|
|
|
|
patternrdy,
|
|
|
|
patternsem,
|
|
|
|
patternmtx,
|
|
|
|
patternmsg,
|
2009-02-18 12:58:35 +00:00
|
|
|
patternmbox,
|
2009-02-16 18:22:49 +00:00
|
|
|
patternevt,
|
|
|
|
patternheap,
|
|
|
|
patternpools,
|
|
|
|
patterndyn,
|
|
|
|
patternbmk,
|
2008-06-26 10:54:55 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool_t local_fail, global_fail;
|
|
|
|
static char *failmsg;
|
|
|
|
static char tokens_buffer[MAX_TOKENS];
|
|
|
|
static char *tokp;
|
2008-11-29 10:54:24 +00:00
|
|
|
static WORKING_AREA(waT0, THREADS_STACK_SIZE);
|
|
|
|
static WORKING_AREA(waT1, THREADS_STACK_SIZE);
|
|
|
|
static WORKING_AREA(waT2, THREADS_STACK_SIZE);
|
|
|
|
static WORKING_AREA(waT3, THREADS_STACK_SIZE);
|
|
|
|
static WORKING_AREA(waT4, THREADS_STACK_SIZE);
|
2008-06-26 10:54:55 +00:00
|
|
|
|
|
|
|
void *wa[MAX_THREADS] = {waT0, waT1, waT2, waT3, waT4};
|
|
|
|
Thread *threads[MAX_THREADS];
|
2007-10-03 17:14:03 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
/*
|
|
|
|
* Console output.
|
|
|
|
*/
|
2007-10-03 17:14:03 +00:00
|
|
|
static FullDuplexDriver *comp;
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
void test_printn(uint32_t n) {
|
2007-11-13 16:38:23 +00:00
|
|
|
char buf[16], *p;
|
|
|
|
|
|
|
|
if (!n)
|
|
|
|
chFDDPut(comp, '0');
|
|
|
|
else {
|
|
|
|
p = buf;
|
|
|
|
while (n)
|
2008-03-05 15:56:12 +00:00
|
|
|
*p++ = (n % 10) + '0', n /= 10;
|
2007-11-13 16:38:23 +00:00
|
|
|
while (p > buf)
|
|
|
|
chFDDPut(comp, *--p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
void test_print(char *msgp) {
|
2007-10-03 17:14:03 +00:00
|
|
|
|
|
|
|
while (*msgp)
|
|
|
|
chFDDPut(comp, *msgp++);
|
2007-11-13 16:38:23 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
void test_println(char *msgp) {
|
2007-11-13 16:38:23 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
test_print(msgp);
|
2007-10-03 17:14:03 +00:00
|
|
|
chFDDPut(comp, '\r');
|
|
|
|
chFDDPut(comp, '\n');
|
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
/*
|
|
|
|
* Tokens.
|
|
|
|
*/
|
|
|
|
static void clear_tokens(void) {
|
2007-12-16 19:01:30 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
tokp = tokens_buffer;
|
2007-12-16 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
static void print_tokens(void) {
|
|
|
|
char *cp = tokens_buffer;
|
2007-12-16 19:01:30 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
while (cp < tokp)
|
|
|
|
chFDDPut(comp, *cp++);
|
2007-12-16 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
void test_emit_token(char token) {
|
2007-12-16 19:01:30 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
chSysLock();
|
|
|
|
*tokp++ = token;
|
|
|
|
chSysUnlock();
|
2007-12-16 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 11:23:56 +00:00
|
|
|
/*
|
2008-06-26 10:54:55 +00:00
|
|
|
* Assertions.
|
2007-12-19 11:23:56 +00:00
|
|
|
*/
|
2008-11-01 17:49:53 +00:00
|
|
|
bool_t _test_fail(char * msg) {
|
2007-12-16 19:01:30 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
local_fail = TRUE;
|
|
|
|
global_fail = TRUE;
|
|
|
|
failmsg = msg;
|
2008-11-01 17:49:53 +00:00
|
|
|
return TRUE;
|
2007-12-16 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2008-11-01 17:49:53 +00:00
|
|
|
bool_t _test_assert(bool_t condition, char * msg) {
|
2007-12-19 11:23:56 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
if (!condition)
|
2008-11-01 17:49:53 +00:00
|
|
|
return _test_fail(msg);
|
|
|
|
return FALSE;
|
2007-12-19 11:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-11-01 17:49:53 +00:00
|
|
|
bool_t _test_assert_sequence(char *expected) {
|
2008-06-26 10:54:55 +00:00
|
|
|
char *cp = tokens_buffer;
|
|
|
|
while (cp < tokp) {
|
|
|
|
if (*cp++ != *expected++)
|
2008-11-01 17:49:53 +00:00
|
|
|
return _test_fail(NULL);
|
2008-06-26 10:54:55 +00:00
|
|
|
}
|
|
|
|
if (*expected)
|
2008-11-01 17:49:53 +00:00
|
|
|
return _test_fail(NULL);
|
|
|
|
return FALSE;
|
2007-12-19 11:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-11-01 17:49:53 +00:00
|
|
|
bool_t _test_assert_time_window(systime_t start, systime_t end) {
|
2007-12-19 11:23:56 +00:00
|
|
|
|
2009-03-10 15:31:58 +00:00
|
|
|
return _test_assert(chTimeIsWithin(start, end), "time window error");
|
2007-12-19 11:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-06-26 10:54:55 +00:00
|
|
|
* Threads utils.
|
2007-12-19 11:23:56 +00:00
|
|
|
*/
|
2008-07-30 14:56:35 +00:00
|
|
|
void test_terminate_threads(void) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_THREADS; i++)
|
|
|
|
if (threads[i])
|
|
|
|
chThdTerminate(threads[i]);
|
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
void test_wait_threads(void) {
|
|
|
|
int i;
|
2007-12-19 11:23:56 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
for (i = 0; i < MAX_THREADS; i++)
|
|
|
|
if (threads[i])
|
|
|
|
chThdWait(threads[i]);
|
2007-12-16 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2008-10-15 18:26:16 +00:00
|
|
|
void test_cpu_pulse(unsigned ms) {
|
2007-10-03 17:14:03 +00:00
|
|
|
|
2008-10-15 18:26:16 +00:00
|
|
|
systime_t duration = MS2ST(ms);
|
2009-03-10 15:31:58 +00:00
|
|
|
systime_t start = chTimeNow();
|
|
|
|
while (chTimeIsWithin(start, start + duration)) {
|
2007-11-14 16:32:41 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
|
|
|
}
|
2007-12-21 15:27:59 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 13:36:25 +00:00
|
|
|
systime_t test_wait_tick(void) {
|
|
|
|
|
2008-07-02 12:32:13 +00:00
|
|
|
chThdSleep(1);
|
2009-03-10 15:31:58 +00:00
|
|
|
return chTimeNow();
|
2008-07-02 12:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timer utils.
|
|
|
|
*/
|
|
|
|
static VirtualTimer vt;
|
|
|
|
bool_t test_timer_done;
|
|
|
|
|
|
|
|
static void tmr(void *p) {
|
|
|
|
|
|
|
|
test_timer_done = TRUE;
|
|
|
|
}
|
|
|
|
|
2008-10-15 18:26:16 +00:00
|
|
|
void test_start_timer(unsigned ms) {
|
2008-07-02 12:32:13 +00:00
|
|
|
|
2008-10-15 18:26:16 +00:00
|
|
|
systime_t duration = MS2ST(ms);
|
2008-07-02 12:32:13 +00:00
|
|
|
test_timer_done = FALSE;
|
|
|
|
chSysLock();
|
2008-10-15 18:26:16 +00:00
|
|
|
chVTSetI(&vt, duration, tmr, NULL);
|
2008-07-02 12:32:13 +00:00
|
|
|
chSysUnlock();
|
2008-06-26 13:36:25 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
/*
|
|
|
|
* Test suite execution.
|
|
|
|
*/
|
|
|
|
static void execute_test(const struct testcase *tcp) {
|
|
|
|
int i;
|
2007-12-21 15:27:59 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
/* Initialization */
|
|
|
|
clear_tokens();
|
|
|
|
local_fail = FALSE;
|
|
|
|
for (i = 0; i < MAX_THREADS; i++)
|
|
|
|
threads[i] = NULL;
|
2007-12-16 19:01:30 +00:00
|
|
|
|
2009-02-16 18:22:49 +00:00
|
|
|
if (tcp->setup != NULL)
|
|
|
|
tcp->setup();
|
2008-06-26 10:54:55 +00:00
|
|
|
tcp->execute();
|
2009-02-16 18:22:49 +00:00
|
|
|
if (tcp->teardown != NULL)
|
|
|
|
tcp->teardown();
|
2007-12-21 15:27:59 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
msg_t TestThread(void *p) {
|
2009-02-16 18:22:49 +00:00
|
|
|
int i, j;
|
2007-12-21 15:27:59 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
comp = p;
|
|
|
|
test_println("");
|
|
|
|
test_println("*****************************");
|
|
|
|
test_println("*** ChibiOS/RT test suite ***");
|
|
|
|
test_println("*****************************");
|
|
|
|
test_println("");
|
2007-11-29 09:16:53 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
global_fail = FALSE;
|
2007-11-29 09:16:53 +00:00
|
|
|
i = 0;
|
2009-02-16 18:22:49 +00:00
|
|
|
while (patterns[i]) {
|
2009-02-16 20:38:05 +00:00
|
|
|
j = 0;
|
|
|
|
while (patterns[i][j]) {
|
2008-06-26 10:54:55 +00:00
|
|
|
#if DELAY_BETWEEN_TESTS > 0
|
2009-02-16 18:22:49 +00:00
|
|
|
chThdSleepMilliseconds(DELAY_BETWEEN_TESTS);
|
2007-11-29 09:16:53 +00:00
|
|
|
#endif
|
2009-02-16 18:22:49 +00:00
|
|
|
test_println("---------------------------------------------------------------------------");
|
|
|
|
test_print("--- Test Case ");
|
|
|
|
test_printn(i + 1);
|
|
|
|
test_print(".");
|
|
|
|
test_printn(j + 1);
|
|
|
|
test_print(" (");
|
|
|
|
test_print(patterns[i][j]->gettest());
|
2008-06-26 10:54:55 +00:00
|
|
|
test_println(")");
|
2009-02-16 18:22:49 +00:00
|
|
|
execute_test(patterns[i][j]);
|
|
|
|
if (local_fail) {
|
|
|
|
test_print("--- Result: FAIL (");
|
|
|
|
if (failmsg)
|
|
|
|
test_print(failmsg);
|
|
|
|
else {
|
|
|
|
test_print("sequence error: ");
|
|
|
|
print_tokens();
|
|
|
|
}
|
|
|
|
test_println(")");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
test_println("--- Result: SUCCESS");
|
|
|
|
j++;
|
2008-06-26 10:54:55 +00:00
|
|
|
}
|
2007-12-03 16:19:47 +00:00
|
|
|
i++;
|
|
|
|
}
|
2008-06-26 13:36:25 +00:00
|
|
|
test_println("---------------------------------------------------------------------------");
|
2008-06-26 10:54:55 +00:00
|
|
|
test_println("");
|
|
|
|
test_print("Final result: ");
|
|
|
|
if (global_fail)
|
|
|
|
test_println("FAIL");
|
|
|
|
else
|
|
|
|
test_println("SUCCESS");
|
2007-12-16 19:01:30 +00:00
|
|
|
|
2007-10-03 17:14:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|