Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sandbox/linux/services/syscall_wrappers.h" | 5 #include "sandbox/linux/services/syscall_wrappers.h" |
| 6 | 6 |
| 7 #include <sys/syscall.h> | 7 #include <sys/syscall.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <sys/wait.h> | 9 #include <sys/wait.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 _exit(1); | 51 _exit(1); |
| 52 } | 52 } |
| 53 | 53 |
| 54 ASSERT_NE(-1, pid); | 54 ASSERT_NE(-1, pid); |
| 55 int status = 0; | 55 int status = 0; |
| 56 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); | 56 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); |
| 57 ASSERT_TRUE(WIFEXITED(status)); | 57 ASSERT_TRUE(WIFEXITED(status)); |
| 58 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status)); | 58 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Some libcs cache the result of the getpid syscall. This tests that | |
| 62 // the cache is updated after sys_clone. | |
| 63 TEST(SyscallWrappers, CloneUpdatesPidCache) { | |
| 64 // Warm up the PID cache. | |
| 65 ASSERT_EQ(sys_getpid(), getpid()); | |
| 66 | |
| 67 pid_t ctid = 0; | |
| 68 pid_t pid = | |
| 69 sys_clone(CLONE_CHILD_SETTID | SIGCHLD, nullptr, nullptr, &ctid, nullptr); | |
| 70 | |
| 71 const int kSuccessExit = 0; | |
| 72 if (0 == pid) { | |
| 73 // In child. The pid cache should have been updated. | |
| 74 ASSERT_EQ(ctid, getpid()); | |
|
jln (very slow on Chromium)
2014/12/15 23:31:35
Let's not use ASSERT in there, it's confusing. I w
rickyz (no longer on Chrome)
2014/12/16 00:35:09
I merged the tests, but actually, I'm curious as t
jln (very slow on Chromium)
2014/12/16 01:11:22
ASSERT is only guaranteed to return from the curre
| |
| 75 _exit(kSuccessExit); | |
| 76 } | |
| 77 | |
| 78 ASSERT_NE(-1, pid); | |
| 79 int status = 0; | |
| 80 ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); | |
| 81 ASSERT_TRUE(WIFEXITED(status)); | |
| 82 EXPECT_EQ(kSuccessExit, WEXITSTATUS(status)); | |
| 83 } | |
| 84 | |
| 61 } // namespace | 85 } // namespace |
| 62 | 86 |
| 63 } // namespace sandbox | 87 } // namespace sandbox |
| OLD | NEW |