diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-11-25 09:17:50 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-12-28 14:22:41 +0100 |
| commit | cbd0445ec3b0b184db66966d8a47e6b37d13692e (patch) | |
| tree | 14ed47723c325ef1b388e4e732a70c0fed4fa101 /pkg/ipc | |
| parent | 2242f77fdc5a6c50bd8fa1021d2abc8b83e09e8d (diff) | |
all: make timeouts configurable
Add sys/targets.Timeouts struct that parametrizes timeouts throughout the system.
The struct allows to control syscall/program/no output timeouts for OS/arch/VM/etc.
See comment on the struct for more details.
Diffstat (limited to 'pkg/ipc')
| -rw-r--r-- | pkg/ipc/ipc.go | 12 | ||||
| -rw-r--r-- | pkg/ipc/ipc_test.go | 10 | ||||
| -rw-r--r-- | pkg/ipc/ipcconfig/ipcconfig.go | 4 |
3 files changed, 18 insertions, 8 deletions
diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go index 0f1bd50a6..7e0bf7e94 100644 --- a/pkg/ipc/ipc.go +++ b/pkg/ipc/ipc.go @@ -73,6 +73,8 @@ type Config struct { // Flags are configuation flags, defined above. Flags EnvFlags + + Timeouts targets.Timeouts } type CallFlags uint32 @@ -154,6 +156,10 @@ func FlagsToSandbox(flags EnvFlags) string { } func MakeEnv(config *Config, pid int) (*Env, error) { + if config.Timeouts.Slowdown == 0 || config.Timeouts.Scale == 0 || + config.Timeouts.Syscall == 0 || config.Timeouts.Program == 0 { + return nil, fmt.Errorf("ipc.MakeEnv: uninitialized timeouts (%+v)", config.Timeouts) + } var inf, outf *os.File var inmem, outmem []byte if config.UseShmem { @@ -731,9 +737,9 @@ func (c *command) exec(opts *ExecOpts, progData []byte) (output []byte, hanged b pid: uint64(c.pid), faultCall: uint64(opts.FaultCall), faultNth: uint64(opts.FaultNth), - syscallTimeoutMS: 50, - programTimeoutMS: 5000, - slowdownScale: 1, + syscallTimeoutMS: uint64(c.config.Timeouts.Syscall / time.Millisecond), + programTimeoutMS: uint64(c.config.Timeouts.Program / time.Millisecond), + slowdownScale: uint64(c.config.Timeouts.Scale), progSize: uint64(len(progData)), } reqData := (*[unsafe.Sizeof(*req)]byte)(unsafe.Pointer(req))[:] diff --git a/pkg/ipc/ipc_test.go b/pkg/ipc/ipc_test.go index e5e919a89..44fdb67bd 100644 --- a/pkg/ipc/ipc_test.go +++ b/pkg/ipc/ipc_test.go @@ -30,7 +30,7 @@ func buildExecutor(t *testing.T, target *prog.Target) string { return bin } -func initTest(t *testing.T) (*prog.Target, rand.Source, int, bool, bool) { +func initTest(t *testing.T) (*prog.Target, rand.Source, int, bool, bool, targets.Timeouts) { t.Parallel() iters := 100 if testing.Short() { @@ -50,7 +50,7 @@ func initTest(t *testing.T) (*prog.Target, rand.Source, int, bool, bool) { if err != nil { t.Fatal(err) } - return target, rs, iters, cfg.UseShmem, cfg.UseForkServer + return target, rs, iters, cfg.UseShmem, cfg.UseForkServer, cfg.Timeouts } // TestExecutor runs all internal executor unit tests. @@ -82,7 +82,7 @@ func TestExecutor(t *testing.T) { } func TestExecute(t *testing.T) { - target, _, _, useShmem, useForkServer := initTest(t) + target, _, _, useShmem, useForkServer, timeouts := initTest(t) bin := buildExecutor(t, target) defer os.Remove(bin) @@ -94,6 +94,7 @@ func TestExecute(t *testing.T) { Executor: bin, UseShmem: useShmem, UseForkServer: useForkServer, + Timeouts: timeouts, } env, err := MakeEnv(cfg, 0) if err != nil { @@ -127,13 +128,14 @@ func TestExecute(t *testing.T) { } func TestParallel(t *testing.T) { - target, _, _, useShmem, useForkServer := initTest(t) + target, _, _, useShmem, useForkServer, timeouts := initTest(t) bin := buildExecutor(t, target) defer os.Remove(bin) cfg := &Config{ Executor: bin, UseShmem: useShmem, UseForkServer: useForkServer, + Timeouts: timeouts, } const P = 10 errs := make(chan error, P) diff --git a/pkg/ipc/ipcconfig/ipcconfig.go b/pkg/ipc/ipcconfig/ipcconfig.go index a99cbdadc..3791322f2 100644 --- a/pkg/ipc/ipcconfig/ipcconfig.go +++ b/pkg/ipc/ipcconfig/ipcconfig.go @@ -18,11 +18,14 @@ var ( flagSignal = flag.Bool("cover", false, "collect feedback signals (coverage)") flagSandbox = flag.String("sandbox", "none", "sandbox for fuzzing (none/setuid/namespace/android)") flagDebug = flag.Bool("debug", false, "debug output from executor") + flagSlowdown = flag.Int("slowdown", 1, "execution slowdown caused by emulation/instrumentation") ) func Default(target *prog.Target) (*ipc.Config, *ipc.ExecOpts, error) { + sysTarget := targets.Get(target.OS, target.Arch) c := &ipc.Config{ Executor: *flagExecutor, + Timeouts: sysTarget.Timeouts(*flagSlowdown), } if *flagSignal { c.Flags |= ipc.FlagSignal @@ -35,7 +38,6 @@ func Default(target *prog.Target) (*ipc.Config, *ipc.ExecOpts, error) { return nil, nil, err } c.Flags |= sandboxFlags - sysTarget := targets.Get(target.OS, target.Arch) c.UseShmem = sysTarget.ExecutorUsesShmem c.UseForkServer = sysTarget.ExecutorUsesForkServer opts := &ipc.ExecOpts{ |
