Xmega Application Note | |||||
Data Structures | |
struct | test_case |
A single test case. More... | |
struct | test_suite |
A test suite. More... | |
Defines | |
#define | __progmem_arg |
Progmem-related defines. | |
#define | ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0])) |
#define | dbg(__fmt_) printf_P(PSTR(__fmt_)) |
Wrappers for printing debug-information. | |
#define | dbg_error(_x,...) printf_P(PSTR(_x), __VA_ARGS__) |
#define | dbg_info(__fmt_,...) printf_P(PSTR(__fmt_), __VA_ARGS__) |
#define | dbg_putchar(c) putc(c, stdout) |
#define | dbg_vprintf_pgm(...) vfprintf_P(stdout, __VA_ARGS__) |
#define | DECLARE_TEST_SUITE(_sym) const struct test_suite _sym |
#define | DEFINE_TEST_ARRAY(_sym) const struct test_case *const _sym[] |
Convenience macro for creating an array of test cases. | |
#define | DEFINE_TEST_CASE(_sym, _setup, _run, _cleanup, _name) |
Convenience macro for creating a test case struct. | |
#define | DEFINE_TEST_SUITE(_sym, _test_array, _name) |
Convenience macro for creating a test suite. | |
#define | test_fail(test, result,...) |
Fail the test. | |
#define | test_fail_unless(test, condition,...) |
Verify that condition is true. | |
Enumerations | |
enum | test_status { TEST_PASS = 0, TEST_FAILED = 1 } |
Status codes returned by test cases and fixtures. More... | |
Functions | |
static int | test_call (void(*func)(const struct test_case *), const struct test_case *test) |
static int | test_case_run (const struct test_case *test) |
static void * | test_get_data (void) |
Get the private data pointer for the current test. | |
void | test_priv_fail (const struct test_case *test, int result, const char *file, unsigned int line, const char __progmem_arg *fmt,...) |
static void | test_report_failure (const struct test_case *test, const char *stage, int result) |
static void | test_set_data (void *data) |
Set private data pointer for the current test. | |
int | test_suite_run (const struct test_suite *suite) |
Run a test suite. | |
Variables | |
static jmp_buf | test_failure_jmpbuf |
void * | test_priv_data |
void * | test_priv_data |
#define __progmem_arg |
#define dbg | ( | __fmt_ | ) | printf_P(PSTR(__fmt_)) |
Wrappers for printing debug-information.
The stream must be set up by the test-application somehow, for now uses printf.
Definition at line 58 of file suite.h.
Referenced by test_case_run().
#define dbg_error | ( | _x, | |||
... | ) | printf_P(PSTR(_x), __VA_ARGS__) |
Definition at line 62 of file suite.h.
Referenced by test_report_failure().
#define dbg_info | ( | __fmt_, | |||
... | ) | printf_P(PSTR(__fmt_), __VA_ARGS__) |
Definition at line 60 of file suite.h.
Referenced by test_case_run().
#define dbg_vprintf_pgm | ( | ... | ) | vfprintf_P(stdout, __VA_ARGS__) |
#define DECLARE_TEST_SUITE | ( | _sym | ) | const struct test_suite _sym |
#define DEFINE_TEST_ARRAY | ( | _sym | ) | const struct test_case *const _sym[] |
#define DEFINE_TEST_CASE | ( | _sym, | |||
_setup, | |||||
_run, | |||||
_cleanup, | |||||
_name | ) |
static const char _test_str_##_sym[] = _name; \ static const struct test_case _sym = { \ .setup = _setup, \ .run = _run, \ .cleanup = _cleanup, \ .name = _test_str_##_sym \ }
Convenience macro for creating a test case struct.
_sym | Variable name of the resulting struct | |
_setup | Function which sets up a test case environment. Can be NULL. | |
_run | Test function | |
_cleanup | Function which cleans up what was set up. Can be NULL. | |
_name | String describing the test case. |
#define DEFINE_TEST_SUITE | ( | _sym, | |||
_test_array, | |||||
_name | ) |
static const char _test_str_##_sym[] = _name; \ const struct test_suite _sym = { \ .nr_tests = ARRAY_LEN(_test_array), \ .tests = _test_array, \ .name = _test_str_##_sym \ }
Convenience macro for creating a test suite.
_sym | Variable name of the resulting struct | |
_test_array | Array of test cases, created with DEFINE_TEST_ARRAY() | |
_name | String describing the test suite. |
#define test_fail | ( | test, | |||
result, | |||||
... | ) |
test_priv_fail(test, result, __FILE__, __LINE__, \ __VA_ARGS__)
Fail the test.
Calling this function will cause the test to terminate with a failure. It will return directly to the test suite core, not to the caller.
test | Test case which failed | |
result | The result of the test (may not be 0) | |
... | printf()-style format string and arguments |
#define test_fail_unless | ( | test, | |||
condition, | |||||
... | ) |
do { \ if (!(condition)) \ test_fail(test, TEST_FAILED, __VA_ARGS__); \ } while (0)
Verify that condition is true.
If condition is false, fail the test with an error message indicating the condition which failed.
test | The test case currently being run | |
condition | Expression to be validated | |
... | Format string and arguments |
enum test_status |
Status codes returned by test cases and fixtures.
Note that test cases and especially fixtures may return any of the status codes defined by status_code as well.
Definition at line 96 of file suite.h.
00096 { 00097 TEST_PASS = 0, 00098 TEST_FAILED = 1, 00099 };
static int test_call | ( | void(*)(const struct test_case *) | func, | |
const struct test_case * | test | |||
) | [static] |
For internal use only.
Call a test or fixture function
This function will initialize test_failure_jmpbuf and call func with test as the parameter.
Definition at line 76 of file suite.c.
References test_failure_jmpbuf, and TEST_PASS.
Referenced by test_case_run().
00078 { 00079 int ret = 0; 00080 00081 if (!func) 00082 return TEST_PASS; 00083 00084 /* 00085 * The first call to setjmp() always return 0. However, if the 00086 * call to func() below goes wrong, we'll return here again with 00087 * a nonzero value. 00088 */ 00089 ret = setjmp(test_failure_jmpbuf); 00090 if (ret) 00091 return ret; 00092 00093 func(test); 00094 00095 return TEST_PASS; 00096 }
static int test_case_run | ( | const struct test_case * | test | ) | [static] |
Definition at line 98 of file suite.c.
References test_case::cleanup, dbg, dbg_info, test_case::name, test_case::run, test_case::setup, test_call(), and test_report_failure().
00099 { 00100 int result; 00101 00102 dbg_info("Running test: %s\n", test->name); 00103 if (test->setup) { 00104 int ret; 00105 dbg("Setting up fixture\n"); 00106 ret = test_call(test->setup, test); 00107 if (ret) { 00108 test_report_failure(test, "setup", ret); 00109 result = ret; 00110 goto out; 00111 } 00112 } 00113 00114 result = test_call(test->run, test); 00115 if (result) 00116 test_report_failure(test, "test", result); 00117 00118 if (test->cleanup) { 00119 int ret; 00120 dbg("Cleaning up fixture\n"); 00121 ret = test_call(test->cleanup, test); 00122 if (ret && !result) { 00123 test_report_failure(test, "cleanup", ret); 00124 result = ret; 00125 } 00126 } 00127 00128 out: 00129 00130 return result; 00131 }
static void* test_get_data | ( | void | ) | [inline, static] |
Get the private data pointer for the current test.
Definition at line 211 of file suite.h.
References test_priv_data.
00212 { 00213 return test_priv_data; 00214 }
void test_priv_fail | ( | const struct test_case * | test, | |
int | result, | |||
const char * | file, | |||
unsigned int | line, | |||
const char __progmem_arg * | fmt, | |||
... | ||||
) |
static void test_report_failure | ( | const struct test_case * | test, | |
const char * | stage, | |||
int | result | |||
) | [static] |
Definition at line 59 of file suite.c.
References dbg_error, and test_case::name.
Referenced by test_case_run().
static void test_set_data | ( | void * | data | ) | [inline, static] |
Set private data pointer for the current test.
data | Pointer to arbitrary run-time data for the test currently being run. |
Definition at line 200 of file suite.h.
References test_priv_data.
00201 { 00202 test_priv_data = data; 00203 }
int test_suite_run | ( | const struct test_suite * | suite | ) |
Run a test suite.
Run all tests in suite, in the order in which they are found in the array.
jmp_buf test_failure_jmpbuf [static] |
For internal use only.
Context saved before executing a test or fixture function. Used for doing non-local jumps from the test cases on failure.
Definition at line 57 of file suite.c.
Referenced by test_call().
void* test_priv_data |
For internal use only.
Definition at line 50 of file suite.c.
Referenced by test_get_data(), and test_set_data().
void* test_priv_data |
For internal use only.
Definition at line 50 of file suite.c.
Referenced by test_get_data(), and test_set_data().
Generated on Fri Oct 22 12:15:26 2010 for AVR1300 Using the Xmega ADC by ![]() |