diff options
author | Jakob Unterwurzacher | 2019-01-01 19:34:12 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2019-01-01 19:34:12 +0100 |
commit | 817c485bb7dbd890a15aca683d6004437772c659 (patch) | |
tree | 9a06ebc358dd035a4ae6031e80c0314e0ca119eb /tests | |
parent | 60e7a0ca9f2a2bcf8a727f606db134d60e9a5e18 (diff) |
tests: save gocryptfs process id in test_helpers.MountPID
This will allow to tests to monitor fd usage and maybe other things.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/matrix/matrix_test.go | 2 | ||||
-rw-r--r-- | tests/test_helpers/helpers.go | 39 |
2 files changed, 36 insertions, 5 deletions
diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go index 8de835f..660f9d7 100644 --- a/tests/matrix/matrix_test.go +++ b/tests/matrix/matrix_test.go @@ -76,6 +76,8 @@ func TestMain(m *testing.M) { test_helpers.MountOrExit(test_helpers.DefaultCipherDir, test_helpers.DefaultPlainDir, opts...) before := test_helpers.ListFds() 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() if len(before) != len(after) { fmt.Printf("fd leak? before, after:\n%v\n%v\n", before, after) diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go index 26eb60c..aac03a8 100644 --- a/tests/test_helpers/helpers.go +++ b/tests/test_helpers/helpers.go @@ -12,6 +12,7 @@ import ( "net" "os" "os/exec" + "os/signal" "path/filepath" "syscall" "testing" @@ -44,6 +45,9 @@ var DefaultPlainDir string // DefaultCipherDir is TmpDir + "/default-cipher" var DefaultCipherDir string +// PID of the running gocryptfs process. Set by Mount(). +var MountPID int + // SwitchTMPDIR changes TMPDIR and hence the directory the test are performed in. // This is used when you want to perform tests on a special filesystem. The // xattr tests cannot run on tmpfs and use /var/tmp instead of /tmp. @@ -155,13 +159,11 @@ func InitFS(t *testing.T, extraArgs ...string) string { // Mount CIPHERDIR "c" on PLAINDIR "p" // Creates "p" if it does not exist. func Mount(c string, p string, showOutput bool, extraArgs ...string) error { - var args []string - args = append(args, "-q", "-wpanic", "-nosyslog") + args := []string{"-q", "-wpanic", "-nosyslog", "-fg", fmt.Sprintf("-notifypid=%d", os.Getpid())} args = append(args, extraArgs...) //args = append(args, "-fusedebug") //args = append(args, "-d") - args = append(args, c) - args = append(args, p) + args = append(args, c, p) if _, err := os.Stat(p); err != nil { err = os.Mkdir(p, 0777) @@ -190,7 +192,34 @@ func Mount(c string, p string, showOutput bool, extraArgs ...string) error { }() } - return cmd.Run() + // Two things can happen: + // 1) The mount fails and the process exits + // 2) The mount succeeds and the process sends us USR1 + chanExit := make(chan error, 1) + chanUsr1 := make(chan os.Signal, 1) + signal.Notify(chanUsr1, syscall.SIGUSR1) + + // Start the process and save the PID + err := cmd.Start() + if err != nil { + return err + } + MountPID = cmd.Process.Pid + + // Wait for exit or usr1 + go func() { + chanExit <- cmd.Wait() + }() + select { + case err := <-chanExit: + return err + case <-chanUsr1: + return nil + case <-time.After(1 * time.Second): + log.Panicf("Timeout waiting for process %d", MountPID) + } + + return nil } // MountOrExit calls Mount() and exits on failure. |