aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/matrix/matrix_test.go8
-rw-r--r--tests/test_helpers/helpers.go27
2 files changed, 34 insertions, 1 deletions
diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go
index 37c7b20..bc964ae 100644
--- a/tests/matrix/matrix_test.go
+++ b/tests/matrix/matrix_test.go
@@ -72,7 +72,15 @@ func TestMain(m *testing.M) {
opts = append(opts, fmt.Sprintf("-aessiv=%v", testcase.aessiv))
opts = append(opts, fmt.Sprintf("-raw64=%v", testcase.raw64))
test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...)
+ before := test_helpers.ListFds()
r := m.Run()
+ after := test_helpers.ListFds()
+ if len(before) != len(after) {
+ fmt.Printf("fd leak? before, after:\n")
+ fmt.Printf("%v\n", before)
+ fmt.Printf("%v\n", after)
+ os.Exit(1)
+ }
test_helpers.UnmountPanic(test_helpers.DefaultPlainDir)
if r != 0 {
os.Exit(r)
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index f92fb79..971948c 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -178,9 +178,14 @@ func Mount(c string, p string, showOutput bool, extraArgs ...string) error {
if err != nil {
return err
}
+ // We can close the fd after cmd.Run() has executed
+ defer pw.Close()
cmd.Stderr = pw
cmd.Stdout = pw
- go func() { io.Copy(os.Stdout, pr) }()
+ go func() {
+ io.Copy(os.Stdout, pr)
+ pr.Close()
+ }()
}
return cmd.Run()
@@ -412,3 +417,23 @@ func ExtractCmdExitCode(err error) int {
code := err2.Sys().(syscall.WaitStatus).ExitStatus()
return code
}
+
+// ListFds lists our open file descriptors.
+// We use /dev/fd because it exists on both Linux and MacOS.
+func ListFds() []string {
+ f, err := os.Open("/dev/fd")
+ if err != nil {
+ log.Panic(err)
+ }
+ defer f.Close()
+ names, err := f.Readdirnames(0)
+ if err != nil {
+ log.Panic(err)
+ }
+ for i, n := range names {
+ // Note: Readdirnames filters "." and ".."
+ target, _ := os.Readlink("/dev/fd/" + n)
+ names[i] = n + "=" + target
+ }
+ return names
+}