.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / sys@v0.0.0-20210124154548-22da62e12c0c / unix / mmap_unix_test.go
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 // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
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         b, err := unix.Mmap(-1, 0, unix.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE)
18         if err != nil {
19                 t.Fatalf("Mmap: %v", err)
20         }
21         if err := unix.Mprotect(b, unix.PROT_READ|unix.PROT_WRITE); err != nil {
22                 t.Fatalf("Mprotect: %v", err)
23         }
24
25         b[0] = 42
26
27         if runtime.GOOS == "aix" {
28                 t.Skip("msync returns invalid argument for AIX, skipping msync test")
29         } else {
30                 if err := unix.Msync(b, unix.MS_SYNC); err != nil {
31                         t.Fatalf("Msync: %v", err)
32                 }
33         }
34
35         if err := unix.Madvise(b, unix.MADV_DONTNEED); err != nil {
36                 t.Fatalf("Madvise: %v", err)
37         }
38         if err := unix.Munmap(b); err != nil {
39                 t.Fatalf("Munmap: %v", err)
40         }
41 }