Skip to content

Commit 2a98149

Browse files
committed
add test case for issue golang#34391
1 parent 843fec1 commit 2a98149

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/runtime/crash_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,18 @@ func buildTestProg(t *testing.T, binary string, flags ...string) (string, error)
143143
return exe, nil
144144
}
145145

146-
func TestVDSO(t *testing.T) {
146+
func TestSIGPROFInVDSO(t *testing.T) {
147147
t.Parallel()
148-
output := runTestProg(t, "testprog", "SignalInVDSO")
148+
output := runTestProg(t, "testprog", "SIGPROFInVDSO")
149+
want := "success\n"
150+
if output != want {
151+
t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want)
152+
}
153+
}
154+
155+
func TestSIGUSR1InVDSO(t *testing.T) {
156+
t.Parallel()
157+
output := runTestProg(t, "testprog", "SIGUSR1InVDSO")
149158
want := "success\n"
150159
if output != want {
151160
t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want)

src/runtime/testdata/testprog/vdso.go

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// Invoke signal hander in the VDSO context (see issue 32912).
5+
// Invoke signal hander in the VDSO context.
6+
// See issue 32912 and 34391.
67

78
package main
89

910
import (
1011
"fmt"
1112
"io/ioutil"
1213
"os"
14+
"os/signal"
1315
"runtime/pprof"
16+
"syscall"
1417
"time"
1518
)
1619

1720
func init() {
18-
register("SignalInVDSO", signalInVDSO)
21+
register("SIGPROFInVDSO", signalSIGPROFInVDSO)
22+
register("SIGUSR1InVDSO", signalSIGUSR1InVDSO)
1923
}
2024

21-
func signalInVDSO() {
25+
func signalSIGPROFInVDSO() {
2226
f, err := ioutil.TempFile("", "timeprofnow")
2327
if err != nil {
2428
fmt.Fprintln(os.Stderr, err)
@@ -53,3 +57,40 @@ func signalInVDSO() {
5357

5458
fmt.Println("success")
5559
}
60+
61+
func signalSIGUSR1InVDSO() {
62+
done := make(chan struct {})
63+
64+
sigch := make(chan os.Signal, 1)
65+
signal.Notify(sigch, syscall.SIGUSR1)
66+
go func() {
67+
for {
68+
select {
69+
case <- done:
70+
return
71+
default:
72+
}
73+
}
74+
}()
75+
76+
p, _ := os.FindProcess(os.Getpid())
77+
go func() {
78+
for {
79+
p.Signal(syscall.SIGUSR1)
80+
select {
81+
case <- done:
82+
return
83+
default:
84+
}
85+
}
86+
}()
87+
88+
t0 := time.Now()
89+
t1 := t0
90+
for t1.Sub(t0) < 60 * time.Second {
91+
t1 = time.Now()
92+
}
93+
close(done)
94+
95+
fmt.Println("success")
96+
}

0 commit comments

Comments
 (0)