static gpointer testServerMonitorThreadFunc(gpointer) { // Wait for the specified timeout to happen. g_usleep(gMaxWaitForChild * G_USEC_PER_SEC); // Kill the child process if not ready yet. if (!gChildIsReady) stopTestServer(); g_thread_exit(0); return 0; }
static void startTestServer() { // Prepare argv[] for spawning the server process. GOwnPtr<char> testServerPath(g_build_filename(WEBKIT_EXEC_PATH, "TestWebKitAPI", "WebKit2Gtk", gTestServerAppName, NULL)); // We install a handler to ensure that we kill the child process // if the parent dies because of whatever the reason is. signal(SIGABRT, sigAbortHandler); char* testServerArgv[2]; testServerArgv[0] = testServerPath.get(); testServerArgv[1] = 0; // Spawn the server, getting its stdout file descriptor to set a // communication channel, so we know when it's ready. int childStdout = 0; g_assert(g_spawn_async_with_pipes(0, testServerArgv, 0, static_cast<GSpawnFlags>(0), 0, 0, &gChildProcessPid, 0, &childStdout, 0, 0)); // Start monitoring the test server (in a separate thread) to // ensure we don't block on the child process more than a timeout. startTestServerMonitor(); char msg[2]; GIOChannel* ioChannel = g_io_channel_unix_new(childStdout); if (g_io_channel_read_chars(ioChannel, msg, 2, 0, 0) == G_IO_STATUS_NORMAL) { // Check whether the server sent a message saying it's ready // and store the result globally, so the monitor can see it. gChildIsReady = msg[0] == 'O' && msg[1] == 'K'; } g_io_channel_unref(ioChannel); close(childStdout); // The timeout was reached and the server is not ready yet, so // stop it inmediately, and let the unit tests fail. if (!gChildIsReady) stopTestServer(); }
void afterAll() { stopTestServer(); }
static void sigAbortHandler(int sigNum) { // Just stop the test server if SIGABRT was received. stopTestServer(); }
void afterAll() { // Ensure we stop the server. stopTestServer(); }