From cce8ebd1002f4970df17ee9a7d9694a0a07fa965 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 21 Jan 2025 11:44:27 +0100 Subject: pkg/instance: extract the smoke test method Move the logic from syz-ci to pkg/instance to make it reusable. In case of a failure without a crash report, report the issue as a SYZFATAL crash instead of just printing to the error log. --- pkg/instance/instance.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'pkg/instance') diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index 411568e65..83a855e36 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -16,6 +16,7 @@ import ( "time" "github.com/google/syzkaller/pkg/build" + "github.com/google/syzkaller/pkg/config" "github.com/google/syzkaller/pkg/csource" "github.com/google/syzkaller/pkg/log" "github.com/google/syzkaller/pkg/mgrconfig" @@ -537,3 +538,41 @@ func (s *Semaphore) Signal() { } s.ch <- struct{}{} } + +// RunSmokeTest executes syz-manager in the smoke test mode and returns two values: +// The crash report, if the testing failed. +// An error if there was a problem not related to testing the kernel. +func RunSmokeTest(cfg *mgrconfig.Config) (*report.Report, error) { + if !vm.AllowsOvercommit(cfg.Type) { + return nil, nil // No support for creating machines out of thin air. + } + osutil.MkdirAll(cfg.Workdir) + configFile := filepath.Join(cfg.Workdir, "manager.cfg") + if err := config.SaveFile(configFile, cfg); err != nil { + return nil, err + } + timeout := 30 * time.Minute * cfg.Timeouts.Scale + bin := filepath.Join(cfg.Syzkaller, "bin", "syz-manager") + output, retErr := osutil.RunCmd(timeout, "", bin, "-config", configFile, "-mode=smoke-test") + if retErr == nil { + return nil, nil + } + // If there was a kernel bug, report it to dashboard. + // Otherwise just save the output in a temp file and log an error, unclear what else we can do. + reportData, err := os.ReadFile(filepath.Join(cfg.Workdir, "report.json")) + if err != nil { + if os.IsNotExist(err) { + rep := &report.Report{ + Title: "SYZFATAL: image testing failed w/o kernel bug", + Output: output, + } + return rep, nil + } + return nil, err + } + rep := new(report.Report) + if err := json.Unmarshal(reportData, rep); err != nil { + return nil, fmt.Errorf("failed to unmarshal smoke test report: %w", err) + } + return rep, nil +} -- cgit mrf-deployment