From d6218a35383c9e6c0376ef8548273e4ea7924c5d Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 16 Mar 2015 14:02:54 +1100 Subject: [PATCH] Updated pwrite tests for Linux. --- samples/memfs/memfs_test.go | 11 ++++++++++- samples/memfs/posix_test.go | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/samples/memfs/memfs_test.go b/samples/memfs/memfs_test.go index 6030236..c4d1847 100644 --- a/samples/memfs/memfs_test.go +++ b/samples/memfs/memfs_test.go @@ -943,9 +943,18 @@ func (t *MemFSTest) AppendMode() { // Read back the contents of the file, which should be correct even though we // seeked to a silly place before writing the world part. + // + // Linux's support for pwrite is buggy; the pwrite(2) man page says this: + // + // POSIX requires that opening a file with the O_APPEND flag should have + // no affect on the location at which pwrite() writes data. However, on + // Linux, if a file is opened with O_APPEND, pwrite() appends data to + // the end of the file, regardless of the value of offset. + // + // So we allow either the POSIX result or the Linux result. n, err = f.ReadAt(buf, 0) AssertEq(io.EOF, err) - ExpectEq("Hello, world!", string(buf[:n])) + ExpectThat(string(buf[:n]), AnyOf("Hello, world!", "Jello, world!H")) } func (t *MemFSTest) ReadsPastEndOfFile() { diff --git a/samples/memfs/posix_test.go b/samples/memfs/posix_test.go index 65e9e36..91ffbc3 100644 --- a/samples/memfs/posix_test.go +++ b/samples/memfs/posix_test.go @@ -260,9 +260,18 @@ func (t *PosixTest) AppendMode() { // Read back the contents of the file, which should be correct even though we // seeked to a silly place before writing the world part. + // + // Linux's support for pwrite is buggy; the pwrite(2) man page says this: + // + // POSIX requires that opening a file with the O_APPEND flag should have + // no affect on the location at which pwrite() writes data. However, on + // Linux, if a file is opened with O_APPEND, pwrite() appends data to + // the end of the file, regardless of the value of offset. + // + // So we allow either the POSIX result or the Linux result. n, err = f.ReadAt(buf, 0) AssertEq(io.EOF, err) - ExpectEq("Hello, world!", string(buf[:n])) + ExpectThat(string(buf[:n]), AnyOf("Hello, world!", "Jello, world!H")) } func (t *PosixTest) ReadsPastEndOfFile() {