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