aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/instance
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-01-21 11:44:27 +0100
committerAleksandr Nogikh <nogikh@google.com>2025-01-21 15:46:02 +0000
commitcce8ebd1002f4970df17ee9a7d9694a0a07fa965 (patch)
tree07857e8b826c1ace00a478b1cf83162a1419a55d /pkg/instance
parent6e87cfa299c98d36e79e8b8718a4126899a3ba2f (diff)
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.
Diffstat (limited to 'pkg/instance')
-rw-r--r--pkg/instance/instance.go39
1 files changed, 39 insertions, 0 deletions
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
+}