diff --git a/gommap_test.go b/gommap_test.go index 3a4d4d3..cdf4570 100644 --- a/gommap_test.go +++ b/gommap_test.go @@ -4,11 +4,12 @@ package gommap import ( "io/ioutil" - . "launchpad.net/gocheck" "os" "path" "syscall" "testing" + + . "launchpad.net/gocheck" ) func TestAll(t *testing.T) { @@ -150,31 +151,3 @@ func (s *S) TestIsResidentUnderOnePage(c *C) { c.Assert(err, IsNil) c.Assert(mapped, DeepEquals, []bool{true}) } - -func (s *S) TestIsResidentTwoPages(c *C) { - testPath := path.Join(c.MkDir(), "test.txt") - file, err := os.Create(testPath) - c.Assert(err, IsNil) - defer file.Close() - - file.Seek(int64(os.Getpagesize()*2-1), 0) - file.Write([]byte{'x'}) - - mmap, err := Map(file.Fd(), PROT_READ|PROT_WRITE, MAP_PRIVATE) - c.Assert(err, IsNil) - defer mmap.UnsafeUnmap() - - // Not entirely a stable test, but should usually work. - - mmap[len(mmap)-1] = 'x' - - mapped, err := mmap.IsResident() - c.Assert(err, IsNil) - c.Assert(mapped, DeepEquals, []bool{false, true}) - - mmap[0] = 'x' - - mapped, err = mmap.IsResident() - c.Assert(err, IsNil) - c.Assert(mapped, DeepEquals, []bool{true, true}) -} diff --git a/gommap_twopage_test.go b/gommap_twopage_test.go new file mode 100644 index 0000000..c2cd434 --- /dev/null +++ b/gommap_twopage_test.go @@ -0,0 +1,38 @@ +// +build !windows,!freebsd + +package gommap + +import ( + "os" + "path" + + . "launchpad.net/gocheck" +) + +func (s *S) TestIsResidentTwoPages(c *C) { + testPath := path.Join(c.MkDir(), "test.txt") + file, err := os.Create(testPath) + c.Assert(err, IsNil) + defer file.Close() + + file.Seek(int64(os.Getpagesize()*2-1), 0) + file.Write([]byte{'x'}) + + mmap, err := Map(file.Fd(), PROT_READ|PROT_WRITE, MAP_PRIVATE) + c.Assert(err, IsNil) + defer mmap.UnsafeUnmap() + + // Not entirely a stable test, but should usually work. + + mmap[len(mmap)-1] = 'x' + + mapped, err := mmap.IsResident() + c.Assert(err, IsNil) + c.Assert(mapped, DeepEquals, []bool{false, true}) + + mmap[0] = 'x' + + mapped, err = mmap.IsResident() + c.Assert(err, IsNil) + c.Assert(mapped, DeepEquals, []bool{true, true}) +} diff --git a/mmap_linux_386.go b/mmap_unix.go similarity index 89% rename from mmap_linux_386.go rename to mmap_unix.go index 9ed4667..ab58c78 100644 --- a/mmap_linux_386.go +++ b/mmap_unix.go @@ -1,3 +1,6 @@ +// +build linux freebsd +// +build 386 + package gommap import "syscall" diff --git a/mmap_linux_amd64.go b/mmap_unix64.go similarity index 83% rename from mmap_linux_amd64.go rename to mmap_unix64.go index c0537ff..66882b2 100644 --- a/mmap_linux_amd64.go +++ b/mmap_unix64.go @@ -1,3 +1,6 @@ +// +build linux freebsd +// +build amd64 arm64 + package gommap import "syscall"