From d041766f6c33a373e0064b832cc4e7a4401b3659 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 3 Oct 2024 17:43:17 +0200 Subject: pkg/manager: factor out the crash storage functionality It reduces the size of the syz-manager/ code and makes it testable. Use it in syz-testbed. --- tools/syz-reporter/reporter.go | 1 + tools/syz-testbed/stats.go | 32 +++++++------------------------- 2 files changed, 8 insertions(+), 25 deletions(-) (limited to 'tools') diff --git a/tools/syz-reporter/reporter.go b/tools/syz-reporter/reporter.go index 6fa4adc47..53ccce4c3 100644 --- a/tools/syz-reporter/reporter.go +++ b/tools/syz-reporter/reporter.go @@ -129,6 +129,7 @@ func collectCrashes(workdir string) ([]*UICrashType, error) { return crashTypes, nil } +// TODO: reuse manager.CrashStore. func readCrash(workdir, dir string) *UICrashType { if len(dir) != 40 { return nil diff --git a/tools/syz-testbed/stats.go b/tools/syz-testbed/stats.go index 185156a5d..6044bfe3d 100644 --- a/tools/syz-testbed/stats.go +++ b/tools/syz-testbed/stats.go @@ -8,10 +8,9 @@ import ( "fmt" "os" "path/filepath" - "strings" "time" - "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/pkg/manager" "github.com/google/syzkaller/pkg/stat/sample" ) @@ -51,33 +50,16 @@ type StatView struct { Groups []RunResultGroup } -// TODO: we're implementing this functionaity at least the 3rd time (see syz-manager/html -// and tools/reporter). Create a more generic implementation and put it into a globally -// visible package. func collectBugs(workdir string) ([]BugInfo, error) { - crashdir := filepath.Join(workdir, "crashes") - dirs, err := osutil.ListDir(crashdir) + list, err := manager.ReadCrashStore(workdir).BugList() if err != nil { return nil, err } - bugs := []BugInfo{} - for _, dir := range dirs { - bugFolder := filepath.Join(crashdir, dir) - titleBytes, err := os.ReadFile(filepath.Join(bugFolder, "description")) - if err != nil { - return nil, err - } - bug := BugInfo{ - Title: strings.TrimSpace(string(titleBytes)), - } - files, err := os.ReadDir(bugFolder) - if err != nil { - return nil, err - } - for _, f := range files { - if strings.HasPrefix(f.Name(), "log") { - bug.Logs = append(bug.Logs, filepath.Join(bugFolder, f.Name())) - } + var bugs []BugInfo + for _, info := range list { + bug := BugInfo{Title: info.Title} + for _, crash := range info.Crashes { + bug.Logs = append(bug.Logs, filepath.Join(workdir, crash.Log)) } bugs = append(bugs, bug) } -- cgit mrf-deployment