From 062c9832a6cdb39bf38ad7a6dad51300a2e9a734 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Thu, 1 Oct 2020 13:16:00 +0200 Subject: vm/vmimpl/merger: remove all CRs from output Get rid of all places stripping \r in pkg/report. And adapt all tests. Signed-off-by: Alexander Egorenkov --- pkg/report/akaros.go | 4 ++-- pkg/report/bsd.go | 12 +----------- pkg/report/freebsd.go | 40 ++++++++++++++++++---------------------- pkg/report/fuzz.go | 6 ++---- pkg/report/linux.go | 3 --- pkg/report/report.go | 4 ++-- pkg/report/report_test.go | 16 ++++++---------- 7 files changed, 31 insertions(+), 54 deletions(-) (limited to 'pkg') diff --git a/pkg/report/akaros.go b/pkg/report/akaros.go index 29c950cc4..ad0d3c3dd 100644 --- a/pkg/report/akaros.go +++ b/pkg/report/akaros.go @@ -54,7 +54,7 @@ func (ctx *akaros) Symbolize(rep *Report) error { var symbolized []byte s := bufio.NewScanner(bytes.NewReader(rep.Report)) for s.Scan() { - line := bytes.Trim(s.Bytes(), "\r") + line := s.Bytes() line = ctx.symbolizeLine(symb.Symbolize, ctx.objfile, line) symbolized = append(symbolized, line...) symbolized = append(symbolized, '\n') @@ -100,7 +100,7 @@ func (ctx *akaros) symbolizeLine(symbFunc func(bin string, pc uint64) ([]symboli func (ctx *akaros) minimizeReport(report []byte) []byte { out := new(bytes.Buffer) for s := bufio.NewScanner(bytes.NewReader(report)); s.Scan(); { - line := bytes.Trim(s.Bytes(), "\r") + line := s.Bytes() if len(line) == 0 || bytes.Contains(line, []byte("Entering Nanwan's Dungeon")) || bytes.Contains(line, []byte("Type 'help' for a list of commands")) { diff --git a/pkg/report/bsd.go b/pkg/report/bsd.go index d79c36b6c..327ddc8c6 100644 --- a/pkg/report/bsd.go +++ b/pkg/report/bsd.go @@ -50,17 +50,7 @@ func (ctx *bsd) ContainsCrash(output []byte) bool { } func (ctx *bsd) Parse(output []byte) *Report { - stripped := bytes.Replace(output, []byte{'\r', '\n'}, []byte{'\n'}, -1) - stripped = bytes.Replace(stripped, []byte{'\n', '\r'}, []byte{'\n'}, -1) - for len(stripped) != 0 && stripped[0] == '\r' { - stripped = stripped[1:] - } - rep := simpleLineParser(stripped, ctx.oopses, nil, ctx.ignores) - if rep == nil { - return nil - } - rep.Output = output - return rep + return simpleLineParser(output, ctx.oopses, nil, ctx.ignores) } func (ctx *bsd) Symbolize(rep *Report) error { diff --git a/pkg/report/freebsd.go b/pkg/report/freebsd.go index 4f6885ef9..e5a1fc92e 100644 --- a/pkg/report/freebsd.go +++ b/pkg/report/freebsd.go @@ -48,11 +48,7 @@ func (ctx *freebsd) Parse(output []byte) *Report { // Console output is indistinguishable from fuzzer output, // so we just collect everything after the oops. if oops != nil { - lineEnd := next - if lineEnd != 0 && output[lineEnd-1] == '\r' { - lineEnd-- - } - rep.Report = append(rep.Report, output[pos:lineEnd]...) + rep.Report = append(rep.Report, output[pos:next]...) rep.Report = append(rep.Report, '\n') } pos = next + 1 @@ -78,19 +74,19 @@ var freebsdOopses = append([]*oops{ []byte("Fatal trap"), []oopsFormat{ { - title: compile("Fatal trap (.+?)\\r?\\n(?:.*\\n)+?" + - "KDB: stack backtrace:\\r?\\n" + + title: compile("Fatal trap (.+?)\\n(?:.*\\n)+?" + + "KDB: stack backtrace:\\n" + "(?:#[0-9]+ {{ADDR}} at (?:kdb_backtrace|vpanic|panic|trap_fatal|" + "trap_pfault|trap|calltrap|m_copydata|__rw_wlock_hard)" + - "\\+{{ADDR}}\\r?\\n)*#[0-9]+ {{ADDR}} at {{FUNC}}{{ADDR}}"), + "\\+{{ADDR}}\\n)*#[0-9]+ {{ADDR}} at {{FUNC}}{{ADDR}}"), fmt: "Fatal trap %[1]v in %[2]v", }, { - title: compile("(Fatal trap [0-9]+:.*) while in (?:user|kernel) mode\\r?\\n(?:.*\\n)+?" + - "KDB: stack backtrace:\\r?\\n" + - "(?:[a-zA-Z0-9_]+\\(\\) at [a-zA-Z0-9_]+\\+0x.*\\r?\\n)*" + - "--- trap 0x[0-9a-fA-F]+.* ---\\r?\\n" + - "([a-zA-Z0-9_]+)\\(\\) at [a-zA-Z0-9_]+\\+0x.*\\r?\\n"), + title: compile("(Fatal trap [0-9]+:.*) while in (?:user|kernel) mode\\n(?:.*\\n)+?" + + "KDB: stack backtrace:\\n" + + "(?:[a-zA-Z0-9_]+\\(\\) at [a-zA-Z0-9_]+\\+0x.*\\n)*" + + "--- trap 0x[0-9a-fA-F]+.* ---\\n" + + "([a-zA-Z0-9_]+)\\(\\) at [a-zA-Z0-9_]+\\+0x.*\\n"), fmt: "%[1]v in %[2]v", }, }, @@ -109,27 +105,27 @@ var freebsdOopses = append([]*oops{ fmt: "panic: %[1]v of destroyed %[2]v at %[3]v", }, { - title: compile("panic: No chunks on the queues for sid [0-9]+\\.\\r?\\n"), + title: compile("panic: No chunks on the queues for sid [0-9]+\\.\\n"), fmt: "panic: sctp: no chunks on the queues", }, { - title: compile("panic: size_on_all_streams = [0-9]+ smaller than control length [0-9]+\\r?\\n"), + title: compile("panic: size_on_all_streams = [0-9]+ smaller than control length [0-9]+\\n"), fmt: "panic: size_on_all_streams smaller than control length", }, { - title: compile("panic: sbflush_internal: ccc [0-9]+ mb [0-9]+ mbcnt [0-9]+\\r?\\n"), + title: compile("panic: sbflush_internal: ccc [0-9]+ mb [0-9]+ mbcnt [0-9]+\\n"), fmt: "panic: sbflush_internal: residual data", }, { - title: compile("(panic: sx lock still held)\\r?\\n(?:.*\\n)+?" + - "KDB: stack backtrace:\\r?\\n" + - "(?:[a-zA-Z0-9_]+\\(\\) at [a-zA-Z0-9_]+\\+0x.*\\r?\\n)*" + - "sx_destroy\\(\\) at [a-zA-Z0-9_+/ ]+\\r?\\n" + - "([a-zA-Z0-9_]+)\\(\\) at [a-zA-Z0-9_+/ ]+\\+0x.*\\r?\\n"), + title: compile("(panic: sx lock still held)\\n(?:.*\\n)+?" + + "KDB: stack backtrace:\\n" + + "(?:[a-zA-Z0-9_]+\\(\\) at [a-zA-Z0-9_]+\\+0x.*\\n)*" + + "sx_destroy\\(\\) at [a-zA-Z0-9_+/ ]+\\n" + + "([a-zA-Z0-9_]+)\\(\\) at [a-zA-Z0-9_+/ ]+\\+0x.*\\n"), fmt: "%[1]v in %[2]v", }, { - title: compile("panic: pfi_dynaddr_setup: dyn is 0x[0-9a-f]+\\r?\\n"), + title: compile("panic: pfi_dynaddr_setup: dyn is 0x[0-9a-f]+\\n"), fmt: "panic: pfi_dynaddr_setup: non-NULL dyn", }, }, diff --git a/pkg/report/fuzz.go b/pkg/report/fuzz.go index 02f02c4db..0db602491 100644 --- a/pkg/report/fuzz.go +++ b/pkg/report/fuzz.go @@ -32,10 +32,8 @@ func Fuzz(data []byte) int { if len(rep.Output) == 0 { panic(fmt.Sprintf("%v: len(Output) == 0", typ)) } - switch os { - case "openbsd", "netbsd", "fuchsia": - // openbsd/netbsd has Start/End/SkipPos set incorrectly due to messing with /r/n. - // fuchsia because it symbolizes before parsing. + if os == "fuchsia" { + // Fuchsia has Start/End/SkipPos set incorrectly because it symbolizes before parsing. continue } if rep.StartPos != 0 && rep.EndPos != 0 && rep.StartPos >= rep.EndPos { diff --git a/pkg/report/linux.go b/pkg/report/linux.go index c8b6eee82..7d1e77f46 100644 --- a/pkg/report/linux.go +++ b/pkg/report/linux.go @@ -304,9 +304,6 @@ func (ctx *linux) findReport(output []byte, oops *oops, startPos int, context st } func (ctx *linux) stripLinePrefix(line []byte, context string, useQuestionable bool) ([]byte, bool) { - if last := len(line) - 1; last >= 0 && line[last] == '\r' { - line = line[:last] - } if context == "" { return line, false } diff --git a/pkg/report/report.go b/pkg/report/report.go index e42c692ad..d79540fb9 100644 --- a/pkg/report/report.go +++ b/pkg/report/report.go @@ -509,7 +509,7 @@ nextPart: for _, part := range parts { if part == parseStackTrace { for s.Scan() { - ln := bytes.Trim(s.Bytes(), "\r") + ln := s.Bytes() if matchesAny(ln, params.corruptedLines) { break nextPart } @@ -527,7 +527,7 @@ nextPart: } } else { for s.Scan() { - ln := bytes.Trim(s.Bytes(), "\r") + ln := s.Bytes() if matchesAny(ln, params.corruptedLines) { break nextPart } diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go index 39cd0deb6..1545a44e9 100644 --- a/pkg/report/report_test.go +++ b/pkg/report/report_test.go @@ -9,7 +9,6 @@ import ( "flag" "fmt" "io/ioutil" - "os" "path/filepath" "regexp" "strings" @@ -40,11 +39,12 @@ type ParseTest struct { } func testParseFile(t *testing.T, reporter Reporter, fn string) { - input, err := os.Open(fn) + data, err := ioutil.ReadFile(fn) if err != nil { t.Fatal(err) } - defer input.Close() + // Strip all \r from reports because the merger removes it. + data = bytes.ReplaceAll(data, []byte{'\r'}, nil) const ( phaseHeaders = iota phaseLog @@ -55,7 +55,7 @@ func testParseFile(t *testing.T, reporter Reporter, fn string) { FileName: fn, } prevEmptyLine := false - s := bufio.NewScanner(input) + s := bufio.NewScanner(bytes.NewReader(data)) for s.Scan() { switch phase { case phaseHeaders: @@ -86,10 +86,6 @@ func testParseFile(t *testing.T, reporter Reporter, fn string) { t.Fatalf("can't find log in input file") } testParseImpl(t, reporter, test) - // In some cases we get output with \r\n for line endings, - // ensure that regexps are not confused by this. - bytes.Replace(test.Log, []byte{'\n'}, []byte{'\r', '\n'}, -1) - testParseImpl(t, reporter, test) } func parseHeaderLine(t *testing.T, test *ParseTest, ln string) { @@ -388,8 +384,8 @@ func TestFuzz(t *testing.T) { "BUG:Disabling lock debugging due to kernel taint", "[0.0] WARNING: ? 0+0x0/0", "BUG: login: [0.0] ", - "cleaned vnod\re", - "kernel\r:", + "cleaned vnode", + "kernel:", } { Fuzz([]byte(data)[:len(data):len(data)]) } -- cgit mrf-deployment