github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/syz-ci/jobs_test.go (about) 1 // Copyright 2019 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package main 5 6 import ( 7 "errors" 8 "fmt" 9 "testing" 10 11 "github.com/google/syzkaller/pkg/instance" 12 "github.com/google/syzkaller/pkg/report" 13 ) 14 15 func TestAggregateTestResults(t *testing.T) { 16 tests := []struct { 17 results []instance.EnvTestResult 18 title string 19 err error 20 rawOut []byte 21 }{ 22 { 23 results: []instance.EnvTestResult{{}, {}, {RawOutput: []byte{1, 2, 3}}}, 24 title: "", 25 err: nil, 26 rawOut: []byte{1, 2, 3}, 27 }, 28 { 29 results: []instance.EnvTestResult{ 30 {Error: &instance.CrashError{Report: &report.Report{Title: "title1"}}}, 31 {Error: &instance.CrashError{Report: &report.Report{Title: "title2"}}}, 32 {Error: &instance.CrashError{Report: &report.Report{Title: "title3"}}}, 33 }, 34 title: "title1", 35 err: nil, 36 }, 37 { 38 results: []instance.EnvTestResult{ 39 {}, 40 {Error: &instance.CrashError{Report: &report.Report{Title: "title2"}}}, 41 {}, 42 }, 43 title: "title2", 44 err: nil, 45 }, 46 { 47 results: []instance.EnvTestResult{ 48 {Error: &instance.TestError{Title: "test error1"}}, 49 {Error: &instance.CrashError{Report: &report.Report{Title: "title2"}}}, 50 {Error: &instance.TestError{Title: "test error2"}}, 51 }, 52 title: "title2", 53 err: nil, 54 }, 55 { 56 results: []instance.EnvTestResult{ 57 {Error: &instance.TestError{Title: "test error1"}}, 58 {Error: &instance.TestError{Title: "test error2"}}, 59 {}, 60 }, 61 title: "", 62 err: nil, 63 }, 64 { 65 results: []instance.EnvTestResult{ 66 {Error: &instance.TestError{Title: "test error1"}}, 67 {Error: &instance.TestError{Title: "test error2"}}, 68 {Error: &instance.TestError{Title: "test error3", Output: []byte("output")}}, 69 }, 70 title: "", 71 err: errors.New("test error3\n\noutput"), 72 }, 73 { 74 results: []instance.EnvTestResult{ 75 {Error: errors.New("infra error1")}, 76 {Error: errors.New("infra error2")}, 77 {Error: &instance.TestError{Title: "test error", Report: &report.Report{ 78 Title: "report title", 79 Report: []byte("report body"), 80 Output: []byte("output"), 81 }}}, 82 }, 83 title: "", 84 err: errors.New("report title\n\nreport body\n\noutput"), 85 }, 86 { 87 results: []instance.EnvTestResult{ 88 {Error: errors.New("infra error1")}, 89 {Error: errors.New("infra error2")}, 90 {Error: errors.New("infra error3")}, 91 }, 92 title: "", 93 err: errors.New("infra error3"), 94 }, 95 { 96 results: []instance.EnvTestResult{ 97 {Error: &instance.CrashError{Report: &report.Report{Title: "title1"}}}, 98 {Error: &instance.CrashError{ 99 Report: &report.Report{ 100 Title: "title2", 101 Report: []byte("report"), 102 }}, 103 RawOutput: []byte{2, 3, 4}, 104 }, 105 {Error: &instance.CrashError{Report: &report.Report{Title: "title3"}}}, 106 }, 107 title: "title2", 108 err: nil, 109 rawOut: []byte{2, 3, 4}, 110 }, 111 } 112 for i, test := range tests { 113 rep, err := aggregateTestResults(test.results) 114 if fmt.Sprint(err) != fmt.Sprint(test.err) { 115 t.Errorf("test #%v: got err: %q, want: %q", i, err, test.err) 116 } 117 got := "" 118 if rep != nil && rep.report != nil { 119 got = rep.report.Title 120 } 121 if got != test.title { 122 t.Errorf("test #%v: got title: %q, want: %q", i, got, test.title) 123 } 124 var gotOutput []byte 125 if rep != nil { 126 gotOutput = rep.rawOutput 127 } 128 if fmt.Sprint(test.rawOut) != fmt.Sprint(gotOutput) { 129 t.Errorf("test #%v: got raw out: %q, want: %q", i, gotOutput, test.rawOut) 130 } 131 } 132 }