From da53941cba5f9ca309d13dfeeaad89b465111cd2 Mon Sep 17 00:00:00 2001 From: Lukas-Heiligenbrunner <30468956+Lukas-Heiligenbrunner@users.noreply.github.com> Date: Tue, 19 May 2020 16:35:57 +0200 Subject: [PATCH 1/8] enable and start iprefresher service automatically after package installation (#18) - dont terminate service if config not valid. --- CMakeLists.txt | 6 ++++-- src/IPRefresher.cpp | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70dc0b8..5e1953f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,8 +226,10 @@ if (${PACKAGING}) if [ ! -f ${CONFIG_PATH} ]; then cat > ${CONFIG_PATH} <<- EOM ${SAMPLECONFIG}EOM -fi\n" - ) +fi + +systemctl enable iprefresher.service +systemctl start iprefresher.service") SET(CPACK_DEB_COMPONENT_INSTALL 1) diff --git a/src/IPRefresher.cpp b/src/IPRefresher.cpp index 3dbcf0f..092b577 100644 --- a/src/IPRefresher.cpp +++ b/src/IPRefresher.cpp @@ -54,14 +54,15 @@ IPRefresher::IPRefresher(bool loop) { if (loop) { Logger::message("startup of service"); Logger::message("Version: " + Version::VERSION); - if (Config::readConfig()) { - while (true) { - Logger::message("starting check"); + + while (true) { + Logger::message("starting check"); + if (Config::readConfig()) { checkIPAdress(false); - std::this_thread::sleep_for(std::chrono::milliseconds(300000)); + } else { + std::cout << "incorrect credentials!" << std::endl; } - } else { - std::cout << "incorrect credentials!" << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(300000)); } } } From fb65ef98fa5e1399cfaa49f914b34d7cff206fde Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 19 May 2020 20:58:18 +0200 Subject: [PATCH 2/8] new gitlab ci for windows build cmake- check if gtest is installed on build system validate compiler after setting of compiler paths --- .gitlab-ci.yml | 84 +++++++++++++++++++++++++++++++++++++++++--------- CMakeLists.txt | 84 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 119 insertions(+), 49 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4524b1c..6cb35d0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,49 +1,103 @@ -image: luki42/dynuiprefresher_build:latest - stages: - cmake - build - - build_package - - test - -cache: - paths: - - build/ - - src/ - - inc/ - - tests/ - - postinst + - post +# Unix Build cmake: stage: cmake + image: luki42/dynuiprefresher_build:latest script: - cmake -S . -B build + cache: + paths: + - build/ + - inc/ + - postinst build: stage: build + image: luki42/dynuiprefresher_build:latest script: - cd build - make artifacts: paths: - "build/bin/*" + cache: + paths: + - build/ + - inc/ + - postinst build_package: - stage: build_package + stage: post + image: luki42/dynuiprefresher_build:latest script: - cd build - make package artifacts: paths: - "build/packages/*" + cache: + paths: + - build/ + - inc/ + - postinst test: - stage: test + stage: post + image: luki42/dynuiprefresher_build:latest script: - cd build - make test - make build-xml artifacts: reports: - junit: build/report.xml \ No newline at end of file + junit: build/report.xml + cache: + paths: + - build/ + - inc/ + - postinst + +# Windows Build +cmake_win64: + stage: cmake + image: luki42/dynuiprefresher_build:windows + script: + - cmake -S . -B build -D WinBuild=ON + cache: + paths: + - build/ + - inc/ + +build_win64: + stage: build + image: luki42/dynuiprefresher_build:windows + script: + - cd build + - make iprefresher + artifacts: + paths: + - "build/bin/*" + cache: + paths: + - build/ + - inc/ + + +build_package_win64: + stage: post + image: luki42/dynuiprefresher_build:windows + script: + - cd build + - make package + artifacts: + paths: + - "build/packages/*" + cache: + paths: + - build/ + - inc/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e1953f..4d341ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ # for test build gtest needs to be installed. cmake_minimum_required(VERSION 3.13) -project(iprefresher DESCRIPTION "Dynu ip refresher") +project(iprefresher DESCRIPTION "Dynu ip refresher" LANGUAGES) SET(PROJECT_VERSION 1.3.3) # CONFIGURATION @@ -19,7 +19,7 @@ SET(LIB_METHOD STATIC) #SHARED / STATIC option(BUILD_DOC "Build documentation" ON) # additional dependency for Doxygen option(PACKAGING "Allow Packaging to , or " ON) # additional dependencies for RPMbuild,dpkg or NSIS option(TESTS "Build Tests" ON) # additional dependencies for GTEST - to build tests -set(WinBuild false) +option(WinBuild "cross compile for Windows Platform" OFF) # helper variables SET(CMAKE_CXX_STANDARD 17) @@ -31,6 +31,7 @@ SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # setup winbuild compilers if (${WinBuild}) + message(STATUS "setup Mingw Toolchain for cross compile.") set(LIBSUFFIX .dll) set(SUFFIX .exe) @@ -40,9 +41,9 @@ if (${WinBuild}) #set(TOOLCHAIN_PREFIX i686-w64-mingw32) # cross compilers to use for C and C++ - set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) - set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) - set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + set(CMAKE_C_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-gcc) + set(CMAKE_CXX_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-g++) + set(CMAKE_RC_COMPILER /usr/bin/${TOOLCHAIN_PREFIX}-windres) # target environment on the build host system set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) @@ -67,6 +68,7 @@ if (${WinBuild}) # windows config path is same as executable set(CONFIG_PATH "./iprefresher.cfg") else () + message(STATUS "using nativ gcc toolchain.") set(LIBSUFFIX .so) set(SUFFIX "") @@ -74,8 +76,16 @@ else () set(CONFIG_PATH "/etc/iprefresher.cfg") endif () +# test compiler settings and enable languages here +message("") +message(STATUS "Testing the C++ compiler!") +enable_language(CXX) +message("") +message(STATUS "Testing the C compiler!") +enable_language(C) # config libs +message("") message(STATUS "Config of Libraries") # libcurl if (${WinBuild}) @@ -313,39 +323,45 @@ endif (BUILD_DOC) # Test Cases if (TESTS) - include(GoogleTest) + # include(GoogleTest) + message(STATUS "Configuring GTEST") + find_package(GTest) + if (GTEST_FOUND) - mark_as_advanced( - BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS - gmock_build_tests gtest_build_samples gtest_build_tests - gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols - ) + mark_as_advanced( + BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS + gmock_build_tests gtest_build_samples gtest_build_tests + gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols + ) - enable_testing() + enable_testing() - macro(package_add_test TESTNAME) - # create an exectuable in which the tests will be stored - add_executable(${TESTNAME} ${ARGN}) - # link the Google test infrastructure, mocking library, and a default main fuction to - target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES}) - # see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it - gtest_discover_tests(${TESTNAME} - WORKING_DIRECTORY ${PROJECT_DIR} - EXTRA_ARGS --gtest_output=xml:report.xml -VV - PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}" - ) - set_target_properties(${TESTNAME} PROPERTIES FOLDER tests) - endmacro() + macro(package_add_test TESTNAME) + # create an exectuable in which the tests will be stored + add_executable(${TESTNAME} ${ARGN}) + # link the Google test infrastructure, mocking library, and a default main fuction to + target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES}) + # see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it + gtest_discover_tests(${TESTNAME} + WORKING_DIRECTORY ${PROJECT_DIR} + EXTRA_ARGS --gtest_output=xml:report.xml -VV + PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}" + ) + set_target_properties(${TESTNAME} PROPERTIES FOLDER tests) + endmacro() - package_add_test(test1 tests/UnitTest.cpp ${SOURCE}) + package_add_test(test1 tests/UnitTest.cpp ${SOURCE}) - add_custom_target(build-test - "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target test - DEPENDS ${PROJECT_NAME} - COMMENT "Packing ${PROJECT_NAME}") + add_custom_target(build-test + "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target test1 test + DEPENDS ${PROJECT_NAME} + COMMENT "Packing ${PROJECT_NAME}") - add_custom_target(build-xml - "bin/test1" --gtest_output="xml:report.xml" - DEPENDS ${PROJECT_NAME} - COMMENT "Packing ${PROJECT_NAME}") + add_custom_target(build-xml + "bin/test1" --gtest_output="xml:report.xml" + DEPENDS ${PROJECT_NAME} + COMMENT "Packing ${PROJECT_NAME}") + else () + message(STATUS "GTEST environment not found!") + endif () ENDIF () \ No newline at end of file From 5271a25cbc5d5c6966f419a257d66d54ffed52ff Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 19 May 2020 21:13:53 +0200 Subject: [PATCH 3/8] use artifacts instead of cache --- .gitlab-ci.yml | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6cb35d0..b95c1da 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ cmake: image: luki42/dynuiprefresher_build:latest script: - cmake -S . -B build - cache: + artifacts: paths: - build/ - inc/ @@ -22,9 +22,6 @@ build: - cd build - make artifacts: - paths: - - "build/bin/*" - cache: paths: - build/ - inc/ @@ -38,9 +35,6 @@ build_package: - cd build - make package artifacts: - paths: - - "build/packages/*" - cache: paths: - build/ - inc/ @@ -56,7 +50,6 @@ test: artifacts: reports: junit: build/report.xml - cache: paths: - build/ - inc/ @@ -68,7 +61,7 @@ cmake_win64: image: luki42/dynuiprefresher_build:windows script: - cmake -S . -B build -D WinBuild=ON - cache: + artifacts: paths: - build/ - inc/ @@ -80,9 +73,6 @@ build_win64: - cd build - make iprefresher artifacts: - paths: - - "build/bin/*" - cache: paths: - build/ - inc/ @@ -95,9 +85,6 @@ build_package_win64: - cd build - make package artifacts: - paths: - - "build/packages/*" - cache: paths: - build/ - inc/ \ No newline at end of file From 1239ae015a08c08cd582d436e1c49c5d35d13497 Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 19 May 2020 21:29:36 +0200 Subject: [PATCH 4/8] right ci camke dependencies for win and unix build --- .gitlab-ci.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b95c1da..9025908 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,12 +20,14 @@ build: image: luki42/dynuiprefresher_build:latest script: - cd build - - make + - make iprefresher artifacts: paths: - build/ - inc/ - postinst + dependencies: + - cmake build_package: @@ -39,6 +41,8 @@ build_package: - build/ - inc/ - postinst + dependencies: + - build test: stage: post @@ -54,6 +58,8 @@ test: - build/ - inc/ - postinst + dependencies: + - build # Windows Build cmake_win64: @@ -76,6 +82,8 @@ build_win64: paths: - build/ - inc/ + dependencies: + - cmake_win64 build_package_win64: @@ -87,4 +95,6 @@ build_package_win64: artifacts: paths: - build/ - - inc/ \ No newline at end of file + - inc/ + dependencies: + - build_win64 \ No newline at end of file From ede1afcce3fb7d7d04e0a8cf06aef7820dd9ef9c Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 19 May 2020 21:50:43 +0200 Subject: [PATCH 5/8] correct build dependencies for unit test --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9025908..c461647 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,7 +49,7 @@ test: image: luki42/dynuiprefresher_build:latest script: - cd build - - make test + - make build-test - make build-xml artifacts: reports: From d8c3d4ffb82f177bf24004f24c98baea0b0862da Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 19 May 2020 23:57:16 +0200 Subject: [PATCH 6/8] correct build of gtests in one target with xml output --- .gitlab-ci.yml | 5 ----- CMakeLists.txt | 8 ++------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c461647..089c8ab 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -50,14 +50,9 @@ test: script: - cd build - make build-test - - make build-xml artifacts: reports: junit: build/report.xml - paths: - - build/ - - inc/ - - postinst dependencies: - build diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d341ab..ed2a914 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -353,12 +353,8 @@ if (TESTS) package_add_test(test1 tests/UnitTest.cpp ${SOURCE}) add_custom_target(build-test - "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target test1 test - DEPENDS ${PROJECT_NAME} - COMMENT "Packing ${PROJECT_NAME}") - - add_custom_target(build-xml - "bin/test1" --gtest_output="xml:report.xml" + "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target test1 + COMMAND ctest --force-new-ctest-process --gtest_output="xml:report.xml" DEPENDS ${PROJECT_NAME} COMMENT "Packing ${PROJECT_NAME}") else () From 998f3ea5e818baba9fef74e5c4d55ccd114d202a Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 20 May 2020 19:25:37 +0200 Subject: [PATCH 7/8] right xml export of unit test cases for test target --- .gitlab-ci.yml | 2 +- CMakeLists.txt | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 089c8ab..b2e2c5b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,7 +52,7 @@ test: - make build-test artifacts: reports: - junit: build/report.xml + junit: build/*.xml dependencies: - build diff --git a/CMakeLists.txt b/CMakeLists.txt index ed2a914..5a428cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -343,20 +343,23 @@ if (TESTS) target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES}) # see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it gtest_discover_tests(${TESTNAME} - WORKING_DIRECTORY ${PROJECT_DIR} - EXTRA_ARGS --gtest_output=xml:report.xml -VV - PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}" + TEST_PREFIX new: + EXTRA_ARGS --gtest_output=xml + XML_OUTPUT_DIR diri ) - set_target_properties(${TESTNAME} PROPERTIES FOLDER tests) + + add_custom_command(TARGET build-test + POST_BUILD + COMMAND "bin/${item}" --gtest_output=xml:${item}-test-report.xml) endmacro() + add_custom_target(build-test + "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target ${testTargets} + DEPENDS ${PROJECT_NAME} + COMMENT "Testing ${PROJECT_NAME}") + package_add_test(test1 tests/UnitTest.cpp ${SOURCE}) - add_custom_target(build-test - "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target test1 - COMMAND ctest --force-new-ctest-process --gtest_output="xml:report.xml" - DEPENDS ${PROJECT_NAME} - COMMENT "Packing ${PROJECT_NAME}") else () message(STATUS "GTEST environment not found!") endif () From 8199fc2c1e2dc3a081027ef1ec81e50924181c87 Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 20 May 2020 19:37:39 +0200 Subject: [PATCH 8/8] correct build of test targets correct upload of report.xml --- CMakeLists.txt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a428cc..d9ea427 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,19 +342,15 @@ if (TESTS) # link the Google test infrastructure, mocking library, and a default main fuction to target_link_libraries(${TESTNAME} gtest gtest_main -lpthread -lm dynuiprefresher api ${CURL_LIBRARIES} ${LIBCONFIG++_LIBRARIES}) # see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it - gtest_discover_tests(${TESTNAME} - TEST_PREFIX new: - EXTRA_ARGS --gtest_output=xml - XML_OUTPUT_DIR diri - ) + gtest_discover_tests(${TESTNAME}) add_custom_command(TARGET build-test POST_BUILD - COMMAND "bin/${item}" --gtest_output=xml:${item}-test-report.xml) + COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target ${TESTNAME} + COMMAND "bin/${TESTNAME}" --gtest_output=xml:${TESTNAME}-report.xml) endmacro() add_custom_target(build-test - "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --target ${testTargets} DEPENDS ${PROJECT_NAME} COMMENT "Testing ${PROJECT_NAME}")