Skip to content

Commit 1f3fe91

Browse files
committed
test: fix recover4 test on 64kb systems
Fix recover4.go to work on 64kb systems. Change-Id: I211cb048de1268a8bbac77c6f3a1e0b8c8277594 Reviewed-on: https://go-review.googlesource.com/7673 Reviewed-by: Minux Ma <[email protected]>
1 parent 4eb9302 commit 1f3fe91

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

test/recover4.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,30 @@ func main() {
4444
// so that memcopy can recover.
4545
debug.SetPanicOnFault(true)
4646

47-
// Map 64 kB block of data with 16 kB hole in middle.
48-
data, err := syscall.Mmap(-1, 0, 64*1024, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
47+
size := syscall.Getpagesize()
48+
49+
// Map 16 pages of data with a 4-page hole in the middle.
50+
data, err := syscall.Mmap(-1, 0, 16*size, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
4951
if err != nil {
5052
log.Fatalf("mmap: %v", err)
5153
}
5254

5355
// Note: Cannot call syscall.Munmap, because Munmap checks
5456
// that you are unmapping a whole region returned by Mmap.
5557
// We are trying to unmap just a hole in the middle.
56-
if _, _, err := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(unsafe.Pointer(&data[32*1024])), 16*1024, 0); err != 0 {
58+
if _, _, err := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(unsafe.Pointer(&data[8*size])), uintptr(4*size), 0); err != 0 {
5759
log.Fatalf("munmap: %v", err)
5860
}
5961

60-
other := make([]byte, 64*1024)
62+
other := make([]byte, 16*size)
6163

6264
// Check that memcopy returns the actual amount copied
63-
// before the fault (32kB - 5, the offset we skip in the argument).
65+
// before the fault (8*size - 5, the offset we skip in the argument).
6466
n, err := memcopy(data[5:], other)
6567
if err == nil {
6668
log.Fatal("no error from memcopy across memory hole")
6769
}
68-
if n != 32*1024-5 {
69-
log.Fatal("memcopy returned %d, want %d", n, 32*1024-5)
70+
if n != 8*size-5 {
71+
log.Fatal("memcopy returned %d, want %d", n, 8*size-5)
7072
}
7173
}

0 commit comments

Comments
 (0)