2008-03-27 12:33:31 +00:00
|
|
|
/*
|
2015-01-11 13:56:55 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2008-03-27 12:33:31 +00:00
|
|
|
|
2013-03-30 10:32:37 +00: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 12:33:31 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2008-03-27 12:33:31 +00:00
|
|
|
|
2013-03-30 10:32:37 +00: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 12:33:31 +00:00
|
|
|
*/
|
|
|
|
|
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
|
2013-09-03 09:51:32 +00:00
|
|
|
#define WA_SIZE THD_WORKING_AREA_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 {
|
2013-09-03 09:51:32 +00: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 09:41:05 +00:00
|
|
|
} 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);
|
2013-09-03 08:48:20 +00: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 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__)
|
2013-07-19 12:22:31 +00:00
|
|
|
extern thread_t *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[];
|
2013-09-03 08:48:20 +00:00
|
|
|
extern bool 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
|
|
|
|
|
|
|
/** @} */
|