...
Source file
src/runtime/runtime_mmap_test.go
Documentation: runtime
1
2
3
4
5
6
7
8 package runtime_test
9
10 import (
11 "runtime"
12 "testing"
13 "unsafe"
14 )
15
16
17
18
19 func TestMmapErrorSign(t *testing.T) {
20 p, err := runtime.Mmap(nil, ^uintptr(0)&^(runtime.GetPhysPageSize()-1), 0, runtime.MAP_ANON|runtime.MAP_PRIVATE, -1, 0)
21
22 if p != nil || err != runtime.ENOMEM {
23 t.Errorf("mmap = %v, %v, want nil, %v", p, err, runtime.ENOMEM)
24 }
25 }
26
27 func TestPhysPageSize(t *testing.T) {
28
29
30 ps := runtime.GetPhysPageSize()
31
32
33 b, err := runtime.Mmap(nil, 2*ps, 0, runtime.MAP_ANON|runtime.MAP_PRIVATE, -1, 0)
34 if err != 0 {
35 t.Fatalf("Mmap: %v", err)
36 }
37
38 if runtime.GOOS == "aix" {
39
40 runtime.Munmap(unsafe.Pointer(uintptr(b)), 2*ps)
41 }
42
43
44 _, err = runtime.Mmap(unsafe.Pointer(uintptr(b)+ps/2), ps, 0, runtime.MAP_ANON|runtime.MAP_PRIVATE|runtime.MAP_FIXED, -1, 0)
45 if err == 0 {
46 t.Errorf("Mmap should have failed with half-page alignment %d, but succeeded: %v", ps/2, err)
47 }
48
49
50 _, err = runtime.Mmap(unsafe.Pointer(uintptr(b)+ps), ps, 0, runtime.MAP_ANON|runtime.MAP_PRIVATE|runtime.MAP_FIXED, -1, 0)
51 if err != 0 {
52 t.Errorf("Mmap at full-page alignment %d failed: %v", ps, err)
53 }
54 }
55
View as plain text