Roll libvpx 861f35:1fff3e
[chromium-blink-merge.git] / sandbox / linux / tests / test_utils.cc
blob747bad27a5d470e9b06d235496122f021b69d9e5
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/linux/tests/test_utils.h"
7 #include <errno.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 #include <sys/wait.h>
11 #include <unistd.h>
13 #include "base/logging.h"
14 #include "base/posix/eintr_wrapper.h"
16 namespace sandbox {
18 bool TestUtils::CurrentProcessHasChildren() {
19 siginfo_t process_info;
20 int ret = HANDLE_EINTR(
21 waitid(P_ALL, 0, &process_info, WEXITED | WNOHANG | WNOWAIT));
22 if (-1 == ret) {
23 PCHECK(ECHILD == errno);
24 return false;
25 } else {
26 return true;
30 void TestUtils::HandlePostForkReturn(pid_t pid) {
31 const int kChildExitCode = 1;
32 if (pid > 0) {
33 int status = 0;
34 PCHECK(pid == HANDLE_EINTR(waitpid(pid, &status, 0)));
35 CHECK(WIFEXITED(status));
36 CHECK_EQ(kChildExitCode, WEXITSTATUS(status));
37 } else if (pid == 0) {
38 _exit(kChildExitCode);
42 } // namespace sandbox