diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-12 22:39:06 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-12 22:39:06 +0200 |
| commit | 13e7970afb3eeac69f82df833f030711e5cf12ec (patch) | |
| tree | 098c4fb8c5a8c8f27547f03f40c9fee0be63fe35 /integrationtests | |
| parent | 1b21e818a69bf73fde3ca60f89d2dc82a79fd605 (diff) | |
internal: embed BPF object into ior binary
Diffstat (limited to 'integrationtests')
| -rw-r--r-- | integrationtests/README.md | 5 | ||||
| -rw-r--r-- | integrationtests/cleanup_test.go | 10 | ||||
| -rw-r--r-- | integrationtests/harness.go | 11 | ||||
| -rw-r--r-- | integrationtests/harness_test.go | 29 | ||||
| -rw-r--r-- | integrationtests/helpers_test.go | 2 |
5 files changed, 41 insertions, 16 deletions
diff --git a/integrationtests/README.md b/integrationtests/README.md index 99a3fc0..be65499 100644 --- a/integrationtests/README.md +++ b/integrationtests/README.md @@ -6,9 +6,12 @@ harness asserts the captured `.ior.zst` output matches expectations. ## Prerequisites -- Built `ior` binary and `ior.bpf.o` (`mage all`) +- Built `ior` binary (`mage all`) - Root privileges or `CAP_BPF` (required for BPF tracepoint attachment) +The binary embeds its default BPF object. Set `IOR_BPF_OBJECT=/path/to/ior.bpf.o` +only when you explicitly want to override the embedded object during testing. + ## Running ```bash diff --git a/integrationtests/cleanup_test.go b/integrationtests/cleanup_test.go index 18a0531..316c1b1 100644 --- a/integrationtests/cleanup_test.go +++ b/integrationtests/cleanup_test.go @@ -80,8 +80,7 @@ func TestCleanupOutputDirContainsOnlyExpectedFiles(t *testing.T) { for _, e := range entries { name := e.Name() validSuffix := strings.HasSuffix(name, ".ior.zst") || - strings.HasSuffix(name, ".svg") || - name == "ior.bpf.o" // symlink created by startIor + strings.HasSuffix(name, ".svg") if !validSuffix { t.Errorf("unexpected file in output dir: %s", name) } @@ -172,11 +171,8 @@ func TestCleanupOutputDirEmptyAfterIorFailure(t *testing.T) { t.Fatalf("read output dir: %v", err) } - // Only the BPF symlink should exist; ior produced no output. - for _, e := range entries { - if e.Name() != "ior.bpf.o" { - t.Errorf("unexpected file in output dir after ior failure: %s", e.Name()) - } + if len(entries) != 0 { + t.Fatalf("expected empty output dir after ior failure, found %d entries", len(entries)) } } diff --git a/integrationtests/harness.go b/integrationtests/harness.go index 17ae994..e3ee900 100644 --- a/integrationtests/harness.go +++ b/integrationtests/harness.go @@ -15,6 +15,7 @@ import ( const ( workloadStartupTimeout = 5 * time.Second iorShutdownGrace = 30 * time.Second + bpfObjectOverrideEnv = "IOR_BPF_OBJECT" ) // TestHarness orchestrates integration tests by starting an ior trace @@ -22,7 +23,7 @@ const ( type TestHarness struct { IorBinary string // path to built ior binary WorkloadBinary string // path to built ioworkload binary - BpfObject string // path to ior.bpf.o + BpfObject string // optional path to external BPF object override OutputDir string // temp dir for .ior.zst output } @@ -120,11 +121,6 @@ func (h *TestHarness) startWorkload(scenario string) (*exec.Cmd, int, error) { } func (h *TestHarness) startIor(pid int, scenario string, duration int, extraArgs []string) (*exec.Cmd, error) { - bpfLink := filepath.Join(h.OutputDir, "ior.bpf.o") - if err := os.Symlink(h.BpfObject, bpfLink); err != nil { - return nil, fmt.Errorf("symlink bpf object: %w", err) - } - args := []string{ "-pid", strconv.Itoa(pid), "-flamegraph", @@ -136,6 +132,9 @@ func (h *TestHarness) startIor(pid int, scenario string, duration int, extraArgs cmd.Dir = h.OutputDir cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr + if h.BpfObject != "" { + cmd.Env = append(os.Environ(), bpfObjectOverrideEnv+"="+h.BpfObject) + } if err := cmd.Start(); err != nil { return nil, fmt.Errorf("start ior: %w", err) diff --git a/integrationtests/harness_test.go b/integrationtests/harness_test.go index 6e076ad..27a122c 100644 --- a/integrationtests/harness_test.go +++ b/integrationtests/harness_test.go @@ -178,3 +178,32 @@ func TestIorStartFailureCleansUpWorkload(t *testing.T) { } } } + +func TestStartIorPassesBPFObjectOverrideEnv(t *testing.T) { + tmpDir := t.TempDir() + outputDir := t.TempDir() + overridePath := filepath.Join(tmpDir, "fake.bpf.o") + iorBin := writeScript(t, tmpDir, "ior", `printf '%s' "$IOR_BPF_OBJECT" > "$PWD/override.txt"`) + + h := TestHarness{ + IorBinary: iorBin, + BpfObject: overridePath, + OutputDir: outputDir, + } + + cmd, err := h.startIor(1234, "test", 5, nil) + if err != nil { + t.Fatalf("startIor returned error: %v", err) + } + if err := cmd.Wait(); err != nil { + t.Fatalf("wait for fake ior: %v", err) + } + + data, err := os.ReadFile(filepath.Join(outputDir, "override.txt")) + if err != nil { + t.Fatalf("read override marker: %v", err) + } + if got, want := string(data), overridePath; got != want { + t.Fatalf("IOR_BPF_OBJECT = %q, want %q", got, want) + } +} diff --git a/integrationtests/helpers_test.go b/integrationtests/helpers_test.go index feb7a55..6ef7ba7 100644 --- a/integrationtests/helpers_test.go +++ b/integrationtests/helpers_test.go @@ -9,7 +9,6 @@ import ( const ( iorBinaryDefault = "../ior" workloadBinaryDefault = "../ioworkload" - bpfObjectDefault = "../ior.bpf.o" defaultDuration = 10 parallelEnvVar = "IOR_INTEGRATION_PARALLEL" ) @@ -23,7 +22,6 @@ func newTestHarness(t *testing.T) TestHarness { return TestHarness{ IorBinary: absPath(t, iorBinaryDefault), WorkloadBinary: absPath(t, workloadBinaryDefault), - BpfObject: absPath(t, bpfObjectDefault), OutputDir: t.TempDir(), } } |
