Removed obsolete files.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14666 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
3ddb05691b
commit
2a9897c8d7
|
@ -1,340 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file ch_test.c
|
|
||||||
* @brief Unit Tests Engine module code.
|
|
||||||
*
|
|
||||||
* @addtogroup CH_TEST
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "hal.h"
|
|
||||||
#include "ch_test.h"
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module local definitions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module exported variables. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test step being executed.
|
|
||||||
*/
|
|
||||||
unsigned test_step;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test result flag.
|
|
||||||
*/
|
|
||||||
bool test_global_fail;
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module local types. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module local variables. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
static bool test_local_fail;
|
|
||||||
static const char *test_failure_message;
|
|
||||||
static char test_tokens_buffer[TEST_CFG_MAX_TOKENS];
|
|
||||||
static char *test_tokp;
|
|
||||||
static BaseSequentialStream *test_chp;
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module local functions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
static void clear_tokens(void) {
|
|
||||||
|
|
||||||
test_tokp = test_tokens_buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_tokens(void) {
|
|
||||||
char *cp = test_tokens_buffer;
|
|
||||||
|
|
||||||
while (cp < test_tokp)
|
|
||||||
streamPut(test_chp, *cp++);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void execute_test(const testcase_t *tcp) {
|
|
||||||
|
|
||||||
/* Initialization */
|
|
||||||
clear_tokens();
|
|
||||||
test_local_fail = false;
|
|
||||||
|
|
||||||
if (tcp->setup != NULL)
|
|
||||||
tcp->setup();
|
|
||||||
tcp->execute();
|
|
||||||
if (tcp->teardown != NULL)
|
|
||||||
tcp->teardown();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_line(void) {
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
for (i = 0; i < 76; i++)
|
|
||||||
streamPut(test_chp, '-');
|
|
||||||
streamWrite(test_chp, (const uint8_t *)"\r\n", 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void print_fat_line(void) {
|
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
for (i = 0; i < 76; i++)
|
|
||||||
streamPut(test_chp, '=');
|
|
||||||
streamWrite(test_chp, (const uint8_t *)"\r\n", 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module exported functions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
bool _test_fail(const char *msg) {
|
|
||||||
|
|
||||||
test_local_fail = true;
|
|
||||||
test_global_fail = true;
|
|
||||||
test_failure_message = msg;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _test_assert(bool condition, const char *msg) {
|
|
||||||
|
|
||||||
if (!condition)
|
|
||||||
return _test_fail(msg);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _test_assert_sequence(char *expected, const char *msg) {
|
|
||||||
char *cp = test_tokens_buffer;
|
|
||||||
|
|
||||||
while (cp < test_tokp) {
|
|
||||||
if (*cp++ != *expected++)
|
|
||||||
return _test_fail(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*expected)
|
|
||||||
return _test_fail(msg);
|
|
||||||
|
|
||||||
clear_tokens();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _test_assert_time_window(systime_t start,
|
|
||||||
systime_t end,
|
|
||||||
const char *msg) {
|
|
||||||
|
|
||||||
return _test_assert(osalTimeIsInRangeX(osalOsGetSystemTimeX(), start, end),
|
|
||||||
msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Prints a decimal unsigned number.
|
|
||||||
*
|
|
||||||
* @param[in] n the number to be printed
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
void test_printn(uint32_t n) {
|
|
||||||
char buf[16], *p;
|
|
||||||
|
|
||||||
if (!n)
|
|
||||||
streamPut(test_chp, '0');
|
|
||||||
else {
|
|
||||||
p = buf;
|
|
||||||
while (n)
|
|
||||||
*p++ = (n % 10) + '0', n /= 10;
|
|
||||||
while (p > buf)
|
|
||||||
streamPut(test_chp, *--p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Prints a line without final end-of-line.
|
|
||||||
*
|
|
||||||
* @param[in] msgp the message
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
void test_print(const char *msgp) {
|
|
||||||
|
|
||||||
while (*msgp)
|
|
||||||
streamPut(test_chp, *msgp++);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Prints a line.
|
|
||||||
*
|
|
||||||
* @param[in] msgp the message
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
void test_println(const char *msgp) {
|
|
||||||
|
|
||||||
test_print(msgp);
|
|
||||||
streamWrite(test_chp, (const uint8_t *)"\r\n", 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Emits a token into the tokens buffer.
|
|
||||||
*
|
|
||||||
* @param[in] token the token as a char
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
void test_emit_token(char token) {
|
|
||||||
|
|
||||||
osalSysLock();
|
|
||||||
if (test_tokp < &test_tokens_buffer[TEST_CFG_MAX_TOKENS])
|
|
||||||
*test_tokp++ = token;
|
|
||||||
osalSysUnlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Emits a token into the tokens buffer from a critical zone.
|
|
||||||
*
|
|
||||||
* @param[in] token the token as a char
|
|
||||||
*
|
|
||||||
* @iclass
|
|
||||||
*/
|
|
||||||
void test_emit_token_i(char token) {
|
|
||||||
|
|
||||||
if (test_tokp < &test_tokens_buffer[TEST_CFG_MAX_TOKENS])
|
|
||||||
*test_tokp++ = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test execution thread function.
|
|
||||||
*
|
|
||||||
* @param[in] stream pointer to a @p BaseSequentialStream object for test
|
|
||||||
* output
|
|
||||||
* @param[in] tsp test suite to execute
|
|
||||||
* @return A failure boolean value casted to @p msg_t.
|
|
||||||
* @retval false if no errors occurred.
|
|
||||||
* @retval true if one or more tests failed.
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
msg_t test_execute(BaseSequentialStream *stream, const testsuite_t *tsp) {
|
|
||||||
int tseq, tcase;
|
|
||||||
|
|
||||||
test_chp = stream;
|
|
||||||
test_println("");
|
|
||||||
if (tsp->name != NULL) {
|
|
||||||
test_print("*** ");
|
|
||||||
test_println(tsp->name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
test_println("*** Test Suite");
|
|
||||||
}
|
|
||||||
test_println("***");
|
|
||||||
test_print("*** Compiled: ");
|
|
||||||
test_println(__DATE__ " - " __TIME__);
|
|
||||||
#if defined(PLATFORM_NAME)
|
|
||||||
test_print("*** Platform: ");
|
|
||||||
test_println(PLATFORM_NAME);
|
|
||||||
#endif
|
|
||||||
#if defined(BOARD_NAME)
|
|
||||||
test_print("*** Test Board: ");
|
|
||||||
test_println(BOARD_NAME);
|
|
||||||
#endif
|
|
||||||
#if TEST_CFG_SIZE_REPORT == TRUE
|
|
||||||
{
|
|
||||||
extern uint8_t __text_base__, __text_end__,
|
|
||||||
__rodata_base__, __rodata_end__,
|
|
||||||
__data_base__, __data_end__,
|
|
||||||
__bss_base__, __bss_end__;
|
|
||||||
test_println("***");
|
|
||||||
test_print("*** Text size: ");
|
|
||||||
test_printn((uint32_t)(&__text_end__ - &__text_base__));
|
|
||||||
test_println(" bytes");
|
|
||||||
test_print("*** RO data size: ");
|
|
||||||
test_printn((uint32_t)(&__rodata_end__ - &__rodata_base__));
|
|
||||||
test_println(" bytes");
|
|
||||||
test_print("*** Data size: ");
|
|
||||||
test_printn((uint32_t)(&__data_end__ - &__data_base__));
|
|
||||||
test_println(" bytes");
|
|
||||||
test_print("*** BSS size: ");
|
|
||||||
test_printn((uint32_t)(&__bss_end__ - &__bss_base__));
|
|
||||||
test_println(" bytes");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if defined(TEST_REPORT_HOOK_HEADER)
|
|
||||||
TEST_REPORT_HOOK_HEADER
|
|
||||||
#endif
|
|
||||||
test_println("");
|
|
||||||
|
|
||||||
test_global_fail = false;
|
|
||||||
tseq = 0;
|
|
||||||
while (tsp->sequences[tseq] != NULL) {
|
|
||||||
#if TEST_CFG_SHOW_SEQUENCES == TRUE
|
|
||||||
print_fat_line();
|
|
||||||
test_print("=== Test Sequence ");
|
|
||||||
test_printn(tseq + 1);
|
|
||||||
test_print(" (");
|
|
||||||
test_print(tsp->sequences[tseq]->name);
|
|
||||||
test_println(")");
|
|
||||||
#endif
|
|
||||||
tcase = 0;
|
|
||||||
while (tsp->sequences[tseq]->cases[tcase] != NULL) {
|
|
||||||
print_line();
|
|
||||||
test_print("--- Test Case ");
|
|
||||||
test_printn(tseq + 1);
|
|
||||||
test_print(".");
|
|
||||||
test_printn(tcase + 1);
|
|
||||||
test_print(" (");
|
|
||||||
test_print(tsp->sequences[tseq]->cases[tcase]->name);
|
|
||||||
test_println(")");
|
|
||||||
#if TEST_CFG_DELAY_BETWEEN_TESTS > 0
|
|
||||||
osalThreadSleepMilliseconds(TEST_CFG_DELAY_BETWEEN_TESTS);
|
|
||||||
#endif
|
|
||||||
execute_test(tsp->sequences[tseq]->cases[tcase]);
|
|
||||||
if (test_local_fail) {
|
|
||||||
test_print("--- Result: FAILURE (#");
|
|
||||||
test_printn(test_step);
|
|
||||||
test_print(" [");
|
|
||||||
print_tokens();
|
|
||||||
test_print("] \"");
|
|
||||||
test_print(test_failure_message);
|
|
||||||
test_println("\")");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
test_println("--- Result: SUCCESS");
|
|
||||||
}
|
|
||||||
tcase++;
|
|
||||||
}
|
|
||||||
tseq++;
|
|
||||||
}
|
|
||||||
print_line();
|
|
||||||
test_println("");
|
|
||||||
test_print("Final result: ");
|
|
||||||
if (test_global_fail)
|
|
||||||
test_println("FAILURE");
|
|
||||||
else
|
|
||||||
test_println("SUCCESS");
|
|
||||||
|
|
||||||
#if defined(TEST_REPORT_HOOK_END)
|
|
||||||
TEST_REPORT_HOOK_END
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (msg_t)test_global_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,230 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file ch_test.h
|
|
||||||
* @brief Unit Tests Engine Module macros and structures.
|
|
||||||
*
|
|
||||||
* @addtogroup CH_TEST
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CH_TEST_H
|
|
||||||
#define CH_TEST_H
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module constants. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module pre-compile time settings. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Maximum number of entries in the tokens buffer.
|
|
||||||
*/
|
|
||||||
#if !defined(TEST_CFG_MAX_TOKENS) || defined(__DOXYGEN__)
|
|
||||||
#define TEST_CFG_MAX_TOKENS 16
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Delay inserted between test cases.
|
|
||||||
*/
|
|
||||||
#if !defined(TEST_CFG_DELAY_BETWEEN_TESTS) || defined(__DOXYGEN__)
|
|
||||||
#define TEST_CFG_DELAY_BETWEEN_TESTS 200
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Shows a sequence header if enabled.
|
|
||||||
*/
|
|
||||||
#if !defined(TEST_CFG_SHOW_SEQUENCES) || defined(__DOXYGEN__)
|
|
||||||
#define TEST_CFG_SHOW_SEQUENCES TRUE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Print executable sizes.
|
|
||||||
* @note Requires specific linker scatter files.
|
|
||||||
*/
|
|
||||||
#if !defined(TEST_CFG_SIZE_REPORT) || defined(__DOXYGEN__)
|
|
||||||
#define TEST_CFG_SIZE_REPORT TRUE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Derived constants and error checks. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module data structures and types. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing a test case.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
const char *name; /**< @brief Test case name. */
|
|
||||||
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. */
|
|
||||||
} testcase_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Structure representing a test sequence.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
const char *name; /**< @brief Name of the test sequence. */
|
|
||||||
const testcase_t * const * cases; /**< @brief Test cases array. */
|
|
||||||
} testsequence_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of a test suite.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
const char *name; /**< @brief Name of the test suite. */
|
|
||||||
const testsequence_t * const * sequences; /**< @brief Test sequences array. */
|
|
||||||
} testsuite_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Type of a test suite.
|
|
||||||
*/
|
|
||||||
//typedef const testcase_t * const *testsuite_t[];
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module macros. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Sets the step identifier.
|
|
||||||
*
|
|
||||||
* @param[in] step the step number
|
|
||||||
*/
|
|
||||||
#define test_set_step(step) test_step = (step)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief End step marker.
|
|
||||||
*
|
|
||||||
* @param[in] step the step number
|
|
||||||
*/
|
|
||||||
#define test_end_step(step) (void)(step);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test failure enforcement.
|
|
||||||
* @note This function can only be called from test_case execute context.
|
|
||||||
*
|
|
||||||
* @param[in] msg failure message as string
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define test_fail(msg) { \
|
|
||||||
_test_fail(msg); \
|
|
||||||
return; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test assertion.
|
|
||||||
* @note This function can only be called from test_case execute context.
|
|
||||||
*
|
|
||||||
* @param[in] condition a boolean expression that must be verified to be true
|
|
||||||
* @param[in] msg failure message as string
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define test_assert(condition, msg) { \
|
|
||||||
if (_test_assert(condition, msg)) \
|
|
||||||
return; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test assertion with lock.
|
|
||||||
* @note This function can only be called from test_case execute context.
|
|
||||||
*
|
|
||||||
* @param[in] condition a boolean expression that must be verified to be true
|
|
||||||
* @param[in] msg failure message as string
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define test_assert_lock(condition, msg) { \
|
|
||||||
osalSysLock(); \
|
|
||||||
if (_test_assert(condition, msg)) { \
|
|
||||||
osalSysUnlock(); \
|
|
||||||
return; \
|
|
||||||
} \
|
|
||||||
osalSysUnlock(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test sequence assertion.
|
|
||||||
* @note This function can only be called from test_case execute context.
|
|
||||||
*
|
|
||||||
* @param[in] expected string to be matched with the tokens buffer
|
|
||||||
* @param[in] msg failure message as string
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define test_assert_sequence(expected, msg) { \
|
|
||||||
if (_test_assert_sequence(expected, msg)) \
|
|
||||||
return; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Test time window assertion.
|
|
||||||
* @note This function can only be called from test_case execute context.
|
|
||||||
*
|
|
||||||
* @param[in] start initial time in the window (included)
|
|
||||||
* @param[in] end final time in the window (not included)
|
|
||||||
* @param[in] msg failure message as string
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
#define test_assert_time_window(start, end, msg) { \
|
|
||||||
if (_test_assert_time_window(start, end, msg)) \
|
|
||||||
return; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* External declarations. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#if !defined(__DOXYGEN__)
|
|
||||||
extern unsigned test_step;
|
|
||||||
extern bool test_global_fail;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
bool _test_fail(const char *message);
|
|
||||||
bool _test_assert(bool condition, const char *msg);
|
|
||||||
bool _test_assert_sequence(char *expected, const char *msg);
|
|
||||||
bool _test_assert_time_window(systime_t start,
|
|
||||||
systime_t end,
|
|
||||||
const char *msg);
|
|
||||||
void test_printn(uint32_t n);
|
|
||||||
void test_print(const char *msgp);
|
|
||||||
void test_println(const char *msgp);
|
|
||||||
void test_emit_token(char token);
|
|
||||||
void test_emit_token_i(char token);
|
|
||||||
msg_t test_execute(BaseSequentialStream *stream, const testsuite_t *tsp);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module inline functions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#endif /* CH_TEST_H */
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,5 +0,0 @@
|
||||||
# List of all the test runtime files.
|
|
||||||
TESTSRC += ${CHIBIOS}/test/lib/ch_test.c
|
|
||||||
|
|
||||||
# Required include directories
|
|
||||||
TESTINC += ${CHIBIOS}/test/lib
|
|
|
@ -1,280 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file irq_storm.c
|
|
||||||
* @brief IRQ Storm stress test code.
|
|
||||||
*
|
|
||||||
* @addtogroup IRQ_STORM
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "ch.h"
|
|
||||||
#include "hal.h"
|
|
||||||
|
|
||||||
#include "chprintf.h"
|
|
||||||
#include "irq_storm.h"
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module local definitions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#define MSG_SEND_LEFT (msg_t)0
|
|
||||||
#define MSG_SEND_RIGHT (msg_t)1
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module exported variables. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module local types. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module local variables. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
static const irq_storm_config_t *config;
|
|
||||||
|
|
||||||
static bool saturated;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Mailboxes and buffers.
|
|
||||||
*/
|
|
||||||
static mailbox_t mb[IRQ_STORM_CFG_NUM_THREADS];
|
|
||||||
static msg_t b[IRQ_STORM_CFG_NUM_THREADS][IRQ_STORM_CFG_MAILBOX_SIZE];
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Threads working areas.
|
|
||||||
*/
|
|
||||||
static THD_WORKING_AREA(irq_storm_thread_wa[IRQ_STORM_CFG_NUM_THREADS],
|
|
||||||
IRQ_STORM_CFG_STACK_SIZE);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Pointers to threads.
|
|
||||||
*/
|
|
||||||
static thread_t *threads[IRQ_STORM_CFG_NUM_THREADS];
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module local functions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module exported functions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Test worker threads.
|
|
||||||
*/
|
|
||||||
static THD_FUNCTION(irq_storm_thread, arg) {
|
|
||||||
static volatile unsigned x = 0;
|
|
||||||
static unsigned cnt = 0;
|
|
||||||
unsigned me = (unsigned)arg;
|
|
||||||
unsigned target;
|
|
||||||
unsigned r;
|
|
||||||
msg_t msg;
|
|
||||||
|
|
||||||
chRegSetThreadName("irq_storm");
|
|
||||||
|
|
||||||
/* Thread loop, until terminated.*/
|
|
||||||
while (chThdShouldTerminateX() == false) {
|
|
||||||
|
|
||||||
/* Waiting for a message.*/
|
|
||||||
chMBFetchTimeout(&mb[me], &msg, TIME_INFINITE);
|
|
||||||
|
|
||||||
#if IRQ_STORM_CFG_RANDOMIZE != FALSE
|
|
||||||
/* Pseudo-random delay.*/
|
|
||||||
{
|
|
||||||
chSysLock();
|
|
||||||
r = rand() & 15;
|
|
||||||
chSysUnlock();
|
|
||||||
while (r--)
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
#else /* IRQ_STORM_CFG_RANDOMIZE == FALSE */
|
|
||||||
/* Fixed delay.*/
|
|
||||||
{
|
|
||||||
r = me >> 4;
|
|
||||||
while (r--)
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
#endif /* IRQ_STORM_CFG_RANDOMIZE == FALSE */
|
|
||||||
|
|
||||||
/* Deciding in which direction to re-send the message.*/
|
|
||||||
if (msg == MSG_SEND_LEFT)
|
|
||||||
target = me - 1;
|
|
||||||
else
|
|
||||||
target = me + 1;
|
|
||||||
|
|
||||||
if (target < IRQ_STORM_CFG_NUM_THREADS) {
|
|
||||||
/* If this thread is not at the end of a chain re-sending the message,
|
|
||||||
note this check works because the variable target is unsigned.*/
|
|
||||||
msg = chMBPostTimeout(&mb[target], msg, TIME_IMMEDIATE);
|
|
||||||
if (msg != MSG_OK)
|
|
||||||
saturated = TRUE;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Provides a visual feedback about the system.*/
|
|
||||||
if (++cnt >= 500) {
|
|
||||||
cnt = 0;
|
|
||||||
palTogglePad(config->port, config->pad);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPT1 callback.
|
|
||||||
*/
|
|
||||||
void irq_storm_gpt1_cb(GPTDriver *gptp) {
|
|
||||||
msg_t msg;
|
|
||||||
|
|
||||||
(void)gptp;
|
|
||||||
chSysLockFromISR();
|
|
||||||
msg = chMBPostI(&mb[0], MSG_SEND_RIGHT);
|
|
||||||
if (msg != MSG_OK)
|
|
||||||
saturated = true;
|
|
||||||
chSysUnlockFromISR();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief GPT2 callback.
|
|
||||||
*/
|
|
||||||
void irq_storm_gpt2_cb(GPTDriver *gptp) {
|
|
||||||
msg_t msg;
|
|
||||||
|
|
||||||
(void)gptp;
|
|
||||||
chSysLockFromISR();
|
|
||||||
msg = chMBPostI(&mb[IRQ_STORM_CFG_NUM_THREADS - 1], MSG_SEND_LEFT);
|
|
||||||
if (msg != MSG_OK)
|
|
||||||
saturated = true;
|
|
||||||
chSysUnlockFromISR();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief IRQ storm execution.
|
|
||||||
*
|
|
||||||
* @param[in] cfg pointer to the test configuration structure
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
void irq_storm_execute(const irq_storm_config_t *cfg) {
|
|
||||||
unsigned i;
|
|
||||||
gptcnt_t interval, threshold, worst;
|
|
||||||
|
|
||||||
/* Global configuration pointer.*/
|
|
||||||
config = cfg;
|
|
||||||
|
|
||||||
/* Starting timers using the stored configurations.*/
|
|
||||||
gptStart(cfg->gpt1p, cfg->gptcfg1p);
|
|
||||||
gptStart(cfg->gpt2p, cfg->gptcfg2p);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initializes the mailboxes and creates the worker threads.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < IRQ_STORM_CFG_NUM_THREADS; i++) {
|
|
||||||
chMBObjectInit(&mb[i], b[i], IRQ_STORM_CFG_MAILBOX_SIZE);
|
|
||||||
threads[i] = chThdCreateStatic(irq_storm_thread_wa[i],
|
|
||||||
sizeof irq_storm_thread_wa[i],
|
|
||||||
IRQ_STORM_CFG_THREADS_PRIORITY,
|
|
||||||
irq_storm_thread,
|
|
||||||
(void *)i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Printing environment information.*/
|
|
||||||
chprintf(cfg->out, "");
|
|
||||||
chprintf(cfg->out, "\r\n*** ChibiOS/RT IRQ-STORM long duration test\r\n***\r\n");
|
|
||||||
chprintf(cfg->out, "*** Kernel: %s\r\n", CH_KERNEL_VERSION);
|
|
||||||
chprintf(cfg->out, "*** Compiled: %s\r\n", __DATE__ " - " __TIME__);
|
|
||||||
#ifdef PORT_COMPILER_NAME
|
|
||||||
chprintf(cfg->out, "*** Compiler: %s\r\n", PORT_COMPILER_NAME);
|
|
||||||
#endif
|
|
||||||
chprintf(cfg->out, "*** Architecture: %s\r\n", PORT_ARCHITECTURE_NAME);
|
|
||||||
#ifdef PORT_CORE_VARIANT_NAME
|
|
||||||
chprintf(cfg->out, "*** Core Variant: %s\r\n", PORT_CORE_VARIANT_NAME);
|
|
||||||
#endif
|
|
||||||
chprintf(cfg->out, "*** System Clock: %d\r\n", cfg->sysclk);
|
|
||||||
#ifdef PORT_INFO
|
|
||||||
chprintf(cfg->out, "*** Port Info: %s\r\n", PORT_INFO);
|
|
||||||
#endif
|
|
||||||
#ifdef PLATFORM_NAME
|
|
||||||
chprintf(cfg->out, "*** Platform: %s\r\n", PLATFORM_NAME);
|
|
||||||
#endif
|
|
||||||
#ifdef BOARD_NAME
|
|
||||||
chprintf(cfg->out, "*** Test Board: %s\r\n", BOARD_NAME);
|
|
||||||
#endif
|
|
||||||
chprintf(cfg->out, "***\r\n");
|
|
||||||
chprintf(cfg->out, "*** Iterations: %d\r\n", IRQ_STORM_CFG_ITERATIONS);
|
|
||||||
chprintf(cfg->out, "*** Randomize: %d\r\n", IRQ_STORM_CFG_RANDOMIZE);
|
|
||||||
chprintf(cfg->out, "*** Threads: %d\r\n", IRQ_STORM_CFG_NUM_THREADS);
|
|
||||||
chprintf(cfg->out, "*** Mailbox size: %d\r\n\r\n", IRQ_STORM_CFG_MAILBOX_SIZE);
|
|
||||||
|
|
||||||
/* Test loop.*/
|
|
||||||
worst = 0;
|
|
||||||
for (i = 1; i <= IRQ_STORM_CFG_ITERATIONS; i++){
|
|
||||||
|
|
||||||
chprintf(cfg->out, "Iteration %d\r\n", i);
|
|
||||||
saturated = false;
|
|
||||||
threshold = 0;
|
|
||||||
|
|
||||||
/* Timer intervals starting at 2mS then decreased by 10% after each
|
|
||||||
cycle.*/
|
|
||||||
for (interval = 2000; interval >= 2; interval -= (interval + 9) / 10) {
|
|
||||||
|
|
||||||
/* Timers programmed slightly out of phase each other.*/
|
|
||||||
gptStartContinuous(cfg->gpt1p, interval - 1); /* Slightly out of phase.*/
|
|
||||||
gptStartContinuous(cfg->gpt2p, interval + 1); /* Slightly out of phase.*/
|
|
||||||
|
|
||||||
/* Storming for one second.*/
|
|
||||||
chThdSleepMilliseconds(1000);
|
|
||||||
|
|
||||||
/* Timers stopped.*/
|
|
||||||
gptStopTimer(cfg->gpt1p);
|
|
||||||
gptStopTimer(cfg->gpt2p);
|
|
||||||
|
|
||||||
/* Did the storm saturate the threads chain?*/
|
|
||||||
if (!saturated)
|
|
||||||
chprintf(cfg->out, ".");
|
|
||||||
else {
|
|
||||||
chprintf(cfg->out, "#");
|
|
||||||
if (threshold == 0)
|
|
||||||
threshold = interval;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Gives threads a chance to empty the mailboxes before next cycle.*/
|
|
||||||
chThdSleepMilliseconds(20);
|
|
||||||
chprintf(cfg->out, "\r\nSaturated at %d uS\r\n\r\n", threshold);
|
|
||||||
if (threshold > worst)
|
|
||||||
worst = threshold;
|
|
||||||
}
|
|
||||||
gptStopTimer(cfg->gpt1p);
|
|
||||||
gptStopTimer(cfg->gpt2p);
|
|
||||||
|
|
||||||
chprintf(cfg->out, "Worst case at %d uS\r\n", worst);
|
|
||||||
chprintf(cfg->out, "\r\nTest Complete\r\n");
|
|
||||||
|
|
||||||
/* Terminating threads and cleaning up.*/
|
|
||||||
for (i = 0; i < IRQ_STORM_CFG_NUM_THREADS; i++) {
|
|
||||||
chThdTerminate(threads[i]);
|
|
||||||
chThdWait(threads[i]);
|
|
||||||
threads[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @} */
|
|
|
@ -1,166 +0,0 @@
|
||||||
/*
|
|
||||||
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file irq_storm.h
|
|
||||||
* @brief IRQ Storm stress test header.
|
|
||||||
*
|
|
||||||
* @addtogroup IRQ_STORM
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef IRQ_STORM_H
|
|
||||||
#define IRQ_STORM_H
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module constants. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module pre-compile time settings. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#ifndef RANDOMIZE
|
|
||||||
#define RANDOMIZE FALSE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef ITERATIONS
|
|
||||||
#define ITERATIONS 100
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef NUM_THREADS
|
|
||||||
#define NUM_THREADS 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef MAILBOX_SIZE
|
|
||||||
#define MAILBOX_SIZE 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @name Configuration options
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @brief Timings randomization.
|
|
||||||
*/
|
|
||||||
#if !defined(IRQ_STORM_CFG_RANDOMIZE) || defined(__DOXYGEN__)
|
|
||||||
#define IRQ_STORM_CFG_RANDOMIZE FALSE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Number of test iterations.
|
|
||||||
*/
|
|
||||||
#if !defined(IRQ_STORM_CFG_ITERATIONS) || defined(__DOXYGEN__)
|
|
||||||
#define IRQ_STORM_CFG_ITERATIONS 100
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Number of storm threads.
|
|
||||||
*/
|
|
||||||
#if !defined(IRQ_STORM_CFG_NUM_THREADS) || defined(__DOXYGEN__)
|
|
||||||
#define IRQ_STORM_CFG_NUM_THREADS 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Priority of storm threads.
|
|
||||||
*/
|
|
||||||
#if !defined(IRQ_STORM_CFG_THREADS_PRIORITY) || defined(__DOXYGEN__)
|
|
||||||
#define IRQ_STORM_CFG_THREADS_PRIORITY (tprio_t)(NORMALPRIO-20)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Mailboxes size.
|
|
||||||
*/
|
|
||||||
#if !defined(IRQ_STORM_CFG_MAILBOX_SIZE) || defined(__DOXYGEN__)
|
|
||||||
#define IRQ_STORM_CFG_MAILBOX_SIZE 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Stack size for worker threads.
|
|
||||||
*/
|
|
||||||
#if !defined(IRQ_STORM_CFG_STACK_SIZE) || defined(__DOXYGEN__)
|
|
||||||
#define IRQ_STORM_CFG_STACK_SIZE 128
|
|
||||||
#endif
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Derived constants and error checks. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module data structures and types. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
/**
|
|
||||||
* @brief Stream for output.
|
|
||||||
*/
|
|
||||||
BaseSequentialStream *out;
|
|
||||||
/**
|
|
||||||
* @brief LED port.
|
|
||||||
*/
|
|
||||||
ioportid_t port;
|
|
||||||
/**
|
|
||||||
* @brief LED bit.
|
|
||||||
*/
|
|
||||||
unsigned pad;
|
|
||||||
/**
|
|
||||||
* @brief GPT driver 1.
|
|
||||||
*/
|
|
||||||
GPTDriver *gpt1p;
|
|
||||||
/**
|
|
||||||
* @brief GPT driver 2.
|
|
||||||
*/
|
|
||||||
GPTDriver *gpt2p;
|
|
||||||
/**
|
|
||||||
* @brief GPT1 configuration 1.
|
|
||||||
*/
|
|
||||||
const GPTConfig *gptcfg1p;
|
|
||||||
/**
|
|
||||||
* @brief GPT1 configuration 2.
|
|
||||||
*/
|
|
||||||
const GPTConfig *gptcfg2p;
|
|
||||||
/**
|
|
||||||
* @brief System clock.
|
|
||||||
*/
|
|
||||||
uint32_t sysclk;
|
|
||||||
} irq_storm_config_t;
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module macros. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* External declarations. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
void irq_storm_gpt1_cb(GPTDriver *gptp);
|
|
||||||
void irq_storm_gpt2_cb(GPTDriver *gptp);
|
|
||||||
void irq_storm_execute(const irq_storm_config_t *cfg);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*===========================================================================*/
|
|
||||||
/* Module inline functions. */
|
|
||||||
/*===========================================================================*/
|
|
||||||
|
|
||||||
#endif /* IRQ_STORM_H */
|
|
||||||
|
|
||||||
/** @} */
|
|
Loading…
Reference in New Issue