diff --git a/drivers/shared/executor/executor_test.go b/drivers/shared/executor/executor_test.go index 05ab48938..aca70a6b4 100644 --- a/drivers/shared/executor/executor_test.go +++ b/drivers/shared/executor/executor_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "runtime" "strings" "syscall" "testing" @@ -58,6 +59,8 @@ func testExecutorCommand(t *testing.T) (*ExecCommand, *allocdir.AllocDir) { DiskMB: task.Resources.DiskMB, }, } + + setupRootfs(t, td.Dir) configureTLogging(cmd) return cmd, allocDir } @@ -123,6 +126,7 @@ func TestExecutor_Start_Wait(pt *testing.T) { execCmd, allocDir := testExecutorCommand(t) execCmd.Cmd = "/bin/echo" execCmd.Args = []string{"hello world"} + defer allocDir.Destroy() executor := factory(testlog.HCLogger(t)) defer executor.Shutdown("", 0) @@ -190,7 +194,7 @@ func TestExecutor_Start_Kill(pt *testing.T) { require := require.New(t) execCmd, allocDir := testExecutorCommand(t) execCmd.Cmd = "/bin/sleep" - execCmd.Args = []string{"10 && hello world"} + execCmd.Args = []string{"10"} defer allocDir.Destroy() executor := factory(testlog.HCLogger(t)) defer executor.Shutdown("", 0) @@ -281,3 +285,36 @@ func TestUniversalExecutor_LookupPath(t *testing.T) { require.Nil(err) } + +// setupRoootfs setups the rootfs for libcontainer executor +// It uses busybox to make some binaries available - somewhat cheaper +// than mounting the underlying host filesystem +func setupRootfs(t *testing.T, rootfs string) { + paths := []string{ + "/bin/sh", + "/bin/sleep", + "/bin/echo", + "/bin/date", + } + + for _, p := range paths { + setupRootfsBinary(t, rootfs, p) + } +} + +// setupRootfsBinary installs a busybox link in the desired path +func setupRootfsBinary(t *testing.T, rootfs, path string) { + t.Helper() + + dst := filepath.Join(rootfs, path) + err := os.MkdirAll(filepath.Dir(dst), 666) + require.NoError(t, err) + + src := filepath.Join( + "test-resources", "busybox", + fmt.Sprintf("busybox-%s-%s", runtime.GOOS, runtime.GOARCH), + ) + + err = os.Link(src, dst) + require.NoError(t, err) +} diff --git a/drivers/shared/executor/test-resources/busybox/README b/drivers/shared/executor/test-resources/busybox/README new file mode 100644 index 000000000..f60a0f318 --- /dev/null +++ b/drivers/shared/executor/test-resources/busybox/README @@ -0,0 +1,3 @@ +Downloaded busybox https://busybox.net/downloads/binaries/ + +Busybox binaries are statically linked binaries, that is a multi-call binary. It's a single binary that can act like many commonly used utilities (e.g. /bin/sh, echo, sleep, etc). More info is found in https://busybox.net/downloads/BusyBox.html . diff --git a/drivers/shared/executor/test-resources/busybox/busybox-linux-amd64 b/drivers/shared/executor/test-resources/busybox/busybox-linux-amd64 new file mode 100755 index 000000000..3391e45b3 Binary files /dev/null and b/drivers/shared/executor/test-resources/busybox/busybox-linux-amd64 differ