Skip to content

Commit

Permalink
cmd/trace: trace error check and more logging in annotations test
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
hyangah committed Feb 26, 2018
1 parent 99843e2 commit a5c987f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/cmd/trace/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func TestAnalyzeAnnotations(t *testing.T) {
// TODO: classify taskless spans

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

res, err := analyzeAnnotations()
if err != nil {
Expand Down Expand Up @@ -126,7 +128,9 @@ func prog1() {

func TestAnalyzeAnnotationTaskTree(t *testing.T) {
// Run prog1 and capture the execution trace.
traceProgram(prog1, "TestAnalyzeAnnotationTaskTree")
if err := traceProgram(prog1, "TestAnalyzeAnnotationTaskTree"); err != nil {
t.Fatalf("failed to trace the program: %v", err)
}

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

func TestAnalyzeAnnotationGC(t *testing.T) {
var gcTime time.Duration
traceProgram(func() {
err := traceProgram(func() {
oldGC := debug.SetGCPercent(10000) // gc, and effectively disable GC
defer debug.SetGCPercent(oldGC)

gcTime = prog2()
}, "TestAnalyzeAnnotationGC")
if err != nil {
t.Fatalf("failed to trace the program: %v", err)
}

res, err := analyzeAnnotations()
if err != nil {
Expand Down Expand Up @@ -241,6 +248,13 @@ func TestAnalyzeAnnotationGC(t *testing.T) {
case "taskWithGC":
if got <= 0 || got >= gcTime {
t.Errorf("%s reported %v as overlapping GC time; want (0, %v): %v", task.name, got, gcTime, task)
buf := new(bytes.Buffer)
fmt.Fprintln(buf, "GC Events")
for _, ev := range res.gcEvents {
fmt.Fprintf(buf, " %s\n", ev)
}
fmt.Fprintf(buf, "%s\n", task)
t.Logf("%s", buf)
}
case "taskWithoutGC":
if got != 0 {
Expand All @@ -264,7 +278,7 @@ func traceProgram(f func(), name string) error {
trace.Stop()

saveTrace(buf, name)
res, err := traceparser.Parse(buf, "")
res, err := traceparser.Parse(buf, name+".faketrace")
if err != nil {
return err
}
Expand Down

0 comments on commit a5c987f

Please sign in to comment.