From 21c56c6ca37b7c08b4d3c9b81bc2780a807730ec Mon Sep 17 00:00:00 2001 From: Marcin Niestroj Date: Thu, 26 Sep 2024 20:46:26 +0200 Subject: [PATCH 1/3] ci: split lint and unit_tests Both are not related to each other and they should be split into separate jobs. Signed-off-by: Marcin Niestroj --- .github/workflows/lint_build_unit_test.yml | 79 ++++++++++++---------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/.github/workflows/lint_build_unit_test.yml b/.github/workflows/lint_build_unit_test.yml index 0e2717252..87c784d8a 100644 --- a/.github/workflows/lint_build_unit_test.yml +++ b/.github/workflows/lint_build_unit_test.yml @@ -6,44 +6,51 @@ on: pull_request: jobs: - lint_and_unit_test: + lint: runs-on: ubuntu-latest + steps: - - name: Checkout repository and submodules - uses: actions/checkout@v4 - with: - submodules: 'recursive' - # Fetch depth must be greater than the number of commits included in the push in order to - # compare against commit prior to merge. 15 is chosen as a reasonable default for the upper - # bound of commits in a single PR. - fetch-depth: 15 - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: 3.x - architecture: 'x64' - - name: Install clang-format - shell: bash - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 17 - sudo apt install clang-format-17 - - name: Check code formatting - shell: bash - run: | - git fetch --no-recurse-submodules - if [[ $GITHUB_EVENT_NAME == 'push' ]]; then - BASE=${{ github.event.before }} - else - BASE=origin/$GITHUB_BASE_REF - fi - git clang-format-17 --verbose --extensions c,h --diff --diffstat $BASE - - name: Run unit tests - shell: bash - run: | - cd tests/unit_tests - ./test.sh + - name: Checkout repository and submodules + uses: actions/checkout@v4 + with: + # Fetch depth must be greater than the number of commits included in the push in order to + # compare against commit prior to merge. 15 is chosen as a reasonable default for the upper + # bound of commits in a single PR. + fetch-depth: 15 + + - name: Install clang-format + shell: bash + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 17 + sudo apt install clang-format-17 + + - name: Check code formatting + shell: bash + run: | + git fetch --no-recurse-submodules + if [[ $GITHUB_EVENT_NAME == 'push' ]]; then + BASE=${{ github.event.before }} + else + BASE=origin/$GITHUB_BASE_REF + fi + git clang-format-17 --verbose --extensions c,h --diff --diffstat $BASE + + unit_tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Run unit tests + shell: bash + run: | + cd tests/unit_tests + ./test.sh linux_build: runs-on: ubuntu-latest From 43a8772ee690a274171014f224ae5bd267b91288 Mon Sep 17 00:00:00 2001 From: Marcin Niestroj Date: Thu, 26 Sep 2024 20:55:50 +0200 Subject: [PATCH 2/3] ci: unit_tests: run unit tests directly with 'ctest' tests/unit_tests/test.sh is very verbose, while it is possible to do most of it with single command. Use Ninja generator to build using multiple threads automatically. Signed-off-by: Marcin Niestroj --- .github/workflows/lint_build_unit_test.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint_build_unit_test.yml b/.github/workflows/lint_build_unit_test.yml index 87c784d8a..2b3af32b4 100644 --- a/.github/workflows/lint_build_unit_test.yml +++ b/.github/workflows/lint_build_unit_test.yml @@ -46,11 +46,18 @@ jobs: with: submodules: 'recursive' + - name: Install ninja + run: | + sudo apt install -y ninja-build + - name: Run unit tests - shell: bash run: | - cd tests/unit_tests - ./test.sh + ctest --build-and-test tests/unit_tests build \ + --build-generator Ninja \ + --test-command \ + ctest \ + --output-on-failure \ + --timeout 2 linux_build: runs-on: ubuntu-latest From b82b42a2696973742f1d1c0cb9e86eca9ab1d717 Mon Sep 17 00:00:00 2001 From: Marcin Niestroj Date: Thu, 26 Sep 2024 21:18:47 +0200 Subject: [PATCH 3/3] ci: unit_tests: collect coverage Install both gcovr and ninja from pypi, so a single tool (pip) is used. Signed-off-by: Marcin Niestroj --- .github/workflows/lint_build_unit_test.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint_build_unit_test.yml b/.github/workflows/lint_build_unit_test.yml index 2b3af32b4..e31f92d50 100644 --- a/.github/workflows/lint_build_unit_test.yml +++ b/.github/workflows/lint_build_unit_test.yml @@ -46,9 +46,9 @@ jobs: with: submodules: 'recursive' - - name: Install ninja + - name: Install gcovr and ninja run: | - sudo apt install -y ninja-build + pip install gcovr ninja - name: Run unit tests run: | @@ -59,6 +59,21 @@ jobs: --output-on-failure \ --timeout 2 + - name: Coverage + run: | + gcovr \ + --gcov-ignore-parse-errors=negative_hits.warn_once_per_file \ + --merge-mode-functions=separate \ + --json coverage.json \ + build + + - name: Upload test coverage artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: unit-test-coverage + path: coverage.json + linux_build: runs-on: ubuntu-latest steps: