From 2b4970017d38fd9b148939c7acdbf704c232f1dc Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 20 Dec 2018 13:21:33 +0100 Subject: pkg/report: fix Start/EndPos calculation for fuchsia We computed Start/EndPos after trimming line prefix, this resulted in offsetted values which are not correct. Fix that. Add more tests and checks for Start/EndPos. --- pkg/report/fuchsia.go | 6 +++--- pkg/report/report_test.go | 23 +++++++++++++++++++++-- pkg/report/testdata/fuchsia/report/30 | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 pkg/report/testdata/fuchsia/report/30 (limited to 'pkg') diff --git a/pkg/report/fuchsia.go b/pkg/report/fuchsia.go index 5e80501ab..cafef6bd2 100644 --- a/pkg/report/fuchsia.go +++ b/pkg/report/fuchsia.go @@ -74,7 +74,7 @@ func (ctx *fuchsia) Parse(output []byte) *Report { func (ctx *fuchsia) shortenReport(report []byte) []byte { out := new(bytes.Buffer) for s := bufio.NewScanner(bytes.NewReader(report)); s.Scan(); { - line := s.Bytes() + line := zirconLinePrefix.ReplaceAll(s.Bytes(), nil) if matchesAny(line, zirconUnrelated) { continue } @@ -92,7 +92,7 @@ func (ctx *fuchsia) symbolize(output []byte) []byte { defer symb.Close() out := new(bytes.Buffer) for s := bufio.NewScanner(bytes.NewReader(output)); s.Scan(); { - line := zirconLinePrefix.ReplaceAll(s.Bytes(), nil) + line := s.Bytes() if bytes.Contains(line, zirconAssertFailed) && len(line) == 127 { // This is super hacky: but zircon splits the most important information in long assert lines // (and they are always long) into several lines in irreversible way. Try to restore full line. @@ -324,7 +324,7 @@ var zirconOopses = []*oops{ []oopsFormat{ { title: compile("panic: .*"), - report: compile("panic: (.*)(?:.*\\n)+?goroutine"), + report: compile("panic: (.*)(?:.*\\n)+?.* goroutine"), fmt: "panic: %[1]v", noStackTrace: true, }, diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go index d5e381dda..9943add00 100644 --- a/pkg/report/report_test.go +++ b/pkg/report/report_test.go @@ -168,8 +168,21 @@ func testParseImpl(t *testing.T, reporter Reporter, test *ParseTest) { if title != "" && len(rep.Report) == 0 { t.Fatalf("found crash message but report is empty") } - if rep != nil { - checkReport(t, rep, test) + if rep == nil { + return + } + checkReport(t, rep, test) + if rep.StartPos != 0 { + // If we parse from StartPos, we must find the same report. + rep1 := reporter.Parse(test.Log[rep.StartPos:]) + if rep1 == nil || rep1.Title != rep.Title { + t.Fatalf("did not find the same report from rep.StartPos=%v", rep.StartPos) + } + // If we parse from EndPos, we must not find the same report. + rep2 := reporter.Parse(test.Log[rep.EndPos:]) + if rep2 != nil && rep2.Title == rep.Title { + t.Fatalf("found the same report after rep.EndPos=%v", rep.EndPos) + } } } @@ -180,6 +193,12 @@ func checkReport(t *testing.T, rep *Report, test *ParseTest) { if !bytes.Equal(rep.Output, test.Log) { t.Fatalf("bad Output:\n%s", rep.Output) } + if rep.StartPos != 0 && rep.EndPos != 0 && rep.StartPos >= rep.EndPos { + t.Fatalf("StartPos=%v >= EndPos=%v", rep.StartPos, rep.EndPos) + } + if rep.EndPos > len(rep.Output) { + t.Fatalf("EndPos=%v > len(Output)=%v", rep.EndPos, len(rep.Output)) + } if test.StartLine != "" { if test.EndLine == "" { test.EndLine = test.StartLine diff --git a/pkg/report/testdata/fuchsia/report/30 b/pkg/report/testdata/fuchsia/report/30 new file mode 100644 index 000000000..c44516351 --- /dev/null +++ b/pkg/report/testdata/fuchsia/report/30 @@ -0,0 +1,22 @@ +TITLE: unexpected kernel reboot +START: [00000.000] 00000.00000> welcome to Zircon + +000> PMM: boot reserve marking WIRED [0x100000, 0x2b5fff] +[00000.000] 00000.00000> PMM: boot reserve marking WIRED [0x743000, 0xc4ffff] +[00000.000] 00000.00000> +[00000.000] 00000.00000> welcome to Zircon +[00000.000] 00000.00000> +[00000.000] 00000.00000> KASLR: .text section at 0xffffffff00100000 +[00000.000] 00000.00000> INIT: cpu 0, calling hook 0xffffffff001a12b8 (global_prng_seed) at level 0x30000, flags 0x1 +[00000.000] 00000.00000> initializing vm pre-heap +[00000.000] 00000.00000> VM: marking boot alloc used range [0xc50000, 0xc50040) +[00000.000] 00000.00000> INIT: cpu 0, calling hook 0xffffffff00142b08 (elf_build_id) at level 0x4fffe, flags 0x1 +[00000.000] 00000.00000> INIT: cpu 0, calling hook 0xffffffff00142c94 (version) at level 0x4ffff, flags 0x1 +[00000.000] 00000.00000> version: +[00000.000] 00000.00000> arch: x86 +[00000.000] 00000.00000> platform: pc +[00000.000] 00000.00000> target: pc +[00000.000] 00000.00000> project: x64 +[00000.000] 00000.00000> buildid: git-09a563b00c52cd79375e7ae0d212857ce1647c91 +[00000.000] 00000.00000> ELF build ID: a3466affc9bd84b3edf7d5bf0ee25bbfb043a5dd +[00000.000] 00000.00000> initializing heap -- cgit mrf-deployment