1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
name: Run unit tests
on:
workflow_call:
inputs:
runs-on:
description: 'A tag to indicate which runner to use'
required: true
type: string
code:
description: 'Code to test (c, go)'
required: true
type: string
c-compiler:
description: 'Compiler for C code'
type: string
default: ''
required: false
gochannel:
description: 'The snap store channel to use to install the go snap'
required: false
type: string
skip-coverage:
description: 'If true, will not generate test coverage files'
type: boolean
default: false
required: false
go-build-tags:
description: 'Tag to add to go test'
type: string
required: false
go-test-race:
description: 'If true, will add race tag to go test'
type: boolean
default: false
required: false
snapd-debug:
description: 'If true, will set SNAPD_DEBUG=1'
type: boolean
default: false
required: false
jobs:
unit-tests:
runs-on: ${{ inputs.runs-on }}
env:
# Set PATH to ignore the load of magic binaries from /usr/local/bin And
# to use the go snap automatically. Note that we install go from the
# snap in a step below. Without this we get the GitHub-controlled latest
# version of go.
PATH: /snap/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${{ github.workspace }}/bin
GOROOT: ""
GO_BUILD_TAGS: ${{ inputs.go-build-tags }}
CC: ${{ inputs.c-compiler }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download and install Debian dependencies
# Github does not allow variables in "uses"; this has to be a hard-coded path
uses: ./.github/actions/download-install-debian-deps
with:
snapd-src-dir: "${{ github.workspace }}"
# golang latest ensures things work on the edge
- name: Install the go snap
if: ${{ inputs.code == 'go' }}
run: |
if [ -z "${{ inputs.gochannel }}" ]; then
echo "gochannel is unset"
exit 1
fi
sudo snap install --classic --channel=${{ inputs.gochannel }} go
- name: Get deps
if: ${{ inputs.code == 'go' }}
run: |
./get-deps.sh
- name: Build C
if: ${{ inputs.code == 'c' }}
run: |
if [ -z "${{ inputs.c-compiler }}" ]; then
echo "c-compiler is unset"
exit 1
fi
cd cmd/
./autogen.sh
make -j$(nproc)
make clean
- name: Build Go
if: ${{ inputs.code == 'go' }}
run: |
go build ./...
- name: Test C (distcheck)
if: ${{ inputs.code == 'c' }}
run: |
cd cmd/ && make distcheck
- name: Test C (check & ASan & UBsan)
if: ${{ inputs.code == 'c' }}
run: |
cd cmd/
./autogen.sh --enable-sanitize
make -j$(nproc)
make check
make clean
- name: Set SNAPD_DEBUG=1
if: ${{ inputs.snapd-debug }}
run: echo "SNAPD_DEBUG=1" >> $GITHUB_ENV
- name: Set GO_TEST_RACE=1
if: ${{ inputs.go-test-race }}
run: echo "GO_TEST_RACE=1" >> $GITHUB_ENV
- name: Set SKIP_COVERAGE=1
if: ${{ inputs.skip-coverage }}
run: echo "SKIP_COVERAGE=1" >> $GITHUB_ENV
- name: Test C (check & coverage)
if: ${{ inputs.code == 'c' }}
run: |
HAVE_GCOV=/usr/bin/gcov
if [ "$CC" = 'clang' ]; then
# gcovr can normally guess this, but in our setup things need to
# be explicit
HAVE_GCOV='/usr/bin/llvm-cov-18 gcov'
fi
cd cmd/
HAVE_GCOV="$HAVE_GCOV" ./autogen.sh --enable-test-coverage
if [ -n "$SKIP_COVERAGE" ]; then
make check
else
make coverage.lcov
mkdir -p "${{ github.workspace }}/.coverage"
cp coverage.lcov "${{ github.workspace }}/.coverage/coverage-c-code-gcovr-$CC.lcov"
make clean
fi
- name: Test Go
if: ${{ inputs.code == 'go' }}
run: |
./run-checks --unit
- name: Create coverage results name
if: ${{ ! inputs.skip-coverage }}
run: |
converted=$(tr '/' '-' <<<'${{ inputs.gochannel }}')
name="coverage-files-${{ inputs.code }}-${converted}-${{ inputs.go-build-tags || 'notags' }}${{ inputs.go-test-race && '-race' || ''}}${{ inputs.snapd-debug && '-snapddebug' || ''}}${{ inputs.c-compiler }}"
echo "COVERAGE_NAME=$name" >> $GITHUB_ENV
- name: Upload the coverage results
if: ${{ ! inputs.skip-coverage }}
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "${{ env.COVERAGE_NAME }}"
path: "${{ github.workspace }}/.coverage/coverage*"
|