diff --git a/cmake/gtest/px4_add_gtest.cmake b/cmake/gtest/px4_add_gtest.cmake index a69bdaf57d..f9d4f505ad 100644 --- a/cmake/gtest/px4_add_gtest.cmake +++ b/cmake/gtest/px4_add_gtest.cmake @@ -91,7 +91,7 @@ function(px4_add_functional_gtest) add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC}) # link the libary to test and gtest - target_link_libraries(${TESTNAME} ${LINKLIBS} gtest_main + target_link_libraries(${TESTNAME} ${LINKLIBS} gtest_functional_main px4_daemon px4_platform modules__uORB diff --git a/src/lib/CollisionPrevention/CollisionPreventionTest.cpp b/src/lib/CollisionPrevention/CollisionPreventionTest.cpp index 11910ce724..cb3e73bcc7 100644 --- a/src/lib/CollisionPrevention/CollisionPreventionTest.cpp +++ b/src/lib/CollisionPrevention/CollisionPreventionTest.cpp @@ -39,16 +39,9 @@ class CollisionPreventionTest : public ::testing::Test { public: - void SetUp() override - { - uORB::Manager::initialize(); - param_init(); - } - void TearDown() override { param_reset_all(); - uORB::Manager::terminate(); } }; diff --git a/src/lib/parameters/ParameterTest.cpp b/src/lib/parameters/ParameterTest.cpp index 491fadc615..783dd1bf5e 100644 --- a/src/lib/parameters/ParameterTest.cpp +++ b/src/lib/parameters/ParameterTest.cpp @@ -41,16 +41,9 @@ class ParameterTest : public ::testing::Test { public: - void SetUp() override - { - uORB::Manager::initialize(); - param_init(); - } - void TearDown() override { param_reset_all(); - uORB::Manager::terminate(); } }; diff --git a/src/platforms/CMakeLists.txt b/src/platforms/CMakeLists.txt index 6055801eae..272e4d66bd 100644 --- a/src/platforms/CMakeLists.txt +++ b/src/platforms/CMakeLists.txt @@ -35,4 +35,5 @@ add_subdirectory(common) if (${PX4_PLATFORM} STREQUAL "posix" AND BUILD_TESTING) add_subdirectory(posix/test_stubs) + add_subdirectory(posix/gtest_runner) endif() diff --git a/src/platforms/posix/gtest_runner/CMakeLists.txt b/src/platforms/posix/gtest_runner/CMakeLists.txt new file mode 100644 index 0000000000..0000dda9f8 --- /dev/null +++ b/src/platforms/posix/gtest_runner/CMakeLists.txt @@ -0,0 +1,39 @@ +############################################################################ +# +# Copyright (c) 2019 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. +# +############################################################################ + +set(SRCS + gtest_functional_main.cpp + ) + +px4_add_library(gtest_functional_main ${SRCS}) +target_link_libraries(gtest_functional_main PUBLIC gtest) diff --git a/src/platforms/posix/gtest_runner/gtest_functional_main.cpp b/src/platforms/posix/gtest_runner/gtest_functional_main.cpp new file mode 100644 index 0000000000..dc44167a34 --- /dev/null +++ b/src/platforms/posix/gtest_runner/gtest_functional_main.cpp @@ -0,0 +1,45 @@ +/**************************************************************************** + * + * Copyright (c) 2012-2019 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. + * + ****************************************************************************/ + +#include + +#include + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + uORB::Manager::initialize(); + param_init(); + return RUN_ALL_TESTS(); +}