forked from Imagelibrary/rtems
tests: Use rtems_test_begin and rtems_test_end.
Add a tests enum and move all test banner test to the library in libmisc. Update #3199.
This commit is contained in:
@@ -58,28 +58,51 @@ void rtems_test_fatal_extension(
|
|||||||
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, rtems_test_fatal_extension }
|
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, rtems_test_fatal_extension }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Begin of test message format string.
|
* @brief Test states.
|
||||||
*/
|
*/
|
||||||
#define TEST_BEGIN_STRING "\n\n*** BEGIN OF TEST %s ***\n", rtems_test_name
|
typedef enum
|
||||||
|
{
|
||||||
|
RTEMS_TEST_STATE_PASS,
|
||||||
|
RTEMS_TEST_STATE_FAIL,
|
||||||
|
RTEMS_TEST_STATE_USER_INPUT,
|
||||||
|
RTEMS_TEST_STATE_INDETERMINATE,
|
||||||
|
RTEMS_TEST_STATE_BENCHMARK
|
||||||
|
} RTEMS_TEST_STATE;
|
||||||
|
|
||||||
/**
|
#if (TEST_STATE_EXPECTED_FAIL && TEST_STATE_USER_INPUT) || \
|
||||||
* @brief End of test message format string.
|
(TEST_STATE_EXPECTED_FAIL && TEST_STATE_INDETERMINATE) || \
|
||||||
*/
|
(TEST_STATE_EXPECTED_FAIL && TEST_STATE_BENCHMARK) || \
|
||||||
#define TEST_END_STRING "*** END OF TEST %s ***\n", rtems_test_name
|
(TEST_STATE_USER_INPUT && TEST_STATE_INDETERMINATE) || \
|
||||||
|
(TEST_STATE_USER_INPUT && TEST_STATE_BENCHMARK) || \
|
||||||
|
(TEST_STATE_INDETERMINATE && TEST_STATE_BENCHMARK)
|
||||||
|
#error Test states must be unique
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TEST_STATE_EXPECTED_FAIL
|
||||||
|
#define TEST_STATE RTEMS_TEST_STATE_FAIL
|
||||||
|
#elif TEST_STATE_USER_INPUT
|
||||||
|
#define TEST_STATE RTEMS_TEST_STATE_USER_INPUT
|
||||||
|
#elif TEST_STATE_INDETERMINATE
|
||||||
|
#define TEST_STATE RTEMS_TEST_STATE_INDETERMINATE
|
||||||
|
#elif TEST_STATE_BENCHMARK
|
||||||
|
#define TEST_STATE RTEMS_TEST_STATE_BENCHMARK
|
||||||
|
#else
|
||||||
|
#define TEST_STATE RTEMS_TEST_STATE_PASS
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints a begin of test message using printf().
|
* @brief Prints a begin of test message using printf().
|
||||||
*
|
*
|
||||||
* @returns As specified by printf().
|
* @returns As specified by printf().
|
||||||
*/
|
*/
|
||||||
int rtems_test_begin(void);
|
int rtems_test_begin(const char* name, const RTEMS_TEST_STATE state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints an end of test message using printf().
|
* @brief Prints an end of test message using printf().
|
||||||
*
|
*
|
||||||
* @returns As specified by printf().
|
* @returns As specified by printf().
|
||||||
*/
|
*/
|
||||||
int rtems_test_end(void);
|
int rtems_test_end(const char* name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints via the RTEMS printer.
|
* @brief Prints via the RTEMS printer.
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
* Germany
|
* Germany
|
||||||
* <rtems@embedded-brains.de>
|
* <rtems@embedded-brains.de>
|
||||||
*
|
*
|
||||||
|
* Copyright (c) 2017 Chris Johns <chrisj@rtems.org>. All rights reserved.
|
||||||
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
* http://www.rtems.org/license/LICENSE.
|
* http://www.rtems.org/license/LICENSE.
|
||||||
@@ -18,24 +20,106 @@
|
|||||||
|
|
||||||
#include <rtems/test.h>
|
#include <rtems/test.h>
|
||||||
#include <rtems/bspIo.h>
|
#include <rtems/bspIo.h>
|
||||||
|
#include <rtems/version.h>
|
||||||
|
|
||||||
|
#define TEST_BUILD_DEFAULT "default"
|
||||||
|
#if RTEMS_POSIX
|
||||||
|
#define TEST_BUILD_DEFAULT ""
|
||||||
|
#define TEST_BUILD_POSIX "posix "
|
||||||
|
#else
|
||||||
|
#define TEST_BUILD_POSIX
|
||||||
|
#endif
|
||||||
|
#if RTEMS_SMP
|
||||||
|
#define TEST_BUILD_DEFAULT ""
|
||||||
|
#define TEST_BUILD_SMP "smp "
|
||||||
|
#else
|
||||||
|
#define TEST_BUILD_SMP
|
||||||
|
#endif
|
||||||
|
#if RTEMS_MULTIPROCESSING
|
||||||
|
#define TEST_BUILD_DEFAULT ""
|
||||||
|
#define TEST_BUILD_MP "mp "
|
||||||
|
#else
|
||||||
|
#define TEST_BUILD_MP
|
||||||
|
#endif
|
||||||
|
#if RTEMS_PARAVIRT
|
||||||
|
#define TEST_BUILD_DEFAULT ""
|
||||||
|
#define TEST_BUILD_PARAVIRT "paravirt "
|
||||||
|
#else
|
||||||
|
#define TEST_BUILD_PARAVIRT
|
||||||
|
#endif
|
||||||
|
#if RTEMS_NETWORKING
|
||||||
|
#define TEST_BUILD_DEFAULT ""
|
||||||
|
#define TEST_BUILD_NETWORKING "legacy-net "
|
||||||
|
#else
|
||||||
|
#define TEST_BUILD_NETWORKING
|
||||||
|
#endif
|
||||||
|
#if RTEMS_DEBUG
|
||||||
|
#define TEST_BUILD_DEFAULT ""
|
||||||
|
#define TEST_BUILD_DEBUG "debug "
|
||||||
|
#else
|
||||||
|
#define TEST_BUILD_DEBUG
|
||||||
|
#endif
|
||||||
|
#if RTEMS_PROFILING
|
||||||
|
#define TEST_BUILD_DEFAULT ""
|
||||||
|
#define TEST_BUILD_PROFILING "profiling "
|
||||||
|
#else
|
||||||
|
#define TEST_BUILD_PROFILING
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TEST_BUILD_STRING \
|
||||||
|
TEST_BUILD_DEFAULT \
|
||||||
|
TEST_BUILD_POSIX \
|
||||||
|
TEST_BUILD_SMP \
|
||||||
|
TEST_BUILD_MP \
|
||||||
|
TEST_BUILD_PARAVIRT \
|
||||||
|
TEST_BUILD_NETWORKING \
|
||||||
|
TEST_BUILD_DEBUG \
|
||||||
|
TEST_BUILD_PROFILING
|
||||||
|
|
||||||
rtems_printer rtems_test_printer = {
|
rtems_printer rtems_test_printer = {
|
||||||
.printer = rtems_printk_printer
|
.printer = rtems_printk_printer
|
||||||
};
|
};
|
||||||
|
|
||||||
int rtems_test_begin(void)
|
static const char* const test_state_strings[] =
|
||||||
{
|
{
|
||||||
return rtems_printf(
|
"EXPECTED-PASS",
|
||||||
|
"EXPECTED-FAIL",
|
||||||
|
"USER_INPUT",
|
||||||
|
"INDETERMINATE",
|
||||||
|
"BENCHMARK"
|
||||||
|
};
|
||||||
|
|
||||||
|
int rtems_test_begin(const char* name, const RTEMS_TEST_STATE state)
|
||||||
|
{
|
||||||
|
int l;
|
||||||
|
l = rtems_printf(
|
||||||
&rtems_test_printer,
|
&rtems_test_printer,
|
||||||
TEST_BEGIN_STRING
|
"\n\n*** BEGIN OF TEST %s ***\n", name
|
||||||
);
|
);
|
||||||
|
l += rtems_printf(
|
||||||
|
&rtems_test_printer,
|
||||||
|
"*** TEST VERSION: %s\n", rtems_version()
|
||||||
|
);
|
||||||
|
l += rtems_printf(
|
||||||
|
&rtems_test_printer,
|
||||||
|
"*** TEST STATE: %s\n", test_state_strings[state]
|
||||||
|
);
|
||||||
|
l += rtems_printf(
|
||||||
|
&rtems_test_printer,
|
||||||
|
"*** TEST BUILD: %s\n", TEST_BUILD_STRING
|
||||||
|
);
|
||||||
|
l += rtems_printf(
|
||||||
|
&rtems_test_printer,
|
||||||
|
"*** TEST TOOLS: " __VERSION__ "\n"
|
||||||
|
);
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rtems_test_end(void)
|
int rtems_test_end(const char* name)
|
||||||
{
|
{
|
||||||
return rtems_printf(
|
return rtems_printf(
|
||||||
&rtems_test_printer,
|
&rtems_test_printer,
|
||||||
TEST_END_STRING
|
"\n*** END OF TEST %s ***\n\n", name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,14 +47,14 @@ static int num_inst = 0;
|
|||||||
static void check_begin_of_test(void)
|
static void check_begin_of_test(void)
|
||||||
{
|
{
|
||||||
if ( num_inst == 0 ) {
|
if ( num_inst == 0 ) {
|
||||||
printf(TEST_BEGIN_STRING);
|
TEST_BEGIN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_end_of_test(void)
|
static void check_end_of_test(void)
|
||||||
{
|
{
|
||||||
if ( num_inst == 0 ) {
|
if ( num_inst == 0 ) {
|
||||||
printk(TEST_END_STRING);
|
TEST_END();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ static long buffers[ BUFFER_COUNT ][ BUFFER_SIZE / sizeof(long) ];
|
|||||||
|
|
||||||
void end_of_test( void )
|
void end_of_test( void )
|
||||||
{
|
{
|
||||||
rtems_test_printf( TEST_END_STRING );
|
TEST_END();
|
||||||
rtems_printer_task_drain( &printer_task );
|
rtems_printer_task_drain( &printer_task );
|
||||||
rtems_test_exit( 0 );
|
rtems_test_exit( 0 );
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ rtems_task Init(
|
|||||||
error = rtems_print_printer_task( &rtems_test_printer, &printer_task );
|
error = rtems_print_printer_task( &rtems_test_printer, &printer_task );
|
||||||
rtems_test_assert( error == 0 );
|
rtems_test_assert( error == 0 );
|
||||||
|
|
||||||
rtems_test_printf( TEST_BEGIN_STRING );
|
TEST_BEGIN();
|
||||||
|
|
||||||
Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
|
Task_name[ 1 ] = rtems_build_name( 'T', 'A', '1', ' ' );
|
||||||
Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' );
|
Task_name[ 2 ] = rtems_build_name( 'T', 'A', '2', ' ' );
|
||||||
|
|||||||
@@ -11,28 +11,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Test states. No state string is an expected pass.
|
|
||||||
*/
|
|
||||||
#if (TEST_STATE_EXPECTED_FAIL && TEST_STATE_USER_INPUT) || \
|
|
||||||
(TEST_STATE_EXPECTED_FAIL && TEST_STATE_INDETERMINATE) || \
|
|
||||||
(TEST_STATE_EXPECTED_FAIL && TEST_STATE_BENCHMARK) || \
|
|
||||||
(TEST_STATE_USER_INPUT && TEST_STATE_INDETERMINATE) || \
|
|
||||||
(TEST_STATE_USER_INPUT && TEST_STATE_BENCHMARK) || \
|
|
||||||
(TEST_STATE_INDETERMINATE && TEST_STATE_BENCHMARK)
|
|
||||||
#error Test states must be unique
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TEST_STATE_EXPECTED_FAIL
|
|
||||||
#define TEST_STATE_STRING "*** TEST STATE: EXPECTED-FAIL\n"
|
|
||||||
#elif TEST_STATE_USER_INPUT
|
|
||||||
#define TEST_STATE_STRING "*** TEST STATE: USER_INPUT\n"
|
|
||||||
#elif TEST_STATE_INDETERMINATE
|
|
||||||
#define TEST_STATE_STRING "*** TEST STATE: INDETERMINATE\n"
|
|
||||||
#elif TEST_STATE_BENCHMARK
|
|
||||||
#define TEST_STATE_STRING "*** TEST STATE: BENCHMARK\n"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef printf
|
#undef printf
|
||||||
#define printf(...) \
|
#define printf(...) \
|
||||||
do { \
|
do { \
|
||||||
@@ -61,27 +39,8 @@ extern "C" {
|
|||||||
do { \
|
do { \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#if defined(TEST_STATE_STRING)
|
#define TEST_BEGIN() rtems_test_begin(rtems_test_name, TEST_STATE)
|
||||||
#define TEST_BEGIN() \
|
#define TEST_END() rtems_test_end(rtems_test_name)
|
||||||
do { \
|
|
||||||
rtems_printf( &rtems_test_printer, "\n"); \
|
|
||||||
rtems_printf( &rtems_test_printer, TEST_BEGIN_STRING ); \
|
|
||||||
rtems_printf( &rtems_test_printer, TEST_STATE_STRING ); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define TEST_BEGIN() \
|
|
||||||
do { \
|
|
||||||
rtems_printf( &rtems_test_printer, "\n" ); \
|
|
||||||
rtems_printf( &rtems_test_printer, TEST_BEGIN_STRING ); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TEST_END() \
|
|
||||||
do { \
|
|
||||||
rtems_printf( &rtems_test_printer, "\n" ); \
|
|
||||||
rtems_printf( &rtems_test_printer, TEST_END_STRING ); \
|
|
||||||
rtems_printf( &rtems_test_printer, "\n" ); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user