mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 18:33:34 +08:00
test: add google fuzztest to unit test build
From https://github.com/google/fuzztest. This will now also add gtest (via cmake FetchContent) And requires newer cmake (container updates): CMake 3.19 or higher is required. You are running version 3.16.3
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(googletest-download NONE)
|
||||
|
||||
include(ExternalProject)
|
||||
ExternalProject_Add(googletest
|
||||
URL https://github.com/google/googletest/archive/b796f7d44681514f58a683a3a71ff17c94edb0c1.zip # 1.13
|
||||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
# Wrap download, configure and build steps in a script to log output
|
||||
LOG_DOWNLOAD ON
|
||||
LOG_CONFIGURE ON
|
||||
LOG_BUILD ON
|
||||
)
|
||||
@@ -1,52 +0,0 @@
|
||||
############################################################################
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Download and unpack googletest at configure time
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . RESULT_VARIABLE result1 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} --build . RESULT_VARIABLE result2 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download)
|
||||
if(result1 OR result2)
|
||||
message(FATAL_ERROR "Preparing googletest failed: ${result1} ${result2}")
|
||||
endif()
|
||||
|
||||
# Add googletest, defines gtest and gtest_main targets
|
||||
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL)
|
||||
|
||||
# Remove visibility.h from the compile flags for gtest because of poisoned exit()
|
||||
get_target_property(GTEST_COMPILE_FLAGS gtest COMPILE_OPTIONS)
|
||||
list(REMOVE_ITEM GTEST_COMPILE_FLAGS "-include")
|
||||
list(REMOVE_ITEM GTEST_COMPILE_FLAGS "visibility.h")
|
||||
# Remove float warnings added by PX4 which trigger in gtest-printers.h
|
||||
list(REMOVE_ITEM GTEST_COMPILE_FLAGS "-Wdouble-promotion")
|
||||
list(REMOVE_ITEM GTEST_COMPILE_FLAGS "-Wfloat-equal")
|
||||
set_target_properties(gtest PROPERTIES COMPILE_OPTIONS "${GTEST_COMPILE_FLAGS}")
|
||||
@@ -105,6 +105,7 @@ function(px4_add_common_flags)
|
||||
-Wno-unknown-warning-option
|
||||
-Wno-unused-const-variable
|
||||
-Wno-varargs
|
||||
-Wno-vla-cxx-extension # FIXME: do not use variable length arrays
|
||||
)
|
||||
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
|
||||
@@ -57,7 +57,7 @@ function(px4_add_unit_gtest)
|
||||
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC} ${EXTRA_SRCS})
|
||||
|
||||
# link the libary to test and gtest
|
||||
target_link_libraries(${TESTNAME} ${LINKLIBS} gtest_main)
|
||||
target_link_libraries(${TESTNAME} PRIVATE ${LINKLIBS})
|
||||
|
||||
if(COMPILE_FLAGS)
|
||||
target_compile_options(${TESTNAME} PRIVATE ${COMPILE_FLAGS})
|
||||
@@ -66,6 +66,7 @@ function(px4_add_unit_gtest)
|
||||
if(INCLUDES)
|
||||
target_include_directories(${TESTNAME} PRIVATE ${INCLUDES})
|
||||
endif()
|
||||
link_fuzztest(${TESTNAME})
|
||||
|
||||
# add the test to the ctest plan
|
||||
add_test(NAME ${TESTNAME}
|
||||
@@ -97,7 +98,7 @@ function(px4_add_functional_gtest)
|
||||
add_executable(${TESTNAME} EXCLUDE_FROM_ALL ${SRC} ${EXTRA_SRCS})
|
||||
|
||||
# link the libary to test and gtest
|
||||
target_link_libraries(${TESTNAME} ${LINKLIBS} gtest_functional_main
|
||||
target_link_libraries(${TESTNAME} PRIVATE ${LINKLIBS} gtest_functional_main
|
||||
px4_layer
|
||||
px4_platform
|
||||
uORB
|
||||
@@ -111,7 +112,9 @@ function(px4_add_functional_gtest)
|
||||
perf
|
||||
tinybson
|
||||
uorb_msgs
|
||||
test_stubs) #put test_stubs last
|
||||
fuzztest::fuzztest # Do not use link_fuzztest() here because that
|
||||
# also links to fuzztest_gtest_main
|
||||
test_stubs) # put test_stubs last
|
||||
|
||||
if(COMPILE_FLAGS)
|
||||
target_compile_options(${TESTNAME} PRIVATE ${COMPILE_FLAGS})
|
||||
Reference in New Issue
Block a user