chore: cmakes formatting

Co-Authored-By: Lorenzo Fontana <lo@linux.com>
Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
This commit is contained in:
Leonardo Di Donato
2019-06-27 10:33:50 +00:00
committed by Lorenzo Fontana
parent 3a1c0ea916
commit 1a0cf69b03
7 changed files with 793 additions and 578 deletions

View File

@@ -3,29 +3,45 @@
# #
# This file is part of falco . # This file is part of falco .
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License"); you may not
# you may not use this file except in compliance with the License. # use this file except in compliance with the License. You may obtain a copy of
# You may obtain a copy of the License at # the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# See the License for the specific language governing permissions and # License for the specific language governing permissions and limitations under
# limitations under the License. # the License.
# #
if(CPACK_GENERATOR MATCHES "DEB") if(CPACK_GENERATOR MATCHES "DEB")
list(APPEND CPACK_INSTALL_COMMANDS "mkdir -p _CPack_Packages/${CPACK_TOPLEVEL_TAG}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}/etc/init.d/") list(
list(APPEND CPACK_INSTALL_COMMANDS "cp scripts/debian/falco _CPack_Packages/${CPACK_TOPLEVEL_TAG}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}/etc/init.d") APPEND
CPACK_INSTALL_COMMANDS
"mkdir -p _CPack_Packages/${CPACK_TOPLEVEL_TAG}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}/etc/init.d/"
)
list(
APPEND
CPACK_INSTALL_COMMANDS
"cp scripts/debian/falco _CPack_Packages/${CPACK_TOPLEVEL_TAG}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}/etc/init.d"
)
endif() endif()
if(CPACK_GENERATOR MATCHES "RPM") if(CPACK_GENERATOR MATCHES "RPM")
list(APPEND CPACK_INSTALL_COMMANDS "mkdir -p _CPack_Packages/${CPACK_TOPLEVEL_TAG}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}/etc/rc.d/init.d/") list(
list(APPEND CPACK_INSTALL_COMMANDS "cp scripts/rpm/falco _CPack_Packages/${CPACK_TOPLEVEL_TAG}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}/etc/rc.d/init.d") APPEND
CPACK_INSTALL_COMMANDS
"mkdir -p _CPack_Packages/${CPACK_TOPLEVEL_TAG}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}/etc/rc.d/init.d/"
)
list(
APPEND
CPACK_INSTALL_COMMANDS
"cp scripts/rpm/falco _CPack_Packages/${CPACK_TOPLEVEL_TAG}/${CPACK_GENERATOR}/${CPACK_PACKAGE_FILE_NAME}/etc/rc.d/init.d"
)
endif() endif()
if(CPACK_GENERATOR MATCHES "TGZ") if(CPACK_GENERATOR MATCHES "TGZ")
set(CPACK_SET_DESTDIR "ON") set(CPACK_SET_DESTDIR "ON")
set(CPACK_STRIP_FILES "OFF") set(CPACK_STRIP_FILES "OFF")
endif() endif()

File diff suppressed because it is too large Load Diff

View File

@@ -92,15 +92,13 @@ same as the Catch name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
#]=======================================================================] #]=======================================================================]
#------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function(catch_discover_tests TARGET) function(catch_discover_tests TARGET)
cmake_parse_arguments( cmake_parse_arguments(""
"" ""
"" "TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST"
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST" "TEST_SPEC;EXTRA_ARGS;PROPERTIES"
"TEST_SPEC;EXTRA_ARGS;PROPERTIES" ${ARGN})
${ARGN}
)
if(NOT _WORKING_DIRECTORY) if(NOT _WORKING_DIRECTORY)
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
@@ -109,67 +107,78 @@ function(catch_discover_tests TARGET)
set(_TEST_LIST ${TARGET}_TESTS) set(_TEST_LIST ${TARGET}_TESTS)
endif() endif()
## Generate a unique name based on the extra arguments # Generate a unique name based on the extra arguments
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS}") string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS}")
string(SUBSTRING ${args_hash} 0 7 args_hash) string(SUBSTRING ${args_hash}
0
7
args_hash)
# Define rule to generate test list for aforementioned test executable # Define rule to generate test list for aforementioned test executable
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include-${args_hash}.cmake") set(ctest_include_file
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests-${args_hash}.cmake") "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include-${args_hash}.cmake")
set(ctest_tests_file
"${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests-${args_hash}.cmake")
get_property(crosscompiling_emulator get_property(crosscompiling_emulator
TARGET ${TARGET} TARGET ${TARGET}
PROPERTY CROSSCOMPILING_EMULATOR PROPERTY CROSSCOMPILING_EMULATOR)
) add_custom_command(TARGET
add_custom_command( ${TARGET}
TARGET ${TARGET} POST_BUILD POST_BUILD
BYPRODUCTS "${ctest_tests_file}" BYPRODUCTS
COMMAND "${CMAKE_COMMAND}" "${ctest_tests_file}"
-D "TEST_TARGET=${TARGET}" COMMAND "${CMAKE_COMMAND}"
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>" -D
-D "TEST_EXECUTOR=${crosscompiling_emulator}" "TEST_TARGET=${TARGET}"
-D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}" -D
-D "TEST_SPEC=${_TEST_SPEC}" "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}" -D
-D "TEST_PROPERTIES=${_PROPERTIES}" "TEST_EXECUTOR=${crosscompiling_emulator}"
-D "TEST_PREFIX=${_TEST_PREFIX}" -D
-D "TEST_SUFFIX=${_TEST_SUFFIX}" "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
-D "TEST_LIST=${_TEST_LIST}" -D
-D "CTEST_FILE=${ctest_tests_file}" "TEST_SPEC=${_TEST_SPEC}"
-P "${_CATCH_DISCOVER_TESTS_SCRIPT}" -D
VERBATIM "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
) -D
"TEST_PROPERTIES=${_PROPERTIES}"
-D
"TEST_PREFIX=${_TEST_PREFIX}"
-D
"TEST_SUFFIX=${_TEST_SUFFIX}"
-D
"TEST_LIST=${_TEST_LIST}"
-D
"CTEST_FILE=${ctest_tests_file}"
-P
"${_CATCH_DISCOVER_TESTS_SCRIPT}"
VERBATIM)
file(WRITE "${ctest_include_file}" file(
WRITE "${ctest_include_file}"
"if(EXISTS \"${ctest_tests_file}\")\n" "if(EXISTS \"${ctest_tests_file}\")\n"
" include(\"${ctest_tests_file}\")\n" " include(\"${ctest_tests_file}\")\n"
"else()\n" "else()\n"
" add_test(${TARGET}_NOT_BUILT-${args_hash} ${TARGET}_NOT_BUILT-${args_hash})\n" " add_test(${TARGET}_NOT_BUILT-${args_hash} ${TARGET}_NOT_BUILT-${args_hash})\n"
"endif()\n" "endif()\n")
)
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0") if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
# Add discovered tests to directory TEST_INCLUDE_FILES # Add discovered tests to directory TEST_INCLUDE_FILES
set_property(DIRECTORY set_property(DIRECTORY
APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}" APPEND
) PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}")
else() else()
# Add discovered tests as directory TEST_INCLUDE_FILE if possible # Add discovered tests as directory TEST_INCLUDE_FILE if possible
get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET) get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET)
if (NOT ${test_include_file_set}) if(NOT ${test_include_file_set})
set_property(DIRECTORY set_property(DIRECTORY PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}")
PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}"
)
else() else()
message(FATAL_ERROR message(FATAL_ERROR "Cannot set more than one TEST_INCLUDE_FILE")
"Cannot set more than one TEST_INCLUDE_FILE"
)
endif() endif()
endif() endif()
endfunction() endfunction()
############################################################################### # ##############################################################################
set(_CATCH_DISCOVER_TESTS_SCRIPT set(_CATCH_DISCOVER_TESTS_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/CatchAddTests.cmake)
${CMAKE_CURRENT_LIST_DIR}/CatchAddTests.cmake
)

View File

@@ -24,49 +24,50 @@ endfunction()
# Run test executable to get list of available tests # Run test executable to get list of available tests
if(NOT EXISTS "${TEST_EXECUTABLE}") if(NOT EXISTS "${TEST_EXECUTABLE}")
message(FATAL_ERROR message(
"Specified test executable '${TEST_EXECUTABLE}' does not exist" FATAL_ERROR "Specified test executable '${TEST_EXECUTABLE}' does not exist")
)
endif() endif()
execute_process( execute_process(COMMAND ${TEST_EXECUTOR}
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only "${TEST_EXECUTABLE}"
OUTPUT_VARIABLE output ${spec}
RESULT_VARIABLE result --list-test-names-only
) OUTPUT_VARIABLE output
# Catch --list-test-names-only reports the number of tests, so 0 is... surprising RESULT_VARIABLE result)
# Catch --list-test-names-only reports the number of tests, so 0 is...
# surprising
if(${result} EQUAL 0) if(${result} EQUAL 0)
message(WARNING message(WARNING "Test executable '${TEST_EXECUTABLE}' contains no tests!\n")
"Test executable '${TEST_EXECUTABLE}' contains no tests!\n"
)
elseif(${result} LESS 0) elseif(${result} LESS 0)
message(FATAL_ERROR message(FATAL_ERROR "Error running test executable '${TEST_EXECUTABLE}':\n"
"Error running test executable '${TEST_EXECUTABLE}':\n" " Result: ${result}\n" " Output: ${output}\n")
" Result: ${result}\n"
" Output: ${output}\n"
)
endif() endif()
string(REPLACE "\n" ";" output "${output}") string(REPLACE "\n"
";"
output
"${output}")
# Parse output # Parse output
foreach(line ${output}) foreach(line ${output})
set(test ${line}) set(test ${line})
# use escape commas to handle properly test cases with commans inside the name # use escape commas to handle properly test cases with commans inside the name
string(REPLACE "," "\\," test_name ${test}) string(REPLACE ","
"\\,"
test_name
${test})
# ...and add to script # ...and add to script
add_command(add_test add_command(add_test
"${prefix}${test}${suffix}" "${prefix}${test}${suffix}"
${TEST_EXECUTOR} ${TEST_EXECUTOR}
"${TEST_EXECUTABLE}" "${TEST_EXECUTABLE}"
"${test_name}" "${test_name}"
${extra_args} ${extra_args})
)
add_command(set_tests_properties add_command(set_tests_properties
"${prefix}${test}${suffix}" "${prefix}${test}${suffix}"
PROPERTIES PROPERTIES
WORKING_DIRECTORY "${TEST_WORKING_DIR}" WORKING_DIRECTORY
${properties} "${TEST_WORKING_DIR}"
) ${properties})
list(APPEND tests "${prefix}${test}${suffix}") list(APPEND tests "${prefix}${test}${suffix}")
endforeach() endforeach()

View File

@@ -0,0 +1,39 @@
#
# Copyright (C) 2016-2019 Draios Inc dba Sysdig.
#
# This file is part of falco .
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
include(ExternalProject)
set(CATCH2_INCLUDE ${CMAKE_BINARY_DIR}/catch2-prefix/include)
set(CATCH_EXTERNAL_URL
URL
https://github.com/catchorg/catch2/archive/v2.9.1.tar.gz
URL_HASH
MD5=4980778888fed635bf191d8a86f9f89c)
ExternalProject_Add(
catch2
PREFIX ${CMAKE_BINARY_DIR}/catch2-prefix
${CATCH_EXTERNAL_URL}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND
${CMAKE_COMMAND}
-E
copy
${CMAKE_BINARY_DIR}/catch2-prefix/src/catch2/single_include/catch2/catch.hpp
${CATCH2_INCLUDE}/catch.hpp)

View File

@@ -1,34 +0,0 @@
#
# Copyright (C) 2016-2019 Draios Inc dba Sysdig.
#
# This file is part of falco .
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include(ExternalProject)
set(CATCH_EXTERNAL_URL
URL https://github.com/catchorg/Catch2/archive/v2.9.1.tar.gz
URL_HASH MD5=4980778888fed635bf191d8a86f9f89c)
ExternalProject_Add(catch2
PREFIX ${CMAKE_BINARY_DIR}/catch2-prefix
${CATCH_EXTERNAL_URL}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/catch2-prefix/src/catch2/single_include/catch2/catch.hpp
${CMAKE_BINARY_DIR}/catch2-prefix/include/catch.hpp
)
add_library(catch INTERFACE)
add_dependencies(catch catch2)
target_include_directories(catch INTERFACE ${CMAKE_BINARY_DIR}/catch2-prefix/include)

View File

@@ -3,52 +3,46 @@
# #
# This file is part of falco . # This file is part of falco .
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License"); you may not
# you may not use this file except in compliance with the License. # use this file except in compliance with the License. You may obtain a copy of
# You may obtain a copy of the License at # the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# See the License for the specific language governing permissions and # License for the specific language governing permissions and limitations under
# limitations under the License. # the License.
# #
set(FALCO_TESTS_SOURCES set(FALCO_TESTS_SOURCES test_base.cpp engine/test_token_bucket.cpp)
test_base.cpp
engine/test_token_bucket.cpp)
set(FALCO_TESTED_LIBRARIES set(FALCO_TESTED_LIBRARIES falco_engine)
falco_engine)
option(FALCO_BUILD_TESTS "Determines whether to build tests." ON) option(FALCO_BUILD_TESTS "Determines whether to build tests." ON)
if(FALCO_BUILD_TESTS) if(FALCO_BUILD_TESTS)
enable_testing() enable_testing()
if(NOT TARGET catch) if(NOT TARGET catch)
include(FindCatch) include(DownloadCatch)
endif() endif()
add_executable(falco_test ${FALCO_TESTS_SOURCES}) if(NOT TARGET fakeit)
include(DownloadFakeIt)
endif()
target_link_libraries(falco_test PUBLIC ${FALCO_TESTED_LIBRARIES} catch) add_executable(falco_test ${FALCO_TESTS_SOURCES})
target_include_directories(falco_test PUBLIC
"${SYSDIG_DIR}/userspace/libsinsp/third-party/jsoncpp"
"${SYSDIG_DIR}/userspace/libscap"
"${SYSDIG_DIR}/userspace/libsinsp"
"${LUAJIT_INCLUDE}"
"${NJSON_INCLUDE}"
"${CURL_INCLUDE_DIR}"
"${TBB_INCLUDE_DIR}"
"${LUAJIT_INCLUDE}"
"${NJSON_INCLUDE}"
"${PROJECT_SOURCE_DIR}/userspace/engine"
)
include(CTest) target_link_libraries(falco_test PUBLIC ${FALCO_TESTED_LIBRARIES})
include(Catch) target_include_directories(
catch_discover_tests(falco_test) falco_test
PUBLIC "${CATCH2_INCLUDE}"
"${FAKEIT_INCLUDE}"
"${PROJECT_SOURCE_DIR}/userspace/engine")
add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS falco_test) include(CTest)
include(Catch)
catch_discover_tests(falco_test)
add_custom_target(tests COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS falco_test)
endif() endif()