2014-08-12 01:48:46 +04:00
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-08-21 21:56:25 +03:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
2014-08-12 01:48:46 +04:00
|
|
|
|
2014-08-12 02:58:26 +04:00
|
|
|
package unix_test
|
2014-08-12 01:48:46 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2014-08-13 09:59:00 +04:00
|
|
|
|
2014-11-10 00:56:17 +03:00
|
|
|
"golang.org/x/sys/unix"
|
2014-08-12 01:48:46 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMmap(t *testing.T) {
|
2014-08-12 02:58:26 +04:00
|
|
|
b, err := unix.Mmap(-1, 0, unix.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE)
|
2014-08-12 01:48:46 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Mmap: %v", err)
|
|
|
|
}
|
2017-09-21 12:26:02 +03:00
|
|
|
if err := unix.Mprotect(b, unix.PROT_READ|unix.PROT_WRITE); err != nil {
|
2017-08-16 18:16:36 +03:00
|
|
|
t.Fatalf("Mprotect: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b[0] = 42
|
|
|
|
|
|
|
|
if err := unix.Msync(b, unix.MS_SYNC); err != nil {
|
|
|
|
t.Fatalf("Msync: %v", err)
|
|
|
|
}
|
|
|
|
if err := unix.Madvise(b, unix.MADV_DONTNEED); err != nil {
|
|
|
|
t.Fatalf("Madvise: %v", err)
|
|
|
|
}
|
2014-08-12 02:58:26 +04:00
|
|
|
if err := unix.Munmap(b); err != nil {
|
2014-08-12 01:48:46 +04:00
|
|
|
t.Fatalf("Munmap: %v", err)
|
|
|
|
}
|
|
|
|
}
|