Microchip® Advanced Software Framework

Test suite core declarations.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <parts.h>
#include <stdio.h>
#include <progmem.h>

Data Structures

struct  test_case
 A test case. More...
 
struct  test_suite
 A test suite. More...
 

Macros

#define Assert(expr)
 
#define Assert(expr)
 Assert() macro definition for unit testing. More...
 
#define dbg(__fmt_)   printf(__fmt_)
 
#define dbg_error(_x,...)   printf(_x, __VA_ARGS__)
 
#define dbg_info(__fmt_,...)   printf(__fmt_, __VA_ARGS__)
 
#define dbg_putchar(c)   putc(c, stdout)
 
#define dbg_vprintf_pgm(...)   vfprintf(stdout, __VA_ARGS__)
 
#define DEFINE_TEST_ARRAY(_sym)   const struct test_case *const _sym[]
 
#define DEFINE_TEST_CASE(_sym, _setup, _run, _cleanup, _name)
 
#define DEFINE_TEST_SUITE(_sym, _test_array, _name)
 
#define test_assert_false(test, condition,...)   test_assert_true(test, !(condition), __VA_ARGS__)
 
#define test_assert_true(test, condition,...)
 
#define test_fail(test, result,...)   test_case_fail(test, result, __FILE__, __LINE__, __VA_ARGS__)
 
#define TEST_SUITE_H_INCLUDED
 
Wrappers for printing debug information
Note
The test suite framework feeds its output to printf. It is left up to the test application to set up the stream.
#define dbg(__fmt_)   printf_P(PROGMEM_STRING(__fmt_))
 
#define dbg_info(__fmt_,...)   printf_P(PROGMEM_STRING(__fmt_), __VA_ARGS__)
 
#define dbg_error(_x,...)   printf_P(PROGMEM_STRING(_x), __VA_ARGS__)
 
#define dbg_putchar(c)   putc(c, stdout)
 
#define dbg_vprintf_pgm(...)   vfprintf_P(stdout, __VA_ARGS__)
 
Test suite definition macros
#define DEFINE_TEST_CASE(_sym, _setup, _run, _cleanup, _name)
 Create a test case struct. More...
 
#define DEFINE_TEST_ARRAY(_sym)   const struct test_case *const _sym[]
 Create an array of test case pointers. More...
 
#define DEFINE_TEST_SUITE(_sym, _test_array, _name)
 Create a test suite. More...
 

Functions

void test_case_fail (const struct test_case *test, int result, const char *file, unsigned int line, const char *fmt,...)
 Report a failure and jump out of current test case function. More...
 
Test suite interaction
int test_suite_run (const struct test_suite *suite)
 Run a test suite. More...
 

Test data access

void * test_priv_data
 Data pointer for test cases. More...
 
static void test_set_data (void *data)
 Set private data pointer for the current test. More...
 
static void * test_get_data (void)
 Get the private data pointer for the current test. More...
 

Test case pointer access

struct test_casetest_case_ptr
 Pointer to current test case. More...
 
static void test_set_case (const struct test_case *test)
 Set pointer to current test. More...
 
static struct test_casetest_get_case (void)
 Get pointer to current test. More...
 

Test result reporting

#define test_fail(test, result,...)   test_case_fail(test, result, __FILE__, __LINE__, __VA_ARGS__)
 Fail the test. More...
 
#define test_assert_true(test, condition,...)
 Verify that condition is true. More...
 
#define test_assert_false(test, condition,...)   test_assert_true(test, !(condition), __VA_ARGS__)
 Verify that condition is false. More...
 
enum  test_status {
  TEST_ERROR = -1,
  TEST_PASS = 0,
  TEST_FAIL = 1
}
 Status codes returned by test cases and fixtures. More...
 

#define Assert (   expr)
Value:
{ \
if (test_get_case() != NULL) { \
"Assertion failed: %s", #expr); \
} else { \
if (!(expr)) { \
dbg_error("Assertion '%s' failed at %s:%d\r\n", \
#expr, __FILE__, __LINE__); \
while (true); \
} \
} \
}
#define test_assert_true(test, condition,...)
Verify that condition is true.
Definition: suite.h:386
#define dbg_error(_x,...)
Definition: suite.h:208
static struct test_case * test_get_case(void)
Get pointer to current test.
Definition: suite.h:328

Assert() macro definition for unit testing.

The Assert() macro is set up to use test_assert_true(), as this will only halt execution of the current test, allowing the remaining tests a chance to complete.

#define dbg (   __fmt_)    printf(__fmt_)

Referenced by test_case_run().

#define dbg_error (   _x,
  ... 
)    printf(_x, __VA_ARGS__)
#define dbg_info (   __fmt_,
  ... 
)    printf(__fmt_, __VA_ARGS__)

Referenced by test_case_run(), and test_suite_run().

#define dbg_putchar (   c)    putc(c, stdout)

Referenced by test_case_fail().

#define dbg_vprintf_pgm (   ...)    vfprintf(stdout, __VA_ARGS__)

Referenced by test_case_fail().

#define DEFINE_TEST_ARRAY (   _sym)    const struct test_case *const _sym[]

Referenced by main().

#define DEFINE_TEST_CASE (   _sym,
  _setup,
  _run,
  _cleanup,
  _name 
)
Value:
static const char _test_str_##_sym[] = _name; \
static const struct test_case _sym = { \
.setup = _setup, \
.run = _run, \
.cleanup = _cleanup, \
.name = _test_str_##_sym, \
}
A test case.
Definition: suite.h:157
void(* setup)(const struct test_case *test)
Set up the environment in which test is to be run.
Definition: suite.h:165

Referenced by main().

#define DEFINE_TEST_SUITE (   _sym,
  _test_array,
  _name 
)
Value:
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, \
}
A test suite.
Definition: suite.h:187
unsigned int nr_tests
The number of tests in this suite.
Definition: suite.h:189

Referenced by main().

#define test_assert_false (   test,
  condition,
  ... 
)    test_assert_true(test, !(condition), __VA_ARGS__)
#define test_assert_true (   test,
  condition,
  ... 
)
Value:
do { \
if (!(condition)) { \
test_fail(test, TEST_FAIL, __VA_ARGS__); \
} \
} while (0)
#define test_fail(test, result,...)
Test failure.
Definition: suite.h:346

Referenced by run_sd_mmc_init_test(), run_sd_mmc_rw_test(), run_sd_mmc_sdio_rw_test(), and run_sdio_rw_test().

#define test_fail (   test,
  result,
  ... 
)    test_case_fail(test, result, __FILE__, __LINE__, __VA_ARGS__)
#define TEST_SUITE_H_INCLUDED