diff options
author | Russ Cox <rsc@golang.org> | 2014-10-03 12:22:19 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-10-03 12:22:19 -0400 |
commit | c5aca6fedbdd83d9153f6a00dc656aaabb0774c5 (patch) | |
tree | 26952b971b307783cde4b126c0a133f62ac3c893 /src/runtime/runtime_test.go | |
parent | 4eb6792aa572c7e6d3448d4cf22223b61b65724f (diff) | |
parent | 338c7ea5df93e25ac4dc143970603a1e88b26124 (diff) | |
download | go-c5aca6fedbdd83d9153f6a00dc656aaabb0774c5.tar.gz |
[dev.garbage] merge default into dev.garbage
Diffstat (limited to 'src/runtime/runtime_test.go')
-rw-r--r-- | src/runtime/runtime_test.go | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/runtime/runtime_test.go b/src/runtime/runtime_test.go index cffc9f7d3..1688364a8 100644 --- a/src/runtime/runtime_test.go +++ b/src/runtime/runtime_test.go @@ -157,8 +157,8 @@ var faultAddrs = []uint64{ // or else malformed. 0xffffffffffffffff, 0xfffffffffffff001, - // no 0xffffffffffff0001; 0xffff0001 is mapped for 32-bit user space on OS X - // no 0xfffffffffff00001; 0xfff00001 is mapped for 32-bit user space sometimes on Linux + 0xffffffffffff0001, + 0xfffffffffff00001, 0xffffffffff000001, 0xfffffffff0000001, 0xffffffff00000001, @@ -182,26 +182,32 @@ func TestSetPanicOnFault(t *testing.T) { old := debug.SetPanicOnFault(true) defer debug.SetPanicOnFault(old) + nfault := 0 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" { t.Skip("nacl doesn't seem to fault on high addresses") } defer func() { - if err := recover(); err == nil { - t.Fatalf("did not find error in recover") + if err := recover(); err != nil { + *nfault++ } }() - var p *int - p = (*int)(unsafe.Pointer(addr)) - println(*p) - t.Fatalf("still here - should have faulted on address %#x", addr) + // 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. + v := *(*byte)(unsafe.Pointer(addr)) + t.Logf("addr %#x: %#x\n", addr, v) } func eqstring_generic(s1, s2 string) bool { |