diff --git a/cmake/configs/nuttx_aerocore2_default.cmake b/cmake/configs/nuttx_aerocore2_default.cmake index 417043f012..a6a79bfe42 100644 --- a/cmake/configs/nuttx_aerocore2_default.cmake +++ b/cmake/configs/nuttx_aerocore2_default.cmake @@ -63,7 +63,6 @@ set(config_module_list #modules/commander/commander_tests #lib/controllib/controllib_test #modules/mavlink/mavlink_tests - #modules/unit_test #modules/uORB/uORB_tests #systemcmds/tests diff --git a/cmake/configs/nuttx_auav-x21_default.cmake b/cmake/configs/nuttx_auav-x21_default.cmake index d4db053711..c5b774cf55 100644 --- a/cmake/configs/nuttx_auav-x21_default.cmake +++ b/cmake/configs/nuttx_auav-x21_default.cmake @@ -84,7 +84,6 @@ set(config_module_list lib/controllib/controllib_test modules/mavlink/mavlink_tests modules/mc_pos_control/mc_pos_control_tests - modules/unit_test modules/uORB/uORB_tests systemcmds/tests diff --git a/cmake/configs/nuttx_mindpx-v2_default.cmake b/cmake/configs/nuttx_mindpx-v2_default.cmake index 2903a545a2..7ab56290f8 100644 --- a/cmake/configs/nuttx_mindpx-v2_default.cmake +++ b/cmake/configs/nuttx_mindpx-v2_default.cmake @@ -86,7 +86,6 @@ set(config_module_list modules/mc_pos_control/mc_pos_control_tests lib/controllib/controllib_test modules/mavlink/mavlink_tests - modules/unit_test modules/uORB/uORB_tests systemcmds/tests diff --git a/cmake/configs/nuttx_px4fmu-v2_test.cmake b/cmake/configs/nuttx_px4fmu-v2_test.cmake index 8f627f8ad4..36f2bf3ae4 100644 --- a/cmake/configs/nuttx_px4fmu-v2_test.cmake +++ b/cmake/configs/nuttx_px4fmu-v2_test.cmake @@ -84,7 +84,6 @@ set(config_module_list modules/mc_pos_control/mc_pos_control_tests lib/controllib/controllib_test modules/mavlink/mavlink_tests - modules/unit_test modules/uORB/uORB_tests systemcmds/tests diff --git a/cmake/configs/nuttx_px4fmu-v3_default.cmake b/cmake/configs/nuttx_px4fmu-v3_default.cmake index 38fc8b2bc1..a2654535fd 100644 --- a/cmake/configs/nuttx_px4fmu-v3_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v3_default.cmake @@ -91,7 +91,6 @@ set(config_module_list lib/controllib/controllib_test modules/mavlink/mavlink_tests modules/mc_pos_control/mc_pos_control_tests - modules/unit_test modules/uORB/uORB_tests systemcmds/tests diff --git a/cmake/configs/nuttx_px4fmu-v4_default.cmake b/cmake/configs/nuttx_px4fmu-v4_default.cmake index 1a411f549e..a7be253942 100644 --- a/cmake/configs/nuttx_px4fmu-v4_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v4_default.cmake @@ -90,7 +90,6 @@ set(config_module_list modules/mc_pos_control/mc_pos_control_tests lib/controllib/controllib_test modules/mavlink/mavlink_tests - modules/unit_test modules/uORB/uORB_tests systemcmds/tests diff --git a/cmake/configs/nuttx_px4fmu-v4pro_default.cmake b/cmake/configs/nuttx_px4fmu-v4pro_default.cmake index 089e740f19..1b61fa64c7 100644 --- a/cmake/configs/nuttx_px4fmu-v4pro_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v4pro_default.cmake @@ -91,7 +91,6 @@ set(config_module_list lib/controllib/controllib_test modules/mavlink/mavlink_tests modules/mc_pos_control/mc_pos_control_tests - modules/unit_test modules/uORB/uORB_tests systemcmds/tests diff --git a/cmake/configs/nuttx_px4fmu-v5_default.cmake b/cmake/configs/nuttx_px4fmu-v5_default.cmake index bbd7f592ef..a293eb7731 100644 --- a/cmake/configs/nuttx_px4fmu-v5_default.cmake +++ b/cmake/configs/nuttx_px4fmu-v5_default.cmake @@ -89,7 +89,6 @@ set(config_module_list lib/controllib/controllib_test modules/mavlink/mavlink_tests modules/mc_pos_control/mc_pos_control_tests - modules/unit_test modules/uORB/uORB_tests systemcmds/tests diff --git a/cmake/configs/posix_sitl_default.cmake b/cmake/configs/posix_sitl_default.cmake index 34fda5cce5..b8099b1ffd 100644 --- a/cmake/configs/posix_sitl_default.cmake +++ b/cmake/configs/posix_sitl_default.cmake @@ -51,7 +51,6 @@ set(config_module_list lib/controllib/controllib_test modules/mavlink/mavlink_tests modules/mc_pos_control/mc_pos_control_tests - modules/unit_test modules/uORB/uORB_tests systemcmds/tests diff --git a/src/drivers/sf0x/sf0x_tests/SF0XTest.cpp b/src/drivers/sf0x/sf0x_tests/SF0XTest.cpp index f88a9056bd..d2bf65eaa3 100644 --- a/src/drivers/sf0x/sf0x_tests/SF0XTest.cpp +++ b/src/drivers/sf0x/sf0x_tests/SF0XTest.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/modules/unit_test/unit_test.h b/src/include/unit_test.h similarity index 88% rename from src/modules/unit_test/unit_test.h rename to src/include/unit_test.h index 2a6150d4c4..f9fac8f80b 100644 --- a/src/modules/unit_test/unit_test.h +++ b/src/include/unit_test.h @@ -53,15 +53,28 @@ class __EXPORT UnitTest { public: - UnitTest(); - virtual ~UnitTest(); + UnitTest() = default; + virtual ~UnitTest() = default; /// @brief Override to run your unit tests. Unit tests should be called using ut_run_test macro. /// @return true: all unit tests succeeded, false: one or more unit tests failed virtual bool run_tests(void) = 0; /// @brief Prints results from running of unit tests. - void print_results(void); + void print_results() + { + if (_tests_failed) { + PX4_ERR("SOME TESTS FAILED"); + + } else { + PX4_INFO("ALL TESTS PASSED"); + } + + PX4_INFO(" Tests passed : %d", _tests_passed); + PX4_INFO(" Tests failed : %d", _tests_failed); + PX4_INFO(" Tested assertions : %d", _assertions); + } + /// @brief Macro to create a function which will run a unit test class and print results. #define ut_declare_test(test_function, test_class) \ @@ -175,14 +188,21 @@ protected: virtual void _init(void) { }; ///< Run before each unit test. Override to provide custom behavior. virtual void _cleanup(void) { }; ///< Run after each unit test. Override to provide custom behavior. - void _print_assert(const char *msg, const char *test, const char *file, int line); - void _print_compare(const char *msg, const char *v1_text, int v1, const char *v2_text, int v2, const char *file, - int line); + void _print_assert(const char *msg, const char *test, const char *file, int line) + { + PX4_ERR("Assertion failed: %s - %s (%s:%d)", msg, test, file, line); + } - int _tests_run; ///< The number of individual unit tests run - int _tests_failed; ///< The number of unit tests which failed - int _tests_passed; ///< The number of unit tests which passed - int _assertions; ///< Total number of assertions tested by all unit tests + void _print_compare(const char *msg, const char *v1_text, int v1, const char *v2_text, int v2, const char *file, + int line) + { + PX4_ERR("Compare failed: %s - (%s:%d) (%s:%d) (%s:%d)", msg, v1_text, v1, v2_text, v2, file, line); + } + + int _tests_run{0}; ///< The number of individual unit tests run + int _tests_failed{0}; ///< The number of unit tests which failed + int _tests_passed{0}; ///< The number of unit tests which passed + int _assertions{0}; ///< Total number of assertions tested by all unit tests }; #endif /* UNIT_TEST_H_ */ diff --git a/src/lib/rc/rc_tests/RCTest.cpp b/src/lib/rc/rc_tests/RCTest.cpp index d0ea23478e..cff76b42e6 100644 --- a/src/lib/rc/rc_tests/RCTest.cpp +++ b/src/lib/rc/rc_tests/RCTest.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/modules/commander/commander_tests/state_machine_helper_test.cpp b/src/modules/commander/commander_tests/state_machine_helper_test.cpp index f69842c517..86c43f985d 100644 --- a/src/modules/commander/commander_tests/state_machine_helper_test.cpp +++ b/src/modules/commander/commander_tests/state_machine_helper_test.cpp @@ -41,7 +41,7 @@ #include "state_machine_helper_test.h" #include "../state_machine_helper.h" -#include +#include class StateMachineHelperTest : public UnitTest { diff --git a/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h b/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h index 7708d2a630..58a41ae25d 100644 --- a/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h +++ b/src/modules/mavlink/mavlink_tests/mavlink_ftp_test.h @@ -36,7 +36,7 @@ #pragma once -#include +#include #include "../mavlink_bridge_header.h" #include "../mavlink_ftp.h" diff --git a/src/modules/mc_pos_control/mc_pos_control_tests/mc_pos_control_tests.cpp b/src/modules/mc_pos_control/mc_pos_control_tests/mc_pos_control_tests.cpp index 2653297617..df297e51f8 100644 --- a/src/modules/mc_pos_control/mc_pos_control_tests/mc_pos_control_tests.cpp +++ b/src/modules/mc_pos_control/mc_pos_control_tests/mc_pos_control_tests.cpp @@ -40,7 +40,7 @@ */ #include -#include +#include #include extern "C" __EXPORT int mc_pos_control_tests_main(int argc, char *argv[]); diff --git a/src/modules/unit_test/CMakeLists.txt b/src/modules/unit_test/CMakeLists.txt deleted file mode 100644 index c3b1fbbb03..0000000000 --- a/src/modules/unit_test/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -############################################################################ -# -# Copyright (c) 2015 PX4 Development Team. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. Neither the name PX4 nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS -# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# -############################################################################ -px4_add_module( - MODULE modules__unit_test - COMPILE_FLAGS - SRCS - unit_test.cpp - DEPENDS - platforms__common - ) -# vim: set noet ft=cmake fenc=utf-8 ff=unix : diff --git a/src/modules/unit_test/unit_test.cpp b/src/modules/unit_test/unit_test.cpp deleted file mode 100644 index e3f40359b2..0000000000 --- a/src/modules/unit_test/unit_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * - * Copyright (C) 2013 PX4 Development Team. All rights reserved. - * Author: Simon Wilks - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name PX4 nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -#include "unit_test.h" - -#include - -UnitTest::UnitTest() : - _tests_run(0), - _tests_failed(0), - _tests_passed(0), - _assertions(0) -{ -} - -UnitTest::~UnitTest() -{ -} - -void UnitTest::print_results() -{ - if (_tests_failed) { - PX4_ERR("SOME TESTS FAILED"); - - } else { - PX4_INFO("ALL TESTS PASSED"); - } - - PX4_INFO(" Tests passed : %d", _tests_passed); - PX4_INFO(" Tests failed : %d", _tests_failed); - PX4_INFO(" Tested assertions : %d", _assertions); -} - -/// @brief Used internally to the ut_assert macro to print assert failures. -void UnitTest::_print_assert(const char *msg, const char *test, const char *file, int line) -{ - PX4_ERR("Assertion failed: %s - %s (%s:%d)", msg, test, file, line); -} - -/// @brief Used internally to the ut_compare macro to print assert failures. -void UnitTest::_print_compare(const char *msg, const char *v1_text, int v1, const char *v2_text, int v2, - const char *file, int line) -{ - PX4_ERR("Compare failed: %s - (%s:%d) (%s:%d) (%s:%d)", msg, v1_text, v1, v2_text, v2, file, line); -} diff --git a/src/systemcmds/tests/test_autodeclination.cpp b/src/systemcmds/tests/test_autodeclination.cpp index 309cd7a858..b39471954b 100644 --- a/src/systemcmds/tests/test_autodeclination.cpp +++ b/src/systemcmds/tests/test_autodeclination.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/systemcmds/tests/test_conv.cpp b/src/systemcmds/tests/test_conv.cpp index fae383c622..9a47a5aeae 100644 --- a/src/systemcmds/tests/test_conv.cpp +++ b/src/systemcmds/tests/test_conv.cpp @@ -51,7 +51,7 @@ #include #include -#include +#include #include int test_conv(int argc, char *argv[]) diff --git a/src/systemcmds/tests/test_float.cpp b/src/systemcmds/tests/test_float.cpp index 50b5854d7d..bc67cf5b9b 100644 --- a/src/systemcmds/tests/test_float.cpp +++ b/src/systemcmds/tests/test_float.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/systemcmds/tests/test_hysteresis.cpp b/src/systemcmds/tests/test_hysteresis.cpp index 1f53c25686..8569a17b45 100644 --- a/src/systemcmds/tests/test_hysteresis.cpp +++ b/src/systemcmds/tests/test_hysteresis.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/src/systemcmds/tests/test_int.cpp b/src/systemcmds/tests/test_int.cpp index 026cc60111..f24a297dce 100644 --- a/src/systemcmds/tests/test_int.cpp +++ b/src/systemcmds/tests/test_int.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/systemcmds/tests/test_mathlib.cpp b/src/systemcmds/tests/test_mathlib.cpp index 422369c743..b43cfa30d3 100644 --- a/src/systemcmds/tests/test_mathlib.cpp +++ b/src/systemcmds/tests/test_mathlib.cpp @@ -31,7 +31,7 @@ * ****************************************************************************/ -#include +#include #include #include diff --git a/src/systemcmds/tests/test_matrix.cpp b/src/systemcmds/tests/test_matrix.cpp index 5285591f04..59f5f26048 100644 --- a/src/systemcmds/tests/test_matrix.cpp +++ b/src/systemcmds/tests/test_matrix.cpp @@ -1,5 +1,5 @@ -#include +#include #include #include diff --git a/src/systemcmds/tests/test_mixer.cpp b/src/systemcmds/tests/test_mixer.cpp index 772b37cc5f..04f228018f 100644 --- a/src/systemcmds/tests/test_mixer.cpp +++ b/src/systemcmds/tests/test_mixer.cpp @@ -64,7 +64,7 @@ #include "tests_main.h" -#include +#include static int mixer_callback(uintptr_t handle, uint8_t control_group, diff --git a/src/systemcmds/tests/test_parameters.cpp b/src/systemcmds/tests/test_parameters.cpp index 4e9dc2bf87..36a42f666f 100644 --- a/src/systemcmds/tests/test_parameters.cpp +++ b/src/systemcmds/tests/test_parameters.cpp @@ -1,4 +1,4 @@ -#include +#include class ParameterTest : public UnitTest {