diff --git a/cmake/configs/nuttx_aerocore2_default.cmake b/cmake/configs/nuttx_aerocore2_default.cmake index 417043f012e4d1ee17c0019f240f08737a038457..a6a79bfe4209f355c8628e109d2146a031eb118d 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 d4db053711ed380de3903bc309886f4accfcf974..c5b774cf55b1c5ba3787a00248b5b4d02a5c2dd7 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 2903a545a29aeb1b8e6b1ad63ab986e2c0bde851..7ab56290f866ce2625a37bdde9611b40d00d5c18 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 8f627f8ad43e6562ef0f2fb7a52a2eeec76e14e1..36f2bf3ae4f2e45b7210d59afdef35b414cc31a7 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 38fc8b2bc112b37cf6c284634131b830f146d291..a2654535fd6f58cade4c0eec4946b73c846c8164 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 1a411f549e7e4e7d22d7420642d63d1cece0e4c8..a7be2539427fc1c10bf3ced06589014de38688c3 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 089e740f19b71be3767fe7a8498c68484c520ce7..1b61fa64c793911139f3d95b6a3fe4a7e68634d3 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 bbd7f592ef3fecad036a2e3fab05ead47140f0f6..a293eb7731d674a680cba3422d29a7a1b7447569 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 34fda5cce5857acdd94732a0fc4dad9c20cfd8e2..b8099b1ffdb6d6d0f01387197a4ae77971eb80d5 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 f88a9056bd8c659cc67cc7902dc87ed36ea1e86f..d2bf65eaa30ca5b1b8ef8491a57c0ea6c809fa93 100644 --- a/src/drivers/sf0x/sf0x_tests/SF0XTest.cpp +++ b/src/drivers/sf0x/sf0x_tests/SF0XTest.cpp @@ -1,4 +1,4 @@ -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <drivers/sf0x/sf0x_parser.h> 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 2a6150d4c4b86b9dcfaa6dc20a16bb935f323d80..f9fac8f80b8bb8a77e0717e2c995e61b2dc1f90a 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_assert(const char *msg, const char *test, const char *file, int line) + { + PX4_ERR("Assertion failed: %s - %s (%s:%d)", msg, test, file, line); + } + void _print_compare(const char *msg, const char *v1_text, int v1, const char *v2_text, int v2, const char *file, - int line); + 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; ///< 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 + 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 d0ea23478e1635d61bee75d3f20177ee0863889e..cff76b42e675603b5e1ec3451615aa3b07353cca 100644 --- a/src/lib/rc/rc_tests/RCTest.cpp +++ b/src/lib/rc/rc_tests/RCTest.cpp @@ -1,4 +1,4 @@ -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <systemlib/err.h> 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 f69842c51793ded7e0c9abf6ada8826b92afddb1..86c43f985df9771806bce06c3951367bf6e6de1b 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 <unit_test/unit_test.h> +#include <unit_test.h> 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 7708d2a630355acf01e060812d9624f07230e2b2..58a41ae25d25cc560422bac9c12f4d2193b1e335 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 <unit_test/unit_test.h> +#include <unit_test.h> #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 26532976172cd551ee576058b08dc42118ec1017..df297e51f8c17845310fbc27e999e9e826601ba6 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 <systemlib/err.h> -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <mathlib/mathlib.h> 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 c3b1fbbb032f25766c2f078370bfe68ce56a146b..0000000000000000000000000000000000000000 --- 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 e3f40359b240e914eb03260144c5385e613bf429..0000000000000000000000000000000000000000 --- 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 <sjwilks@gmail.com> - * - * 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 <systemlib/err.h> - -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 309cd7a858116ed8a62f555b0c011ed1cdd429a7..b39471954b8d2b99c9fe2a212ea08570e3130891 100644 --- a/src/systemcmds/tests/test_autodeclination.cpp +++ b/src/systemcmds/tests/test_autodeclination.cpp @@ -1,4 +1,4 @@ -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <drivers/drv_hrt.h> #include <geo/geo.h> diff --git a/src/systemcmds/tests/test_conv.cpp b/src/systemcmds/tests/test_conv.cpp index fae383c622118addd5424e9ba9d3128a7970fd7b..9a47a5aeae53e60c27ee1b1a67955a8706096118 100644 --- a/src/systemcmds/tests/test_conv.cpp +++ b/src/systemcmds/tests/test_conv.cpp @@ -51,7 +51,7 @@ #include <math.h> #include <float.h> -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <px4iofirmware/protocol.h> int test_conv(int argc, char *argv[]) diff --git a/src/systemcmds/tests/test_float.cpp b/src/systemcmds/tests/test_float.cpp index 50b5854d7d217d625c2acd46f2ae0ed8a167e81a..bc67cf5b9bcb4551cc3c6031b3ba3e5fffb2d3c6 100644 --- a/src/systemcmds/tests/test_float.cpp +++ b/src/systemcmds/tests/test_float.cpp @@ -1,4 +1,4 @@ -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <px4_config.h> #include <cfloat> diff --git a/src/systemcmds/tests/test_hysteresis.cpp b/src/systemcmds/tests/test_hysteresis.cpp index 1f53c256863ebf3359d8951588720f877e583214..8569a17b45048aff632af9fb28ef4da6961703db 100644 --- a/src/systemcmds/tests/test_hysteresis.cpp +++ b/src/systemcmds/tests/test_hysteresis.cpp @@ -1,4 +1,4 @@ -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <systemlib/hysteresis/hysteresis.h> diff --git a/src/systemcmds/tests/test_int.cpp b/src/systemcmds/tests/test_int.cpp index 026cc601115b241e48d554cc58877c64e2b4fd96..f24a297dce6bd03ee1fa74e70625e75eb0251a08 100644 --- a/src/systemcmds/tests/test_int.cpp +++ b/src/systemcmds/tests/test_int.cpp @@ -1,4 +1,4 @@ -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <errno.h> #include <fcntl.h> diff --git a/src/systemcmds/tests/test_mathlib.cpp b/src/systemcmds/tests/test_mathlib.cpp index 422369c74396483459a3b0f39bc1de877a05eef5..b43cfa30d3c11f274df408a36222e8e4d5ac6198 100644 --- a/src/systemcmds/tests/test_mathlib.cpp +++ b/src/systemcmds/tests/test_mathlib.cpp @@ -31,7 +31,7 @@ * ****************************************************************************/ -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <errno.h> #include <fcntl.h> diff --git a/src/systemcmds/tests/test_matrix.cpp b/src/systemcmds/tests/test_matrix.cpp index 5285591f04ffc1751d030b8133b7c7f6173092bf..59f5f26048533dbad79fccba1e1d1e55db817616 100644 --- a/src/systemcmds/tests/test_matrix.cpp +++ b/src/systemcmds/tests/test_matrix.cpp @@ -1,5 +1,5 @@ -#include <unit_test/unit_test.h> +#include <unit_test.h> #include <matrix/math.hpp> #include <matrix/filter.hpp> diff --git a/src/systemcmds/tests/test_mixer.cpp b/src/systemcmds/tests/test_mixer.cpp index 772b37cc5f6c86807f902497a88d988310949648..04f228018ff4bbea63297c2afa9ae59f996d93e5 100644 --- a/src/systemcmds/tests/test_mixer.cpp +++ b/src/systemcmds/tests/test_mixer.cpp @@ -64,7 +64,7 @@ #include "tests_main.h" -#include <unit_test/unit_test.h> +#include <unit_test.h> 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 4e9dc2bf87cde81937c5e72852243e3a142b713b..36a42f666f0d7f6a15cc4f21d1e82b2257a934c7 100644 --- a/src/systemcmds/tests/test_parameters.cpp +++ b/src/systemcmds/tests/test_parameters.cpp @@ -1,4 +1,4 @@ -#include <unit_test/unit_test.h> +#include <unit_test.h> class ParameterTest : public UnitTest {