[RTEMS Project] #3199: New test framework
RTEMS trac
trac at rtems.org
Thu Oct 19 10:12:46 UTC 2017
#3199: New test framework
-----------------------------+-----------------------------
Reporter: Sebastian Huber | Owner: Sebastian Huber
Type: enhancement | Status: assigned
Priority: normal | Milestone: Indefinite
Component: lib | Version: 4.12
Severity: normal | Keywords:
-----------------------------+-----------------------------
Requirements:
* Support for RTEMS and general POSIX systems such as Linux or FreeBSD
* Test output functions
* printf() like
* No floating point support by default
* Optional floating point support
* Non-blocking
* Arbitrary context, e.g. during system start, before device drivers, in
interrupt context
* Automatic test case registrations (constructors, linker set)
* Standard test case output, e.g. begin/end of test case message
* Ability to sort test cases at run-time
* Safe assert functions, e.g. assert(a == b) vs. assert(a = b) vs.
assert_eq(a, b)
* Easy to write, e.g. avoid long namespace prefix rtems_test_*
* Support multiple threads
* No dependency on C++
* Context validation, context invariant validation (e.g. thread dispatch
disable level, interrupt state, heap state)
* Test pattern support (e.g. spintercritical*, parallel tests on SMP)
No ready to use framework exists which fulfils these requirements. We have
to write something for RTEMS.
API proposal (header file <T.h>):
{{{
T_eq(a, b)
T_gt(a, b)
T_printf(fmt, ...)
T_output_printf(putchar, fmt, ...)
T_output_string(putchar, s, n)
T_output_add_format_handler(handler, arg)
}}}
Example for T_output_add_format():
{{{
#include <stdio.h>
#include <string.h>
typedef void (*T_putchar)(char c);
typedef size_t (*T_format_handler)(void *arg, T_putchar putchar, const
char *fmt, const char *s, int *out);
int T_printf(const char *fmt, ...);
void T_output_printf(T_putchar putchar, const char *fmt, ...);
void T_output_string(T_putchar putchar, const char *s, size_t n);
void T_output_add_format_handler(T_format_handler handler, void *arg);
size_t T_output_float_handler(void *arg, T_putchar putchar, const char
*fmt, const char *s, int *out)
{
char buf[32];
if (strncmp(fmt, "%f", 2) != 0) {
return 0;
}
*out = snprintf(buf, sizeof(buf), "%f", s);
if (*out > 0) {
T_output_string(putchar, s, (size_t) *out);
}
return 2;
}
void f(void)
{
T_output_add_format_handler(T_output_float_handler, NULL);
}
}}}
--
Ticket URL: <http://devel.rtems.org/ticket/3199>
RTEMS Project <http://www.rtems.org/>
RTEMS Project
More information about the bugs
mailing list