From d4480042e9dcaa1d1a71222c8056a0b9b9c5bd9a Mon Sep 17 00:00:00 2001 From: Alexander Potapenko Date: Mon, 2 Dec 2024 15:27:50 +0100 Subject: syz-manager: pkg: skip seeds with mismatching requirements in fuzzing mode When running in the test mode, syz-manager already ignores tests that have arch requirements mismatching the target arch. Because the same tests are also used as seeds in the fuzzing mode, skip them likewise, instead of reporting errors if they contain arch-specific syscalls. The code and tests for parsing the requirements is moved from pkg/runtest to pkg/manager. --- pkg/runtest/run.go | 62 ++++--------------------------------------------- pkg/runtest/run_test.go | 21 ----------------- 2 files changed, 4 insertions(+), 79 deletions(-) (limited to 'pkg/runtest') diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go index 1ea5c7a7e..213ce3f58 100644 --- a/pkg/runtest/run.go +++ b/pkg/runtest/run.go @@ -14,6 +14,7 @@ import ( "bufio" "bytes" "context" + "errors" "fmt" "os" "path/filepath" @@ -305,13 +306,10 @@ func parseProg(target *prog.Target, dir, filename string, requires map[string]bo if err != nil { return nil, nil, nil, fmt.Errorf("failed to read %v: %w", filename, err) } - properties := parseRequires(data) - // Need to check arch requirement early as some programs - // may fail to deserialize on some arches due to missing syscalls. - if !checkArch(properties, target.Arch) || !match(properties, requires) { + p, properties, err := manager.ParseSeedWithRequirements(target, data, requires) + if errors.Is(err, manager.ErrSkippedTest) { return nil, nil, nil, nil } - p, err := manager.ParseSeedStrict(target, data) if err != nil { return nil, nil, nil, fmt.Errorf("failed to deserialize %v: %w", filename, err) } @@ -366,42 +364,11 @@ func parseProg(target *prog.Target, dir, filename string, requires map[string]bo return p, properties, info, nil } -func parseRequires(data []byte) map[string]bool { - requires := make(map[string]bool) - for s := bufio.NewScanner(bytes.NewReader(data)); s.Scan(); { - const prefix = "# requires:" - line := s.Text() - if !strings.HasPrefix(line, prefix) { - continue - } - for _, req := range strings.Fields(line[len(prefix):]) { - positive := true - if req[0] == '-' { - positive = false - req = req[1:] - } - requires[req] = positive - } - } - return requires -} - -func checkArch(requires map[string]bool, arch string) bool { - for req, positive := range requires { - const prefix = "arch=" - if strings.HasPrefix(req, prefix) && - arch != req[len(prefix):] == positive { - return false - } - } - return true -} - func (ctx *Context) produceTest(req *runRequest, name string, properties, requires map[string]bool, results *flatrpc.ProgInfo) { req.name = name req.results = results - if !match(properties, requires) { + if !manager.MatchRequirements(properties, requires) { req.skip = "excluded by constraints" } ctx.createTest(req) @@ -445,27 +412,6 @@ func (ctx *Context) submit(req *runRequest) { req.executor.Submit(req.Request) } -func match(props, requires map[string]bool) bool { - for req, positive := range requires { - if positive { - if !props[req] { - return false - } - continue - } - matched := true - for _, req1 := range strings.Split(req, ",") { - if !props[req1] { - matched = false - } - } - if matched { - return false - } - } - return true -} - func (ctx *Context) createSyzTest(p *prog.Prog, sandbox string, threaded, cov bool) (*runRequest, error) { var opts flatrpc.ExecOpts sandboxFlags, err := flatrpc.SandboxToFlags(sandbox) diff --git a/pkg/runtest/run_test.go b/pkg/runtest/run_test.go index 5d6235fd8..dd2c4a245 100644 --- a/pkg/runtest/run_test.go +++ b/pkg/runtest/run_test.go @@ -589,24 +589,3 @@ func TestParsing(t *testing.T) { } } } - -func TestRequires(t *testing.T) { - { - requires := parseRequires([]byte("# requires: manual arch=amd64")) - if !checkArch(requires, "amd64") { - t.Fatalf("amd64 does not pass check") - } - if checkArch(requires, "riscv64") { - t.Fatalf("riscv64 passes check") - } - } - { - requires := parseRequires([]byte("# requires: -arch=arm64 manual -arch=riscv64")) - if !checkArch(requires, "amd64") { - t.Fatalf("amd64 does not pass check") - } - if checkArch(requires, "riscv64") { - t.Fatalf("riscv64 passes check") - } - } -} -- cgit mrf-deployment