...
1
2
3
4
5
6
7 package unix_test
8
9 import (
10 "runtime"
11 "testing"
12
13 "golang.org/x/sys/unix"
14 )
15
16 func TestMmap(t *testing.T) {
17 mmapProt := unix.PROT_NONE
18 mprotectProt := unix.PROT_READ | unix.PROT_WRITE
19
20
21
22 if runtime.GOOS == "netbsd" {
23
24
25 mmapProt = mprotectProt << 3
26 }
27 b, err := unix.Mmap(-1, 0, unix.Getpagesize(), mmapProt, unix.MAP_ANON|unix.MAP_PRIVATE)
28 if err != nil {
29 t.Fatalf("Mmap: %v", err)
30 }
31 if err := unix.Mprotect(b, mprotectProt); err != nil {
32 t.Fatalf("Mprotect: %v", err)
33 }
34
35 b[0] = 42
36
37 if runtime.GOOS == "aix" {
38 t.Skip("msync returns invalid argument for AIX, skipping msync test")
39 } else {
40 if err := unix.Msync(b, unix.MS_SYNC); err != nil {
41 t.Fatalf("Msync: %v", err)
42 }
43 }
44
45 if err := unix.Madvise(b, unix.MADV_DONTNEED); err != nil {
46 t.Fatalf("Madvise: %v", err)
47 }
48 if err := unix.Munmap(b); err != nil {
49 t.Fatalf("Munmap: %v", err)
50 }
51 }
52
View as plain text