Skip to content

Commit

Permalink
chg: dev: reset coverage workflow using ubuntu 22 and clang/llvm
Browse files Browse the repository at this point in the history
* add some cmake help to fine versioned llvm-cov tools
* swap out autotools build for ctest in smoke workflow

Signed-off-by: Stephen L Arnold <[email protected]>
  • Loading branch information
sarnold committed Mar 1, 2025
1 parent e48219b commit 3270351
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 41 deletions.
32 changes: 18 additions & 14 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
jobs:
pre_ci:
name: Prepare CI environment
runs-on: ubuntu-24.04
runs-on: ubuntu-22.04
permissions:
# only required for workflows in private repositories
actions: read
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
base:
name: Base coverage
runs-on: ubuntu-24.04
runs-on: ubuntu-22.04
permissions:
# only required for workflows in private repositories
actions: read
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
check:
name: Pre CI check
runs-on: ubuntu-24.04
runs-on: ubuntu-22.04
permissions:
# only required for workflows in private repositories
actions: read
Expand All @@ -130,7 +130,7 @@ jobs:
cov_data:
name: Generate test coverage data
runs-on: ubuntu-24.04
runs-on: ubuntu-22.04
permissions:
# only required for workflows in private repositories
actions: read
Expand All @@ -144,6 +144,7 @@ jobs:
coverage: ${{ steps.coverage.outputs.coverage }}
coverage-rounded-display: ${{ steps.coverage.outputs.coverage-rounded-display }}
env:
ENV_LLVM_VER: '14'
PYTHONIOENCODING: utf-8
PIP_DOWNLOAD_CACHE: ${{ github.workspace }}/../.pip_download_cache

Expand Down Expand Up @@ -181,23 +182,26 @@ jobs:
run: |
sudo apt-get -qq update
sudo apt-get install -yqq software-properties-common redis-server
sudo add-apt-repository -y -s ppa:nerdboy/embedded
sudo add-apt-repository -y -s ppa:ubuntu-toolchain-r/ppa
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
sudo apt-get -qq update
sudo apt-get install -yqq libjson-c-dev libhiredis-dev libgtest-dev libgmock-dev lcov
sudo apt-get install -yqq libjson-c-dev libhiredis-dev libgtest-dev libgmock-dev
sudo systemctl stop redis
sudo apt-get install -y g++-13 g++-13-multilib
echo "CC=gcc-13" >> $GITHUB_ENV
echo "CXX=g++-13" >> $GITHUB_ENV
sudo apt-get install -y clang-${{ env.ENV_LLVM_VER }} llvm-${{ env.ENV_LLVM_VER }} lld-${{ env.ENV_LLVM_VER }} g++-multilib
echo "CC=clang-${{ env.ENV_LLVM_VER }}" >> $GITHUB_ENV
echo "CXX=clang++-${{ env.ENV_LLVM_VER }}" >> $GITHUB_ENV
- name: Add python requirements
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tests
env:
CC: ${{ env.CC }}
CXX: ${{ env.CXX }}
ENV_LLVM_VER: ${{ env.ENV_LLVM_VER }}
run: |
tox -e tests,cover
tox -e clang,lcov
- uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -246,7 +250,7 @@ jobs:

test:
name: Coverage check
runs-on: ubuntu-24.04
runs-on: ubuntu-22.04
needs: [cov_data, base]
permissions:
# required for workflows in private repositories
Expand All @@ -272,7 +276,7 @@ jobs:
comment_cov_change:
name: Comment on PR with coverage delta
runs-on: ubuntu-24.04
runs-on: ubuntu-22.04
needs: [test, base]
permissions:
pull-requests: write
Expand Down Expand Up @@ -355,7 +359,7 @@ jobs:
# - This is a pull request event and the pull actor is the same as the repo owner
# if: ${{ ( github.event_name == 'pull_request' && github.actor == github.repository_owner ) || github.ref == 'refs/heads/master' }}
name: Generate badge image with test coverage value
runs-on: ubuntu-24.04
runs-on: ubuntu-22.04
permissions:
pull-requests: write
# required for workflows in private repositories
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
- os: 'ubuntu-24.04'
compiler: gcc
version: "13"
test_cmd: 'auto'
test_cmd: 'ctest'
- os: 'ubuntu-22.04'
compiler: clang
version: "13"
version: "14"
test_cmd: 'clang'

steps:
Expand Down Expand Up @@ -57,9 +57,10 @@ jobs:
echo "CC=gcc-${{ matrix.version }}" >> $GITHUB_ENV
echo "CXX=g++-${{ matrix.version }}" >> $GITHUB_ENV
else
sudo apt-get install -y clang-${{ matrix.version }} llvm-${{ matrix.version }} lld-${{ matrix.version }} g++-multilib
sudo apt-get install -y clang-${{ matrix.version }} llvm-${{ matrix.version }} lld-${{ matrix.version }}
echo "CC=clang-${{ matrix.version }}" >> $GITHUB_ENV
echo "CXX=clang++-${{ matrix.version }}" >> $GITHUB_ENV
echo "ENV_LLVM_VER=${{ matrix.version }}" >> $GITHUB_ENV
fi
- name: Add python requirements
Expand All @@ -71,6 +72,7 @@ jobs:
env:
CC: ${{ env.CC }}
CXX: ${{ env.CXX }}
ENV_LLVM_VER: "${{ env.ENV_LLVM_VER }}"
run: |
tox -e "${{ matrix.test_cmd }}"
Expand Down
85 changes: 85 additions & 0 deletions cmake/FindLLVMCov.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright 2020-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# CMake find_package() module for llvm-cov.
#
# Example usage:
#
# find_package(LLVMCov)
#
# If successful, the following variables will be defined:
# LLVMCov_EXE- The path to llvm-cov executable
# LLVMCov_FOUND
# LLVMCov_VERSION

# Check if a LLVM_TOOLS_HOME envvar is defined. If so, then search specifically
# in that path or else search in default locations. The check is to allow
# a particular LLVM_COV executable to be used when there are multiple LLVM_COV
# versions installed in the system.

if(DEFINED ENV{LLVM_TOOLS_HOME})
find_program(LLVMCov_EXE
llvm-cov
PATHS $ENV{LLVM_TOOLS_HOME}
NO_DEFAULT_PATH
)
if(${LLVMCov_EXE} STREQUAL "LLVMCov_EXE-NOTFOUND")
message(WARN
"$ENV{LLVM_TOOLS_HOME} does not have an llvm-cov executable"
)
endif()
else()
find_program(LLVMCov_EXE llvm-cov)
endif()

if(NOT ${LLVMCov_EXE} STREQUAL "LLVMCov_EXE-NOTFOUND")
# get the version of llvm-cov
execute_process(
COMMAND ${LLVMCov_EXE} "--version"
RESULT_VARIABLE result
OUTPUT_VARIABLE version_string
)
# If llvm-cov is found then set the package variables
if(${result} MATCHES "0")
string(REPLACE "\n" ";" VERSION_LIST "${version_string}")
list(GET VERSION_LIST 1 ver_line)
# Extract the llvm-cov version
string(REGEX MATCH "[0-9]+\.[0-9]+\.[0-9]+" LLVMCov_VERSION ${ver_line})
# Split out the version into major, minor an patch
string(REPLACE "." ";" VERSION_LIST1 "${LLVMCov_VERSION}")
list(GET VERSION_LIST1 0 LLVMCov_VERSION_MAJOR)
list(GET VERSION_LIST1 1 LLVMCov_VERSION_MINOR)
list(GET VERSION_LIST1 2 LLVMCov_VERSION_PATCH)
endif()
# Check if a specific version of llvm-cov is required.
if(LLVMCov_FIND_VERSION AND (DEFINED LLVMCov_VERSION))
string(COMPARE LESS_EQUAL
${LLVMCov_FIND_VERSION_MAJOR}
${LLVMCov_VERSION_MAJOR}
VERSION_MATCH
)
if(VERSION_MATCH)
set(LLVMCov_FOUND TRUE)
endif()
else()
set(LLVMCov_FOUND TRUE)
endif()
message(STATUS "llvm-cov ${LLVMCov_VERSION} found at ${LLVMCov_EXE}.")
endif()

find_package_handle_standard_args(LLVMCov DEFAULT_MSG
LLVMCov_EXE
LLVMCov_FOUND
LLVMCov_VERSION
)
42 changes: 42 additions & 0 deletions cmake/FindLLVMProfdata.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2020-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# CMake find_package() module for llvm-cov.
#
# Example usage:
#
# find_package(LLVMCov)
#
# If successful, the following variables will be defined:
# LLVMProfdata_EXE The path to llvm-cov executable
# LLVMProfdata_FOUND

if(DEFINED ENV{LLVM_TOOLS_HOME})
find_program(LLVMProfdata_EXE
llvm-profdata
PATHS $ENV{LLVM_TOOLS_HOME}
NO_DEFAULT_PATH
)
if(${LLVMProfdata_EXE} STREQUAL "LLVMProfdata_EXE-NOTFOUND")
message(WARN
"$ENV{LLVM_TOOLS_HOME} does not have an llvm-profdata executable"
)
endif()
else()
find_program(LLVMProfdata_EXE llvm-profdata)
endif()

find_package_handle_standard_args(LLVMProfdata DEFAULT_MSG
LLVMProfdata_EXE
)
31 changes: 7 additions & 24 deletions cmake/coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,11 @@ if(COVERAGE_BUILD)
"Source coverage is enabled. TEXT=${COVERAGE_TEXT}, LCOV=${COVERAGE_LCOV}, HTML=${COVERAGE_HTML}"
)

find_package(LLVM REQUIRED CONFIG)
get_filename_component(LLVM_PREFIX "${LLVM_DIR}" DIRECTORY)
message(STATUS "Found llvm directory: ${LLVM_PREFIX}")
find_package(LLVMCov ${ENV_LLVM_VER} REQUIRED)
find_package(LLVMProfdata REQUIRED)

find_program(
LLVM_COV_PATH
NAMES llvm-cov
HINTS ${LLVM_PREFIX}
PATH_SUFFIXES bin
)
find_program(
LLVM_PROFDATA_PATH
NAMES llvm-profdata
HINTS ${LLVM_PREFIX}
PATH_SUFFIXES bin
)

if(LLVM_COV_PATH AND LLVM_PROFDATA_PATH)
if(NOT ${LLVMCov_EXE} STREQUAL "LLVMCov_EXE-NOTFOUND" AND NOT ${LLVMProfdata_EXE} STREQUAL "LLVMProfdata_EXE-NOTFOUND")
set(RIPC_HAVE_LLVM_COVERAGE_TOOLS TRUE)

message(STATUS "Found llvm-cov: ${LLVM_COV_PATH}")
message(STATUS "Found llvm-profdata: ${LLVM_PROFDATA_PATH}")
else()
message(FATAL_ERROR "llvm-cov stack required for coverage!")
endif()
Expand Down Expand Up @@ -68,7 +51,7 @@ function(add_coverage TARGET)
${CMAKE_COMMAND} -E env
LLVM_PROFILE_FILE="${COVERAGE_PATH}/test_%p.profraw"
${CMAKE_CTEST_COMMAND} ${CMAKE_CTEST_ARGUMENTS}
COMMAND ${LLVM_PROFDATA_PATH} merge -sparse
COMMAND ${LLVMProfdata_EXE} merge -sparse
${COVERAGE_PATH}/*.profraw -o ${COVERAGE_PROFDATA}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
Expand All @@ -79,7 +62,7 @@ function(add_coverage TARGET)
add_custom_target(
coverage-text
COMMAND
${LLVM_COV_PATH} report `cat ${COVERAGE_TARGETS}`
${LLVMCov_EXE} report `cat ${COVERAGE_TARGETS}`
-instr-profile=${COVERAGE_PROFDATA}
-ignore-filename-regex="${COVERAGE_EXCLUDE_REGEX}"
DEPENDS coverage-profdata
Expand All @@ -91,7 +74,7 @@ function(add_coverage TARGET)
add_custom_target(
coverage-html
COMMAND
${LLVM_COV_PATH} show `cat ${COVERAGE_TARGETS}`
${LLVMCov_EXE} show `cat ${COVERAGE_TARGETS}`
-instr-profile=${COVERAGE_PROFDATA}
-show-line-counts-or-regions
-output-dir=${COVERAGE_PATH}/html -format="html"
Expand All @@ -105,7 +88,7 @@ function(add_coverage TARGET)
add_custom_target(
coverage-lcov
COMMAND
${LLVM_COV_PATH} export `cat ${COVERAGE_TARGETS}`
${LLVMCov_EXE} export `cat ${COVERAGE_TARGETS}`
-format="lcov" -instr-profile=${COVERAGE_PROFDATA}
-ignore-filename-regex="${COVERAGE_EXCLUDE_REGEX}" >
${COVERAGE_PATH}/lcov.info
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ passenv =
setenv =
clang: CC = {env:CC:clang}
clang: CXX = {env:CXX:clang++}
clang: ENV_LLVM_VER = {env:ENV_LLVM_VER:19}
bionic: ENV_RIPC_RUNTIME_DIR = {env:ENV_RIPC_RUNTIME_DIR:{envtmpdir}}

allowlist_externals =
Expand Down

0 comments on commit 3270351

Please sign in to comment.