summaryrefslogtreecommitdiff
path: root/libgo/go/syscall/dirent_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-02-11 14:53:56 -0800
committerIan Lance Taylor <iant@golang.org>2022-02-11 15:01:19 -0800
commit8dc2499aa62f768c6395c9754b8cabc1ce25c494 (patch)
tree43d7fd2bbfd7ad8c9625a718a5e8718889351994 /libgo/go/syscall/dirent_test.go
parent9a56779dbc4e2d9c15be8d31e36f2f59be7331a8 (diff)
downloadgcc-8dc2499aa62f768c6395c9754b8cabc1ce25c494.tar.gz
libgo: update to Go1.18beta2
gotools/ * Makefile.am (go_cmd_cgo_files): Add ast_go118.go (check-go-tool): Copy golang.org/x/tools directories. * Makefile.in: Regenerate. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384695
Diffstat (limited to 'libgo/go/syscall/dirent_test.go')
-rw-r--r--libgo/go/syscall/dirent_test.go40
1 files changed, 27 insertions, 13 deletions
diff --git a/libgo/go/syscall/dirent_test.go b/libgo/go/syscall/dirent_test.go
index 71b445ba9b5..aeb40e57c18 100644
--- a/libgo/go/syscall/dirent_test.go
+++ b/libgo/go/syscall/dirent_test.go
@@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
-// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
package syscall_test
@@ -23,7 +22,7 @@ import (
func TestDirent(t *testing.T) {
const (
- direntBufSize = 2048
+ direntBufSize = 2048 // arbitrary? See https://go.dev/issue/37323.
filenameMinSize = 11
)
@@ -38,23 +37,38 @@ func TestDirent(t *testing.T) {
}
}
- buf := bytes.Repeat([]byte("DEADBEAF"), direntBufSize/8)
+ names := make([]string, 0, 10)
+
fd, err := syscall.Open(d, syscall.O_RDONLY, 0)
if err != nil {
t.Fatalf("syscall.open: %v", err)
}
defer syscall.Close(fd)
- n, err := syscall.ReadDirent(fd, buf)
- if err != nil {
- t.Fatalf("syscall.readdir: %v", err)
- }
- buf = buf[:n]
- names := make([]string, 0, 10)
- for len(buf) > 0 {
- var bc int
- bc, _, names = syscall.ParseDirent(buf, -1, names)
- buf = buf[bc:]
+ buf := bytes.Repeat([]byte{0xCD}, direntBufSize)
+ for {
+ n, err := syscall.ReadDirent(fd, buf)
+ if err == syscall.EINVAL {
+ // On linux, 'man getdents64' says that EINVAL indicates “result buffer is too small”.
+ // Try a bigger buffer.
+ t.Logf("ReadDirent: %v; retrying with larger buffer", err)
+ buf = bytes.Repeat([]byte{0xCD}, len(buf)*2)
+ continue
+ }
+ if err != nil {
+ t.Fatalf("syscall.readdir: %v", err)
+ }
+ t.Logf("ReadDirent: read %d bytes", n)
+ if n == 0 {
+ break
+ }
+
+ var consumed, count int
+ consumed, count, names = syscall.ParseDirent(buf[:n], -1, names)
+ t.Logf("ParseDirent: %d new name(s)", count)
+ if consumed != n {
+ t.Fatalf("ParseDirent: consumed %d bytes; expected %d", consumed, n)
+ }
}
sort.Strings(names)