From cbd0445ec3b0b184db66966d8a47e6b37d13692e Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 25 Nov 2020 09:17:50 +0100 Subject: 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. --- pkg/csource/csource.go | 8 +++++--- pkg/csource/csource_test.go | 1 + pkg/csource/options.go | 10 +++++++--- pkg/csource/options_test.go | 11 +++++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) (limited to 'pkg/csource') diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go index b53b3b97f..a01141567 100644 --- a/pkg/csource/csource.go +++ b/pkg/csource/csource.go @@ -29,6 +29,7 @@ import ( "regexp" "sort" "strings" + "time" "github.com/google/syzkaller/prog" "github.com/google/syzkaller/sys/targets" @@ -93,11 +94,12 @@ func Write(p *prog.Prog, opts Options) ([]byte, error) { replacements["SANDBOX_FUNC"] = replacements["SYSCALLS"] replacements["SYSCALLS"] = "unused" } - replacements["PROGRAM_TIMEOUT_MS"] = "5000" - timeoutExpr := "45" + timeouts := ctx.sysTarget.Timeouts(opts.Slowdown) + replacements["PROGRAM_TIMEOUT_MS"] = fmt.Sprint(int(timeouts.Program / time.Millisecond)) + timeoutExpr := fmt.Sprint(int(timeouts.Syscall / time.Millisecond)) for i, call := range p.Calls { if timeout := call.Meta.Attrs.Timeout; timeout != 0 { - timeoutExpr += fmt.Sprintf(" + (call == %d ? %d : 0)", i, timeout) + timeoutExpr += fmt.Sprintf(" + (call == %v ? %v : 0)", i, timeout*uint64(timeouts.Scale)) } } replacements["CALL_TIMEOUT_MS"] = timeoutExpr diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go index f6d04b35c..951f9f09a 100644 --- a/pkg/csource/csource_test.go +++ b/pkg/csource/csource_test.go @@ -53,6 +53,7 @@ var executorOpts = Options{ Collide: true, Repeat: true, Procs: 2, + Slowdown: 1, Sandbox: "none", Repro: true, UseTmpDir: true, diff --git a/pkg/csource/options.go b/pkg/csource/options.go index ebea29fc2..3c1790483 100644 --- a/pkg/csource/options.go +++ b/pkg/csource/options.go @@ -23,6 +23,7 @@ type Options struct { Repeat bool `json:"repeat,omitempty"` RepeatTimes int `json:"repeat_times,omitempty"` // if non-0, repeat that many times Procs int `json:"procs"` + Slowdown int `json:"slowdown"` Sandbox string `json:"sandbox"` Fault bool `json:"fault,omitempty"` // inject fault into FaultCall/FaultNth @@ -154,6 +155,7 @@ func DefaultOpts(cfg *mgrconfig.Config) Options { Collide: true, Repeat: true, Procs: cfg.Procs, + Slowdown: cfg.Timeouts.Slowdown, Sandbox: cfg.Sandbox, UseTmpDir: true, HandleSegv: true, @@ -190,9 +192,11 @@ func (opts Options) Serialize() []byte { } func DeserializeOptions(data []byte) (Options, error) { - var opts Options - // Before CloseFDs was added, close_fds() was always called, so default to true. - opts.CloseFDs = true + opts := Options{ + Slowdown: 1, + // Before CloseFDs was added, close_fds() was always called, so default to true. + CloseFDs: true, + } if err := json.Unmarshal(data, &opts); err == nil { return opts, nil } diff --git a/pkg/csource/options_test.go b/pkg/csource/options_test.go index b9594e341..cd247fada 100644 --- a/pkg/csource/options_test.go +++ b/pkg/csource/options_test.go @@ -37,6 +37,7 @@ func TestParseOptionsCanned(t *testing.T) { Collide: true, Repeat: true, Procs: 10, + Slowdown: 1, Sandbox: "namespace", Fault: true, FaultCall: 1, @@ -59,6 +60,7 @@ func TestParseOptionsCanned(t *testing.T) { Collide: true, Repeat: true, Procs: 10, + Slowdown: 1, Sandbox: "android", Fault: true, FaultCall: 1, @@ -78,6 +80,7 @@ func TestParseOptionsCanned(t *testing.T) { Collide: true, Repeat: true, Procs: 1, + Slowdown: 1, Sandbox: "none", Fault: false, FaultCall: -1, @@ -95,6 +98,7 @@ func TestParseOptionsCanned(t *testing.T) { Collide: true, Repeat: true, Procs: 1, + Slowdown: 1, Sandbox: "", Fault: false, FaultCall: -1, @@ -112,6 +116,7 @@ func TestParseOptionsCanned(t *testing.T) { Collide: true, Repeat: true, Procs: 1, + Slowdown: 1, Sandbox: "namespace", Fault: false, FaultCall: -1, @@ -147,6 +152,7 @@ func allOptionsSingle(OS string) []Options { Repeat: true, Sandbox: "none", UseTmpDir: true, + Slowdown: 1, } opts = append(opts, enumerateField(OS, opt, i)...) } @@ -200,6 +206,11 @@ func enumerateField(OS string, opt Options, field int) []Options { fld.SetInt(times) opts = append(opts, opt) } + } else if fldName == "Slowdown" { + for _, val := range []int64{1, 10} { + fld.SetInt(val) + opts = append(opts, opt) + } } else if fldName == "FaultCall" { opts = append(opts, opt) } else if fldName == "FaultNth" { -- cgit mrf-deployment