Skip to content

Commit

Permalink
pkg/fuzzer: collect executor debug logs in tests
Browse files Browse the repository at this point in the history
It should hopefully let us debug #5674.
  • Loading branch information
a-nogikh committed Jan 30, 2025
1 parent e961d16 commit ec43420
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions pkg/fuzzer/fuzzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,29 @@ func (f *testFuzzer) run() {
f.crashes = make(map[string]int)
ctx, done := context.WithCancel(context.Background())
f.done = done
var output bytes.Buffer
cfg := &rpcserver.LocalConfig{
Config: rpcserver.Config{
Config: vminfo.Config{
Debug: true,
Target: f.target,
Features: flatrpc.FeatureSandboxNone,
Sandbox: flatrpc.ExecEnvSandboxNone,
},
Procs: 4,
Slowdown: 1,
},
Executor: f.executor,
Dir: f.t.TempDir(),
Context: ctx,
Executor: f.executor,
Dir: f.t.TempDir(),
Context: ctx,
OutputWriter: &output,
}
cfg.MachineChecked = func(features flatrpc.Feature, syscalls map[*prog.Syscall]bool) queue.Source {
cfg.Cover = true
return f
}
if err := rpcserver.RunLocal(cfg); err != nil {
f.t.Logf("executor output:\n%s", output.String())
f.t.Fatal(err)
}
assert.Equal(f.t, len(f.expectedCrashes), len(f.crashes), "not all expected crashes were found")
Expand Down
14 changes: 10 additions & 4 deletions pkg/rpcserver/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package rpcserver
import (
"context"
"fmt"
"io"
"os"
"os/exec"

Expand All @@ -28,9 +29,11 @@ type LocalConfig struct {
// Handle ctrl+C and exit.
HandleInterrupts bool
// Run executor under gdb.
GDB bool
MaxSignal []uint64
CoverFilter []uint64
GDB bool
// Can be used to intercept stdout/stderr output.
OutputWriter io.Writer
MaxSignal []uint64
CoverFilter []uint64
// RunLocal exits when the context is cancelled.
Context context.Context
MachineChecked func(features flatrpc.Feature, syscalls map[*prog.Syscall]bool) queue.Source
Expand Down Expand Up @@ -82,7 +85,10 @@ func RunLocal(cfg *LocalConfig) error {
}
cmd := exec.CommandContext(ctx, bin, args...)
cmd.Dir = cfg.Dir
if cfg.Debug || cfg.GDB {
if cfg.OutputWriter != nil {
cmd.Stdout = cfg.OutputWriter
cmd.Stderr = cfg.OutputWriter
} else if cfg.Debug || cfg.GDB {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
Expand Down

0 comments on commit ec43420

Please sign in to comment.