From d2a0a1f3507fb878630983bac2b18eb8761fd03d Mon Sep 17 00:00:00 2001 From: Raffaello Bertini Date: Tue, 12 May 2020 16:08:29 +0100 Subject: [PATCH] [azure-pipeline] test integration --- CMakeLists.txt | 1 + appveyor.yml | 27 ++++++-- azure-pipelines/templates/ci-steps.yml | 13 +++- azure-pipelines/templates/sonarcloud-job.yml | 28 ++++++++- azure-pipelines/variables/build_switches.yml | 1 + azure-pipelines/win-gcc.yml | 1 + sdl2-vga-terminal/CMakeLists.txt | 65 ++++++++++---------- 7 files changed, 92 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbb18f1d..8fb89673 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ include(CPack) option(BUILD_SHARED_LIBS "build shared libs with C inteface" ON) option(BUILD_EXAMPLES "build examples" ON) include(CTest) +option(ENABLE_CODECOVERAGE "compile Debug with code coverage" OFF) option(BUILD_SNAPSHOT "build snapshot test" OFF) include(CMakeDependentOption) CMAKE_DEPENDENT_OPTION(TEST_DUMP_SNAPSHOT "build test to dump the expected output instead of verifing it" OFF diff --git a/appveyor.yml b/appveyor.yml index ac65772f..edf69029 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,8 +5,8 @@ branches: skip_branch_with_pr: false image: - - Visual Studio 2019 - - Ubuntu + #- Visual Studio 2019 + #- Ubuntu - macOS platform: @@ -19,6 +19,7 @@ configuration: environment: VCPKG_SCRIPT: scripts/buildsystems/vcpkg.cmake + ENABLE_CODE_COVERAGE: OFF matrix: allow_failures: @@ -46,17 +47,31 @@ for: environment: WS: /Users/appveyor/projects TRIPLET: $PLATFORM-osx + ENABLE_CODE_COVERAGE: ON cache: #- $WS/vcpkg - $WS/vcpkg/installed init: - sh: if [ $PLATFORM = "x86" ]; then exit 1; fi - - sh: brew install p7zip + - sh: brew install p7zip lcov - sh: cd $WS && git clone https://github.com/Microsoft/vcpkg.git - sh: cd $APPVEYOR_BUILD_FOLDER + # /Library/Developer/CommandLineTools/usr/bin/llvm-cov + #- sh: sudo find / -name llvm-cov 2> /dev/null + #- sh: llvm-cov --help test_script: - sh: ctest -V - + - sh: cd out + - sh: find . -name *.gcda + - sh: echo '#!/bin/bash' > g.sh + - sh: echo 'exec /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov gcov "$@"' >> g.sh + - sh: chmod +x g.sh + - sh: ./g.sh -f -b -u $(find . -name *.gcda) + - sh: lcov --directory . --base-directory . --gcov-tool ./g.sh --capture -o cov.info + - sh: lcov --remove cov.info '/usr/*' --output-file coverage.info + - sh: lcov --list coverage.info + - sh: bash <(curl -s https://codecov.io/bash) -t b8f07100-6985-49f7-aa4c-14e36f29ac80 + - sh: cd .. skip_commits: files: @@ -90,8 +105,8 @@ before_build: build_script: - mkdir out - cd out - - cmd: cmake -G "Ninja" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DWITH_SDL2_STATIC=OFF -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/%VCPKG_SCRIPT% .. - - sh : cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION -DWITH_SDL2_STATIC=ON -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=$WS/vcpkg/$VCPKG_SCRIPT .. + - cmd: cmake -G "Ninja" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DWITH_SDL2_STATIC=OFF -DBUILD_SNAPSHOT=OFF -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/%VCPKG_SCRIPT% .. + - sh : cmake -DCMAKE_BUILD_TYPE=$CONFIGURATION -DWITH_SDL2_STATIC=ON -DBUILD_SNAPSHOT=OFF -DENABLE_CODE_COVERAGE=$ENABLE_CODE_COVERAGE -DCMAKE_TOOLCHAIN_FILE=$WS/vcpkg/$VCPKG_SCRIPT .. - cmake --build . test_script: diff --git a/azure-pipelines/templates/ci-steps.yml b/azure-pipelines/templates/ci-steps.yml index 45687eda..c8d4b8c9 100644 --- a/azure-pipelines/templates/ci-steps.yml +++ b/azure-pipelines/templates/ci-steps.yml @@ -64,9 +64,20 @@ steps: arch: ${{ parameters.arch }} #build_wrapper: - ${{ if eq(parameters.test, true) }}: - - script: ctest -C ${{ parameters.build_type }} -V + - script: ctest -C ${{ parameters.build_type }} -v -V -T Test displayName: cmake test (ctest) workingDirectory: build + - task: PublishTestResults@2 + inputs: + testResultsFormat: 'cTest' # Options: JUnit, NUnit, VSTest, xUnit, cTest + testResultsFiles: '**/Test.xml' + searchFolder: build # Optional + #mergeTestResults: false # Optional + #failTaskOnFailedTests: false # Optional + #testRunTitle: # Optional + #buildPlatform: # Optional + #buildConfiguration: # Optional + #publishRunAttachments: true # Optional - ${{ if eq(parameters.install, true) }}: - script: cmake --build . --target install diff --git a/azure-pipelines/templates/sonarcloud-job.yml b/azure-pipelines/templates/sonarcloud-job.yml index b50799bd..b0511da9 100644 --- a/azure-pipelines/templates/sonarcloud-job.yml +++ b/azure-pipelines/templates/sonarcloud-job.yml @@ -128,12 +128,34 @@ jobs: build_wrapper: "${{ parameters.build_wrapper }} --out-dir bw-output" - ${{ if eq(parameters.test, true) }}: - - script: ctest -C ${{ parameters.build_type }} -V - displayName: cmake test (ctest) + - script: ctest -C ${{ parameters.build_type }} + displayName: ctest workingDirectory: build - - bash: llvm-cov gcov -f -b -u $(find . -name *.gcda) + # /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov + - bash: | + echo '#!/bin/bash' > g.sh + echo 'exec /usr/local/Cellar/llvm/10.0.0_3/bin/llvm-cov gcov "$@"' >> g.sh + chmod +x g.sh + displayName: llvm-cov gcov wrapper + workingDirectory: build + condition: ne(variables['Agent.OS'], 'Windows_NT') + + #- bash: sudo find / -name llvm-cov 2> /dev/null + # displayName: llvm-cov DEBUG + # condition: ne(variables['Agent.OS'], 'Windows_NT') + - bash: | + echo $OSTYPE + #test $OSTYPE = "Darwin" && brew install lcov || echo "not implemented" + brew install lcov + find . -name *.gcda + ./g.sh -f -b -u $(find . -name *.gcda) + lcov --directory . --base-directory . --gcov-tool ./g.sh --capture -o cov.info + lcov --remove cov.info '/usr/*' --output-file coverage.info + lcov --list coverage.info + bash <(curl -s https://codecov.io/bash) -t b8f07100-6985-49f7-aa4c-14e36f29ac80 displayName: collect coverage data workingDirectory: build + condition: ne(variables['Agent.OS'], 'Windows_NT') - task: SonarCloudAnalyze@1 - task: SonarCloudPublish@1 inputs: diff --git a/azure-pipelines/variables/build_switches.yml b/azure-pipelines/variables/build_switches.yml index a7db19d7..49888b70 100644 --- a/azure-pipelines/variables/build_switches.yml +++ b/azure-pipelines/variables/build_switches.yml @@ -4,3 +4,4 @@ variables: BUILD_SHARED_LIBS: ON BUILD_EXAMPLES: ON BUILD_SNAPSHOT: OFF + ENABLE_CODE_COVERAGE: OFF diff --git a/azure-pipelines/win-gcc.yml b/azure-pipelines/win-gcc.yml index b5da9620..befea922 100644 --- a/azure-pipelines/win-gcc.yml +++ b/azure-pipelines/win-gcc.yml @@ -55,6 +55,7 @@ stages: variables: BUILD_EXAMPLES: OFF BUILD_SHARED_LIBS: OFF + ENABLE_CODE_COVERAGE: ON jobs: # - template: 'templates/sonarcloud-job.yml' # parameters: diff --git a/sdl2-vga-terminal/CMakeLists.txt b/sdl2-vga-terminal/CMakeLists.txt index c2524dbc..5d178470 100644 --- a/sdl2-vga-terminal/CMakeLists.txt +++ b/sdl2-vga-terminal/CMakeLists.txt @@ -153,28 +153,35 @@ endif() if(CMAKE_CXX_COMPILER_ID MATCHES "^MSVC") # @see https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=vs-2019 - target_compile_options(vga-terminal-static PUBLIC /W4 /WX + target_compile_options(vga-terminal-static PRIVATE /W4 #/WX $<$:/Od /GR /GS /Gs /guard:cf /RTC1c /D_ALLOW_RTCc_IN_STL> $<$:/O2 /Ot /GA /GL /Gw> ) - #if (BUILD_SHARED_LIBS) - # target_compile_options(vga-terminal PRIVATE /W4 /WX - # $<$:/Od /GR /GS /Gs /guard:cf /RTC1c /D_ALLOW_RTCc_IN_STL> - # $<$:/O2 /Ot /GA /GL /Gw> - # ) - #endif() + if (BUILD_SHARED_LIBS) + target_compile_options(vga-terminal PRIVATE /W4 #/WX + $<$:/Od /GR /GS /Gs /guard:cf /RTC1c /D_ALLOW_RTCc_IN_STL> + $<$:/O2 /Ot /GA /GL /Gw> + ) + endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES "^GNU") - target_compile_options(vga-terminal-static PUBLIC -Wall -Wextra -pedantic -fPIC + target_compile_options(vga-terminal-static PRIVATE -Wall -Wextra -pedantic -fPIC $<$: -O0;-D_GLIBCXX_DEBUG;-D_GLIBCXX_ASSERTIONS;-fexceptions; -W; -Wshadow; -Wunused-variable; -Wunused-parameter; -Wunused-function; -Wunused; -Wno-system-headers; - -Wno-deprecated; -Woverloaded-virtual; -Wwrite-strings; -fprofile-arcs; -ftest-coverage; + -Wno-deprecated; -Woverloaded-virtual; -Wwrite-strings; > #$<$:-O2;-fexceptions;-fstack-clash-protection;-D_FORTIFY_SOURCE=2> $<$:-O2;-fexceptions;-D_FORTIFY_SOURCE=2> ) #-Werror) - target_link_options(vga-terminal-static INTERFACE $<$:-fprofile-arcs; -ftest-coverage; --coverage;>) + + if (ENABLE_CODE_COVERAGE) + target_compile_options(vga-terminal-static PRIVATE + $<$: -fprofile-arcs; -ftest-coverage;> + ) + target_link_options(vga-terminal-static PRIVATE $<$:-fprofile-arcs; -ftest-coverage; --coverage;>) + endif() + #if (BUILD_SHARED_LIBS) # target_compile_options(vga-terminal INTERAFCE # $<$: @@ -190,36 +197,26 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "^GNU") elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang") target_compile_options(vga-terminal-static PRIVATE -WCL4 -Wabstract-vbase-init -Wassign-enum - -Watomic-implicit-seq-cst -Watomic-properties -Wbad-function-cast -Wbinary-literal - -fPIC - $<$: - -g; - > - $<$: - -O2; - > - ) #-Weverything #-Werror - - - ### This if Clang is shipped with VS2019 CE + -Watomic-implicit-seq-cst -Watomic-properties -Wbad-function-cast -Wbinary-literal + ) + if (WIN32) set(LINK_SUBSYS_WIN /subsystem:windows) message(STATUS ${LINK_SUBSYS_WIN}) - target_link_options(vga-terminal-static INTERFACE ${LINK_SUBSYS_WIN}) + target_link_options(vga-terminal-static PUBLIC ${LINK_SUBSYS_WIN}) elseif(UNIX) - #target_compile_options(vga-terminal-static PUBLIC -fprofile-instr-generate -fcoverage-mapping) - target_compile_options(vga-terminal-static INTERFACE - $<$: - #-flto; -fsanitize=address; -fsanitize=thread; -fsanitize=memory; -fsanitize=undefined; -fsanitize=dataflow; - #-fsanitize=cfi; -fsanitize=safe-stack; - #-fprofile-instr-generate; -fcoverage-mapping; - -c -ftest-coverage; - > - $<$: - > + target_compile_options(vga-terminal-static PRIVATE -fPIC + $<$: -g;> + $<$:-O2;> ) + + if(ENABLE_CODE_COVERAGE) + target_compile_options(vga-terminal-static PRIVATE + $<$:-c -ftest-coverage;> + ) + target_link_options(vga-terminal-static PUBLIC $<$: -ftest-coverage; --coverage;>) #target_link_options(vga-terminal-static PUBLIC $<$: -fprofile-instr-generate; -fcoverage-mapping;>) - target_link_options(vga-terminal-static INTERFACE $<$: -ftest-coverage; --coverage;>) + endif() else() message(ERROR "Unknown OS") endif()