mmap_unix_test.go 976 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
  5. package unix_test
  6. import (
  7. "runtime"
  8. "testing"
  9. "golang.org/x/sys/unix"
  10. )
  11. func TestMmap(t *testing.T) {
  12. b, err := unix.Mmap(-1, 0, unix.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE)
  13. if err != nil {
  14. t.Fatalf("Mmap: %v", err)
  15. }
  16. if err := unix.Mprotect(b, unix.PROT_READ|unix.PROT_WRITE); err != nil {
  17. t.Fatalf("Mprotect: %v", err)
  18. }
  19. b[0] = 42
  20. if runtime.GOOS == "aix" {
  21. t.Skip("msync returns invalid argument for AIX, skipping msync test")
  22. } else {
  23. if err := unix.Msync(b, unix.MS_SYNC); err != nil {
  24. t.Fatalf("Msync: %v", err)
  25. }
  26. }
  27. if err := unix.Madvise(b, unix.MADV_DONTNEED); err != nil {
  28. t.Fatalf("Madvise: %v", err)
  29. }
  30. if err := unix.Munmap(b); err != nil {
  31. t.Fatalf("Munmap: %v", err)
  32. }
  33. }