-
Notifications
You must be signed in to change notification settings - Fork 17.9k
/
Copy pathreadfrom_freebsd_test.go
57 lines (46 loc) · 1.49 KB
/
readfrom_freebsd_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
// 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{newCopyFileRangeTest}
copyFileHooks = []copyFileTestHook{hookCopyFileRange}
)
func testCopyFiles(t *testing.T, size, limit int64) {
testCopyFileRange(t, size, limit)
}
func testCopyFileRange(t *testing.T, size int64, limit int64) {
dst, src, data, hook, name := newCopyFileRangeTest(t, size)
testCopyFile(t, dst, src, data, hook, limit, name)
}
// newCopyFileRangeTest initializes a new test for copy_file_range.
// It hooks package os' call to poll.CopyFileRange and returns the hook,
// so it can be inspected.
func newCopyFileRangeTest(t *testing.T, size int64) (dst, src *File, data []byte, hook *copyFileHook, name string) {
t.Helper()
name = "newCopyFileRangeTest"
dst, src, data = newCopyFileTest(t, size)
hook, _ = hookCopyFileRange(t)
return
}
func hookCopyFileRange(t *testing.T) (hook *copyFileHook, name string) {
name = "hookCopyFileRange"
hook = new(copyFileHook)
orig := *PollCopyFileRangeP
t.Cleanup(func() {
*PollCopyFileRangeP = orig
})
*PollCopyFileRangeP = func(dst, src *poll.FD, remain int64) (int64, bool, error) {
hook.called = true
hook.dstfd = dst.Sysfd
hook.srcfd = src.Sysfd
hook.written, hook.handled, hook.err = orig(dst, src, remain)
return hook.written, hook.handled, hook.err
}
return
}