github.com/etecs-ru/go-sys-wineventlog@v0.0.0-20210227233244-4c3abb794018/unix/mmap_unix_test.go (about) 1 // Copyright 2014 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris 6 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris 7 8 package unix_test 9 10 import ( 11 "runtime" 12 "testing" 13 14 "golang.org/x/sys/unix" 15 ) 16 17 func TestMmap(t *testing.T) { 18 b, err := unix.Mmap(-1, 0, unix.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE) 19 if err != nil { 20 t.Fatalf("Mmap: %v", err) 21 } 22 if err := unix.Mprotect(b, unix.PROT_READ|unix.PROT_WRITE); err != nil { 23 t.Fatalf("Mprotect: %v", err) 24 } 25 26 b[0] = 42 27 28 if runtime.GOOS == "aix" { 29 t.Skip("msync returns invalid argument for AIX, skipping msync test") 30 } else { 31 if err := unix.Msync(b, unix.MS_SYNC); err != nil { 32 t.Fatalf("Msync: %v", err) 33 } 34 } 35 36 if err := unix.Madvise(b, unix.MADV_DONTNEED); err != nil { 37 t.Fatalf("Madvise: %v", err) 38 } 39 if err := unix.Munmap(b); err != nil { 40 t.Fatalf("Munmap: %v", err) 41 } 42 }