NoErrorsTest.Mmap_WithMsync_CloseBeforeMunmap
parent
2f5062ac6c
commit
3aaca555a4
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue