aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2024-04-25 11:53:45 -0700
committerDamien Neil <dneil@google.com>2024-04-26 18:12:56 +0000
commitb384ee7cebe1b386e324dcca2c93beb96ea31c9e (patch)
tree16913efe13aedcfc2c2ae37433241c6296865361 /src/os
parent196916299da7568a2a2165246e5164637df03fb9 (diff)
downloadgo-b384ee7cebe1b386e324dcca2c93beb96ea31c9e.tar.gz
go-b384ee7cebe1b386e324dcca2c93beb96ea31c9e.zip
net, os, internal/poll: test for use of sendfile
The net package's sendfile tests exercise various paths where we expect sendfile to be used, but don't verify that sendfile was in fact used. Add a hook to internal/poll.SendFile to let us verify that sendfile was called when expected. Update os package tests (which use their own hook mechanism) to use this hook as well. For #66988 Change-Id: I7afb130dcfe0063d60c6ea0f8560cf8665ad5a81 Reviewed-on: https://go-review.googlesource.com/c/go/+/581778 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/os')
-rw-r--r--src/os/export_linux_test.go1
-rw-r--r--src/os/writeto_linux_test.go33
-rw-r--r--src/os/zero_copy_linux.go3
3 files changed, 13 insertions, 24 deletions
diff --git a/src/os/export_linux_test.go b/src/os/export_linux_test.go
index 942b48a17d..78c2d144be 100644
--- a/src/os/export_linux_test.go
+++ b/src/os/export_linux_test.go
@@ -7,6 +7,5 @@ package os
var (
PollCopyFileRangeP = &pollCopyFileRange
PollSpliceFile = &pollSplice
- PollSendFile = &pollSendFile
GetPollFDAndNetwork = getPollFDAndNetwork
)
diff --git a/src/os/writeto_linux_test.go b/src/os/writeto_linux_test.go
index 5ffab88a2a..e3900631ba 100644
--- a/src/os/writeto_linux_test.go
+++ b/src/os/writeto_linux_test.go
@@ -109,8 +109,18 @@ func newSendFileTest(t *testing.T, proto string, size int64) (net.Conn, *File, n
func hookSendFile(t *testing.T) *sendFileHook {
h := new(sendFileHook)
- h.install()
- t.Cleanup(h.uninstall)
+ orig := poll.TestHookDidSendFile
+ t.Cleanup(func() {
+ poll.TestHookDidSendFile = orig
+ })
+ poll.TestHookDidSendFile = func(dstFD *poll.FD, src int, written int64, err error, handled bool) {
+ h.called = true
+ h.dstfd = dstFD.Sysfd
+ h.srcfd = src
+ h.written = written
+ h.err = err
+ h.handled = handled
+ }
return h
}
@@ -118,29 +128,10 @@ type sendFileHook struct {
called bool
dstfd int
srcfd int
- remain int64
written int64
handled bool
err error
-
- original func(dst *poll.FD, src int, remain int64) (int64, error, bool)
-}
-
-func (h *sendFileHook) install() {
- h.original = *PollSendFile
- *PollSendFile = func(dst *poll.FD, src int, remain int64) (int64, error, bool) {
- h.called = true
- h.dstfd = dst.Sysfd
- h.srcfd = src
- h.remain = remain
- h.written, h.err, h.handled = h.original(dst, src, remain)
- return h.written, h.err, h.handled
- }
-}
-
-func (h *sendFileHook) uninstall() {
- *PollSendFile = h.original
}
func createTempFile(t *testing.T, size int64) (*File, []byte) {
diff --git a/src/os/zero_copy_linux.go b/src/os/zero_copy_linux.go
index 70a05ffa1e..0afc19e125 100644
--- a/src/os/zero_copy_linux.go
+++ b/src/os/zero_copy_linux.go
@@ -13,7 +13,6 @@ import (
var (
pollCopyFileRange = poll.CopyFileRange
pollSplice = poll.Splice
- pollSendFile = poll.SendFile
)
// wrapSyscallError takes an error and a syscall name. If the error is
@@ -38,7 +37,7 @@ func (f *File) writeTo(w io.Writer) (written int64, handled bool, err error) {
}
rerr := sc.Read(func(fd uintptr) (done bool) {
- written, err, handled = pollSendFile(pfd, int(fd), 1<<63-1)
+ written, err, handled = poll.SendFile(pfd, int(fd), 1<<63-1)
return true
})