Skip to content

Ryanjfield dev #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions .github/workflows/fdp_cpp_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
- name: Install Dependencies
run: |
sudo apt update
sudo apt install -y lcov libjsoncpp-dev curl libcurl4-openssl-dev libyaml-cpp-dev
sudo apt install -y lcov libjsoncpp-dev curl libcurl4-openssl-dev libyaml-cpp-dev gcovr
- name: Configure Library
run: |
cmake -Bbuild -DFDPAPI_BUILD_TESTS=ON
cmake -Bbuild -DFDPAPI_BUILD_TESTS=ON -DFDPAPI_CODE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
- name: Fetch cache
uses: actions/cache@v2.1.5
with:
Expand All @@ -60,21 +60,19 @@ jobs:
wget -nv https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
unzip -q build-wrapper-linux-x86.zip
echo "${PWD}/build-wrapper-linux-x86" >> $GITHUB_PATH
- name: Compile FDP-Cpp-API
run: build-wrapper-linux-x86-64 --out-dir bw-outputs cmake --build build
env:
CIBuild: 1
BUILD_TESTS: True
- name: Run Unit Tests
- name: Build and Run Unit Tests
run: |
cmake --build build --target test
build-wrapper-linux-x86-64 --out-dir bw-outputs cmake --build build --target coverage
if [ $? -eq 0 ]; then
echo "Unit tests completed successfully"
exit 0
else
echo "Unit tests failed"
exit 1
fi
env:
CIBuild: 1
BUILD_TESTS: True
- name: SonarCloud Scan
run: |
sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -X
Expand Down
63 changes: 18 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ ELSE()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release")
ENDIF()

IF( FDPAPI_CODE_COVERAGE )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 --coverage")
message("CXX Flags: ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
ENDIF()

# Define Project
PROJECT( fdpapi
VERSION 0.1.0
Expand Down Expand Up @@ -76,49 +82,16 @@ ENDIF()

# Compile Code Coverage if Specified with Tests
IF( FDPAPI_CODE_COVERAGE AND FDPAPI_BUILD_TESTS )
MESSAGE( STATUS "[Coverage]")
SET( COVERAGE_COMPILER_FLAGS "--coverage -fprofile-arcs -ftest-coverage" )
SET( CMAKE_CXX_FLAGS "-std=gnu++17 -O0 -Wall -Wextra -Werror ${COVERAGE_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}" )
SET( CMAKE_C_FLAGS "-O0 -Wall -Wextra ${COVERAGE_COMPILER_FLAGS} ${CMAKE_C_FLAGS}" )
MESSAGE( "\t CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}" )
MESSAGE( "\t CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}" )


find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl)
find_program( GCOV_PATH gcov )

set(LCOV_EXCLUDES "build/*" "/usr*")

add_custom_target(coverage

# Cleanup lcov
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -directory . -b ${PROJECT_SOURCE_DIR} --zerocounters

# Create baseline to make sure untouched files show up in the report
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -c -i -d . -b ${PROJECT_SOURCE_DIR} -o ${FDPAPI}.base

# Run executables
COMMAND ${CMAKE_BINARY_DIR}/test/${FDPAPI}-tests ${COV_TEST_FLAGS}

# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} --directory . -b ${PROJECT_SOURCE_DIR} --capture --output-file ${FDPAPI}.capture

# add baseline counters
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} -a ${FDPAPI}.base -a ${FDPAPI}.capture --output-file ${FDPAPI}.total

# filter collected data to final coverage report and merge outputs
COMMAND ${LCOV_PATH} --gcov-tool ${GCOV_PATH} --remove ${FDPAPI}.total ${LCOV_EXCLUDES} --output-file ${FDPAPI}.info

# Set output files as GENERATED (will be removed on 'make clean')
BYPRODUCTS
${FDPAPI}.base
${FDPAPI}.capture
${FDPAPI}.total
${FDPAPI}.info
${FDPAPI} # report directory

WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
VERBATIM # Protect arguments to commands
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
if(CMAKE_COMPILER_IS_GNUCXX)
LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules")
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()

#set(COVERAGE_EXCLUDES 'build/*' 'usr/*')
#set(Coverage_BASE_DIRECTORY ${CMAKE_SOURCE_DIR})
setup_target_for_coverage_gcovr_sonar(NAME coverage
EXECUTABLE bin/${FDPAPI}-tests
DEPENDENCIES ${FDPAPI}-tests
BASE_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()
ENDIF()
Loading