Skip to content

Commit 6f2f5a3

Browse files
committed
ci: replace virtme with vimto
vimto is a lightweight wrapper around qemu with the sole purpose of executing Go unit tests. Use it instead of virtme, which has not had a reliable upstream for a while. Signed-off-by: Lorenz Bauer <[email protected]>
1 parent e0a2f35 commit 6f2f5a3

File tree

8 files changed

+67
-209
lines changed

8 files changed

+67
-209
lines changed

.github/workflows/ci.yml

+22-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ env:
1111
CI_MIN_CLANG_VERSION: '11'
1212
go_version: '~1.22'
1313
prev_go_version: '~1.21'
14+
CGO_ENABLED: '0'
1415
# This needs to match whatever Netlify supports.
1516
# Also defined in Pipfile.
1617
python_version: '~3.8'
@@ -108,6 +109,8 @@ jobs:
108109
runs-on: ubuntu-latest-4cores-16gb
109110
needs: build-and-lint
110111
timeout-minutes: 15
112+
env:
113+
CI_KERNEL_SELFTESTS: '/usr/src/linux/tools/testing/selftests/bpf'
111114
steps:
112115
- uses: actions/checkout@v4
113116

@@ -116,15 +119,16 @@ jobs:
116119
with:
117120
go-version: '${{ env.prev_go_version }}'
118121

122+
- run: go install lmb.io/vimto@latest
119123
- run: go install gotest.tools/[email protected]
120-
- run: sudo pip3 install https://github.com/amluto/virtme/archive/beb85146cd91de37ae455eccb6ab67c393e6e290.zip
121124
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-system-x86
125+
- run: sudo chmod 0666 /dev/kvm
122126

123127
- name: Test
124-
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- ./run-tests.sh $CI_MAX_KERNEL_VERSION -short -count 1 -json ./...
128+
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- vimto -kernel :${CI_MAX_KERNEL_VERSION}-selftests -- go test -short -count 1 -json ./...
125129

126130
- name: Benchmark
127-
run: go test -exec sudo -short -run '^$' -bench . -benchtime=1x ./...
131+
run: vimto -kernel :${CI_MAX_KERNEL_VERSION}-selftests -- go test -short -run '^$' -bench . -benchtime=1x ./...
128132

129133
- name: Upload Test Results
130134
if: always()
@@ -167,15 +171,22 @@ jobs:
167171
sudo dmesg
168172
169173
vm-test:
170-
name: Run tests on pre-built kernel
174+
name: Run tests
171175
runs-on: ubuntu-latest-4cores-16gb
172176
needs: build-and-lint
173177
timeout-minutes: 15
174178
strategy:
175179
matrix:
176-
version: ["6.8", "6.6", "6.1", "5.15", "5.10", "5.4", "4.19", "4.14", "4.9"]
177-
env:
178-
KERNEL_VERSION: "${{ matrix.version }}"
180+
tag:
181+
- "6.8"
182+
- "6.6"
183+
- "6.1"
184+
- "5.15"
185+
- "5.10"
186+
- "5.4"
187+
- "4.19"
188+
- "4.14"
189+
- "4.9"
179190
steps:
180191
- uses: actions/checkout@v4
181192

@@ -185,15 +196,16 @@ jobs:
185196
go-version: '${{ env.go_version }}'
186197

187198
- run: go install gotest.tools/[email protected]
188-
- run: sudo pip3 install https://github.com/amluto/virtme/archive/beb85146cd91de37ae455eccb6ab67c393e6e290.zip
199+
- run: go install lmb.io/vimto@latest
189200
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-system-x86
201+
- run: sudo chmod 0666 /dev/kvm
190202

191203
- name: Test
192-
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- ./run-tests.sh $KERNEL_VERSION -short -count 1 -json ./...
204+
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- vimto -kernel :${{ matrix.tag }} -- go test -short -count 1 -json ./...
193205

194206
- name: Upload Test Results
195207
if: always()
196208
uses: actions/upload-artifact@v4
197209
with:
198-
name: Test Results (${{ matrix.version }})
210+
name: Test Results (${{ matrix.tag }})
199211
path: junit.xml

.vimto.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kernel="ghcr.io/cilium/ci-kernels:stable"
2+
smp="cpus=2"
3+
memory="1G"
4+
user="root"
5+
setup=[
6+
"mount -t cgroup2 -o nosuid,noexec,nodev cgroup2 /sys/fs/cgroup",
7+
"/bin/sh -c 'modprobe bpf_testmod || true'",
8+
"dmesg --clear",
9+
]
10+
teardown=[
11+
"dmesg --read-clear",
12+
]

docs/ebpf/contributing/index.md

+9-16
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,24 @@ the contents of the DCO.
2222
Many of the tests require privileges to set resource limits and load eBPF code.
2323
The easiest way to obtain these is to run the tests with `sudo`.
2424

25-
To test the current package with your local kernel you can simply run:
26-
```
27-
go test -exec sudo ./...
28-
```
29-
30-
To test the current package with a different kernel version you can use the [run-tests.sh] script.
31-
It requires [virtme], qemu and docker to be installed.
32-
Unfortunately virtme is not well maintained at the moment, so we recommend installing
33-
a known working version:
25+
Run all tests with the following command:
3426

3527
```shell-session
36-
pip3 install https://github.com/amluto/virtme/archive/beb85146cd91de37ae455eccb6ab67c393e6e290.zip
28+
go test -exec sudo ./...
3729
```
3830

39-
Once you have the dependencies you can run all tests on a different kernel:
31+
To test the current package with a different kernel version you can use [vimto].
32+
Once you have installed `vimto` and its dependencies you can run all tests on a
33+
different kernel:
4034

4135
```shell-session
42-
./run-tests.sh 5.4
36+
vimto -- go test ./...
4337
```
4438

45-
Or run a subset of tests:
39+
Use one of the [precompiled kernels](https://github.com/cilium/ci-kernels/pkgs/container/ci-kernels/versions) like so:
4640

4741
```shell-session
48-
./run-tests.sh 5.4 -run TCX ./link
42+
vimto -kernel :mainline -- go test ./...
4943
```
5044

5145
## Regenerating testdata and source code
@@ -105,8 +99,7 @@ you as a code owner. Please create an issue in the repository.
10599
* Maintain roadmap and encourage contributions towards it
106100
* Merge approved PRs
107101
108-
[virtme]: https://github.com/amluto/virtme
109-
[run-tests.sh]: https://github.com/cilium/ebpf/blob/main/run-tests.sh
102+
[vimto]: https://github.com/lmb/vimto
110103
[permissions]: https://docs.github.com/en/organizations/managing-user-access-to-your-organizations-repositories/repository-roles-for-an-organization#permissions-for-each-role
111104
[ebpf-go-contributors]: https://github.com/orgs/cilium/teams/ebpf-go-contributors/members
112105
[ebpf-go-reviewers]: https://github.com/orgs/cilium/teams/ebpf-go-reviewers/members

elf_reader_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ func TestIPRoute2Compat(t *testing.T) {
907907
}
908908

909909
var (
910-
elfPath = flag.String("elfs", os.Getenv("KERNEL_SELFTESTS"), "`Path` containing libbpf-compatible ELFs (defaults to $KERNEL_SELFTESTS)")
910+
elfPath = flag.String("elfs", os.Getenv("CI_KERNEL_SELFTESTS"), "`Path` containing libbpf-compatible ELFs (defaults to $CI_KERNEL_SELFTESTS)")
911911
elfPattern = flag.String("elf-pattern", "*.o", "Glob `pattern` for object files that should be tested")
912912
)
913913

internal/version_test.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package internal
22

33
import (
4-
"os"
54
"testing"
5+
6+
"github.com/go-quicktest/qt"
67
)
78

89
func TestVersion(t *testing.T) {
@@ -48,19 +49,8 @@ func TestKernelVersion(t *testing.T) {
4849
}
4950

5051
func TestCurrentKernelVersion(t *testing.T) {
51-
v, err := KernelVersion()
52-
if err != nil {
53-
t.Fatal(err)
54-
}
55-
if evStr := os.Getenv("KERNEL_VERSION"); evStr != "" {
56-
ev, err := NewVersion(evStr)
57-
if err != nil {
58-
t.Fatal(err)
59-
}
60-
if ev[0] != v[0] || ev[1] != v[1] {
61-
t.Errorf("expected kernel version %d.%d, got %d.%d", ev[0], ev[1], v[0], v[1])
62-
}
63-
}
52+
_, err := KernelVersion()
53+
qt.Assert(t, qt.IsNil(err))
6454
}
6555

6656
func TestVersionFromCode(t *testing.T) {

run-tests.sh

-144
This file was deleted.

testdata/sh/lib.sh

-23
This file was deleted.

testdata/sh/update-kernel-deps.sh

+19-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,25 @@
22

33
set -euo pipefail
44

5-
source "$(dirname "$(realpath "$0")")/lib.sh"
5+
readonly docker="${CONTAINER_ENGINE:-docker}"
6+
7+
extract_oci_image() {
8+
local image_name=$1
9+
local target_directory=$2
10+
11+
echo -n "Fetching $image_name... "
12+
13+
# We abuse the --output flag of docker buildx to obtain a copy of the image.
14+
# This is simpler than creating a temporary container and using docker cp.
15+
# It also automatically fetches the image for us if necessary.
16+
if ! echo "FROM $image_name" | "$docker" buildx build --quiet --pull --output="$target_directory" - &> /dev/null; then
17+
echo "failed"
18+
return 1
19+
fi
20+
21+
echo "ok"
22+
return 0
23+
}
624

725
tmp=$(mktemp -d)
826

0 commit comments

Comments
 (0)