aboutsummaryrefslogtreecommitdiff
path: root/tests/test_helpers/helpers.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_helpers/helpers.go')
-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.