Debian Codegraph @

trace/testdata/generators/go122-fail-first-gen-first.go

raw symbols SCIP
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 // Code generated by "gen.bash" from internal/trace; DO NOT EDIT.
6
7 //go:build go1.23
8
9 // Regression test for #55160.
10 //
11 // The issue is that the parser reads ahead to the first batch of the
12 // next generation to find generation boundaries, but if it finds an
13 // error, it needs to delay handling that error until later. Previously
14 // it would handle that error immediately and a totally valid generation
15 // would be skipped for parsing and rejected because of an error in a
16 // batch in the following generation.
17 //
18 // This test captures this behavior by making both the first generation
19 // and second generation bad. It requires that the issue in the first
20 // generation, which is caught when actually ordering events, be reported
21 // instead of the second one.
22
23 package main
24
25 import (
26 "golang.org/x/exp/trace/internal/testgen"
27 "golang.org/x/exp/trace/internal/tracev2"
28 "golang.org/x/exp/trace/internal/version"
29 )
30
31 func main() {
32 testgen.Main(version.Go122, gen)
33 }
34
35 func gen(t *testgen.Trace) {
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.EvFrequency, nil, 15625000)
39
40 // A running goroutine emits a task begin.
41 t.RawEvent(tracev2.EvEventBatch, nil, 1 /*gen*/, 0 /*thread ID*/, 0 /*timestamp*/, 5 /*batch length*/)
42 t.RawEvent(tracev2.EvGoCreate, nil, 0 /*timestamp delta*/, 1 /*go ID*/, 0, 0)
43
44 // Write an invalid batch event for the next generation.
45 t.RawEvent(tracev2.EvEventBatch, nil, 2 /*gen*/, 0 /*thread ID*/, 0 /*timestamp*/, 50 /*batch length (invalid)*/)
46
47 // We should fail at the first issue, not the second one.
48 t.ExpectFailure("expected a proc but didn't have one")
49 }