Skip to content

Commit a5c987f

Browse files
committed
cmd/trace: trace error check and more logging in annotations test
This is for debugging the reported flaky tests. Update #24081 Change-Id: Ica046928f675d69e38251a47a6f225efedce920c Reviewed-on: https://go-review.googlesource.com/96855 Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 99843e2 commit a5c987f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/cmd/trace/annotations_test.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ func TestAnalyzeAnnotations(t *testing.T) {
6363
// TODO: classify taskless spans
6464

6565
// Run prog0 and capture the execution trace.
66-
traceProgram(prog0, "TestAnalyzeAnnotations")
66+
if err := traceProgram(prog0, "TestAnalyzeAnnotations"); err != nil {
67+
t.Fatalf("failed to trace the program: %v", err)
68+
}
6769

6870
res, err := analyzeAnnotations()
6971
if err != nil {
@@ -126,7 +128,9 @@ func prog1() {
126128

127129
func TestAnalyzeAnnotationTaskTree(t *testing.T) {
128130
// Run prog1 and capture the execution trace.
129-
traceProgram(prog1, "TestAnalyzeAnnotationTaskTree")
131+
if err := traceProgram(prog1, "TestAnalyzeAnnotationTaskTree"); err != nil {
132+
t.Fatalf("failed to trace the program: %v", err)
133+
}
130134

131135
res, err := analyzeAnnotations()
132136
if err != nil {
@@ -208,12 +212,15 @@ func prog2() (gcTime time.Duration) {
208212

209213
func TestAnalyzeAnnotationGC(t *testing.T) {
210214
var gcTime time.Duration
211-
traceProgram(func() {
215+
err := traceProgram(func() {
212216
oldGC := debug.SetGCPercent(10000) // gc, and effectively disable GC
213217
defer debug.SetGCPercent(oldGC)
214218

215219
gcTime = prog2()
216220
}, "TestAnalyzeAnnotationGC")
221+
if err != nil {
222+
t.Fatalf("failed to trace the program: %v", err)
223+
}
217224

218225
res, err := analyzeAnnotations()
219226
if err != nil {
@@ -241,6 +248,13 @@ func TestAnalyzeAnnotationGC(t *testing.T) {
241248
case "taskWithGC":
242249
if got <= 0 || got >= gcTime {
243250
t.Errorf("%s reported %v as overlapping GC time; want (0, %v): %v", task.name, got, gcTime, task)
251+
buf := new(bytes.Buffer)
252+
fmt.Fprintln(buf, "GC Events")
253+
for _, ev := range res.gcEvents {
254+
fmt.Fprintf(buf, " %s\n", ev)
255+
}
256+
fmt.Fprintf(buf, "%s\n", task)
257+
t.Logf("%s", buf)
244258
}
245259
case "taskWithoutGC":
246260
if got != 0 {
@@ -264,7 +278,7 @@ func traceProgram(f func(), name string) error {
264278
trace.Stop()
265279

266280
saveTrace(buf, name)
267-
res, err := traceparser.Parse(buf, "")
281+
res, err := traceparser.Parse(buf, name+".faketrace")
268282
if err != nil {
269283
return err
270284
}

0 commit comments

Comments
 (0)