[testrunner] Restrict environment of subprocesses.
Change-Id: Ia2a3872b56b3e684135974d1dcdb9c8e499c42be
diff --git a/cmd/testrunner/main.go b/cmd/testrunner/main.go
index 5a1911c..5755425 100644
--- a/cmd/testrunner/main.go
+++ b/cmd/testrunner/main.go
@@ -179,7 +179,10 @@
}
localTester := &SubprocessTester{
- WD: localWD,
+ wd: localWD,
+ }
+ if devCtx != nil {
+ localTester.env = []string{devCtx.EnvironEntry()}
}
if err := runTests(linux, localTester.Test, output); err != nil {
diff --git a/cmd/testrunner/tester.go b/cmd/testrunner/tester.go
index ef3cbd3..d74cbda 100644
--- a/cmd/testrunner/tester.go
+++ b/cmd/testrunner/tester.go
@@ -18,7 +18,8 @@
// SubprocessTester executes tests in local subprocesses.
type SubprocessTester struct {
- WD string
+ wd string
+ env []string
}
func (t *SubprocessTester) Test(ctx context.Context, test testsharder.Test, stdout io.Writer, stderr io.Writer) error {
@@ -29,8 +30,11 @@
command = test.Command
}
- runner := new(testrunner.SubprocessRunner)
- runner.WD = t.WD
+ runner := &testrunner.SubprocessRunner{
+ WD: t.wd,
+ Env: t.env,
+ }
+
return runner.Run(ctx, command, stdout, stderr)
}
diff --git a/testrunner/subprocess_runner.go b/testrunner/subprocess_runner.go
index 3ad36a1..db70a56 100644
--- a/testrunner/subprocess_runner.go
+++ b/testrunner/subprocess_runner.go
@@ -22,6 +22,10 @@
// WD is the working directory of the subprocesses; if unspecified, that
// of the current process will be used.
WD string
+
+ // Env is the environment of the subprocess, following the usual convention of a list of
+ // strings of the form "<environment variable name>=<value>".
+ Env []string
}
// Run executes the given command.
@@ -32,6 +36,7 @@
Stdout: stdout,
Stderr: stderr,
Dir: r.WD,
+ Env: r.Env,
SysProcAttr: &syscall.SysProcAttr{Setpgid: true},
}