38 #include <px4_platform_common/log.h> 40 #define ut_declare_test_c(test_function, test_class) \ 42 int test_function(int argc, char *argv[]); \ 43 int test_function(int argc, char *argv[]) \ 45 test_class* test = new test_class(); \ 46 bool success = test->run_tests(); \ 47 test->print_results(); \ 49 return success ? 0 : -1; \ 63 virtual bool run_tests(
void) = 0;
69 PX4_ERR(
"SOME TESTS FAILED");
72 PX4_INFO(
"ALL TESTS PASSED");
75 PX4_INFO(
" Tests passed : %d", _tests_passed);
76 PX4_INFO(
" Tests failed : %d", _tests_failed);
77 PX4_INFO(
" Tested assertions : %d", _assertions);
82 #define ut_declare_test(test_function, test_class) \ 83 bool test_function(void) \ 85 test_class* test = new test_class(); \ 86 bool success = test->run_tests(); \ 87 test->print_results(); \ 96 #define ut_run_test(test) \ 98 PX4_INFO("RUNNING TEST: %s", #test); \ 102 PX4_ERR("TEST FAILED: %s", #test); \ 105 PX4_INFO("TEST PASSED: %s", #test); \ 113 #define ut_assert(message, test) \ 116 _print_assert(message, #test, __FILE__, __LINE__); \ 124 #define ut_test(test) ut_assert("test", test) 127 #define ut_assert_true(test) \ 129 if ((test) != true) { \ 130 _print_assert("result not true", #test, __FILE__, __LINE__); \ 138 #define ut_assert_false(test) \ 140 if ((test) != false) { \ 141 _print_assert("result not false", #test, __FILE__, __LINE__); \ 150 #define ut_compare(message, v1, v2) \ 155 _print_compare(message, #v1, _v1, #v2, _v2, __FILE__, __LINE__); \ 164 #define ut_compare_float(message, v1, v2, precision) \ 166 int _p = powf(10.0f, precision); \ 167 int _v1 = (int)(v1 * _p + 0.5f); \ 168 int _v2 = (int)(v2 * _p + 0.5f); \ 170 _print_compare(message, #v1, _v1, #v2, _v2, __FILE__, __LINE__); \ 179 #define ut_less_than(message, v1_smaller, v2_bigger) \ 181 int _v1 = v1_smaller; \ 182 int _v2 = v2_bigger; \ 183 if (!(_v1 < _v2)) { \ 184 _print_compare(message, #v1_smaller, _v1, #v2_bigger, _v2, __FILE__, __LINE__); \ 196 PX4_ERR(
"Assertion failed: %s - %s (%s:%d)", msg, test, file, line);
202 PX4_ERR(
"Compare failed: %s - (%s:%d) (%s:%d) (%s:%d)", msg, v1_text, v1, v2_text, v2, file, line);
206 int _tests_failed{0};
207 int _tests_passed{0};
virtual void _init(void)
Run before each unit test. Override to provide custom behavior.
void _print_assert(const char *msg, const char *test, const char *file, int line)
Base class to be used for unit tests.
static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE]
virtual void _cleanup(void)
Run after each unit test. Override to provide custom behavior.
void _print_compare(const char *msg, const char *v1_text, int v1, const char *v2_text, int v2, const char *file, int line)
void test(enum LPS25H_BUS busid)
Perform some basic functional tests on the driver; make sure we can collect data from the sensor in p...
void print_results()
Prints results from running of unit tests.
struct @83::@85::@87 file