Source file
src/os/readfrom_solaris_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{newSendfileTest}
15 copyFileHooks = []copyFileTestHook{hookSendFile}
16 )
17
18 func testCopyFiles(t *testing.T, size, limit int64) {
19 testSendfile(t, size, limit)
20 }
21
22 func testSendfile(t *testing.T, size int64, limit int64) {
23 dst, src, data, hook, name := newSendfileTest(t, size)
24 testCopyFile(t, dst, src, data, hook, limit, name)
25 }
26
27
28
29
30 func newSendfileTest(t *testing.T, size int64) (dst, src *File, data []byte, hook *copyFileHook, name string) {
31 t.Helper()
32
33 name = "newSendfileTest"
34
35 dst, src, data = newCopyFileTest(t, size)
36 hook, _ = hookSendFile(t)
37
38 return
39 }
40
41 func hookSendFile(t *testing.T) (*copyFileHook, string) {
42 return hookSendFileTB(t), "hookSendFile"
43 }
44
45 func hookSendFileTB(tb testing.TB) *copyFileHook {
46 hook := new(copyFileHook)
47 orig := poll.TestHookDidSendFile
48 tb.Cleanup(func() {
49 poll.TestHookDidSendFile = orig
50 })
51 poll.TestHookDidSendFile = func(dstFD *poll.FD, src int, written int64, err error, handled bool) {
52 hook.called = true
53 hook.dstfd = dstFD.Sysfd
54 hook.srcfd = src
55 hook.written = written
56 hook.err = err
57 hook.handled = handled
58 }
59 return hook
60 }
61
View as plain text