Source file
src/os/readfrom_freebsd_test.go
1
2
3
4
5 package os_test
6
7 import (
8 "internal/poll"
9 . "os"
10 "testing"
11 )
12
13 var (
14 copyFileTests = []copyFileTestFunc{newCopyFileRangeTest}
15 copyFileHooks = []copyFileTestHook{hookCopyFileRange}
16 )
17
18 func testCopyFiles(t *testing.T, size, limit int64) {
19 testCopyFileRange(t, size, limit)
20 }
21
22 func testCopyFileRange(t *testing.T, size int64, limit int64) {
23 dst, src, data, hook, name := newCopyFileRangeTest(t, size)
24 testCopyFile(t, dst, src, data, hook, limit, name)
25 }
26
27
28
29
30 func newCopyFileRangeTest(t *testing.T, size int64) (dst, src *File, data []byte, hook *copyFileHook, name string) {
31 t.Helper()
32
33 name = "newCopyFileRangeTest"
34
35 dst, src, data = newCopyFileTest(t, size)
36 hook, _ = hookCopyFileRange(t)
37
38 return
39 }
40
41 func hookCopyFileRange(t *testing.T) (hook *copyFileHook, name string) {
42 name = "hookCopyFileRange"
43
44 hook = new(copyFileHook)
45 orig := *PollCopyFileRangeP
46 t.Cleanup(func() {
47 *PollCopyFileRangeP = orig
48 })
49 *PollCopyFileRangeP = func(dst, src *poll.FD, remain int64) (int64, bool, error) {
50 hook.called = true
51 hook.dstfd = dst.Sysfd
52 hook.srcfd = src.Sysfd
53 hook.written, hook.handled, hook.err = orig(dst, src, remain)
54 return hook.written, hook.handled, hook.err
55 }
56 return
57 }
58
View as plain text