summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cli/cli_test.go4
-rw-r--r--tests/matrix/matrix_test.go6
-rw-r--r--tests/test_helpers/mount_unmount.go20
3 files changed, 18 insertions, 12 deletions
diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go
index d0ac5d8..423afdf 100644
--- a/tests/cli/cli_test.go
+++ b/tests/cli/cli_test.go
@@ -22,9 +22,9 @@ var testPw = []byte("test")
func TestMain(m *testing.M) {
test_helpers.ResetTmpDir(false)
- before := test_helpers.ListFds(0)
+ before := test_helpers.ListFds(0, "")
r := m.Run()
- after := test_helpers.ListFds(0)
+ after := test_helpers.ListFds(0, "")
if len(before) != len(after) {
fmt.Printf("fd leak in test process? before, after:\n%v\n%v\n", before, after)
os.Exit(1)
diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go
index e4424a7..af4769a 100644
--- a/tests/matrix/matrix_test.go
+++ b/tests/matrix/matrix_test.go
@@ -77,11 +77,13 @@ func TestMain(m *testing.M) {
opts = append(opts, fmt.Sprintf("-raw64=%v", testcase.raw64))
opts = append(opts, testcase.extraArgs...)
test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...)
- before := test_helpers.ListFds(0)
+ before := test_helpers.ListFds(0, test_helpers.TmpDir)
r := m.Run()
// Catch fd leaks in the tests. NOTE: this does NOT catch leaks in
// the gocryptfs FUSE process, but only in the tests that access it!
- after := test_helpers.ListFds(0)
+ // All fds that point outside TmpDir are not interesting (the Go test
+ // infrastucture creates temporary log files we don't care about).
+ after := test_helpers.ListFds(0, test_helpers.TmpDir)
if len(before) != len(after) {
fmt.Printf("fd leak in test process? before, after:\n%v\n%v\n", before, after)
os.Exit(1)
diff --git a/tests/test_helpers/mount_unmount.go b/tests/test_helpers/mount_unmount.go
index 453ea20..7b5dafa 100644
--- a/tests/test_helpers/mount_unmount.go
+++ b/tests/test_helpers/mount_unmount.go
@@ -91,7 +91,7 @@ func Mount(c string, p string, showOutput bool, extraArgs ...string) error {
}
// Save PID and open FDs
- MountInfo[p] = mountInfo{pid, ListFds(pid)}
+ MountInfo[p] = mountInfo{pid, ListFds(pid, "")}
return nil
}
@@ -160,13 +160,13 @@ func UnmountErr(dir string) (err error) {
// when testing "-ctlsock" is as well. Wait a little and
// hope that all close commands get through to the gocryptfs
// process.
- fdsNow = ListFds(pid)
+ fdsNow = ListFds(pid, "")
if len(fdsNow) <= len(fds)+maxCacheFds {
break
}
fmt.Printf("UnmountErr: fdsOld=%d fdsNow=%d, retrying\n", len(fds), len(fdsNow))
time.Sleep(10 * time.Millisecond)
- fdsNow = ListFds(pid)
+ fdsNow = ListFds(pid, "")
}
}
cmd := exec.Command(UnmountScript, "-u", dir)
@@ -187,8 +187,8 @@ func UnmountErr(dir string) (err error) {
}
// ListFds lists the open file descriptors for process "pid". Pass pid=0 for
-// ourselves.
-func ListFds(pid int) []string {
+// ourselves. Pass a prefix to ignore all paths that do not start with "prefix".
+func ListFds(pid int, prefix string) []string {
// We need /proc to get the list of fds for other processes. Only exists
// on Linux.
if runtime.GOOS != "linux" && pid > 0 {
@@ -211,7 +211,7 @@ func ListFds(pid int) []string {
log.Panic(err)
}
var out []string
- hidden := 0
+ var filtered []string
for _, n := range names {
fdPath := dir + "/" + n
fi, err := os.Lstat(fdPath)
@@ -235,11 +235,15 @@ func ListFds(pid int) []string {
// creates spurious test failures. Ignore all pipes.
// Also get rid of the "eventpoll" fd that is always there and not
// interesting.
- hidden++
+ filtered = append(filtered, target)
+ continue
+ }
+ if prefix != "" && !strings.HasPrefix(target, prefix) {
+ filtered = append(filtered, target)
continue
}
out = append(out, n+"="+target)
}
- out = append(out, fmt.Sprintf("(hidden:%d)", hidden))
+ out = append(out, fmt.Sprintf("(filtered: %s)", strings.Join(filtered, ", ")))
return out
}