ci: enable coverge for unit and integration

This commit is contained in:
Zxilly 2025-09-11 10:43:07 +08:00
parent 4711e06805
commit 44abda9cdc
2 changed files with 41 additions and 82 deletions

View File

@ -56,95 +56,22 @@ jobs:
cmake --build build
./build/ua2f_test
test-coverage:
name: Run coverage tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install dependencies
- name: Generate unit test coverage
run: |
sudo apt-get update
sudo apt-get install -y cmake libnetfilter-queue-dev libmnl-dev libnetfilter-conntrack-dev libjson-c-dev lcov
- name: Build and install libubox
working-directory: /tmp
run: |
git clone https://github.com/openwrt/libubox.git
cd libubox
mkdir build
cd build
cmake .. -DBUILD_LUA=OFF -DBUILD_EXAMPLES=OFF
make
sudo make install
- name: Build and install libuci
working-directory: /tmp
run: |
git clone https://github.com/openwrt/uci.git
cd uci
mkdir build
cd build
cmake .. -DBUILD_LUA=OFF
make
sudo make install
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install Python requirements
run: |
pip install -r scripts/requirements.txt --break-system-packages
- name: Enable ipv6
uses: fscarmen/warp-on-actions@v1.3
with:
stack: dual
mode: client
- name: Configure ipv6
run: |
echo "net.ipv6.conf.all.disable_ipv6=0" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6=0" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.lo.disable_ipv6=0" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
- name: Debug IPv6
run: |
ip -6 addr
ping6 -c 4 ::1 || { echo "::1 is not reachable"; exit 1; }
- name: Generate comprehensive coverage report
run: |
cmake -S . -B build-coverage -DUA2F_BUILD_TESTS=ON -DUA2F_ENABLE_COVERAGE=ON -DUA2F_ENABLE_UCI=OFF
cmake -S . -B build-coverage -DUA2F_BUILD_TESTS=ON
cmake --build build-coverage
cd build-coverage
make coverage-combined
sudo ./ua2f --version
sudo -E $(which python3) ../scripts/test.py ./ua2f
make coverage-merge
make coverage
- name: Upload comprehensive coverage to Codecov
- name: Upload unit test coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: build-coverage/coverage_combined_filtered.info
fail_ci_if_error: true
files: build-coverage/coverage_filtered.info
flags: unittests
fail_ci_if_error: false
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage report artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: build-coverage/coverage_combined_html/
test-standalone:
name: Run unit tests without uci support
runs-on: ubuntu-latest
@ -217,6 +144,32 @@ jobs:
sudo ./build/ua2f --version
sudo -E $(which python3) scripts/test.py ./build/ua2f
- name: Generate integration test coverage
run: |
# Build with coverage enabled for integration testing
cmake -S . -B build-coverage -DUA2F_BUILD_TESTS=ON -DUA2F_ENABLE_UCI=OFF ${{ matrix.cache }}
cmake --build build-coverage
cd build-coverage
# Run unit tests and prepare for integration coverage
make coverage-combined
# Run integration tests with coverage-enabled binary
sudo ./ua2f --version
sudo -E $(which python3) ../scripts/test.py ./ua2f
# Merge coverage data
make coverage-merge
- name: Upload integration test coverage to Codecov
if: matrix.cache == '-DUA2F_NO_CACHE=OFF' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: codecov/codecov-action@v4
with:
file: build-coverage/coverage_combined_filtered.info
flags: integration
fail_ci_if_error: false
verbose: true
- name: Upload log
uses: actions/upload-artifact@v4
with:
@ -228,7 +181,6 @@ jobs:
runs-on: ubuntu-latest
needs:
- test
- test-coverage
- test-standalone
- test-integration
strategy:

View File

@ -6,7 +6,14 @@ set(CMAKE_C_STANDARD 17)
cmake_policy(SET CMP0135 NEW)
OPTION(UA2F_BUILD_TESTS "Build tests" OFF)
OPTION(UA2F_ENABLE_COVERAGE "Enable code coverage" OFF)
if(DEFINED ENV{CI} AND UA2F_BUILD_TESTS AND NOT DEFINED UA2F_ENABLE_COVERAGE)
set(UA2F_ENABLE_COVERAGE ON CACHE BOOL "Enable code coverage (auto-enabled in CI)" FORCE)
message(STATUS "Auto-enabling coverage in CI environment")
else()
OPTION(UA2F_ENABLE_COVERAGE "Enable code coverage" OFF)
endif()
OPTION(UA2F_ENABLE_UCI "Enable UCI support" ON)
OPTION(UA2F_NO_CACHE "Disable cache" OFF)
OPTION(UA2F_ENABLE_BACKTRACE "Enable libbacktrace support" ON)