Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ebpf test runner #208

Merged
merged 36 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8159c9e
init commit
fearful-symmetry Sep 18, 2024
0d8811d
move around files
fearful-symmetry Sep 19, 2024
8826ef0
go code done
fearful-symmetry Sep 20, 2024
5a7db2b
modify makefile, refactor reader
fearful-symmetry Sep 20, 2024
ee746d7
final cleanup
fearful-symmetry Sep 20, 2024
60d1e8d
cleanup, format
fearful-symmetry Sep 20, 2024
0b585d7
try newer go version?
fearful-symmetry Sep 20, 2024
b6ac236
try different compile args?
fearful-symmetry Sep 20, 2024
15f7f4e
try to deal with weird buffer errors
fearful-symmetry Sep 20, 2024
d1f8406
tinker with timeouts
fearful-symmetry Sep 20, 2024
03f5639
fix script
fearful-symmetry Sep 20, 2024
44dc5bc
tinker with scripts
fearful-symmetry Sep 20, 2024
a2a826e
try to get timing info
fearful-symmetry Sep 20, 2024
01c2d45
tinker with profiling
fearful-symmetry Sep 23, 2024
73ac51e
fix resource leak
fearful-symmetry Sep 23, 2024
351e251
Merge remote-tracking branch 'origin/main' into test-runner-refactor
fearful-symmetry Sep 23, 2024
44c7bc4
bad merge
fearful-symmetry Sep 23, 2024
4479d6a
re-add DNS test
fearful-symmetry Sep 23, 2024
9e0aad9
clean up test bins, improve dns tests
fearful-symmetry Sep 23, 2024
ac02e96
format
fearful-symmetry Sep 23, 2024
06d204c
tinker with overlay tests
fearful-symmetry Sep 23, 2024
7dce409
add back removed test, small cleanup
fearful-symmetry Sep 24, 2024
9b110c6
try to move around files
fearful-symmetry Sep 24, 2024
d7be2a4
rename, part one
fearful-symmetry Sep 24, 2024
2c68285
rename, part two
fearful-symmetry Sep 24, 2024
78a7fef
restore old file
fearful-symmetry Sep 24, 2024
b14d021
try again
fearful-symmetry Sep 24, 2024
935f078
try rename again
fearful-symmetry Sep 24, 2024
35b00ab
try other command
fearful-symmetry Sep 24, 2024
523aa7d
try restore
fearful-symmetry Sep 24, 2024
a9b7da8
restore, 2
fearful-symmetry Sep 24, 2024
4ba1630
completely restore old file
fearful-symmetry Sep 24, 2024
4933315
rename old file
fearful-symmetry Sep 24, 2024
9a517bc
modify in different commit
fearful-symmetry Sep 24, 2024
3d052ac
update docs
fearful-symmetry Sep 24, 2024
e43c601
clean up network tests
fearful-symmetry Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/multikernel-tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: '1.17'
go-version: '1.22'
- name: Run tests
run: make run-multikernel-test IMG_FILTER=${{ matrix.kernel_flavor }} ARCH=${{ inputs.architecture }} ARTIFACTS_PATH=${PWD}/artifacts
- name: Prepare for archival
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ctags
cscope.out

# Test results and other stuff in testing/
testing/testrunner/testrunner.test
testing/bpf-check-summary.txt
testing/*.cpio
testing/*.tar
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ CONTAINER_LOCAL_TAG ?= ebpf-builder:${USER}-latest
IMAGEPACK_REPOSITORY ?= ghcr.io/elastic/ebpf-imagepack
IMAGEPACK_PULL_TAG ?= 20231006-0053

TESTBIN_SRC = $(wildcard testing/test_bins/*.c)
TESTBIN_PROGS = $(patsubst testing/test_bins/%.c,testing/test_bins/bin/${ARCH}/%,$(TESTBIN_SRC))

ifdef BUILD_CONTAINER_IMAGE
CONTAINER_IMAGE = ${CONTAINER_LOCAL_TAG}
else
Expand Down Expand Up @@ -170,5 +173,14 @@ endif
go install github.com/florianl/bluebox@b8590fb1850f56df6e6d7786931fcabdc1e9173d
cd testing && ./run_tests.sh ${ARCH} ${ARTIFACTS_PATH} ${PWD}/kernel-images/${IMG_FILTER}/${ARCH}/*

testbins: testbinpath $(TESTBIN_PROGS)

testbinpath:
mkdir -p testing/test_bins/bin/${ARCH}
fearful-symmetry marked this conversation as resolved.
Show resolved Hide resolved

testing/test_bins/bin/${ARCH}/%: testing/test_bins/%.c
$(CC) -g -static -o $@ $<

clean:
${SUDO} rm -rf artifacts-*
rm -r testing/test_bins/bin/*
5 changes: 4 additions & 1 deletion non-GPL/Events/EventsTrace/EventsTrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ static void out_escaped_string(const char *value)
break;
default:
if (!isascii(c) || iscntrl(c))
printf("\\x%02x", c);
// \x is not a valid escape character in json,
// and something like '\xff' will break a remarkable number of JSON parsers.
// we have to print as '0xff'
fearful-symmetry marked this conversation as resolved.
Show resolved Hide resolved
printf("0x%02x", (uint8_t)c);
else
fearful-symmetry marked this conversation as resolved.
Show resolved Hide resolved
printf("%c", c);
}
Expand Down
16 changes: 16 additions & 0 deletions testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ By default `run_tests.sh` will pass `-j$(nproc)` to `parallel` (i.e. spin up as
many jobs as there are CPU cores). You can change this by passing
`-j <number of jobs>` to `run-tests.sh`.

## Running tests locally

This test framework leverages the go stdlib test suite, so all ebpf tests can
be run as normal go tests, outside of the bluebox VMs:

```
#compile the test in advance, so we don't need root to have a go environment
go test -c
# run all tests
sudo ./testrunner.test
# run a single test
sudo ./testrunner.test -test.run TestEbpf/Tcpv6ConnectionClose
# run in verbose mode
sudo ./testrunner.test -test.run TestEbpf/Tcpv6ConnectionClose -test.v
fearful-symmetry marked this conversation as resolved.
Show resolved Hide resolved
```

## Building Kernels

A dockerized setup is provided at `kernel_builder/` to build mainline kernel
Expand Down
8 changes: 5 additions & 3 deletions testing/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
readonly PROGNAME=$(basename $0)
readonly ARGS="$@"

readonly SUCCESS_STRING="ALL BPF TESTS PASSED"
readonly SUCCESS_STRING="exit status 0"
readonly SUMMARY_FILE="bpf-check-summary.txt"
readonly RESULTS_DIR="results"

Expand Down Expand Up @@ -70,8 +70,7 @@ EOF
}

main() {
local arch=$1
local artifacts="$2"

local jobs=$(nproc)

while getopts "j:" opt; do
Expand All @@ -85,6 +84,9 @@ main() {
esac
done

local arch=$1
local artifacts="$2"

shift 2

is_empty $arch \
Expand Down
4 changes: 2 additions & 2 deletions testing/scripts/gen_initramfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ build_testrunner() {
pushd testrunner > /dev/null

go clean
GOARCH=$goarch go build
GOARCH=$goarch CGO_ENABLED=0 go test -c -o testrunner -ldflags '-extldflags "-static"'

if [[ $? -ne 0 ]]
then
Expand Down Expand Up @@ -78,7 +78,7 @@ invoke_bluebox() {

local cmd="bluebox"
cmd+=" -a $goarch"
cmd+=" -e testrunner/testrunner"
cmd+=" -e testrunner/testrunner:-test.v"
cmd+=" -r $eventstrace"
cmd+=" -r $tcfiltertests"
cmd+=" -r $tcfilterbpf"
Expand Down
17 changes: 17 additions & 0 deletions testing/test_bins/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,20 @@ void gen_pid_info_json(char *buf, size_t size)
(pid_t)syscall(SYS_gettid), getppid(), getpid(), getsid(0), getpgid(0), cap_permitted,
cap_effective);
}

int dump_info(int client_port, int server_port)
{
char pid_info[8192];
gen_pid_info_json(pid_info, sizeof(pid_info));

char netns[128];
ssize_t nbytes;
CHECK(nbytes = readlink("/proc/self/ns/net", netns, sizeof(netns)), -1);
netns[nbytes] = '\0';

uint64_t netns_inode;
sscanf(netns, "net:[%lu]", &netns_inode);

printf("{ \"pid_info\": %s, \"client_port\": %d, \"server_port\": %d, \"netns\": %lu }\n",
pid_info, client_port, server_port, netns_inode);
}
5 changes: 5 additions & 0 deletions testing/test_bins/create_rename_delete_file_container.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ int main()

cleanup:
// Clean up directories created by child

// in the 5.10 test kernels, this umount call fails, so don't check.
// Can't reproduce the issue locally, but `unmount` operations on overlayfs have historically
// been quirky.
umount2(ovl_mountpoint, MNT_FORCE);
CHECK(rm_recursive(ovl_mountpoint), -1);
CHECK(rm_recursive(ovl_upperdir), -1);
CHECK(rm_recursive(ovl_lowerdir), -1);
Expand Down
17 changes: 0 additions & 17 deletions testing/test_bins/tcpv4_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@

#define BOUND_PORT 2048

int dump_info(int client_port, int server_port)
{
char pid_info[8192];
gen_pid_info_json(pid_info, sizeof(pid_info));

char netns[128];
ssize_t nbytes;
CHECK(nbytes = readlink("/proc/self/ns/net", netns, sizeof(netns)), -1);
netns[nbytes] = '\0';

uint64_t netns_inode;
sscanf(netns, "net:[%lu]", &netns_inode);

printf("{ \"pid_info\": %s, \"client_port\": %d, \"server_port\": %d, \"netns\": %lu }\n",
pid_info, client_port, server_port, netns_inode);
}

int main()
{
struct sockaddr_in serveraddr;
Expand Down
17 changes: 0 additions & 17 deletions testing/test_bins/tcpv6_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@

#define BOUND_PORT 2048

int dump_info(int client_port, int server_port)
{
char pid_info[8192];
gen_pid_info_json(pid_info, sizeof(pid_info));

char netns[128];
ssize_t nbytes;
CHECK(nbytes = readlink("/proc/self/ns/net", netns, sizeof(netns)), -1);
netns[nbytes] = '\0';

uint64_t netns_inode;
sscanf(netns, "net:[%lu]", &netns_inode);

printf("{ \"pid_info\": %s, \"client_port\": %d, \"server_port\": %d, \"netns\": %lu }\n",
pid_info, client_port, server_port, netns_inode);
}

int main()
{
struct sockaddr_in6 serveraddr;
Expand Down
4 changes: 4 additions & 0 deletions testing/test_bins/udp_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <string.h>
#include <unistd.h>

#include "common.h"

int main(int argc, char *argv[])
{
struct sockaddr_in sin;
Expand All @@ -38,5 +40,7 @@ int main(int argc, char *argv[])
else if (n != sizeof(buf))
errx(1, "sendto: shortcount");

dump_info(53, 0);

return (0);
}
Loading
Loading