Skip to content

Commit 5d04e76

Browse files
committed
add test case for #32912
1 parent aae0b5b commit 5d04e76

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/runtime/crash_test.go

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

146+
func TestVDSO(t *testing.T) {
147+
output := runTestProg(t, "testprog", "SignalInVDSO")
148+
want := "success\n"
149+
if output != want {
150+
t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want);
151+
}
152+
}
153+
146154
var (
147155
staleRuntimeOnce sync.Once // guards init of staleRuntimeErr
148156
staleRuntimeErr error

src/runtime/testdata/testprog/vdso.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2019 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+
// Invoke signal hander in the VDSO context (see issue 32912).
6+
7+
package main
8+
9+
import (
10+
"fmt"
11+
"io/ioutil"
12+
"os"
13+
"runtime/pprof"
14+
"time"
15+
)
16+
17+
func init() {
18+
register("SignalInVDSO", signalInVDSO)
19+
}
20+
21+
func signalInVDSO() {
22+
f, err := ioutil.TempFile("", "timeprofnow")
23+
if err != nil {
24+
fmt.Fprintln(os.Stderr, err)
25+
os.Exit(2)
26+
}
27+
28+
if err := pprof.StartCPUProfile(f); err != nil {
29+
fmt.Fprintln(os.Stderr, err)
30+
os.Exit(2)
31+
}
32+
33+
t0 := time.Now()
34+
t1 := t0
35+
// We should get a profiling signal 100 times a second,
36+
// so running for 10 seconds should be sufficient.
37+
for t1.Sub(t0) < 10*time.Second {
38+
t1 = time.Now()
39+
}
40+
41+
pprof.StopCPUProfile()
42+
43+
name := f.Name()
44+
if err := f.Close(); err != nil {
45+
fmt.Fprintln(os.Stderr, err)
46+
os.Exit(2)
47+
}
48+
49+
if err := os.Remove(name); err != nil {
50+
fmt.Fprintln(os.Stderr, err)
51+
os.Exit(2)
52+
}
53+
54+
fmt.Println("success");
55+
}

0 commit comments

Comments
 (0)