Skip to content

Commit 6dd3bfb

Browse files
committed
runtime: move Segv and TgkillSegv to testprog
The non-cgo test points Segv and TgkillSegv are currently in testprogcgo. Although the test points don't explicitly use cgo, being a cgo program, there is still some C code that runs when the test point is invoked, such as thread creation code. For the cgo test points, sometimes we fail to unwind the stack if C code is involved. For the non-cgo ones, we want to always be able to unwind the stack, so we check for stack unwinding failures. But if a signal is landed in the small piece of C code mentioned above, we may still fail to unwind. Move the non-cgo test points to a pure-Go program to avoid this problem. May fix #52963. Updates #59029, #59443, #59492. Change-Id: I35d99a0dd4c7cdb627e2083d2414887a24a2822d Reviewed-on: https://go-review.googlesource.com/c/go/+/500535 Reviewed-by: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Cherry Mui <[email protected]>
1 parent 96b79bd commit 6dd3bfb

File tree

5 files changed

+66
-41
lines changed

5 files changed

+66
-41
lines changed

src/runtime/crash_cgo_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,11 @@ func TestSegv(t *testing.T) {
648648
}
649649

650650
t.Parallel()
651-
got := runTestProg(t, "testprogcgo", test)
651+
prog := "testprog"
652+
if strings.HasSuffix(test, "InCgo") {
653+
prog = "testprogcgo"
654+
}
655+
got := runTestProg(t, prog, test)
652656
t.Log(got)
653657
want := "SIGSEGV"
654658
if !strings.Contains(got, want) {

src/runtime/testdata/testprog/segv.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2020 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+
//go:build unix
6+
7+
package main
8+
9+
import "syscall"
10+
11+
func init() {
12+
register("Segv", Segv)
13+
}
14+
15+
var Sum int
16+
17+
func Segv() {
18+
c := make(chan bool)
19+
go func() {
20+
close(c)
21+
for i := 0; ; i++ {
22+
Sum += i
23+
}
24+
}()
25+
26+
<-c
27+
28+
syscall.Kill(syscall.Getpid(), syscall.SIGSEGV)
29+
30+
// Wait for the OS to deliver the signal.
31+
select {}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2022 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+
package main
6+
7+
import "syscall"
8+
9+
func init() {
10+
register("TgkillSegv", TgkillSegv)
11+
}
12+
13+
func TgkillSegv() {
14+
c := make(chan bool)
15+
go func() {
16+
close(c)
17+
for i := 0; ; i++ {
18+
// Sum defined in segv.go.
19+
Sum += i
20+
}
21+
}()
22+
23+
<-c
24+
25+
syscall.Tgkill(syscall.Getpid(), syscall.Gettid(), syscall.SIGSEGV)
26+
27+
// Wait for the OS to deliver the signal.
28+
select {}
29+
}

src/runtime/testdata/testprogcgo/segv.go

-21
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build unix
6-
// +build unix
76

87
package main
98

@@ -14,29 +13,9 @@ import "C"
1413
import "syscall"
1514

1615
func init() {
17-
register("Segv", Segv)
1816
register("SegvInCgo", SegvInCgo)
1917
}
2018

21-
var Sum int
22-
23-
func Segv() {
24-
c := make(chan bool)
25-
go func() {
26-
close(c)
27-
for i := 0; ; i++ {
28-
Sum += i
29-
}
30-
}()
31-
32-
<-c
33-
34-
syscall.Kill(syscall.Getpid(), syscall.SIGSEGV)
35-
36-
// Wait for the OS to deliver the signal.
37-
C.pause()
38-
}
39-
4019
func SegvInCgo() {
4120
c := make(chan bool)
4221
go func() {

src/runtime/testdata/testprogcgo/segv_linux.go

-19
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,9 @@ import "C"
1111
import "syscall"
1212

1313
func init() {
14-
register("TgkillSegv", TgkillSegv)
1514
register("TgkillSegvInCgo", TgkillSegvInCgo)
1615
}
1716

18-
func TgkillSegv() {
19-
c := make(chan bool)
20-
go func() {
21-
close(c)
22-
for i := 0; ; i++ {
23-
// Sum defined in segv.go.
24-
Sum += i
25-
}
26-
}()
27-
28-
<-c
29-
30-
syscall.Tgkill(syscall.Getpid(), syscall.Gettid(), syscall.SIGSEGV)
31-
32-
// Wait for the OS to deliver the signal.
33-
C.pause()
34-
}
35-
3617
func TgkillSegvInCgo() {
3718
c := make(chan bool)
3819
go func() {

0 commit comments

Comments
 (0)