Skip to content

Commit 26c9c44

Browse files
committed
pkg/manager: store tail reports
1 parent cf472fe commit 26c9c44

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

dashboard/app/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,7 @@ func handleTextImpl(c context.Context, w http.ResponseWriter, r *http.Request, t
15351535
// https://bugs.chromium.org/p/chromium/issues/detail?id=608342
15361536
w.Header().Set("Content-Disposition", "inline; filename="+textFilename(tag))
15371537
augmentRepro(c, w, tag, bug, crash)
1538+
data = report.SplitReportBytes(data)[0]
15381539
w.Write(data)
15391540
return nil
15401541
}

pkg/manager/crash.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/google/syzkaller/pkg/log"
1818
"github.com/google/syzkaller/pkg/mgrconfig"
1919
"github.com/google/syzkaller/pkg/osutil"
20+
"github.com/google/syzkaller/pkg/report"
2021
"github.com/google/syzkaller/prog"
2122
)
2223

@@ -85,9 +86,10 @@ func (cs *CrashStore) SaveCrash(crash *Crash) (bool, error) {
8586
}
8687
osutil.WriteFile(filename, data)
8788
}
89+
reps := append([]*report.Report{crash.Report}, crash.TailReports...)
8890
writeOrRemove("log", crash.Output)
8991
writeOrRemove("tag", []byte(cs.Tag))
90-
writeOrRemove("report", crash.Report.Report)
92+
writeOrRemove("report", report.MergeReportBytes(reps))
9193
writeOrRemove("machineInfo", crash.MachineInfo)
9294

9395
return first, nil

pkg/report/report.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,3 +943,18 @@ func TitleToCrashType(title string) crash.Type {
943943
}
944944
return crash.UnknownType
945945
}
946+
947+
const reportSeparator = "\n<<<<<<<<<<<<<<< tail report >>>>>>>>>>>>>>>\n\n"
948+
949+
func MergeReportBytes(reps []*Report) []byte {
950+
var res []byte
951+
for _, rep := range reps {
952+
res = append(res, rep.Report...)
953+
res = append(res, []byte(reportSeparator)...)
954+
}
955+
return res
956+
}
957+
958+
func SplitReportBytes(data []byte) [][]byte {
959+
return bytes.Split(data, []byte(reportSeparator))
960+
}

pkg/report/report_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,38 @@ BCDEF`), Truncate([]byte(`0123456789ABCDEF`), 0, 5))
510510
511511
DEF`), Truncate([]byte(`0123456789ABCDEF`), 4, 3))
512512
}
513+
514+
func TestSplitReportBytes(t *testing.T) {
515+
tests := []struct {
516+
name string
517+
input []byte
518+
wantFirst string
519+
}{
520+
{
521+
name: "empty",
522+
input: nil,
523+
wantFirst: "",
524+
},
525+
{
526+
name: "single",
527+
input: []byte("report1"),
528+
wantFirst: "report1",
529+
},
530+
{
531+
name: "split in the middle",
532+
input: []byte("report1" + reportSeparator + "report2"),
533+
wantFirst: "report1",
534+
},
535+
{
536+
name: "split in the middle, save new line",
537+
input: []byte("report1\n" + reportSeparator + "report2"),
538+
wantFirst: "report1\n",
539+
},
540+
}
541+
for _, test := range tests {
542+
t.Run(test.name, func(t *testing.T) {
543+
splitted := SplitReportBytes(test.input)
544+
assert.Equal(t, test.wantFirst, string(splitted[0]))
545+
})
546+
}
547+
}

0 commit comments

Comments
 (0)