Skip to content

eBPF-based security platform

testing: reorganize kernel observability tests

John Fastabend39259255d604
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 732340db..18c79340 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -545,7 +545,7 @@ TEST_HELPERS := testing/helper/test-json-parser \
testing/helper/test-upatch-serializer-pages \
testing/helper/test-signed-load \
testing/helper/test-exec-churn \
- testing/kernel-obs/exec-paths
+ testing/upatch/kernel-obs/exec/exec-paths
testing/helper/test-json-parser: testing/helper/test-json-parser.c util/json.o util/hex.o util/malloc.o
@printf ' CC $@\n'
@@ -668,7 +668,7 @@ testing/helper/test-exec-churn: testing/helper/test-exec-churn.c util/io.o util/
@printf ' CC $@\n'
$(Q)$(CC) $(CFLAGS) -o $@ $^
-testing/kernel-obs/exec-paths: testing/kernel-obs/exec_paths.c
+testing/upatch/kernel-obs/exec/exec-paths: testing/upatch/kernel-obs/exec/exec_paths.c
@printf ' CC $@\n'
$(Q)$(CC) $(CFLAGS) -pthread -o $@ $^
diff --git a/contrib/build-test-vm-bundle.sh b/contrib/build-test-vm-bundle.sh
index 8d1fa2e3..c9de9841 100755
--- a/contrib/build-test-vm-bundle.sh
+++ b/contrib/build-test-vm-bundle.sh
@@ -303,7 +303,7 @@ trap cleanup EXIT
make -C "$REPO_ROOT" DESTDIR="$TMP_DIR/root" install-target
install -d "$TMP_DIR/test-helpers/testing/helper" \
- "$TMP_DIR/test-helpers/testing/kernel-obs"
+ "$TMP_DIR/test-helpers/testing/upatch/kernel-obs/exec"
while IFS= read -r helper; do
install -m 0755 "$REPO_ROOT/$helper" "$TMP_DIR/test-helpers/$helper"
done <<'EOF'
@@ -320,7 +320,7 @@ testing/helper/test-upatch-decode
testing/helper/test-upatch-serializer-pages
testing/helper/test-signed-load
testing/helper/test-exec-churn
-testing/kernel-obs/exec-paths
+testing/upatch/kernel-obs/exec/exec-paths
testing/helper/otel-mock.py
testing/helper/test-oci-registry.py
EOF
diff --git a/testing/Makefile b/testing/Makefile
index 88d11700..d7f8eb73 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -112,7 +112,7 @@ TEST_VM_BUNDLE_SOURCES := $(sort $(wildcard \
$(ROOT)/vendor/libbpf/include/uapi/linux/*.h \
$(ROOT)/vendor/libbpf/include/asm/*.h \
$(ROOT)/testing/helper/*.c $(ROOT)/testing/helper/*.py \
- $(ROOT)/testing/kernel-obs/*.c $(ROOT)/completion/* $(ROOT)/systemd/*.in \
+ $(ROOT)/testing/upatch/kernel-obs/exec/*.c $(ROOT)/completion/* $(ROOT)/systemd/*.in \
$(ROOT)/systemd/*.timer $(ROOT)/testing/fixtures/*.c $(ROOT)/testing/fixtures/*.lua \
$(ROOT)/testing/fixtures/decoders/* \
$(ROOT)/upatches/kernel-obs/*.c $(ROOT)/upatches/kernel-obs/*.h $(ROOT)/upatches/kernel-obs/*.list \
diff --git a/testing/run-target-obs-tests.sh b/testing/run-target-obs-tests.sh
index ca918966..31593fad 100755
--- a/testing/run-target-obs-tests.sh
+++ b/testing/run-target-obs-tests.sh
@@ -9,9 +9,9 @@ cd "$(dirname "$0")"
fail=0
: "${SHIRUDO_TEST_SUITE_FAILURES_FILE:=}"
for test_script in \
- kernel-obs/t1210-kernel-obs.sh \
- kernel-obs/kernel-obs-priv.sh \
- kernel-obs/t1211-kernel-obs-dns-matrix.sh
+ upatch/kernel-obs/network/t1210-kernel-obs.sh \
+ upatch/kernel-obs/priv/kernel-obs-priv.sh \
+ upatch/kernel-obs/dns/t1211-kernel-obs-dns-matrix.sh
do
if sh "$test_script"; then
:
diff --git a/testing/run-tests.sh b/testing/run-tests.sh
index 3a47176e..40efa184 100755
--- a/testing/run-tests.sh
+++ b/testing/run-tests.sh
@@ -28,7 +28,7 @@ for t in t0[0-9][0-9][0-9]-*.sh; do
fi
done
-for t in kernel-obs/t0[0-9][0-9][0-9]-*.sh; do
+for t in upatch/kernel-obs/dns/t0[0-9][0-9][0-9]-*.sh; do
[ -e "$t" ] || continue
found=1
if sh "$t"; then
diff --git a/testing/kernel-obs/dns_obs_matrix.py b/testing/upatch/kernel-obs/dns/dns_obs_matrix.py
similarity index 100%
rename from testing/kernel-obs/dns_obs_matrix.py
rename to testing/upatch/kernel-obs/dns/dns_obs_matrix.py
diff --git a/testing/kernel-obs/t0019-dns-observability-matrix.sh b/testing/upatch/kernel-obs/dns/t0019-dns-observability-matrix.sh
similarity index 74%
rename from testing/kernel-obs/t0019-dns-observability-matrix.sh
rename to testing/upatch/kernel-obs/dns/t0019-dns-observability-matrix.sh
index 863ebd0e..c6b7cffd 100755
--- a/testing/kernel-obs/t0019-dns-observability-matrix.sh
+++ b/testing/upatch/kernel-obs/dns/t0019-dns-observability-matrix.sh
@@ -2,13 +2,13 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
-cd "$(dirname "$0")/.."
+cd "$(dirname "$0")/../../.."
. ./test-lib.sh
command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
test_expect_success 'DNS packet-case builders and batch encoding are valid' '
- python3 kernel-obs/dns_obs_matrix.py --self-test
+ python3 upatch/kernel-obs/dns/dns_obs_matrix.py --self-test
'
test_done
diff --git a/testing/kernel-obs/t1211-kernel-obs-dns-matrix.sh b/testing/upatch/kernel-obs/dns/t1211-kernel-obs-dns-matrix.sh
similarity index 92%
rename from testing/kernel-obs/t1211-kernel-obs-dns-matrix.sh
rename to testing/upatch/kernel-obs/dns/t1211-kernel-obs-dns-matrix.sh
index 21783b43..e02edf21 100755
--- a/testing/kernel-obs/t1211-kernel-obs-dns-matrix.sh
+++ b/testing/upatch/kernel-obs/dns/t1211-kernel-obs-dns-matrix.sh
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
-cd "$(dirname "$0")/.."
+cd "$(dirname "$0")/../../.."
. ./integration-lib.sh
target_guard
command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
@@ -55,8 +55,8 @@ PYTHON
test_expect_success 'DNS observations use real loopback UDP traffic' '
"$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >/dev/null 2>&1 &&
- python3 kernel-obs/kernel_obs_events.py dns-long &&
- python3 kernel-obs/kernel_obs_events.py dns-many &&
+ python3 upatch/kernel-obs/network/kernel_obs_events.py dns-long &&
+ python3 upatch/kernel-obs/network/kernel_obs_events.py dns-many &&
"$SHIRUDO_BIN" upatch map "$NAME" dns --json="$WORK/dns.ndjson" >/dev/null &&
python3 "$WORK/check.py" "$WORK/dns.ndjson" &&
"$SHIRUDO_BIN" upatch map "$NAME" dns --json="$WORK/dns-empty.ndjson" >/dev/null &&
diff --git a/testing/kernel-obs/exec_paths.c b/testing/upatch/kernel-obs/exec/exec_paths.c
similarity index 100%
rename from testing/kernel-obs/exec_paths.c
rename to testing/upatch/kernel-obs/exec/exec_paths.c
diff --git a/testing/kernel-obs/kernel_obs_events.py b/testing/upatch/kernel-obs/network/kernel_obs_events.py
similarity index 96%
rename from testing/kernel-obs/kernel_obs_events.py
rename to testing/upatch/kernel-obs/network/kernel_obs_events.py
index 2fb262b2..1499789b 100755
--- a/testing/kernel-obs/kernel_obs_events.py
+++ b/testing/upatch/kernel-obs/network/kernel_obs_events.py
@@ -25,14 +25,14 @@ def exec_event():
shutil.copyfile("/bin/true", executable)
os.chmod(executable, 0o755)
subprocess.run([executable], check=True)
- subprocess.run(["./kernel-obs/exec-paths", directory], check=True)
+ subprocess.run(["./upatch/kernel-obs/exec/exec-paths", directory], check=True)
for method in ("execveat-empty", "fexecve"):
fd_executable = os.path.join(directory, f"true-{method}")
shutil.copyfile("/bin/true", fd_executable)
os.chmod(fd_executable, 0o755)
- subprocess.run(["./kernel-obs/exec-paths", f"--{method}",
+ subprocess.run(["./upatch/kernel-obs/exec/exec-paths", f"--{method}",
fd_executable], check=True)
- subprocess.run(["./kernel-obs/exec-paths", "--replace", executable],
+ subprocess.run(["./upatch/kernel-obs/exec/exec-paths", "--replace", executable],
check=True)
diff --git a/testing/kernel-obs/t1210-kernel-obs.sh b/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh
similarity index 95%
rename from testing/kernel-obs/t1210-kernel-obs.sh
rename to testing/upatch/kernel-obs/network/t1210-kernel-obs.sh
index c911b800..f4e6c7cc 100755
--- a/testing/kernel-obs/t1210-kernel-obs.sh
+++ b/testing/upatch/kernel-obs/network/t1210-kernel-obs.sh
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
-cd "$(dirname "$0")/.."
+cd "$(dirname "$0")/../../.."
. ./integration-lib.sh
target_guard
command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
@@ -92,7 +92,7 @@ assert any(r["name"] == "true" and r["path"].endswith("/true")
for r in tables["exec"]), tables["exec"]
assert any("caller" in r for r in tables["exec"]), tables["exec"]
helper_records = [r for r in tables["exec"]
- if r["path"].endswith("/kernel-obs/exec-paths")]
+ if r["path"].endswith("/kernel-obs/exec/exec-paths")]
helper = next(r for r in helper_records
if (r.get("caller", {}).get("dev"),
r.get("caller", {}).get("ino")) !=
@@ -224,16 +224,16 @@ test_expect_success 'kernel-obs upatch loads with seven serializers' '
'
test_expect_success 'exec, net, listen, DNS, privilege and file events produce records' '
- python3 kernel-obs/kernel_obs_events.py all &&
- python3 kernel-obs/kernel_obs_events.py dns-long &&
- python3 kernel-obs/kernel_obs_events.py dns-many &&
+ python3 upatch/kernel-obs/network/kernel_obs_events.py all &&
+ python3 upatch/kernel-obs/network/kernel_obs_events.py dns-long &&
+ python3 upatch/kernel-obs/network/kernel_obs_events.py dns-many &&
export_maps "$WORK/events.ndjson" &&
python3 "$WORK/check.py" "$WORK/events.ndjson" &&
python3 "$WORK/check_events.py" "$WORK/events.ndjson"
'
test_expect_success 'watched destinations are recorded with the metric' '
- python3 kernel-obs/kernel_obs_events.py watch &&
+ python3 upatch/kernel-obs/network/kernel_obs_events.py watch &&
export_maps "$WORK/watch.ndjson" &&
python3 "$WORK/check_watch.py" "$WORK/watch.ndjson"
'
@@ -244,7 +244,7 @@ test_expect_success 'an export drains the tables' '
'
test_expect_success 'only the touched tables carry records' '
- python3 kernel-obs/kernel_obs_events.py exec &&
+ python3 upatch/kernel-obs/network/kernel_obs_events.py exec &&
export_maps "$WORK/exec-only.ndjson" &&
python3 "$WORK/check_exec_only.py" "$WORK/exec-only.ndjson"
'
diff --git a/testing/kernel-obs/kernel-obs-priv.sh b/testing/upatch/kernel-obs/priv/kernel-obs-priv.sh
similarity index 88%
rename from testing/kernel-obs/kernel-obs-priv.sh
rename to testing/upatch/kernel-obs/priv/kernel-obs-priv.sh
index a1a95586..13c1db47 100755
--- a/testing/kernel-obs/kernel-obs-priv.sh
+++ b/testing/upatch/kernel-obs/priv/kernel-obs-priv.sh
@@ -59,20 +59,20 @@ test_expect_success 'kernel-obs upatch loads with the priv serializer' '
test_expect_success 'non-executable mappings do not produce exec protection records' '
SHIRUDO_TEST_WORK_DIR="$WORK/events" \
- python3 kernel-obs/priv_events.py negative &&
+ python3 upatch/kernel-obs/priv/priv_events.py negative &&
export_priv "$WORK/negative.ndjson" &&
- python3 kernel-obs/priv_events.py check-negative "$WORK/negative.ndjson"
+ python3 upatch/kernel-obs/priv/priv_events.py check-negative "$WORK/negative.ndjson"
'
test_expect_success 'privilege events produce attributed priv records' '
cat "$MODPROBE_FILE" >"$MODPROBE_BACKUP" &&
printf '%s\n' /bin/false >"$MODPROBE_FILE" &&
SHIRUDO_TEST_WORK_DIR="$WORK/events" \
- python3 kernel-obs/priv_events.py generate "$WORK/expected.json" &&
+ python3 upatch/kernel-obs/priv/priv_events.py generate "$WORK/expected.json" &&
cat "$MODPROBE_BACKUP" >"$MODPROBE_FILE" &&
rm -f "$MODPROBE_BACKUP" &&
export_priv "$WORK/priv.ndjson" &&
- python3 kernel-obs/priv_events.py check \
+ python3 upatch/kernel-obs/priv/priv_events.py check \
"$WORK/expected.json" "$WORK/priv.ndjson"
'
diff --git a/testing/kernel-obs/priv_events.py b/testing/upatch/kernel-obs/priv/priv_events.py
similarity index 100%
rename from testing/kernel-obs/priv_events.py
rename to testing/upatch/kernel-obs/priv/priv_events.py
diff --git a/upatches/kernel-obs/dns.todo b/upatches/kernel-obs/dns.todo
index e2ea9552..a3fca30c 100644
--- a/upatches/kernel-obs/dns.todo
+++ b/upatches/kernel-obs/dns.todo
@@ -4,7 +4,7 @@ The UDP DNS parser correlates requests with a canonical key made from
the network-namespace cookie, address family, client/resolver addresses
and ports, and transaction ID, and attributes the answer to the querying
socket's owner. The items below are the remaining parser and
-correlation gaps. `testing/kernel-obs/dns_obs_matrix.py` now validates
+correlation gaps. `testing/upatch/kernel-obs/dns/dns_obs_matrix.py` now validates
case construction and batch encoding only. Its former target runner used
`BPF_PROG_TEST_RUN`, which is restricted to Shirudo. The target suite uses
live loopback UDP exchanges for representative query and response