eBPF-based security platform
testing: check the JSON form of upatch get
Daniel Borkmannf8529500c5a3
diff --git a/AGENTS.md b/AGENTS.mdindex 17209e11..c37c11a1 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -60,7 +60,7 @@ remote-management or transport layers.| `Documentation/requirements.rst` | Kernel options, operator toolchain, target runtime. || `Documentation/getting-started.rst` | Quickstart: build, sign, initialise a target, load and unload, publish and install packages. || `Documentation/telemetry.rst` | OTLP export of map snapshots and status keepalives, the signed Lua decoders, and collector integration (OpenTelemetry Collector, ClickHouse, Splunk, custom). |-| `Documentation/developer-guide.rst` | Working from a checkout, the operator-only tools, the test tiers (unit, functional, end-to-end), the test numbers, running the tests, the test VM and the open coverage gaps. Read it before adding or moving a test. |+| `Documentation/developer-guide.rst` | Working from a checkout, the operator-only tools, the test tiers (unit, functional, end-to-end), the test numbers, running the tests and the test VM. Read it before adding or moving a test. || `Documentation/coding-style.rst` | The kernel's coding style, applied to all C here. || `Documentation/contributing.rst` | Commit message form, the mandatory `Signed-off-by:` and the kernel's attribution tags. Read it before crafting a commit. |diff --git a/Documentation/developer-guide.rst b/Documentation/developer-guide.rstindex ca4cbd6a..bab4416c 100644--- a/Documentation/developer-guide.rst+++ b/Documentation/developer-guide.rst@@ -218,8 +218,3 @@ the dm-verity runtime image and the signed config images, whichguest with a software TPM and the bundle and, in test mode, has``guest.sh`` run one family's tests in it. ``testing/swtpm.sh`` runs asoftware TPM on the host for development without a VM.--8) Open work---------------``upatch get`` is checked for the loaded source, not its JSON form.diff --git a/testing/functional/upatch/t3106-upatch-get.sh b/testing/functional/upatch/t3106-upatch-get.shindex deef9fc2..45dc46c3 100644--- a/testing/functional/upatch/t3106-upatch-get.sh+++ b/testing/functional/upatch/t3106-upatch-get.sh@@ -4,12 +4,14 @@## t3106 -- `shirudo upatch get <name>` dumps the BPF line info (source)# of a LOADED upatch read from the kernel (the BTF the signed gen_loader-# installed). Builds + loads a marker fentry upatch, asserts `get` shows-# the marker source, then unloads + cleans up on EXIT.+# installed). Loads the marker fentry upatch, asserts `get` shows the+# marker source, in text and in its JSON form with the payload the+# artifact names, then unloads + cleans up on EXIT.cd "$(dirname "$0")/../..". ./integration-lib.shtarget_guard+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"FIXTURES=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}NAME=shirudo-test-marker@@ -37,4 +39,38 @@ test_expect_success 'upatch get dumps the loaded source line from the kernel' '"$SHIRUDO_BIN" upatch get "$NAME" 2>/dev/null | grep -q "shirudo_test_marker"'+test_expect_success 'its JSON form names the program, payload and source' '+ "$SHIRUDO_BIN" upatch get "$NAME" >"$WORK/get.txt" &&+ "$SHIRUDO_BIN" upatch get "$NAME" --json >"$WORK/get.json" &&+ "$SHIRUDO_BIN" upatch info --json "$LOAD" >"$WORK/info.json" &&+ python3 - "$WORK/get.json" "$WORK/info.json" "$WORK/get.txt" <<'\''PY'\''+import json, re, sys+doc = json.load(open(sys.argv[1]))+payload = json.load(open(sys.argv[2]))["payload_sha256"]+text = open(sys.argv[3]).read()+assert set(doc) == {"schema", "upatch"} and doc["schema"] == 1, doc+u = doc["upatch"]+assert set(u) == {"name", "location", "prog_id", "loaded_at", "age",+ "payload_sha256", "source", "maps"}, u+assert u["name"] == "shirudo-test-marker"+assert u["location"] == "fentry/do_nanosleep"+assert u["prog_id"] > 0+assert re.search(r"^Prog id: +%d$" % u["prog_id"], text, re.M)+assert re.fullmatch(r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ", u["loaded_at"])+assert u["age"]+assert u["payload_sha256"] == payload+lines = [(f["path"], line["line"], line["src"])+ for f in u["source"]["files"] for line in f["lines"]]+assert any(path.endswith("/marker.bpf.c") and n > 0 and+ "shirudo_test_marker" in src for path, n, src in lines), lines+assert u["maps"] == []+PY+'++test_expect_success 'a name that is not loaded has no JSON form' '+ ! "$SHIRUDO_BIN" upatch get shirudo-test-not-loaded --json \+ >"$WORK/missing.json" 2>/dev/null &&+ [ ! -s "$WORK/missing.json" ]+'+test_done