From 3aaca555a40eb4110b2433219e070ae8c181d7c1 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 24 Mar 2015 13:01:32 +1100 Subject: [PATCH] NoErrorsTest.Mmap_WithMsync_CloseBeforeMunmap --- samples/flushfs/flush_fs_test.go | 49 ++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index d5a04b1..5a5ff14 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -639,9 +639,10 @@ func (t *NoErrorsTest) Mmap_NoMsync_CloseBeforeMunmap() { AssertThat(t.getFlushes(), ElementsAre("taco")) AssertThat(t.getFsyncs(), ElementsAre()) - // Modify then unmap. + // Modify the contents. data[0] = 'p' + // Unmap. err = syscall.Munmap(data) AssertEq(nil, err) @@ -701,7 +702,51 @@ func (t *NoErrorsTest) Mmap_WithMsync_MunmapBeforeClose() { } func (t *NoErrorsTest) Mmap_WithMsync_CloseBeforeMunmap() { - AssertTrue(false, "TODO") + var n int + var err error + + // Open the file. + t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0) + AssertEq(nil, err) + + // Write some contents to the file. + n, err = t.f1.Write([]byte("taco")) + AssertEq(nil, err) + AssertEq(4, n) + + // mmap the file. + data, err := syscall.Mmap( + int(t.f1.Fd()), 0, 4, + syscall.PROT_READ|syscall.PROT_WRITE, + syscall.MAP_SHARED) + + AssertEq(nil, err) + AssertEq("taco", string(data)) + + // Close the file. We should see a flush. + err = t.f1.Close() + t.f1 = nil + AssertEq(nil, err) + + AssertThat(t.getFlushes(), ElementsAre("taco")) + AssertThat(t.getFsyncs(), ElementsAre()) + + // Modify the contents. + data[0] = 'p' + + // msync. This causes a write, but not a flush. + err = msync(data) + ExpectEq(nil, err) + + ExpectThat(t.getFlushes(), ElementsAre("taco")) + ExpectThat(t.getFsyncs(), ElementsAre()) + + // Unmap. Again, this does not cause a flush. + err = syscall.Munmap(data) + AssertEq(nil, err) + + ExpectThat(t.getFlushes(), ElementsAre("taco")) + ExpectThat(t.getFsyncs(), ElementsAre()) } func (t *NoErrorsTest) Directory() {