From b100074e1fe1c80f57fe295b7f05d6186e279004 Mon Sep 17 00:00:00 2001 From: Felix Herrmann Date: Mon, 25 May 2020 15:30:41 +0200 Subject: execute unittests with cmake now you can do make test after make :) === Sample build and test: $ cmake -Bbuild -H. \ -DDLT_IPC=UNIX_SOCKET \ -DWITH_DLT_ADAPTOR=ON \ -DWITH_DLT_UNIT_TESTS=ON \ -DWITH_DLT_CXX11_EXT=ON \ -DWITH_DLT_MONITOR=OFF \ -DWITH_DLT_USE_IPv6=OFF $ cd build $ make $ make test Running tests... Test project /home/fherrmann/git/dlt-daemon/build Start 1: gtest_dlt_common 1/5 Test #1: gtest_dlt_common ................. Passed 0.02 sec Start 2: gtest_dlt_user 2/5 Test #2: gtest_dlt_user ................... Passed 1.01 sec Start 3: gtest_dlt_daemon_common 3/5 Test #3: gtest_dlt_daemon_common .......... Passed 0.01 sec Start 4: dlt_env_ll_unit_test 4/5 Test #4: dlt_env_ll_unit_test ............. Passed 0.04 sec Start 5: gtest_dlt_daemon_event_handler 5/5 Test #5: gtest_dlt_daemon_event_handler ... Passed 1.01 sec 100% tests passed, 0 tests failed out of 5 Total Test time (real) = 2.09 sec === Signed-off-by: Felix Herrmann Signed-off-by: KHANH LUONG HONG DUY --- .travis/gtest_dlt_all.sh | 12 ++---------- CMakeLists.txt | 12 ++++-------- cmake/dlt_version.h.cmake | 8 ++++---- tests/CMakeLists.txt | 45 +++++++++++++++++++++++++++++++------------- util/create_dlt_version_h.py | 7 +++++++ 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/.travis/gtest_dlt_all.sh b/.travis/gtest_dlt_all.sh index 4273859..1eeb231 100755 --- a/.travis/gtest_dlt_all.sh +++ b/.travis/gtest_dlt_all.sh @@ -41,15 +41,9 @@ function gtest_run_test() echo "$1 passed" } -pushd tests > /dev/null - -gtest_run_test gtest_dlt_common - -gtest_run_test gtest_dlt_user +CTEST_OUTPUT_ON_FAILURE=1 make test -gtest_run_test gtest_dlt_daemon_common - -gtest_run_test gtest_dlt_daemon_event_handler +pushd tests > /dev/null # Without General section in dlt_gateway.conf ./gtest_dlt_daemon_gateway.sh > /dev/null @@ -62,6 +56,4 @@ gtest_run_test gtest_dlt_daemon_gateway ./gtest_dlt_daemon_logstorage.sh > /dev/null gtest_run_test gtest_dlt_daemon_offline_log -gtest_run_test dlt_env_ll_unit_test - popd > /dev/null diff --git a/CMakeLists.txt b/CMakeLists.txt index a9c40cf..9d4f2ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,20 +13,15 @@ # For further information see http://www.genivi.org/. ####### -cmake_minimum_required(VERSION 2.8.5) -project(automotive-dlt) +cmake_minimum_required(VERSION 3.3) +project(automotive-dlt VERSION 2.18.4) mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE) include(GNUInstallDirs) # Set version parameters -set(DLT_MAJOR_VERSION 2) -set(DLT_MINOR_VERSION 18) -set(DLT_PATCH_LEVEL 4) -set(DLT_VERSION ${DLT_MAJOR_VERSION}.${DLT_MINOR_VERSION}.${DLT_PATCH_LEVEL}) set(DLT_VERSION_STATE STABLE) -set(DLT_REVISION "") execute_process(COMMAND git describe --tags WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE DLT_REVISION @@ -227,8 +222,9 @@ add_subdirectory(doc) add_subdirectory(src) add_subdirectory(include/dlt) add_subdirectory(testscripts) -if(WITH_DLT_UNIT_TESTS) +if (WITH_DLT_UNIT_TESTS) add_subdirectory( gtest-1.7.0 ) + enable_testing() add_subdirectory(tests) endif() diff --git a/cmake/dlt_version.h.cmake b/cmake/dlt_version.h.cmake index 61d5ed3..78442ee 100644 --- a/cmake/dlt_version.h.cmake +++ b/cmake/dlt_version.h.cmake @@ -18,10 +18,10 @@ #define __DLT_VERSION_H_ #define _DLT_PACKAGE_VERSION_STATE "@DLT_VERSION_STATE@" -#define _DLT_PACKAGE_VERSION "@DLT_VERSION@" -#define _DLT_PACKAGE_MAJOR_VERSION "@DLT_MAJOR_VERSION@" -#define _DLT_PACKAGE_MINOR_VERSION "@DLT_MINOR_VERSION@" -#define _DLT_PACKAGE_PATCH_LEVEL "@DLT_PATCH_LEVEL@" +#define _DLT_PACKAGE_VERSION "@PROJECT_VERSION@" +#define _DLT_PACKAGE_MAJOR_VERSION "@PROJECT_VERSION_MAJOR@" +#define _DLT_PACKAGE_MINOR_VERSION "@PROJECT_VERSION_MINOR@" +#define _DLT_PACKAGE_PATCH_LEVEL "@PROJECT_VERSION_PATCH@" #define _DLT_PACKAGE_REVISION "@DLT_REVISION@" #ifdef DLT_SYSTEMD_ENABLE diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index db9160c..53b3949 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,3 @@ -# Setup testing -enable_testing() - #add_compile_options(-g -fsanitize=address) add_compile_options(-isystem ${gtest_SOURCE_DIR}/include) @@ -20,29 +17,51 @@ if(WITH_SYSTEMD OR WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD_JOURNAL) endif() add_executable(gtest_dlt_common gtest_dlt_common.cpp) +target_link_libraries(gtest_dlt_common ${DLT_LIBRARIES}) +add_test(NAME gtest_dlt_common + COMMAND gtest_dlt_common + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_executable(gtest_dlt_user gtest_dlt_user.cpp) +target_link_libraries(gtest_dlt_user ${DLT_LIBRARIES}) +add_test(NAME gtest_dlt_user + COMMAND gtest_dlt_user + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_executable(gtest_dlt_daemon_common gtest_dlt_daemon_common.cpp ../src/daemon/dlt_daemon_common.c) +target_link_libraries(gtest_dlt_daemon_common ${DLT_LIBRARIES}) +add_test(NAME gtest_dlt_daemon_common + COMMAND gtest_dlt_daemon_common + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_executable(dlt_test_receiver dlt_test_receiver.c) +target_link_libraries(dlt_test_receiver dlt) + add_executable(dlt_env_ll_unit_test dlt_env_ll_unit_test.cpp) +target_link_libraries(dlt_env_ll_unit_test ${DLT_LIBRARIES}) +add_test(NAME dlt_env_ll_unit_test + COMMAND gtest_dlt_common + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_executable(dlt-test-preregister-context dlt-test-preregister-context.c) +target_link_libraries(dlt-test-preregister-context ${DLT_LIBRARIES}) + add_executable(gtest_dlt_daemon_gateway gtest_dlt_daemon_gateway.cpp ${systemd_SRCS}) +target_link_libraries(gtest_dlt_daemon_gateway ${DLT_DAEMON_LIBRARIES}) + add_executable(gtest_dlt_daemon_event_handler gtest_dlt_daemon_event_handler.cpp ${systemd_SRCS}) +target_link_libraries(gtest_dlt_daemon_event_handler ${DLT_DAEMON_LIBRARIES}) +add_test(NAME gtest_dlt_daemon_event_handler + COMMAND gtest_dlt_daemon_event_handler + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + add_executable(gtest_dlt_daemon_offline_log gtest_dlt_daemon_offline_log.cpp ${systemd_SRCS}) +target_link_libraries(gtest_dlt_daemon_offline_log ${DLT_DAEMON_LIBRARIES}) if(WITH_DLT_SHM_ENABLE) add_executable(gtest_dlt_shm gtest_dlt_shm.cpp) endif(WITH_DLT_SHM_ENABLE) -target_link_libraries(gtest_dlt_common ${DLT_LIBRARIES}) -target_link_libraries(gtest_dlt_user ${DLT_LIBRARIES}) -target_link_libraries(gtest_dlt_daemon_common ${DLT_LIBRARIES}) -target_link_libraries(dlt_test_receiver dlt) -target_link_libraries(dlt_env_ll_unit_test ${DLT_LIBRARIES}) -target_link_libraries(dlt-test-preregister-context ${DLT_LIBRARIES}) -target_link_libraries(gtest_dlt_daemon_gateway ${DLT_DAEMON_LIBRARIES}) -target_link_libraries(gtest_dlt_daemon_event_handler ${DLT_DAEMON_LIBRARIES}) -target_link_libraries(gtest_dlt_daemon_offline_log ${DLT_DAEMON_LIBRARIES}) - if(WITH_DLT_SHM_ENABLE) target_link_libraries(gtest_dlt_shm ${DLT_DAEMON_LIBRARIES}) endif(WITH_DLT_SHM_ENABLE) diff --git a/util/create_dlt_version_h.py b/util/create_dlt_version_h.py index 2b685b7..767c789 100755 --- a/util/create_dlt_version_h.py +++ b/util/create_dlt_version_h.py @@ -53,6 +53,13 @@ def main(cmake_file, header_in_file, header_out_file): else: undetermined_vars[key] = val + m = re.match('project\(\s+ VERSION (?P\d+)\.(?P\d+)\.(?P\d+)\(.(?P\d+))?', src) + if m: + determined_vars['PROJECT_VERSION_MAJOR'] = m.group('major') + determined_vars['PROJECT_VERSION_MINOR'] = m.group('minor') + determined_vars['PROJECT_VERSION_PATCH'] = m.group('patch') + determined_vars['PROJECT_VERSION_TWEAK'] = m.groupdict.get('tweak', '') + # Try to resolve all variables referencing other vars e.g.: # set(DLT_VERSION ${DLT_MAJOR_VERSION}.${DLT_MINOR_VERSION}.${DLT_PATCH_LEVEL}) no_changes = 5 -- cgit v1.2.1