From 1642899159103942176fd5aa13139507f16f3204 Mon Sep 17 00:00:00 2001 From: "[[sroracle]]" Date: Fri, 24 May 2019 14:27:24 -0400 Subject: [PATCH] test: fix RunTest on systems with single file core utilities (#95) On systems such as Alpine Linux (with busybox) and Adelie Linux (with coreutils), the shell core utilities such as pwd, true, false, env, and yes are all symlinks to a single binary. This single binary relies on the name of the symlink to determine which command ("applet" in busybox parlance) to execute. Therefore creating symlinks to these symlinks will not work since the single binary will only see the top-level symlink and thus think it is an invalid command. Instead, generate executable shell scripts that exec into the desired command. This also allows $PATH based resolution to occur instead of hard-coding the command paths. See also issue #94. --- test/test-run.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/test-run.cpp b/test/test-run.cpp index 4edfd90..23d4a56 100644 --- a/test/test-run.cpp +++ b/test/test-run.cpp @@ -68,13 +68,16 @@ protected: TempDir tmp; class Run run; - void setRunLink(const char* path) { - tmp.fs->symlink(kj::Path{"cfg","jobs",run.name+".run"}, path, kj::WriteMode::CREATE|kj::WriteMode::CREATE_PARENT|kj::WriteMode::EXECUTABLE); + void setRunLink(const char * path) { + KJ_IF_MAYBE(f, tmp.fs->tryOpenFile(kj::Path{"cfg", "jobs", run.name + ".run"}, + kj::WriteMode::CREATE | kj::WriteMode::CREATE_PARENT | kj::WriteMode::EXECUTABLE)) { + (f->get())->writeAll(std::string("#!/bin/sh\nexec ") + path + "\n"); + } } }; TEST_F(RunTest, WorkingDirectory) { - setRunLink("/bin/pwd"); + setRunLink("pwd"); run.configure(1, node, *tmp.fs); runAll(); std::string cwd{tmp.path.append(kj::Path{"run","foo","1"}).toString(true).cStr()}; @@ -82,21 +85,21 @@ TEST_F(RunTest, WorkingDirectory) { } TEST_F(RunTest, SuccessStatus) { - setRunLink("/bin/true"); + setRunLink("true"); run.configure(1, node, *tmp.fs); runAll(); EXPECT_EQ(RunState::SUCCESS, run.result); } TEST_F(RunTest, FailedStatus) { - setRunLink("/bin/false"); + setRunLink("false"); run.configure(1, node, *tmp.fs); runAll(); EXPECT_EQ(RunState::FAILED, run.result); } TEST_F(RunTest, Environment) { - setRunLink("/usr/bin/env"); + setRunLink("env"); run.configure(1234, node, *tmp.fs); runAll(); @@ -113,7 +116,7 @@ TEST_F(RunTest, Environment) { } TEST_F(RunTest, ParamsToEnv) { - setRunLink("/usr/bin/env"); + setRunLink("env"); run.params["foo"] = "bar"; run.configure(1, node, *tmp.fs); runAll(); @@ -122,7 +125,7 @@ TEST_F(RunTest, ParamsToEnv) { } TEST_F(RunTest, Abort) { - setRunLink("/usr/bin/yes"); + setRunLink("yes"); run.configure(1, node, *tmp.fs); run.step(); usleep(200); // TODO fix