| 1 |
// Copyright 2023 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
// Regression test for #55160. |
| 6 |
// |
| 7 |
// The issue is that the parser reads ahead to the first batch of the |
| 8 |
// next generation to find generation boundaries, but if it finds an |
| 9 |
// error, it needs to delay handling that error until later. Previously |
| 10 |
// it would handle that error immediately and a totally valid generation |
| 11 |
// would be skipped for parsing and rejected because of an error in a |
| 12 |
// batch in the following generation. |
| 13 |
// |
| 14 |
// This test captures this behavior by making both the first generation |
| 15 |
// and second generation bad. It requires that the issue in the first |
| 16 |
// generation, which is caught when actually ordering events, be reported |
| 17 |
// instead of the second one. |
| 18 |
|
| 19 |
package main |
| 20 |
|
| 21 |
import ( |
| 22 |
"internal/trace/internal/testgen" |
| 23 |
"internal/trace/tracev2" |
| 24 |
"internal/trace/version" |
| 25 |
) |
| 26 |
|
| 27 |
func main() { |
| 28 |
testgen.Main(version.Go122, gen) |
| 29 |
} |
| 30 |
|
| 31 |
func gen(t *testgen.Trace) { |
| 32 |
// A running goroutine emits a task begin. |
| 33 |
t.RawEvent(tracev2.EvEventBatch, nil, 1 /*gen*/, 0 /*thread ID*/, 0 /*timestamp*/, 5 /*batch length*/) |
| 34 |
t.RawEvent(tracev2.EvFrequency, nil, 15625000) |
| 35 |
|
| 36 |
// A running goroutine emits a task begin. |
| 37 |
t.RawEvent(tracev2.EvEventBatch, nil, 1 /*gen*/, 0 /*thread ID*/, 0 /*timestamp*/, 5 /*batch length*/) |
| 38 |
t.RawEvent(tracev2.EvGoCreate, nil, 0 /*timestamp delta*/, 1 /*go ID*/, 0, 0) |
| 39 |
|
| 40 |
// Write an invalid batch event for the next generation. |
| 41 |
t.RawEvent(tracev2.EvEventBatch, nil, 2 /*gen*/, 0 /*thread ID*/, 0 /*timestamp*/, 50 /*batch length (invalid)*/) |
| 42 |
|
| 43 |
// We should fail at the first issue, not the second one. |
| 44 |
t.ExpectFailure("expected a proc but didn't have one") |
| 45 |
} |