src.dualinventive.com/jjacobs/dinetrpcll-sniffer/libdi/tests/CMakeLists.txt

169 lines
4.7 KiB
CMake
Executable File

if (NOT BUILD_TESTING)
message("-- libdi tests disabled")
return()
endif()
message("-- libdi tests enabled")
include_directories("${PROJECT_SOURCE_DIR}/src")
set(test_logdir "${CMAKE_CURRENT_BINARY_DIR}/log")
file(MAKE_DIRECTORY "${test_logdir}")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/data" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
set(test_reportdir "${CMAKE_CURRENT_BINARY_DIR}/report")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/report" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
configure_file("${test_reportdir}/libdi-test-report.tex.in" "${test_reportdir}/libdi-test-report.tex")
# TODO: we should generate TESTS list from GLOB *.cpp in this folder
set(LINUX_TESTS
linux_time
)
set(TESTS
assert
array
buffer
can
can_bitops
can_crc
can_send
can_reassemble
can_callback
can_example
can_log
can_lowlevel
can_frame
can_framing
can_msg
can_msg_gc
can_msg_state
can_msg_write
can_msg_read
can_msg_recv
can_msg_reqrep
can_msg_rt
can_msg_timesync
can_net
can_net_discover
can_net_discover_fsm
can_net_execute
can_net_node_events
can_net_node_error
can_net_node_uid
can_net_self
can_net_self_leader
# can_net_self_leader_giveup
can_raw
can_raw_dncm
can_rpc
can_str
can_zkl
config
crc
device_activation
device_error
device_state
device_state_callback
device_token
device_uid
device_service
drv_hl854x
drv_hl854x_con
drv_hl854x_cme_error
drv_hl854x_gps_pvt
drv_hl854x_mec
drv_hl854x_net
drv_hl854x_str
drv_hl854x_read_timeout
drv_hl854x_tcp
drv_hl854x_udp
drv_xbee
drv_xbee_checksum
drv_xbee_frame
drv_xbee_at_cmd
drv_crtm
errno
hash
logging
encoding_me
misc_hexstr
pp
mpack
rpc
rpc_serialize
rpc_serialize_data
rpc_serialize_msg
rpc_deserialize_msg
rpc_deserialize_msg_params
rpc_lowlevel
rpc_lowlevel_decode
rpc_lowlevel_encode
rpc_lowlevel_rpc_writer
rpc_sensor
rpc_param
semaphore
stdio
time
tws_du_strike
)
include("${DI_COMMON_CMAKE_DIR}/libs/gtest.txt")
find_package(Threads)
set(gtest_xml_dir "${CMAKE_CURRENT_BINARY_DIR}/gtest")
file(MAKE_DIRECTORY ${gtest_xml_dir})
foreach(test ${TESTS})
set(test_path "${CMAKE_CURRENT_BINARY_DIR}/${test}")
set(test_args "--gtest_output=xml:${gtest_xml_dir}/${test}.xml")
# Append a C-file to a list of sources for a test when it is needed
# needed for rpc_sensor.cpp/c
set(source "${test}.cpp")
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test}.c")
set(source "${source};${test}.c")
endif()
add_executable(${test} "${source}")
# -Wno-old-style-cast -> Ignore old style warnings because we actual test C
# -Wno-write-strings -> C++ deprecates string writing, ignore
# -fno-exceptions -> Disable exceptions because branches are incorrect reported, and this is C code..
set_source_files_properties(${test}.cpp PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast -Wno-write-strings -fno-exceptions")
add_dependencies(${test} di gtest)
target_link_libraries(${test} di)
target_link_libraries(${test} ${gtest_main_library})
target_link_libraries(${test} ${gtest_library})
target_link_libraries(${test} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME "${test}" COMMAND "${test_path}" "${test_args}")
set_property(TEST "${test}" PROPERTY ENVIRONMENT "TESTNAME=${test}")
endforeach()
foreach(test ${LINUX_TESTS})
set(test_path "${CMAKE_CURRENT_BINARY_DIR}/${test}")
set(test_args "--gtest_output=xml:${gtest_xml_dir}/${test}.xml")
# Append a C-file to a list of sources for a test when it is needed
# needed for rpc_sensor.cpp/c
set(source "${test}.cpp")
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${test}.c")
set(source "${source};${test}.c")
endif()
add_executable(${test} "${source}")
# -Wno-old-style-cast -> Ignore old style warnings because we actual test C
# -Wno-write-strings -> C++ deprecates string writing, ignore
# -fno-exceptions -> Disable exceptions because branches are incorrect reported, and this is C code..
set_source_files_properties(${test}.cpp PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast -Wno-write-strings -fno-exceptions")
add_dependencies(${test} dilinux gtest)
target_link_libraries(${test} dilinux)
target_link_libraries(${test} ${gtest_main_library})
target_link_libraries(${test} ${gtest_library})
target_link_libraries(${test} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME "${test}" COMMAND "${test_path}" "${test_args}")
set_property(TEST "${test}" PROPERTY ENVIRONMENT "TESTNAME=${test}")
endforeach()
add_test(NAME "json_validator" COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/json_validator.py" "${test_logdir}")
set_property(TEST "json_validator" PROPERTY ENVIRONMENT "TESTNAME=json_validator")
add_custom_target(test-report COMMAND "${CMAKE_SOURCE_DIR}/common/gtest-report/gtest-report.py" "'${gtest_xml_dir}/*.xml'" WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(test-report-pdf COMMAND "make" WORKING_DIRECTORY ${test_reportdir})