PX4 Firmware
PX4 Autopilot Software http://px4.io
unit_test.h File Reference
#include <px4_platform_common/log.h>
Include dependency graph for unit_test.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  UnitTest
 Base class to be used for unit tests. More...
 

Macros

#define ut_declare_test_c(test_function, test_class)
 
#define ut_declare_test(test_function, test_class)
 Macro to create a function which will run a unit test class and print results. More...
 
#define ut_run_test(test)
 Runs a single unit test. More...
 
#define ut_assert(message, test)
 Used to assert a value within a unit test. More...
 
#define ut_test(test)   ut_assert("test", test)
 Used to assert a value within a unit test. More...
 
#define ut_assert_true(test)
 To assert specifically to true. More...
 
#define ut_assert_false(test)
 To assert specifically to true. More...
 
#define ut_compare(message, v1, v2)
 Used to compare two integer values within a unit test. More...
 
#define ut_compare_float(message, v1, v2, precision)
 Used to compare two float values within a unit test. More...
 
#define ut_less_than(message, v1_smaller, v2_bigger)
 Used to compare two integer values within a unit test. More...
 

Macro Definition Documentation

◆ ut_assert

◆ ut_assert_false

#define ut_assert_false (   test)
Value:
do { \
if ((test) != false) { \
_print_assert("result not false", #test, __FILE__, __LINE__); \
return false; \
} else { \
_assertions++; \
} \
} while (0)
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...
Definition: lps25h.cpp:792

To assert specifically to true.

Definition at line 138 of file unit_test.h.

◆ ut_assert_true

#define ut_assert_true (   test)
Value:
do { \
if ((test) != true) { \
_print_assert("result not true", #test, __FILE__, __LINE__); \
return false; \
} else { \
_assertions++; \
} \
} while (0)
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...
Definition: lps25h.cpp:792

To assert specifically to true.

Definition at line 127 of file unit_test.h.

Referenced by BezierQuadTest::_get_arc_length(), BezierQuadTest::_get_states_from_time(), SmoothZTest::accelerateDownwardFromBrake(), SmoothZTest::accelerateUpwardFromBrake(), SmoothZTest::brakeDownward(), SmoothZTest::brakeUpward(), VersioningTest::run_tests(), ParameterTest::SimpleFind(), ListTest::test_add(), IntrusiveQueueTest::test_pop(), IntrusiveQueueTest::test_push(), IntrusiveQueueTest::test_push_duplicate(), ListTest::test_range_based_for(), IntrusiveQueueTest::test_remove(), ListTest::test_remove(), MathlibTest::testVector2(), and MathlibTest::testVector3().

◆ ut_compare

#define ut_compare (   message,
  v1,
  v2 
)
Value:
do { \
int _v1 = v1; \
int _v2 = v2; \
if (_v1 != _v2) { \
_print_compare(message, #v1, _v1, #v2, _v2, __FILE__, __LINE__); \
return false; \
} else { \
_assertions++; \
} \
} while (0)

Used to compare two integer values within a unit test.

If possible use ut_compare instead of ut_assert since it will give you better error reporting of the actual values being compared.

Definition at line 150 of file unit_test.h.

Referenced by MavlinkFtpTest::_ack_test(), ParameterTest::_assert_parameter_float_value(), ParameterTest::_assert_parameter_int_value(), MavlinkFtpTest::_bad_datasize_test(), MavlinkFtpTest::_bad_opcode_test(), MavlinkFtpTest::_burst_test(), MavlinkFtpTest::_createdirectory_test(), MavlinkFtpTest::_decode_message(), MavlinkFtpTest::_list_eof_test(), MavlinkFtpTest::_list_test(), MavlinkFtpTest::_open_badfile_test(), MavlinkFtpTest::_open_terminate_test(), MavlinkFtpTest::_read_badsession_test(), MavlinkFtpTest::_read_test(), MavlinkFtpTest::_receive_message_handler_burst(), MavlinkFtpTest::_removedirectory_test(), MavlinkFtpTest::_removefile_test(), MavlinkFtpTest::_terminate_badsession_test(), StateMachineHelperTest::armingStateTransitionTest(), RCTest::crsfTest(), FloatTest::doublePrecisionTests(), RCTest::dsmTest(), ParameterTest::exportImport(), ParameterTest::exportImportAll(), StateMachineHelperTest::isSafeTest(), MixerTest::load_mixer(), StateMachineHelperTest::mainStateTransitionTest(), ParameterTest::SimpleFind(), FloatTest::singlePrecisionTests(), ListTest::test_add(), IntrusiveQueueTest::test_pop(), IntrusiveQueueTest::test_push(), IntrusiveQueueTest::test_push_duplicate(), ListTest::test_range_based_for(), IntrusiveQueueTest::test_remove(), and ListTest::test_remove().

◆ ut_compare_float

#define ut_compare_float (   message,
  v1,
  v2,
  precision 
)
Value:
do { \
int _p = powf(10.0f, precision); \
int _v1 = (int)(v1 * _p + 0.5f); \
int _v2 = (int)(v2 * _p + 0.5f); \
if (_v1 != _v2) { \
_print_compare(message, #v1, _v1, #v2, _v2, __FILE__, __LINE__); \
return false; \
} else { \
_assertions++; \
} \
} while (0)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Definition: integration.cpp:8

Used to compare two float values within a unit test.

If possible use ut_compare_float instead of ut_assert since it will give you better error reporting of the actual values being compared.

Definition at line 164 of file unit_test.h.

Referenced by ParameterTest::_assert_parameter_float_value(), BezierQuadTest::_get_states_from_time(), BezierQuadTest::_set_bez_from_vel(), AutoDeclinationTest::autodeclination_check(), and ParameterTest::exportImport().

◆ ut_declare_test

#define ut_declare_test (   test_function,
  test_class 
)
Value:
bool test_function(void) \
{ \
test_class* test = new test_class(); \
bool success = test->run_tests(); \
test->print_results(); \
delete test; \
return success; \
}
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...
Definition: lps25h.cpp:792

Macro to create a function which will run a unit test class and print results.

Definition at line 82 of file unit_test.h.

Referenced by MavlinkFtpTest::run_tests(), and StateMachineHelperTest::run_tests().

◆ ut_declare_test_c

#define ut_declare_test_c (   test_function,
  test_class 
)
Value:
extern "C" { \
int test_function(int argc, char *argv[]); \
int test_function(int argc, char *argv[]) \
{ \
test_class* test = new test_class(); \
bool success = test->run_tests(); \
test->print_results(); \
delete test; \
return success ? 0 : -1; \
} \
}
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...
Definition: lps25h.cpp:792

Definition at line 40 of file unit_test.h.

Referenced by SearchMinTest::_no_extremum(), SmoothZTest::accelerateDownwardFromBrake(), BezierQuadTest::random(), MatrixTest::run_tests(), ParameterTest::run_tests(), AutoDeclinationTest::run_tests(), FloatTest::run_tests(), IntTest::run_tests(), MathlibTest::run_tests(), SF0XTest::sf0xTest(), RCTest::sumdTest(), ListTest::test_range_based_for(), and IntrusiveQueueTest::test_remove().

◆ ut_less_than

#define ut_less_than (   message,
  v1_smaller,
  v2_bigger 
)
Value:
do { \
int _v1 = v1_smaller; \
int _v2 = v2_bigger; \
if (!(_v1 < _v2)) { \
_print_compare(message, #v1_smaller, _v1, #v2_bigger, _v2, __FILE__, __LINE__); \
return false; \
} else { \
_assertions++; \
} \
} while (0)

Used to compare two integer values within a unit test.

If possible use ut_less_than instead of ut_assert since it will give you better error reporting of the actual values being compared.

Definition at line 179 of file unit_test.h.

◆ ut_run_test

#define ut_run_test (   test)
Value:
do { \
PX4_INFO("RUNNING TEST: %s", #test); \
_tests_run++; \
_init(); \
if (!test()) { \
PX4_ERR("TEST FAILED: %s", #test); \
_tests_failed++; \
} else { \
PX4_INFO("TEST PASSED: %s", #test); \
_tests_passed++; \
} \
_cleanup(); \
printf("\n"); \
} while (0)
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...
Definition: lps25h.cpp:792

Runs a single unit test.

Unit tests must have the function signature of bool test(void). The unit test should return true if it succeeded, false for fail.

Definition at line 96 of file unit_test.h.

Referenced by SF0XTest::run_tests(), RCTest::run_tests(), SmoothZTest::run_tests(), IntrusiveQueueTest::run_tests(), MavlinkFtpTest::run_tests(), BezierQuadTest::run_tests(), MatrixTest::run_tests(), ParameterTest::run_tests(), ListTest::run_tests(), StateMachineHelperTest::run_tests(), AutoDeclinationTest::run_tests(), FloatTest::run_tests(), IntTest::run_tests(), SearchMinTest::run_tests(), MathlibTest::run_tests(), MicroBenchHRT::MicroBenchHRT::run_tests(), MicroBenchMath::MicroBenchMath::run_tests(), MicroBenchMatrix::MicroBenchMatrix::run_tests(), MixerTest::run_tests(), and MicroBenchORB::MicroBenchORB::run_tests().

◆ ut_test