Skip to content

Commit

Permalink
Testing gcov and lcov on Linux runner
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanzou committed Feb 19, 2025
1 parent 8e31c5d commit 1ea7366
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 246 deletions.
246 changes: 0 additions & 246 deletions .github/workflows/ci.yml

This file was deleted.

92 changes: 92 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CI

on:
push:
pull_request:

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
GTEST_REF: b85864c64758dec007208e56af933fc3f52044ee

jobs:
build-on-ubuntu:
runs-on: ubuntu-latest

steps:
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: '3.24.x'
- name: Test cmake version
run: cmake --version

- name: Set relative paths
run: |
GTEST=$GITHUB_WORKSPACE/googletest
echo "GTEST=$GTEST" >> $GITHUB_ENV
SSCDIR=$GITHUB_WORKSPACE/ssc
echo "SSCDIR=$SSCDIR" >> $GITHUB_ENV
- name: Get cached GTest
uses: actions/cache@v4
id: cachedgtest
with:
path: ${{env.GTEST}}/
key: gtest-ubuntu

- name: Clone Gtest
if: steps.cachedgtest.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: google/googletest
path: googletest
ref: ${{env.GTEST_REF}}

- name: build Gtest
if: steps.cachedgtest.outputs.cache-hit != 'true'
run: |
export
mkdir ${GTEST}/build
cd ${GTEST}/build
cmake -DCMAKE_CXX_FLAGS=-std=c++11 ..
make
- name: Checkout SSC
uses: actions/checkout@v4
with:
path: ssc

- name: Configure CMake
# Configure cmake to build ssc tests but not tools
run: |
mkdir ${SSCDIR}/build
cd ${SSCDIR}/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DSAM_SKIP_TOOLS=1
- name: Build
# Build your program with the given configuration
run: |
cd ${SSCDIR}/build
make -j4
- name: Test
# Turn off fast fail for when the landbosse tests write to cerr
shell: bash
run: |
set -e
${SSCDIR}/build/test/Test
- name: Coverage
working-directory: ${{runner.workspace}}/build
shell: bash
run: make coverage

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: SSC Linux Shared Libraries
path: |
${{env.SSCDIR}}/build/ssc/libssc.so
${{env.SSCDIR}}/build/ssc/ssc.so
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ function(set_default_compile_options target)
if (SAMAPI_EXPORT AND APPLE)
SET(MAIN_CFLAGS "${MAIN_CFLAGS} -mmacosx-version-min=12" )
endif()

# setup for code coverage testing
if(CMAKE_BUILD_TYPE STREQUAL "Debug"
AND ENABLE_COVERAGE
AND NOT WIN32)
enable_testing()

# set compiler flags
set(CMAKE_CXX_FLAGS "-g -O0 --coverage")

# find required tools
find_program(LCOV lcov REQUIRED)
find_program(GENHTML genhtml REQUIRED)

# add coverage target
add_custom_target(
coverage
# gather data
COMMAND
${LCOV} --directory . --capture --exclude '*/external/*' --exclude
'*/tests/*' --exclude '/usr/*' --exclude '/Applications/*' --exclude
'v1/*' --output-file coverage.info --ignore-errors unused
# generate report
COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

set_target_properties(${target} PROPERTIES COMPILE_FLAGS ${MAIN_CFLAGS})
endfunction()

Expand Down

0 comments on commit 1ea7366

Please sign in to comment.