aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/instance
diff options
context:
space:
mode:
authorMara Mihali <maramihali@google.com>2021-06-23 16:23:53 +0000
committerDmitry Vyukov <dvyukov@google.com>2021-06-30 09:35:14 +0200
commitbf86d29b9edb7e1346978c74ea837b5ec3683b2d (patch)
tree3b2421a7eeea0adf572e467cef1d0430ed200cd4 /pkg/instance
parent090883682f4b0031511214e359fb7b4355e71364 (diff)
pkg/instance: add RunnerCmd
This function creates the command for starting a runner with the provided command line arguments.
Diffstat (limited to 'pkg/instance')
-rw-r--r--pkg/instance/instance.go4
-rw-r--r--pkg/instance/instance_test.go35
2 files changed, 39 insertions, 0 deletions
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go
index 52881b353..19c71c067 100644
--- a/pkg/instance/instance.go
+++ b/pkg/instance/instance.go
@@ -499,3 +499,7 @@ var MakeBin = func() string {
}
return "make"
}()
+
+func RunnerCmd(prog, fwdAddr, os, arch string, poolIdx, vmIdx int) string {
+ return fmt.Sprintf("%s -addr=%s -os=%s -arch=%s -pool=%v -vm=%v", prog, fwdAddr, os, arch, poolIdx, vmIdx)
+}
diff --git a/pkg/instance/instance_test.go b/pkg/instance/instance_test.go
index d95b6623e..c5d8cd1d1 100644
--- a/pkg/instance/instance_test.go
+++ b/pkg/instance/instance_test.go
@@ -141,3 +141,38 @@ func TestExecprogCmd(t *testing.T) {
t.Errorf("bad slowdown: %v, want: %v", *flagSlowdown, 10)
}
}
+
+func TestRunnerCmd(t *testing.T) {
+ flags := flag.NewFlagSet("", flag.ContinueOnError)
+ flagFwdAddr := flags.String("addr", "", "verifier rpc address")
+ flagOS := flags.String("os", "", "target OS")
+ flagArch := flags.String("arch", "", "target architecture")
+ flagPool := flags.Int("pool", 0, "index of pool that started VM")
+ flagVM := flags.Int("vm", 0, "index of VM that started the Runner")
+
+ cmdLine := RunnerCmd(os.Args[0], "localhost:1234", targets.Linux, targets.AMD64, 0, 0)
+ args := strings.Split(cmdLine, " ")[1:]
+ if err := flags.Parse(args); err != nil {
+ t.Fatalf("error parsing flags: %v, want: nil", err)
+ }
+
+ if got, want := *flagFwdAddr, "localhost:1234"; got != want {
+ t.Errorf("bad addr: %q, want: %q", got, want)
+ }
+
+ if got, want := *flagOS, targets.Linux; got != want {
+ t.Errorf("bad os: %q, want %q", got, want)
+ }
+
+ if got, want := *flagArch, targets.AMD64; got != want {
+ t.Errorf("bad arch: %q, want: %q", got, want)
+ }
+
+ if got, want := *flagPool, 0; got != want {
+ t.Errorf("bad pool index: %d, want: %d", got, want)
+ }
+
+ if got, want := *flagVM, 0; got != want {
+ t.Errorf("bad vm index: %d, want: %d", got, want)
+ }
+}