Pass report files by file descriptor.
parent
a438466587
commit
b62be9632c
|
@ -66,12 +66,6 @@ func (t *flushFSTest) setUp(
|
|||
// Set up test config.
|
||||
t.MountType = "flushfs"
|
||||
t.MountFlags = []string{
|
||||
"--flushfs.flushes_file",
|
||||
t.flushes.Name(),
|
||||
|
||||
"--flushfs.fsyncs_file",
|
||||
t.fsyncs.Name(),
|
||||
|
||||
"--flushfs.flush_error",
|
||||
fmt.Sprintf("%d", int(flushErr)),
|
||||
|
||||
|
@ -79,6 +73,11 @@ func (t *flushFSTest) setUp(
|
|||
fmt.Sprintf("%d", int(fsyncErr)),
|
||||
}
|
||||
|
||||
t.MountFiles = map[string]*os.File{
|
||||
"flushfs.flushes_file": t.flushes,
|
||||
"flushfs.fsyncs_file": t.fsyncs,
|
||||
}
|
||||
|
||||
t.SubprocessTest.SetUp(ti)
|
||||
}
|
||||
|
||||
|
|
|
@ -31,30 +31,21 @@ import (
|
|||
var fType = flag.String("type", "", "The name of the samples/ sub-dir.")
|
||||
var fMountPoint = flag.String("mount_point", "", "Path to mount point.")
|
||||
|
||||
var fFlushesFile = flag.String("flushfs.flushes_file", "", "")
|
||||
var fFsyncsFile = flag.String("flushfs.fsyncs_file", "", "")
|
||||
var fFlushesFile = flag.Uint64("flushfs.flushes_file", 0, "")
|
||||
var fFsyncsFile = flag.Uint64("flushfs.fsyncs_file", 0, "")
|
||||
var fFlushError = flag.Int("flushfs.flush_error", 0, "")
|
||||
var fFsyncError = flag.Int("flushfs.fsync_error", 0, "")
|
||||
|
||||
func makeFlushFS() (fs fuse.FileSystem, err error) {
|
||||
// Check the flags.
|
||||
if *fFlushesFile == "" || *fFsyncsFile == "" {
|
||||
if *fFlushesFile == 0 || *fFsyncsFile == 0 {
|
||||
err = fmt.Errorf("You must set the flushfs flags.")
|
||||
return
|
||||
}
|
||||
|
||||
// Open the files.
|
||||
flushes, err := os.OpenFile(*fFlushesFile, os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Opening %s: %v", *fFlushesFile, err)
|
||||
return
|
||||
}
|
||||
|
||||
fsyncs, err := os.OpenFile(*fFsyncsFile, os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Opening %s: %v", *fFsyncsFile, err)
|
||||
return
|
||||
}
|
||||
// Set up the files.
|
||||
flushes := os.NewFile(uintptr(*fFlushesFile), "(flushes file)")
|
||||
fsyncs := os.NewFile(uintptr(*fFsyncsFile), "(fsyncs file)")
|
||||
|
||||
// Set up errors.
|
||||
var flushErr error
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"sync"
|
||||
|
@ -40,6 +41,10 @@ type SubprocessTest struct {
|
|||
// Additional flags to be passed to the mount_sample tool.
|
||||
MountFlags []string
|
||||
|
||||
// A list of files to pass to mount_sample. The given string flag will be
|
||||
// used to pass the file descriptor number.
|
||||
MountFiles map[string]*os.File
|
||||
|
||||
// A context object that can be used for long-running operations.
|
||||
Ctx context.Context
|
||||
|
||||
|
@ -132,7 +137,7 @@ func (t *SubprocessTest) initialize() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// Set up a command.
|
||||
// Set up basic args for the subprocess.
|
||||
args := []string{
|
||||
"--type",
|
||||
t.MountType,
|
||||
|
@ -142,9 +147,22 @@ func (t *SubprocessTest) initialize() (err error) {
|
|||
|
||||
args = append(args, t.MountFlags...)
|
||||
|
||||
// Set up inherited files and appropriate flags.
|
||||
var extraFiles []*os.File
|
||||
for flag, file := range t.MountFiles {
|
||||
// Cf. os/exec.Cmd.ExtraFiles
|
||||
fd := 3 + len(extraFiles)
|
||||
|
||||
extraFiles = append(extraFiles, file)
|
||||
args = append(args, "--"+flag)
|
||||
args = append(args, fmt.Sprintf("%d", fd))
|
||||
}
|
||||
|
||||
// Set up a command.
|
||||
t.mountCmd = exec.Command(toolPath, args...)
|
||||
t.mountCmd.Stdout = &t.mountStdout
|
||||
t.mountCmd.Stderr = &t.mountStderr
|
||||
t.mountCmd.ExtraFiles = extraFiles
|
||||
|
||||
// Start it.
|
||||
if err = t.mountCmd.Start(); err != nil {
|
||||
|
|
Loading…
Reference in New Issue