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"
|
2009-04-13 08:15:51 +00:00
|
|
|
#include "testthd.h"
|
2008-06-26 10:54:55 +00:00
|
|
|
#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"
|
2009-05-03 16:42:52 +00:00
|
|
|
#include "testqueues.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[] = {
|
2009-04-13 08:15:51 +00:00
|
|
|
patternthd,
|
2009-02-16 18:22:49 +00:00
|
|
|
patternsem,
|
|
|
|
patternmtx,
|
|
|
|
patternmsg,
|
2009-02-18 12:58:35 +00:00
|
|
|
patternmbox,
|
2009-02-16 18:22:49 +00:00
|
|
|
patternevt,
|
|
|
|
patternheap,
|
|
|
|
patternpools,
|
|
|
|
patterndyn,
|
2009-05-03 16:42:52 +00:00
|
|
|
patternqueues,
|
2009-02-16 18:22:49 +00:00
|
|
|
patternbmk,
|
2008-06-26 10:54:55 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool_t local_fail, global_fail;
|
2009-04-25 11:12:10 +00:00
|
|
|
static unsigned failpoint;
|
2008-06-26 10:54:55 +00:00
|
|
|
static char tokens_buffer[MAX_TOKENS];
|
|
|
|
static char *tokp;
|
2009-05-16 11:53:48 +00:00
|
|
|
|
2009-05-16 12:37:01 +00:00
|
|
|
/*
|
|
|
|
* Static working areas, the following areas can be used for threads or
|
|
|
|
* used as temporary buffers.
|
|
|
|
*/
|
2009-05-16 11:53:48 +00:00
|
|
|
WORKING_AREA(waT0, THREADS_STACK_SIZE);
|
|
|
|
WORKING_AREA(waT1, THREADS_STACK_SIZE);
|
|
|
|
WORKING_AREA(waT2, THREADS_STACK_SIZE);
|
|
|
|
WORKING_AREA(waT3, THREADS_STACK_SIZE);
|
|
|
|
WORKING_AREA(waT4, THREADS_STACK_SIZE);
|
2008-06-26 10:54:55 +00:00
|
|
|
|
2009-05-16 12:37:01 +00:00
|
|
|
/*
|
|
|
|
* Pointers to the spawned threads.
|
|
|
|
*/
|
2008-06-26 10:54:55 +00:00
|
|
|
Thread *threads[MAX_THREADS];
|
2007-10-03 17:14:03 +00:00
|
|
|
|
2009-05-16 12:37:01 +00:00
|
|
|
/*
|
|
|
|
* Pointers to the working areas.
|
|
|
|
*/
|
|
|
|
void * const wa[5] = {waT0, waT1, waT2, waT3, waT4};
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
/*
|
|
|
|
* Console output.
|
|
|
|
*/
|
2009-05-02 20:15:04 +00:00
|
|
|
static BaseChannel *chp;
|
2007-10-03 17:14:03 +00:00
|
|
|
|
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)
|
2009-05-02 20:15:04 +00:00
|
|
|
chIOPut(chp, '0');
|
2007-11-13 16:38:23 +00:00
|
|
|
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)
|
2009-05-02 20:15:04 +00:00
|
|
|
chIOPut(chp, *--p);
|
2007-11-13 16:38:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
void test_print(char *msgp) {
|
2007-10-03 17:14:03 +00:00
|
|
|
|
|
|
|
while (*msgp)
|
2009-05-02 20:15:04 +00:00
|
|
|
chIOPut(chp, *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);
|
2009-05-02 20:15:04 +00:00
|
|
|
chIOPut(chp, '\r');
|
|
|
|
chIOPut(chp, '\n');
|
2007-10-03 17:14:03 +00:00
|
|
|
}
|
|
|
|
|
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)
|
2009-05-02 20:15:04 +00:00
|
|
|
chIOPut(chp, *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
|
|
|
*/
|
2009-04-25 11:12:10 +00:00
|
|
|
bool_t _test_fail(unsigned point) {
|
2007-12-16 19:01:30 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
local_fail = TRUE;
|
|
|
|
global_fail = TRUE;
|
2009-04-25 11:12:10 +00:00
|
|
|
failpoint = point;
|
2008-11-01 17:49:53 +00:00
|
|
|
return TRUE;
|
2007-12-16 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 11:12:10 +00:00
|
|
|
bool_t _test_assert(unsigned point, bool_t condition) {
|
2007-12-19 11:23:56 +00:00
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
if (!condition)
|
2009-04-25 11:12:10 +00:00
|
|
|
return _test_fail(point);
|
2008-11-01 17:49:53 +00:00
|
|
|
return FALSE;
|
2007-12-19 11:23:56 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 11:12:10 +00:00
|
|
|
bool_t _test_assert_sequence(unsigned point, char *expected) {
|
2008-06-26 10:54:55 +00:00
|
|
|
char *cp = tokens_buffer;
|
|
|
|
while (cp < tokp) {
|
|
|
|
if (*cp++ != *expected++)
|
2009-04-25 11:12:10 +00:00
|
|
|
return _test_fail(point);
|
2008-06-26 10:54:55 +00:00
|
|
|
}
|
|
|
|
if (*expected)
|
2009-04-25 11:12:10 +00:00
|
|
|
return _test_fail(point);
|
2009-05-09 13:06:30 +00:00
|
|
|
clear_tokens();
|
2008-11-01 17:49:53 +00:00
|
|
|
return FALSE;
|
2007-12-19 11:23:56 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 11:12:10 +00:00
|
|
|
bool_t _test_assert_time_window(unsigned point, systime_t start, systime_t end) {
|
2007-12-19 11:23:56 +00:00
|
|
|
|
2009-04-25 11:12:10 +00:00
|
|
|
return _test_assert(point, chTimeIsWithin(start, end));
|
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++)
|
2009-04-12 13:00:42 +00:00
|
|
|
if (threads[i] != NULL) {
|
2008-06-26 10:54:55 +00:00
|
|
|
chThdWait(threads[i]);
|
2009-04-12 13:00:42 +00:00
|
|
|
threads[i] = NULL;
|
|
|
|
}
|
2007-12-16 19:01:30 +00:00
|
|
|
}
|
|
|
|
|
2009-05-09 13:06:30 +00:00
|
|
|
#if CH_DBG_THREADS_PROFILING
|
|
|
|
void test_cpu_pulse(unsigned duration) {
|
2009-05-09 19:36:30 +00:00
|
|
|
systime_t start, end, now;
|
2007-10-03 17:14:03 +00:00
|
|
|
|
2009-05-09 19:36:30 +00:00
|
|
|
start = chThdSelf()->p_time;
|
|
|
|
end = start + MS2ST(duration);
|
|
|
|
do {
|
|
|
|
now = chThdSelf()->p_time;
|
2007-11-14 16:32:41 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
ChkIntSources();
|
|
|
|
#endif
|
|
|
|
}
|
2009-05-09 19:36:30 +00:00
|
|
|
while (end > start ? (now >= start) && (now < end) :
|
|
|
|
(now >= start) || (now < end));
|
2007-12-21 15:27:59 +00:00
|
|
|
}
|
2009-05-09 13:06:30 +00:00
|
|
|
#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();
|
2009-04-12 13:00:42 +00:00
|
|
|
|
|
|
|
test_wait_threads();
|
2007-12-21 15:27:59 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 14:56:16 +00:00
|
|
|
static void print_line(void) {
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < 76; i++)
|
2009-05-02 20:15:04 +00:00
|
|
|
chIOPut(chp, '-');
|
|
|
|
chIOPut(chp, '\r');
|
|
|
|
chIOPut(chp, '\n');
|
2009-04-25 14:56:16 +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
|
|
|
|
2009-05-02 20:15:04 +00:00
|
|
|
chp = p;
|
2008-06-26 10:54:55 +00:00
|
|
|
test_println("");
|
2009-04-25 14:56:16 +00:00
|
|
|
test_println("*** ChibiOS/RT test suite");
|
|
|
|
test_println("***");
|
|
|
|
test_print("*** Kernel: ");
|
|
|
|
test_println(CH_KERNEL_VERSION);
|
|
|
|
test_print("*** Architecture: ");
|
|
|
|
test_println(CH_ARCHITECTURE_NAME);
|
2009-04-25 15:32:28 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
test_print("*** GCC Version: ");
|
|
|
|
test_println(__VERSION__);
|
|
|
|
#endif
|
2008-06-26 10:54:55 +00:00
|
|
|
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-04-25 14:56:16 +00:00
|
|
|
print_line();
|
2009-02-16 18:22:49 +00:00
|
|
|
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) {
|
2009-04-25 15:00:43 +00:00
|
|
|
test_print("--- Result: FAILURE (#");
|
2009-04-25 11:12:10 +00:00
|
|
|
test_printn(failpoint);
|
|
|
|
test_print(" [");
|
|
|
|
print_tokens();
|
|
|
|
test_println("])");
|
2009-02-16 18:22:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
test_println("--- Result: SUCCESS");
|
|
|
|
j++;
|
2008-06-26 10:54:55 +00:00
|
|
|
}
|
2007-12-03 16:19:47 +00:00
|
|
|
i++;
|
|
|
|
}
|
2009-04-25 14:56:16 +00:00
|
|
|
print_line();
|
2008-06-26 10:54:55 +00:00
|
|
|
test_println("");
|
|
|
|
test_print("Final result: ");
|
|
|
|
if (global_fail)
|
2009-04-25 15:00:43 +00:00
|
|
|
test_println("FAILURE");
|
2008-06-26 10:54:55 +00:00
|
|
|
else
|
|
|
|
test_println("SUCCESS");
|
2007-12-16 19:01:30 +00:00
|
|
|
|
2009-03-13 19:30:52 +00:00
|
|
|
return (msg_t)global_fail;
|
2007-10-03 17:14:03 +00:00
|
|
|
}
|