aboutsummaryrefslogtreecommitdiff
path: root/tests/test_helpers
diff options
context:
space:
mode:
authorJakob Unterwurzacher2019-01-01 19:34:12 +0100
committerJakob Unterwurzacher2019-01-01 19:34:12 +0100
commit817c485bb7dbd890a15aca683d6004437772c659 (patch)
tree9a06ebc358dd035a4ae6031e80c0314e0ca119eb /tests/test_helpers
parent60e7a0ca9f2a2bcf8a727f606db134d60e9a5e18 (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/test_helpers')
-rw-r--r--tests/test_helpers/helpers.go39
1 files changed, 34 insertions, 5 deletions
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.