Skip to content

Commit

Permalink
replace virtme with vimto
Browse files Browse the repository at this point in the history
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 <oss@lmb.io>
Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
  • Loading branch information
lmb committed Feb 2, 2024
1 parent 26ffbad commit 764b078
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 181 deletions.
39 changes: 29 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:

env:
TMPDIR: /tmp
CI_MAX_KERNEL_VERSION: '6.6'
CI_MIN_CLANG_VERSION: '11'
CGO_ENABLED: '0'
go_version: '~1.21'
prev_go_version: '~1.20'
# This needs to match whatever Netlify supports.
Expand Down Expand Up @@ -108,7 +108,16 @@ jobs:
runs-on: ubuntu-latest-4cores-16gb
needs: build-and-lint
timeout-minutes: 10
env:
CI_KERNEL_SELFTESTS: '/usr/src/linux/tools/testing/selftests/bpf'
steps:
- name: Set up Go 1.21
uses: actions/setup-go@v4
with:
go-version: '~1.21'

- run: go install lmb.io/vimto@latest

- uses: actions/checkout@v3

- name: Set up Go
Expand All @@ -117,14 +126,14 @@ jobs:
go-version: '${{ env.prev_go_version }}'

- run: go install gotest.tools/gotestsum@v1.8.1
- run: sudo pip3 install https://github.com/amluto/virtme/archive/beb85146cd91de37ae455eccb6ab67c393e6e290.zip
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-system-x86
- run: sudo chmod 0666 /dev/kvm

- name: Test
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- ./run-tests.sh $CI_MAX_KERNEL_VERSION -short -count 1 -json ./...
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- go test -exec vimto -vm.kernel ghcr.io/cilium/ci-kernels:stable-selftests -short -count 1 -json ./...

- name: Benchmark
run: go test -exec sudo -short -run '^$' -bench . -benchtime=1x ./...
run: go test -exec vimto -vm.kernel ghcr.io/cilium/ci-kernels:stable-selftests -short -run '^$' -bench . -benchtime=1x ./...

- name: Upload Test Results
if: always()
Expand All @@ -144,7 +153,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '${{ env.prev_go_version }}'
go-version: '${{ env.go_version }}'

- run: go install gotest.tools/gotestsum@v1.8.1

Expand Down Expand Up @@ -173,23 +182,33 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
version: ["6.7", "6.1", "5.15", "5.10", "5.4", "4.19", "4.14", "4.9"]
tag:
- "stable"
- "6.6"
- "6.1"
- "5.15"
- "5.10"
- "5.4"
- "4.19"
- "4.14"
- "4.9"
env:
KERNEL_VERSION: "${{ matrix.version }}"
CI_MAX_KERNEL_VERSION: '6.6'
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '${{ env.prev_go_version }}'
go-version: '${{ env.go_version }}'

- run: go install gotest.tools/gotestsum@v1.8.1
- run: sudo pip3 install https://github.com/amluto/virtme/archive/beb85146cd91de37ae455eccb6ab67c393e6e290.zip
- run: go install lmb.io/vimto@latest
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-system-x86
- run: sudo chmod 0666 /dev/kvm

- name: Test
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- ./run-tests.sh $KERNEL_VERSION -short -count 1 -json ./...
run: gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml -- go test -exec vimto -vm.kernel ghcr.io/cilium/ci-kernels:${{ matrix.tag }} -short -count 1 -json ./...

- name: Upload Test Results
if: always()
Expand Down
12 changes: 12 additions & 0 deletions .vimto.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kernel="ghcr.io/cilium/ci-kernels:stable"
smp="cpus=1,maxcpus=2"
memory="768M"
user="root"
setup=[
"mount -t cgroup2 -o nosuid,noexec,nodev cgroup2 /sys/fs/cgroup",
"/bin/sh -c '! modprobe bpf_testmod'",
"dmesg --clear",
]
teardown=[
"dmesg --read-clear",
]
26 changes: 10 additions & 16 deletions docs/ebpf/contributing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,25 @@ a better understanding of the high-level goals.
Many of the tests require privileges to set resource limits and load eBPF code.
The easiest way to obtain these is to run the tests with `sudo`.

To test the current package with your local kernel you can simply run:
```
go test -exec sudo ./...
```

To test the current package with a different kernel version you can use the [run-tests.sh] script.
It requires [virtme], qemu and docker to be installed.
Unfortunately virtme is not well maintained at the moment, so we recommend installing
a known working version:
Run all tests with the following command:

```shell-session
pip3 install https://github.com/amluto/virtme/archive/beb85146cd91de37ae455eccb6ab67c393e6e290.zip
go test -exec sudo ./...
```

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

```shell-session
./run-tests.sh 5.4
go test -exec vimto ./...
```

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


```shell-session
./run-tests.sh 5.4 -run TCX ./link
go test -exec vimto -vm.kernel ghcr.io/cilium/ci-kernels:mainline ./...
```

## Regenerating testdata and source code
Expand Down Expand Up @@ -87,8 +82,7 @@ you as a code owner. Please create an issue in the repository.
* Have ["Admin"][permissions] role
* CODEOWNERS of last resort

[virtme]: https://github.com/amluto/virtme
[run-tests.sh]: https://github.com/cilium/ebpf/blob/main/run-tests.sh
[vimto]: https://github.com/lmb/vimto
[permissions]: https://docs.github.com/en/organizations/managing-user-access-to-your-organizations-repositories/repository-roles-for-an-organization#permissions-for-each-role
[ebpf-go-contributors]: https://github.com/orgs/cilium/teams/ebpf-go-contributors/members
[ebpf-go-reviewers]: https://github.com/orgs/cilium/teams/ebpf-go-reviewers/members
Expand Down
2 changes: 1 addition & 1 deletion elf_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ func TestIPRoute2Compat(t *testing.T) {
}

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

Expand Down
2 changes: 1 addition & 1 deletion internal/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestCurrentKernelVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if evStr := os.Getenv("KERNEL_VERSION"); evStr != "" {
if evStr := os.Getenv("CI_KERNEL_VERSION"); evStr != "" {
ev, err := NewVersion(evStr)
if err != nil {
t.Fatal(err)
Expand Down
153 changes: 0 additions & 153 deletions run-tests.sh

This file was deleted.

0 comments on commit 764b078

Please sign in to comment.