Skip to content

Commit 413d8a8

Browse files
committed
cmd/trace: skip tests if parsing fails with timestamp error
runtime/trace test already skips tests in case of the timestamp error. Moreover, relax TestAnalyzeAnnotationGC test condition to deal with the inaccuracy caused from use of cputicks in tracing. Fixes #24081 Updates #16755 Change-Id: I708ecc6da202eaec07e431085a75d3dbfbf4cc06 Reviewed-on: https://go-review.googlesource.com/97757 Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent b3f00c6 commit 413d8a8

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/cmd/trace/annotations_test.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestAnalyzeAnnotations(t *testing.T) {
9090
// TODO: classify taskless spans
9191

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

@@ -155,7 +155,7 @@ func prog1() {
155155

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

@@ -239,7 +239,7 @@ func prog2() (gcTime time.Duration) {
239239

240240
func TestAnalyzeAnnotationGC(t *testing.T) {
241241
var gcTime time.Duration
242-
err := traceProgram(func() {
242+
err := traceProgram(t, func() {
243243
oldGC := debug.SetGCPercent(10000) // gc, and effectively disable GC
244244
defer debug.SetGCPercent(oldGC)
245245

@@ -272,9 +272,19 @@ func TestAnalyzeAnnotationGC(t *testing.T) {
272272
for _, task := range res.tasks {
273273
got := task.overlappingGCDuration(res.gcEvents)
274274
switch task.name {
275+
case "taskWithoutGC":
276+
if got != 0 {
277+
t.Errorf("%s reported %v as overlapping GC time; want 0: %v", task.name, got, task)
278+
}
275279
case "taskWithGC":
276-
if got <= 0 || got >= gcTime {
277-
t.Errorf("%s reported %v as overlapping GC time; want (0, %v):\n%v", task.name, got, gcTime, task)
280+
upperBound := task.duration()
281+
// TODO(hyangah): a tighter upper bound is gcTime, but
282+
// use of it will make the test flaky due to the issue
283+
// described in golang.org/issue/16755. Tighten the upper
284+
// bound when the issue with the timestamp computed
285+
// based on clockticks is resolved.
286+
if got <= 0 || got > upperBound {
287+
t.Errorf("%s reported %v as overlapping GC time; want (0, %v):\n%v", task.name, got, upperBound, task)
278288
buf := new(bytes.Buffer)
279289
fmt.Fprintln(buf, "GC Events")
280290
for _, ev := range res.gcEvents {
@@ -287,10 +297,6 @@ func TestAnalyzeAnnotationGC(t *testing.T) {
287297

288298
t.Logf("\n%s", buf)
289299
}
290-
case "taskWithoutGC":
291-
if got != 0 {
292-
t.Errorf("%s reported %v as overlapping GC time; want 0: %v", task.name, got, task)
293-
}
294300
}
295301
}
296302
}
@@ -300,7 +306,8 @@ func TestAnalyzeAnnotationGC(t *testing.T) {
300306
// point to the parsed trace.
301307
//
302308
// If savetraces flag is set, the captured trace will be saved in the named file.
303-
func traceProgram(f func(), name string) error {
309+
func traceProgram(t *testing.T, f func(), name string) error {
310+
t.Helper()
304311
buf := new(bytes.Buffer)
305312
if err := trace.Start(buf); err != nil {
306313
return err
@@ -310,7 +317,9 @@ func traceProgram(f func(), name string) error {
310317

311318
saveTrace(buf, name)
312319
res, err := traceparser.Parse(buf, name+".faketrace")
313-
if err != nil {
320+
if err == traceparser.ErrTimeOrder {
321+
t.Skipf("skipping due to golang.org/issue/16755: %v", err)
322+
} else if err != nil {
314323
return err
315324
}
316325

0 commit comments

Comments
 (0)