From bf86d29b9edb7e1346978c74ea837b5ec3683b2d Mon Sep 17 00:00:00 2001 From: Mara Mihali Date: Wed, 23 Jun 2021 16:23:53 +0000 Subject: pkg/instance: add RunnerCmd This function creates the command for starting a runner with the provided command line arguments. --- pkg/instance/instance.go | 4 ++++ pkg/instance/instance_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'pkg/instance') 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) + } +} -- cgit mrf-deployment