Commit 5fdea343 authored by Russ Cox's avatar Russ Cox

runtime: revise TestSetPanicOnFault

We can't assume all those addresses are unmapped.
But at least one should be.

What we're really testing is that the program doesn't crash.

Fixes #8542.

LGTM=iant
R=golang-codereviews, iant, minux
CC=golang-codereviews
https://golang.org/cl/144120043
parent 2ed209ea
...@@ -157,8 +157,8 @@ var faultAddrs = []uint64{ ...@@ -157,8 +157,8 @@ var faultAddrs = []uint64{
// or else malformed. // or else malformed.
0xffffffffffffffff, 0xffffffffffffffff,
0xfffffffffffff001, 0xfffffffffffff001,
// no 0xffffffffffff0001; 0xffff0001 is mapped for 32-bit user space on OS X 0xffffffffffff0001,
// no 0xfffffffffff00001; 0xfff00001 is mapped for 32-bit user space sometimes on Linux 0xfffffffffff00001,
0xffffffffff000001, 0xffffffffff000001,
0xfffffffff0000001, 0xfffffffff0000001,
0xffffffff00000001, 0xffffffff00000001,
...@@ -182,26 +182,33 @@ func TestSetPanicOnFault(t *testing.T) { ...@@ -182,26 +182,33 @@ func TestSetPanicOnFault(t *testing.T) {
old := debug.SetPanicOnFault(true) old := debug.SetPanicOnFault(true)
defer debug.SetPanicOnFault(old) defer debug.SetPanicOnFault(old)
nfault := 0
for _, addr := range faultAddrs { for _, addr := range faultAddrs {
testSetPanicOnFault(t, uintptr(addr)) testSetPanicOnFault(t, uintptr(addr), &nfault)
}
if nfault == 0 {
t.Fatalf("none of the addresses faulted")
} }
} }
func testSetPanicOnFault(t *testing.T, addr uintptr) { func testSetPanicOnFault(t *testing.T, addr uintptr, nfault *int) {
if GOOS == "nacl" { if GOOS == "nacl" {
t.Skip("nacl doesn't seem to fault on high addresses") t.Skip("nacl doesn't seem to fault on high addresses")
} }
defer func() { defer func() {
if err := recover(); err == nil { if err := recover(); err != nil {
t.Fatalf("did not find error in recover") *nfault++
} }
}() }()
// The read should fault, except that sometimes we hit
// addresses that have had C or kernel pages mapped there
// readable by user code. So just log the content.
// If no addresses fault, we'll fail the test.
var p *int var p *int
p = (*int)(unsafe.Pointer(addr)) p = (*int)(unsafe.Pointer(addr))
println(*p) t.Logf("addr %#x: %#x\n", addr, *p)
t.Fatalf("still here - should have faulted on address %#x", addr)
} }
func eqstring_generic(s1, s2 string) bool { func eqstring_generic(s1, s2 string) bool {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment