Skip to content
Merged
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
74 changes: 74 additions & 0 deletions .github/workflows/c-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Reusable C unit tests

on:
workflow_call:
inputs:
additional-apt-packages:
description: 'Additional APT packages to install'
required: false
type: string
default: ''
library-directory:
description: 'Directory to find the C library'
required: true
type: string

jobs:
c-tests:
name: C unit tests
runs-on: ubuntu-24.04

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.13.0
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v6.0.2
with:
submodules: true

- name: Install dev tools
run: |
sudo apt-get update
sudo apt-get install -y libcunit1-dev libconfig-dev \
ninja-build valgrind clang meson gcovr ${{ inputs.additional-apt-packages }}

- name: Configure code
working-directory: {{ inputs.library-directory }}
run: meson setup build-cov -Db_coverage=true

- name: Compile
working-directory: {{ inputs.library-directory }}
run: ninja -C build-cov

- name: Run tests
working-directory: {{ inputs.library-directory }}
run: ninja -C build-cov test

- name: Build coverage report
working-directory: {{ inputs.library-directory }}
run: ninja -C build-cov coverage-xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5.4.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: C
directory: {{ inputs.library-directory }}
gcov_args: --preserve-paths
fail_ci_if_error: true

- name: Compile and test with clang
working-directory: {{ inputs.library-directory }}
run: |
CC=clang meson setup build-clang
meson test -C build-clang

- name: Run tests with valgrind
working-directory: {{ inputs.library-directory }}
run: |
meson setup build-valgrind
meson test -C build-valgrind -t-1 \
--wrapper='valgrind --leak-check=full --error-exitcode=1'