-
Notifications
You must be signed in to change notification settings - Fork 18k
/
Copy pathreadfrom_solaris_test.go
60 lines (49 loc) · 1.5 KB
/
readfrom_solaris_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package os_test
import (
"internal/poll"
. "os"
"testing"
)
var (
copyFileTests = []copyFileTestFunc{newSendfileTest}
copyFileHooks = []copyFileTestHook{hookSendFile}
)
func testCopyFiles(t *testing.T, size, limit int64) {
testSendfile(t, size, limit)
}
func testSendfile(t *testing.T, size int64, limit int64) {
dst, src, data, hook, name := newSendfileTest(t, size)
testCopyFile(t, dst, src, data, hook, limit, name)
}
// newSendFileTest initializes a new test for sendfile over copy_file_range.
// It hooks package os' call to poll.SendFile and returns the hook,
// so it can be inspected.
func newSendfileTest(t *testing.T, size int64) (dst, src *File, data []byte, hook *copyFileHook, name string) {
t.Helper()
name = "newSendfileTest"
dst, src, data = newCopyFileTest(t, size)
hook, _ = hookSendFile(t)
return
}
func hookSendFile(t *testing.T) (*copyFileHook, string) {
return hookSendFileTB(t), "hookSendFile"
}
func hookSendFileTB(tb testing.TB) *copyFileHook {
hook := new(copyFileHook)
orig := poll.TestHookDidSendFile
tb.Cleanup(func() {
poll.TestHookDidSendFile = orig
})
poll.TestHookDidSendFile = func(dstFD *poll.FD, src uintptr, written int64, err error, handled bool) {
hook.called = true
hook.dstfd = dstFD.Sysfd
hook.srcfd = int(src)
hook.written = written
hook.err = err
hook.handled = handled
}
return hook
}