Skip to content

Latest commit

 

History

History
84 lines (68 loc) · 3.76 KB

EXAMPLE.md

File metadata and controls

84 lines (68 loc) · 3.76 KB

Overview

The following is a step by step walk through showcasing bluebox in order to test code against different Linux kernel versions.

Required software

In this example the following software is used.

Get pre-compiled Linux kernel

To get all pre-compiled Linux kernels from the cilium/ci-kernels repository docker buildx is required.

$ mkdir /tmp/ci-kernel
$ echo "FROM ghcr.io/cilium/ci-kernels:4.9" | docker buildx build --quiet --pull --output="/tmp/ci-kernel" -

Prepare testing code

This walk through will test the Linux netlink API using tests from the Go package mdlayher/netlink. In a first step get the code:

$ cd /tmp
$ git clone --depth 1 https://github.com/mdlayher/netlink.git

Then build a statically linked executable from the included tests in this repository.

$ cd /tmp/netlink
$ go test -ldflags='-extldflags=-static' -trimpath -tags 'osusergo netgo static_build linux' -c

Create the initramfs.cpio with bluebox

Create an archive that can be used as initial ramdisk and embedd the statically linked executable.

$ cd /tmp
$ bluebox -e /tmp/netlink/netlink.test:"-test.v"

As argument -test.v is passed to netlink.test once this binary is executed.

Run the tests in a virtual machine

The shown qemu-system-x86_64 command will start the pre-compiled Linux kernel from cilium/ci-kernels and use the archive that was genereated by bluebox as initial ramdisk.

$ qemu-system-x86_64 -nographic -append "console=ttyS0" -m 4G -kernel /tmp/ci-kernel/boot/vmlinuz -initrd /tmp/initramfs.cpio

[...]

[            ]	./netlink.test exited, exit status 1
[            ] stdout
=== RUN   Test_nlmsgAlign
=== RUN   Test_nlmsgAlign/0
=== RUN   Test_nlmsgAlign/1
=== RUN   Test_nlmsgAlign/2
=== RUN   Test_nlmsgAlign/3
=== RUN   Test_nlmsgAlign/4
=== RUN   Test_nlmsgAlign/5
=== RUN   Test_nlmsgAlign/6
=== RUN   Test_nlmsgAlign/7
=== RUN   Test_nlmsgAlign/8
--- PASS: Test_nlmsgAlign (0.00s)
    --- PASS: Test_nlmsgAlign/0 (0.00s)
    --- PASS: Test_nlmsgAlign/1 (0.00s)
    --- PASS: Test_nlmsgAlign/2 (0.00s)
    --- PASS: Test_nlmsgAlign/3 (0.00s)

[...]

=== RUN   TestIntegrationConnSetBuffersSyscallConn/privileged
    conn_linux_integration_test.go:897: $ ip [tuntap add nlprobe0 mode tun]
    conn_linux_integration_test.go:897: failed to start command "ip": exec: "ip": executable file not found in $PATH
=== RUN   ExampleAttributeDecoder_decode
--- PASS: ExampleAttributeDecoder_decode (0.00s)
=== RUN   ExampleAttributeEncoder_encode
--- PASS: ExampleAttributeEncoder_encode (0.00s)
FAIL

bluebox creates a minimal archive that can be used as initial ramdisk. Additional executables like ip are not included. So the test TestIntegrationConnSetBuffersSyscallConn is expected to fail. Tests that interact with the netlink API of the Linux kernel without such an external dependency pass.

CI/CD

The Github Action workflow defined by example.yml in this repository showcases a multi architecture workflow, x86_64 and aarch64, of bluebox in a CI/CD setup.