1
0
mirror of https://github.com/golang/go synced 2024-09-25 01:20:13 -06:00

os: add TestReadAtOffset

In the Plan 9 kernel, there used to be a bug in the implementation of
the pread syscall, where the channel offset was erroneously updated after
calling pread on a file.

This test verifies that ReadAt is behaving as expected.

Fixes #14534.

Change-Id: Ifc9fd40a1f94879ee7eb09b2ffc369aa2bec2926
Reviewed-on: https://go-review.googlesource.com/22244
Run-TryBot: David du Colombier <0intro@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
David du Colombier 2016-04-19 20:59:03 +02:00 committed by Brad Fitzpatrick
parent f05c3aa24d
commit 3d82432288

View File

@ -1376,6 +1376,38 @@ func TestReadAt(t *testing.T) {
}
}
// Verify that ReadAt doesn't affect seek offset.
// In the Plan 9 kernel, there used to be a bug in the implementation of
// the pread syscall, where the channel offset was erroneously updated after
// calling pread on a file.
func TestReadAtOffset(t *testing.T) {
f := newFile("TestReadAtOffset", t)
defer Remove(f.Name())
defer f.Close()
const data = "hello, world\n"
io.WriteString(f, data)
f.Seek(0, 0)
b := make([]byte, 5)
n, err := f.ReadAt(b, 7)
if err != nil || n != len(b) {
t.Fatalf("ReadAt 7: %d, %v", n, err)
}
if string(b) != "world" {
t.Fatalf("ReadAt 7: have %q want %q", string(b), "world")
}
n, err = f.Read(b)
if err != nil || n != len(b) {
t.Fatalf("Read: %d, %v", n, err)
}
if string(b) != "hello" {
t.Fatalf("Read: have %q want %q", string(b), "hello")
}
}
func TestWriteAt(t *testing.T) {
f := newFile("TestWriteAt", t)
defer Remove(f.Name())