golang.org/x/exp@v0.0.0-20240506185415-9bf2ced13842/trace/testdata/generators/go122-create-syscall-with-p.go (about) 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/v2; DO NOT EDIT. 6 7 //go:build go1.21 8 9 // Tests a G being created from within a syscall. 10 // 11 // Specifically, it tests a scenerio wherein a C 12 // thread is calling into Go, creating a goroutine in 13 // a syscall (in the tracer's model). Because the actual 14 // m can be reused, it's possible for that m to have never 15 // had its P (in _Psyscall) stolen if the runtime doesn't 16 // model the scenario correctly. Make sure we reject such 17 // traces. 18 19 package main 20 21 import ( 22 "golang.org/x/exp/trace" 23 "golang.org/x/exp/trace/internal/event/go122" 24 testgen "golang.org/x/exp/trace/internal/testgen/go122" 25 ) 26 27 func main() { 28 testgen.Main(gen) 29 } 30 31 func gen(t *testgen.Trace) { 32 t.ExpectFailure(".*expected a proc but didn't have one.*") 33 34 g := t.Generation(1) 35 36 // A C thread calls into Go and acquires a P. It returns 37 // back to C, destroying the G. It then comes back to Go 38 // on the same thread and again returns to C. 39 // 40 // Note: on pthread platforms this can't happen on the 41 // same thread because the m is stashed in TLS between 42 // calls into Go, until the thread dies. This is still 43 // possible on other platforms, however. 44 b0 := g.Batch(trace.ThreadID(0), 0) 45 b0.Event("GoCreateSyscall", trace.GoID(4)) 46 b0.Event("ProcStatus", trace.ProcID(0), go122.ProcIdle) 47 b0.Event("ProcStart", trace.ProcID(0), testgen.Seq(1)) 48 b0.Event("GoSyscallEndBlocked") 49 b0.Event("GoStart", trace.GoID(4), testgen.Seq(1)) 50 b0.Event("GoSyscallBegin", testgen.Seq(2), testgen.NoStack) 51 b0.Event("GoDestroySyscall") 52 b0.Event("GoCreateSyscall", trace.GoID(4)) 53 b0.Event("GoSyscallEnd") 54 b0.Event("GoSyscallBegin", testgen.Seq(3), testgen.NoStack) 55 b0.Event("GoDestroySyscall") 56 }