Source file src/internal/trace/testdata/generators/go122-fail-first-gen-first.go
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/event/go122" 23 testgen "internal/trace/internal/testgen/go122" 24 ) 25 26 func main() { 27 testgen.Main(gen) 28 } 29 30 func gen(t *testgen.Trace) { 31 // A running goroutine emits a task begin. 32 t.RawEvent(go122.EvEventBatch, nil, 1 /*gen*/, 0 /*thread ID*/, 0 /*timestamp*/, 5 /*batch length*/) 33 t.RawEvent(go122.EvFrequency, nil, 15625000) 34 35 // A running goroutine emits a task begin. 36 t.RawEvent(go122.EvEventBatch, nil, 1 /*gen*/, 0 /*thread ID*/, 0 /*timestamp*/, 5 /*batch length*/) 37 t.RawEvent(go122.EvGoCreate, nil, 0 /*timestamp delta*/, 1 /*go ID*/, 0, 0) 38 39 // Write an invalid batch event for the next generation. 40 t.RawEvent(go122.EvEventBatch, nil, 2 /*gen*/, 0 /*thread ID*/, 0 /*timestamp*/, 50 /*batch length (invalid)*/) 41 42 // We should fail at the first issue, not the second one. 43 t.ExpectFailure("expected a proc but didn't have one") 44 } 45