aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-01-02 13:07:33 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-01-03 10:45:55 +0100
commit188f3a75e1064bb2e6e53ba5b4fef50a3bd8048f (patch)
tree82f8207d5d29a856080d0b2a73b616d37fdd1293
parentab32d50881df9f96f2af301aadca62ad00b7e099 (diff)
dashboard: factor out asset list extraction code
It's useful not only during BugReporting creation, so extract it to a separate function and move to asset_storage.go.
-rw-r--r--dashboard/app/asset_storage.go43
-rw-r--r--dashboard/app/reporting.go39
2 files changed, 44 insertions, 38 deletions
diff --git a/dashboard/app/asset_storage.go b/dashboard/app/asset_storage.go
index 5849977ca..fba449223 100644
--- a/dashboard/app/asset_storage.go
+++ b/dashboard/app/asset_storage.go
@@ -7,10 +7,12 @@ import (
"errors"
"fmt"
"net/http"
+ "sort"
"time"
"github.com/google/syzkaller/dashboard/dashapi"
"github.com/google/syzkaller/pkg/asset"
+ "github.com/google/syzkaller/sys/targets"
"golang.org/x/net/context"
"golang.org/x/sync/errgroup"
"google.golang.org/appengine/v2"
@@ -485,3 +487,44 @@ func queryLatestManagerAssets(c context.Context, ns string, assetType dashapi.As
}
return ret, nil
}
+
+func createAssetList(build *Build, crash *Crash) []dashapi.Asset {
+ assetList := []dashapi.Asset{}
+ for _, reportAsset := range append(build.Assets, crash.Assets...) {
+ typeDescr := asset.GetTypeDescription(reportAsset.Type)
+ if typeDescr == nil || typeDescr.NoReporting {
+ continue
+ }
+ assetList = append(assetList, dashapi.Asset{
+ Title: typeDescr.GetTitle(targets.Get(build.OS, build.Arch)),
+ DownloadURL: reportAsset.DownloadURL,
+ Type: reportAsset.Type,
+ })
+ }
+ sort.SliceStable(assetList, func(i, j int) bool {
+ return asset.GetTypeDescription(assetList[i].Type).ReportingPrio <
+ asset.GetTypeDescription(assetList[j].Type).ReportingPrio
+ })
+ handleDupAssetTitles(assetList)
+ return assetList
+}
+
+// Convert asset lists like {"Mounted image", "Mounted image"} to {"Mounted image #1", "Mounted image #2"}.
+func handleDupAssetTitles(assetList []dashapi.Asset) {
+ duplicates := map[string]bool{}
+ for _, asset := range assetList {
+ if _, ok := duplicates[asset.Title]; ok {
+ duplicates[asset.Title] = true
+ } else {
+ duplicates[asset.Title] = false
+ }
+ }
+ counts := map[string]int{}
+ for i, asset := range assetList {
+ if !duplicates[asset.Title] {
+ continue
+ }
+ counts[asset.Title]++
+ assetList[i].Title = fmt.Sprintf("%s #%d", asset.Title, counts[asset.Title])
+ }
+}
diff --git a/dashboard/app/reporting.go b/dashboard/app/reporting.go
index 273ac3dec..bb595686b 100644
--- a/dashboard/app/reporting.go
+++ b/dashboard/app/reporting.go
@@ -13,7 +13,6 @@ import (
"time"
"github.com/google/syzkaller/dashboard/dashapi"
- "github.com/google/syzkaller/pkg/asset"
"github.com/google/syzkaller/pkg/email"
"github.com/google/syzkaller/pkg/html"
"github.com/google/syzkaller/sys/targets"
@@ -458,23 +457,7 @@ func crashBugReport(c context.Context, bug *Bug, crash *Crash, crashKey *db.Key,
if !bugReporting.Reported.IsZero() {
typ = dashapi.ReportRepro
}
- assetList := []dashapi.Asset{}
- for _, reportAsset := range append(build.Assets, crash.Assets...) {
- typeDescr := asset.GetTypeDescription(reportAsset.Type)
- if typeDescr == nil || typeDescr.NoReporting {
- continue
- }
- assetList = append(assetList, dashapi.Asset{
- Title: typeDescr.GetTitle(targets.Get(build.OS, build.Arch)),
- DownloadURL: reportAsset.DownloadURL,
- Type: reportAsset.Type,
- })
- }
- sort.SliceStable(assetList, func(i, j int) bool {
- return asset.GetTypeDescription(assetList[i].Type).ReportingPrio <
- asset.GetTypeDescription(assetList[j].Type).ReportingPrio
- })
- handleDupAssetTitles(assetList)
+ assetList := createAssetList(build, crash)
kernelRepo := kernelRepoInfo(build)
rep := &dashapi.BugReport{
Type: typ,
@@ -521,26 +504,6 @@ func crashBugReport(c context.Context, bug *Bug, crash *Crash, crashKey *db.Key,
return rep, nil
}
-// Convert asset lists like {"Mounted image", "Mounted image"} to {"Mounted image #1", "Mounted image #2"}.
-func handleDupAssetTitles(assetList []dashapi.Asset) {
- duplicates := map[string]bool{}
- for _, asset := range assetList {
- if _, ok := duplicates[asset.Title]; ok {
- duplicates[asset.Title] = true
- } else {
- duplicates[asset.Title] = false
- }
- }
- counts := map[string]int{}
- for i, asset := range assetList {
- if !duplicates[asset.Title] {
- continue
- }
- counts[asset.Title]++
- assetList[i].Title = fmt.Sprintf("%s #%d", asset.Title, counts[asset.Title])
- }
-}
-
func loadReproSyz(c context.Context, crash *Crash) ([]byte, error) {
reproSyz, _, err := getText(c, textReproSyz, crash.ReproSyz)
if err != nil || len(reproSyz) == 0 {