]> Cypherpunks repositories - gostls13.git/commitdiff
test: fix recover4 test on 64kb systems
authorDave Cheney <dave@cheney.net>
Tue, 17 Mar 2015 03:56:04 +0000 (14:56 +1100)
committerDave Cheney <dave@cheney.net>
Tue, 17 Mar 2015 05:25:01 +0000 (05:25 +0000)
Fix recover4.go to work on 64kb systems.

Change-Id: I211cb048de1268a8bbac77c6f3a1e0b8c8277594
Reviewed-on: https://go-review.googlesource.com/7673
Reviewed-by: Minux Ma <minux@golang.org>
test/recover4.go

index 115d5a0eed767bcd4c48ab1b72543129c9805971..cda08138f9132370221370b94d5564bfa10444b9 100644 (file)
@@ -44,8 +44,10 @@ func main() {
        // so that memcopy can recover.
        debug.SetPanicOnFault(true)
 
-       // Map 64 kB block of data with 16 kB hole in middle.
-       data, err := syscall.Mmap(-1, 0, 64*1024, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
+       size := syscall.Getpagesize()
+
+       // Map 16 pages of data with a 4-page hole in the middle.
+       data, err := syscall.Mmap(-1, 0, 16*size, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
        if err != nil {
                log.Fatalf("mmap: %v", err)
        }
@@ -53,19 +55,19 @@ func main() {
        // Note: Cannot call syscall.Munmap, because Munmap checks
        // that you are unmapping a whole region returned by Mmap.
        // We are trying to unmap just a hole in the middle.
-       if _, _, err := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(unsafe.Pointer(&data[32*1024])), 16*1024, 0); err != 0 {
+       if _, _, err := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(unsafe.Pointer(&data[8*size])), uintptr(4*size), 0); err != 0 {
                log.Fatalf("munmap: %v", err)
        }
 
-       other := make([]byte, 64*1024)
+       other := make([]byte, 16*size)
 
        // Check that memcopy returns the actual amount copied
-       // before the fault (32kB - 5, the offset we skip in the argument).
+       // before the fault (8*size - 5, the offset we skip in the argument).
        n, err := memcopy(data[5:], other)
        if err == nil {
                log.Fatal("no error from memcopy across memory hole")
        }
-       if n != 32*1024-5 {
-               log.Fatal("memcopy returned %d, want %d", n, 32*1024-5)
+       if n != 8*size-5 {
+               log.Fatal("memcopy returned %d, want %d", n, 8*size-5)
        }
 }