MCPcopy Create free account
hub / github.com/apache/mesos / execute

Function execute

src/tests/script.cpp:51–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49namespace tests {
50
51void execute(const string& script)
52{
53 // Create a temporary directory for the test.
54 Try<string> directory = environment->mkdtemp();
55
56 CHECK_SOME(directory) << "Failed to create temporary directory";
57
58 if (flags.verbose) {
59 std::cerr << "Using temporary directory '"
60 << directory.get() << "'" << std::endl;
61 }
62
63 // Determine the path for the script.
64 Result<string> path = os::realpath(getTestScriptPath(script));
65
66 if (!path.isSome()) {
67 FAIL() << "Failed to locate script "
68 << script << ": "
69 << (path.isError() ? path.error() : "No such file or directory");
70 }
71
72 // Fork a process to change directory and run the test.
73 pid_t pid;
74 if ((pid = fork()) == -1) {
75 FAIL() << "Failed to fork to launch script";
76 }
77
78 if (pid > 0) {
79 // In parent process.
80 int status;
81 while (wait(&status) != pid || WIFSTOPPED(status));
82 CHECK(WIFEXITED(status) || WIFSIGNALED(status))
83 << "Unexpected wait status " << status;
84
85 if (!WSUCCEEDED(status)) {
86 FAIL() << script << " " << WSTRINGIFY(status);
87 }
88 } else {
89 // In child process. DO NOT USE GLOG!
90
91 // Start by cd'ing into the temporary directory.
92 Try<Nothing> chdir = os::chdir(directory.get());
93 if (chdir.isError()) {
94 std::cerr << "Failed to chdir to '" << directory.get() << "': "
95 << chdir.error() << std::endl;
96 abort();
97 }
98
99 // Redirect output to /dev/null unless the test is verbose.
100 if (!flags.verbose) {
101 if (freopen(os::DEV_NULL, "w", stdout) == nullptr ||
102 freopen(os::DEV_NULL, "w", stderr) == nullptr) {
103 std::cerr << "Failed to redirect stdout/stderr to /dev/null:"
104 << os::strerror(errno) << std::endl;
105 abort();
106 }
107 }
108

Callers 2

async.hppFile · 0.50
initializeMethod · 0.50

Calls 15

getTestScriptPathFunction · 0.85
WSUCCEEDEDFunction · 0.85
WSTRINGIFYFunction · 0.85
strerrorFunction · 0.85
getTestHelperDirFunction · 0.85
getLauncherDirFunction · 0.85
getSbinDirFunction · 0.85
getWebUIDirFunction · 0.85
from_pathFunction · 0.85
protobufFunction · 0.85
mkdtempMethod · 0.80
principalMethod · 0.80

Tested by

no test coverage detected