2008-03-27 12:33:31 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2013-02-02 10:58:09 +00:00
|
|
|
2011,2012,2013 Giovanni Di Sirio.
|
2008-03-27 12:33:31 +00:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
/**
|
|
|
|
* @file test.h
|
|
|
|
* @brief Tests support header.
|
|
|
|
*
|
|
|
|
* @addtogroup test
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2008-03-27 12:33:31 +00:00
|
|
|
#ifndef _TEST_H_
|
|
|
|
#define _TEST_H_
|
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Delay inserted between test cases.
|
|
|
|
*/
|
|
|
|
#if !defined(DELAY_BETWEEN_TESTS) || defined(__DOXYGEN__)
|
2009-02-16 18:22:49 +00:00
|
|
|
#define DELAY_BETWEEN_TESTS 200
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
/**
|
|
|
|
* @brief If @p TRUE then benchmarks are not included.
|
|
|
|
*/
|
|
|
|
#if !defined(TEST_NO_BENCHMARKS) || defined(__DOXYGEN__)
|
2009-02-16 18:22:49 +00:00
|
|
|
#define TEST_NO_BENCHMARKS FALSE
|
|
|
|
#endif
|
|
|
|
|
2008-06-26 10:54:55 +00:00
|
|
|
#define MAX_THREADS 5
|
|
|
|
#define MAX_TOKENS 16
|
|
|
|
|
2010-06-25 08:55:40 +00:00
|
|
|
#if defined(CH_ARCHITECTURE_AVR) || defined(CH_ARCHITECTURE_MSP430)
|
2008-12-29 12:12:53 +00:00
|
|
|
#define THREADS_STACK_SIZE 48
|
2010-06-25 08:55:40 +00:00
|
|
|
#elif defined(CH_ARCHITECTURE_STM8)
|
|
|
|
#define THREADS_STACK_SIZE 64
|
2010-01-03 08:16:18 +00:00
|
|
|
#elif defined(CH_ARCHITECTURE_SIMIA32)
|
2008-12-13 09:55:16 +00:00
|
|
|
#define THREADS_STACK_SIZE 512
|
2008-06-26 10:54:55 +00:00
|
|
|
#else
|
|
|
|
#define THREADS_STACK_SIZE 128
|
|
|
|
#endif
|
2008-11-29 10:54:24 +00:00
|
|
|
#define WA_SIZE THD_WA_SIZE(THREADS_STACK_SIZE)
|
2008-06-26 10:54:55 +00:00
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Structure representing a test case.
|
|
|
|
*/
|
2008-06-26 10:54:55 +00:00
|
|
|
struct testcase {
|
2010-06-15 11:34:16 +00:00
|
|
|
const char *name; /**< @brief Test case name. */
|
2010-04-27 11:53:03 +00:00
|
|
|
void (*setup)(void); /**< @brief Test case preparation function. */
|
|
|
|
void (*teardown)(void); /**< @brief Test case clean up function. */
|
|
|
|
void (*execute)(void); /**< @brief Test case execution function. */
|
2008-06-26 10:54:55 +00:00
|
|
|
};
|
|
|
|
|
2009-10-17 09:21:59 +00:00
|
|
|
#ifndef __DOXYGEN__
|
2009-10-16 17:45:19 +00:00
|
|
|
union test_buffers {
|
|
|
|
struct {
|
2010-02-24 09:41:05 +00:00
|
|
|
WORKING_AREA(T0, THREADS_STACK_SIZE);
|
|
|
|
WORKING_AREA(T1, THREADS_STACK_SIZE);
|
|
|
|
WORKING_AREA(T2, THREADS_STACK_SIZE);
|
|
|
|
WORKING_AREA(T3, THREADS_STACK_SIZE);
|
|
|
|
WORKING_AREA(T4, THREADS_STACK_SIZE);
|
|
|
|
} wa;
|
2009-10-16 17:45:19 +00:00
|
|
|
uint8_t buffer[WA_SIZE * 5];
|
|
|
|
};
|
2009-10-17 09:21:59 +00:00
|
|
|
#endif
|
2009-10-16 17:45:19 +00:00
|
|
|
|
2008-03-27 12:33:31 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
msg_t TestThread(void *p);
|
2008-06-26 13:36:25 +00:00
|
|
|
void test_printn(uint32_t n);
|
2010-06-26 09:53:51 +00:00
|
|
|
void test_print(const char *msgp);
|
|
|
|
void test_println(const char *msgp);
|
2008-06-26 10:54:55 +00:00
|
|
|
void test_emit_token(char token);
|
2009-04-25 11:12:10 +00:00
|
|
|
bool_t _test_fail(unsigned point);
|
|
|
|
bool_t _test_assert(unsigned point, bool_t condition);
|
|
|
|
bool_t _test_assert_sequence(unsigned point, char *expected);
|
|
|
|
bool_t _test_assert_time_window(unsigned point, systime_t start, systime_t end);
|
2008-07-30 14:56:35 +00:00
|
|
|
void test_terminate_threads(void);
|
2008-06-26 10:54:55 +00:00
|
|
|
void test_wait_threads(void);
|
2008-06-26 13:36:25 +00:00
|
|
|
systime_t test_wait_tick(void);
|
2008-10-15 18:26:16 +00:00
|
|
|
void test_start_timer(unsigned ms);
|
2009-05-09 13:06:30 +00:00
|
|
|
#if CH_DBG_THREADS_PROFILING
|
|
|
|
void test_cpu_pulse(unsigned duration);
|
|
|
|
#endif
|
2008-09-27 08:33:34 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
void ChkIntSources(void);
|
|
|
|
#endif
|
2008-03-27 12:33:31 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Test failure enforcement.
|
|
|
|
*/
|
|
|
|
#define test_fail(point) { \
|
|
|
|
_test_fail(point); \
|
|
|
|
return; \
|
2008-11-01 17:49:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Test assertion.
|
|
|
|
*
|
|
|
|
* @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(point, condition, msg) { \
|
|
|
|
if (_test_assert(point, condition)) \
|
|
|
|
return; \
|
2008-11-01 17:49:53 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 11:10:19 +00:00
|
|
|
/**
|
|
|
|
* @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(); \
|
|
|
|
}
|
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Test sequence assertion.
|
|
|
|
*
|
|
|
|
* @param[in] point numeric assertion identifier
|
|
|
|
* @param[in] expected string to be matched with the tokens buffer
|
|
|
|
*/
|
|
|
|
#define test_assert_sequence(point, expected) { \
|
|
|
|
if (_test_assert_sequence(point, expected)) \
|
|
|
|
return; \
|
2008-11-01 17:49:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Test time window assertion.
|
|
|
|
*
|
|
|
|
* @param[in] point numeric assertion identifier
|
|
|
|
* @param[in] start initial time in the window (included)
|
|
|
|
* @param[in] end final time in the window (not included)
|
|
|
|
*/
|
|
|
|
#define test_assert_time_window(point, start, end) { \
|
|
|
|
if (_test_assert_time_window(point, start, end)) \
|
|
|
|
return; \
|
2008-11-01 17:49:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-27 11:53:03 +00:00
|
|
|
#if !defined(__DOXYGEN__)
|
2008-06-26 10:54:55 +00:00
|
|
|
extern Thread *threads[MAX_THREADS];
|
2009-10-16 17:45:19 +00:00
|
|
|
extern union test_buffers test;
|
2010-06-25 08:55:40 +00:00
|
|
|
extern void * ROMCONST wa[];
|
2008-07-02 12:32:13 +00:00
|
|
|
extern bool_t test_timer_done;
|
2010-04-27 11:53:03 +00:00
|
|
|
#endif
|
2008-06-26 10:54:55 +00:00
|
|
|
|
2008-03-27 12:33:31 +00:00
|
|
|
#endif /* _TEST_H_ */
|
2010-04-27 11:53:03 +00:00
|
|
|
|
|
|
|
/** @} */
|