2008-03-27 05:33:31 -07:00
|
|
|
/*
|
2015-01-11 05:56:55 -08:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2008-03-27 05:33:31 -07:00
|
|
|
|
2013-03-30 03:32:37 -07:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2008-03-27 05:33:31 -07:00
|
|
|
|
2013-03-30 03:32:37 -07:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2008-03-27 05:33:31 -07:00
|
|
|
|
2013-03-30 03:32:37 -07:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2008-03-27 05:33:31 -07:00
|
|
|
*/
|
|
|
|
|
2010-04-27 04:53:03 -07:00
|
|
|
/**
|
|
|
|
* @file test.h
|
|
|
|
* @brief Tests support header.
|
|
|
|
*
|
|
|
|
* @addtogroup test
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2008-03-27 05:33:31 -07:00
|
|
|
#ifndef _TEST_H_
|
|
|
|
#define _TEST_H_
|
|
|
|
|
2010-04-27 04:53:03 -07:00
|
|
|
/**
|
|
|
|
* @brief Delay inserted between test cases.
|
|
|
|
*/
|
|
|
|
#if !defined(DELAY_BETWEEN_TESTS) || defined(__DOXYGEN__)
|
2009-02-16 10:22:49 -08:00
|
|
|
#define DELAY_BETWEEN_TESTS 200
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 04:53:03 -07:00
|
|
|
/**
|
|
|
|
* @brief If @p TRUE then benchmarks are not included.
|
|
|
|
*/
|
|
|
|
#if !defined(TEST_NO_BENCHMARKS) || defined(__DOXYGEN__)
|
2009-02-16 10:22:49 -08:00
|
|
|
#define TEST_NO_BENCHMARKS FALSE
|
|
|
|
#endif
|
|
|
|
|
2008-06-26 03:54:55 -07:00
|
|
|
#define MAX_THREADS 5
|
|
|
|
#define MAX_TOKENS 16
|
|
|
|
|
2010-06-25 01:55:40 -07:00
|
|
|
#if defined(CH_ARCHITECTURE_AVR) || defined(CH_ARCHITECTURE_MSP430)
|
2008-12-29 04:12:53 -08:00
|
|
|
#define THREADS_STACK_SIZE 48
|
2010-06-25 01:55:40 -07:00
|
|
|
#elif defined(CH_ARCHITECTURE_STM8)
|
|
|
|
#define THREADS_STACK_SIZE 64
|
2010-01-03 00:16:18 -08:00
|
|
|
#elif defined(CH_ARCHITECTURE_SIMIA32)
|
2008-12-13 01:55:16 -08:00
|
|
|
#define THREADS_STACK_SIZE 512
|
2008-06-26 03:54:55 -07:00
|
|
|
#else
|
|
|
|
#define THREADS_STACK_SIZE 128
|
|
|
|
#endif
|
2013-09-03 02:51:32 -07:00
|
|
|
#define WA_SIZE THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE)
|
2008-06-26 03:54:55 -07:00
|
|
|
|
2010-04-27 04:53:03 -07:00
|
|
|
/**
|
|
|
|
* @brief Structure representing a test case.
|
|
|
|
*/
|
2008-06-26 03:54:55 -07:00
|
|
|
struct testcase {
|
2010-06-15 04:34:16 -07:00
|
|
|
const char *name; /**< @brief Test case name. */
|
2010-04-27 04:53:03 -07: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 03:54:55 -07:00
|
|
|
};
|
|
|
|
|
2009-10-17 02:21:59 -07:00
|
|
|
#ifndef __DOXYGEN__
|
2009-10-16 10:45:19 -07:00
|
|
|
union test_buffers {
|
|
|
|
struct {
|
2013-09-03 02:51:32 -07:00
|
|
|
THD_WORKING_AREA(T0, THREADS_STACK_SIZE);
|
|
|
|
THD_WORKING_AREA(T1, THREADS_STACK_SIZE);
|
|
|
|
THD_WORKING_AREA(T2, THREADS_STACK_SIZE);
|
|
|
|
THD_WORKING_AREA(T3, THREADS_STACK_SIZE);
|
|
|
|
THD_WORKING_AREA(T4, THREADS_STACK_SIZE);
|
2010-02-24 01:41:05 -08:00
|
|
|
} wa;
|
2009-10-16 10:45:19 -07:00
|
|
|
uint8_t buffer[WA_SIZE * 5];
|
|
|
|
};
|
2009-10-17 02:21:59 -07:00
|
|
|
#endif
|
2009-10-16 10:45:19 -07:00
|
|
|
|
2008-03-27 05:33:31 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
msg_t TestThread(void *p);
|
2008-06-26 06:36:25 -07:00
|
|
|
void test_printn(uint32_t n);
|
2010-06-26 02:53:51 -07:00
|
|
|
void test_print(const char *msgp);
|
|
|
|
void test_println(const char *msgp);
|
2008-06-26 03:54:55 -07:00
|
|
|
void test_emit_token(char token);
|
2013-09-03 01:48:20 -07:00
|
|
|
bool _test_fail(unsigned point);
|
|
|
|
bool _test_assert(unsigned point, bool condition);
|
|
|
|
bool _test_assert_sequence(unsigned point, char *expected);
|
|
|
|
bool _test_assert_time_window(unsigned point, systime_t start, systime_t end);
|
2008-07-30 07:56:35 -07:00
|
|
|
void test_terminate_threads(void);
|
2008-06-26 03:54:55 -07:00
|
|
|
void test_wait_threads(void);
|
2008-06-26 06:36:25 -07:00
|
|
|
systime_t test_wait_tick(void);
|
2008-10-15 11:26:16 -07:00
|
|
|
void test_start_timer(unsigned ms);
|
2009-05-09 06:06:30 -07:00
|
|
|
#if CH_DBG_THREADS_PROFILING
|
|
|
|
void test_cpu_pulse(unsigned duration);
|
|
|
|
#endif
|
2008-09-27 01:33:34 -07:00
|
|
|
#if defined(WIN32)
|
|
|
|
void ChkIntSources(void);
|
|
|
|
#endif
|
2008-03-27 05:33:31 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 04:53:03 -07:00
|
|
|
/**
|
|
|
|
* @brief Test failure enforcement.
|
|
|
|
*/
|
|
|
|
#define test_fail(point) { \
|
|
|
|
_test_fail(point); \
|
|
|
|
return; \
|
2008-11-01 10:49:53 -07:00
|
|
|
}
|
|
|
|
|
2010-04-27 04:53:03 -07: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 10:49:53 -07:00
|
|
|
}
|
|
|
|
|
2011-08-12 04:10:19 -07: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 04:53:03 -07: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 10:49:53 -07:00
|
|
|
}
|
|
|
|
|
2010-04-27 04:53:03 -07: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 10:49:53 -07:00
|
|
|
}
|
|
|
|
|
2010-04-27 04:53:03 -07:00
|
|
|
#if !defined(__DOXYGEN__)
|
2013-07-19 05:22:31 -07:00
|
|
|
extern thread_t *threads[MAX_THREADS];
|
2009-10-16 10:45:19 -07:00
|
|
|
extern union test_buffers test;
|
2010-06-25 01:55:40 -07:00
|
|
|
extern void * ROMCONST wa[];
|
2013-09-03 01:48:20 -07:00
|
|
|
extern bool test_timer_done;
|
2010-04-27 04:53:03 -07:00
|
|
|
#endif
|
2008-06-26 03:54:55 -07:00
|
|
|
|
2008-03-27 05:33:31 -07:00
|
|
|
#endif /* _TEST_H_ */
|
2010-04-27 04:53:03 -07:00
|
|
|
|
|
|
|
/** @} */
|