summaryrefslogtreecommitdiff
path: root/test/fixtures/util.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-01-22 12:24:00 +0100
committerKonstantin Käfer <mail@kkaefer.com>2015-02-04 10:49:06 +0100
commitaa09aa321b24981bf0f8f2dec97ac100727266a5 (patch)
tree9291597f54e8d86357a285f9ffd426ff435f9387 /test/fixtures/util.cpp
parent8a1fce547e9ad0bf750418c844c9b23a3ee6d8dd (diff)
downloadqtlocation-mapboxgl-aa09aa321b24981bf0f8f2dec97ac100727266a5.tar.gz
rearrange tests and make more robust
Diffstat (limited to 'test/fixtures/util.cpp')
-rw-r--r--test/fixtures/util.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/fixtures/util.cpp b/test/fixtures/util.cpp
new file mode 100644
index 0000000000..7434393556
--- /dev/null
+++ b/test/fixtures/util.cpp
@@ -0,0 +1,35 @@
+#include "util.hpp"
+
+#include <csignal>
+
+namespace mbgl {
+namespace test {
+
+pid_t startServer(const char *executable) {
+ const std::string parent_pid = std::to_string(getpid());
+ pid_t pid = fork();
+ if (pid < 0) {
+ throw std::runtime_error("Cannot create server process");
+ } else if (pid == 0) {
+ char *args[] = { const_cast<char *>(executable),
+ const_cast<char *>(parent_pid.c_str()),
+ nullptr };
+ int ret = execv(executable, args);
+ // This call should not return. In case execve failed, we exit anyway.
+ if (ret < 0) {
+ fprintf(stderr, "Failed to start server: %s\n", strerror(errno));
+ }
+ exit(0);
+ } else {
+ // Wait until the server process sends SIGCONT.
+ raise(SIGSTOP);
+ }
+ return pid;
+}
+
+void stopServer(pid_t pid) {
+ kill(pid, SIGTERM);
+}
+
+}
+}