You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

36 lines
844 B

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