OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
58 #include <mach/vm_param.h> | 58 #include <mach/vm_param.h> |
59 #include <malloc/malloc.h> | 59 #include <malloc/malloc.h> |
60 #include "base/mac/mac_util.h" | 60 #include "base/mac/mac_util.h" |
61 #endif | 61 #endif |
62 | 62 |
63 using base::FilePath; | 63 using base::FilePath; |
64 | 64 |
65 namespace { | 65 namespace { |
66 | 66 |
| 67 const char kSignalFileSlow[] = "SlowChildProcess.die"; |
| 68 const char kSignalFileKill[] = "KilledChildProcess.die"; |
| 69 |
| 70 #if defined(OS_POSIX) |
| 71 const char kSignalFileTerm[] = "TerminatedChildProcess.die"; |
| 72 |
67 #if defined(OS_ANDROID) | 73 #if defined(OS_ANDROID) |
68 const char kShellPath[] = "/system/bin/sh"; | 74 const char kShellPath[] = "/system/bin/sh"; |
69 const char kPosixShell[] = "sh"; | 75 const char kPosixShell[] = "sh"; |
70 #else | 76 #else |
71 const char kShellPath[] = "/bin/sh"; | 77 const char kShellPath[] = "/bin/sh"; |
72 const char kPosixShell[] = "bash"; | 78 const char kPosixShell[] = "bash"; |
73 #endif | 79 #endif |
74 | 80 #endif // defined(OS_POSIX) |
75 const char kSignalFileSlow[] = "SlowChildProcess.die"; | |
76 const char kSignalFileKill[] = "KilledChildProcess.die"; | |
77 | |
78 #if defined(OS_POSIX) | |
79 const char kSignalFileTerm[] = "TerminatedChildProcess.die"; | |
80 #endif | |
81 | 81 |
82 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
83 const int kExpectedStillRunningExitCode = 0x102; | 83 const int kExpectedStillRunningExitCode = 0x102; |
84 const int kExpectedKilledExitCode = 1; | 84 const int kExpectedKilledExitCode = 1; |
85 #else | 85 #else |
86 const int kExpectedStillRunningExitCode = 0; | 86 const int kExpectedStillRunningExitCode = 0; |
87 #endif | 87 #endif |
88 | 88 |
89 // Sleeps until file filename is created. | 89 // Sleeps until file filename is created. |
90 void WaitToDie(const char* filename) { | 90 void WaitToDie(const char* filename) { |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 const int kSuccess = 0; | 1018 const int kSuccess = 0; |
1019 | 1019 |
1020 MULTIPROCESS_TEST_MAIN(CheckPidProcess) { | 1020 MULTIPROCESS_TEST_MAIN(CheckPidProcess) { |
1021 const pid_t kInitPid = 1; | 1021 const pid_t kInitPid = 1; |
1022 const pid_t pid = syscall(__NR_getpid); | 1022 const pid_t pid = syscall(__NR_getpid); |
1023 CHECK(pid == kInitPid); | 1023 CHECK(pid == kInitPid); |
1024 CHECK(getpid() == pid); | 1024 CHECK(getpid() == pid); |
1025 return kSuccess; | 1025 return kSuccess; |
1026 } | 1026 } |
1027 | 1027 |
| 1028 #if defined(CLONE_NEWUSER) && defined(CLONE_NEWPID) |
1028 TEST_F(ProcessUtilTest, CloneFlags) { | 1029 TEST_F(ProcessUtilTest, CloneFlags) { |
1029 if (RunningOnValgrind() || | 1030 if (RunningOnValgrind() || |
1030 !base::PathExists(FilePath("/proc/self/ns/user")) || | 1031 !base::PathExists(FilePath("/proc/self/ns/user")) || |
1031 !base::PathExists(FilePath("/proc/self/ns/pid"))) { | 1032 !base::PathExists(FilePath("/proc/self/ns/pid"))) { |
1032 // User or PID namespaces are not supported. | 1033 // User or PID namespaces are not supported. |
1033 return; | 1034 return; |
1034 } | 1035 } |
1035 | 1036 |
1036 base::LaunchOptions options; | 1037 base::LaunchOptions options; |
1037 options.clone_flags = CLONE_NEWUSER | CLONE_NEWPID; | 1038 options.clone_flags = CLONE_NEWUSER | CLONE_NEWPID; |
1038 | 1039 |
1039 base::Process process(SpawnChildWithOptions("CheckPidProcess", options)); | 1040 base::Process process(SpawnChildWithOptions("CheckPidProcess", options)); |
1040 ASSERT_TRUE(process.IsValid()); | 1041 ASSERT_TRUE(process.IsValid()); |
1041 | 1042 |
1042 int exit_code = 42; | 1043 int exit_code = 42; |
1043 EXPECT_TRUE(process.WaitForExit(&exit_code)); | 1044 EXPECT_TRUE(process.WaitForExit(&exit_code)); |
1044 EXPECT_EQ(kSuccess, exit_code); | 1045 EXPECT_EQ(kSuccess, exit_code); |
1045 } | 1046 } |
| 1047 #endif |
1046 | 1048 |
1047 TEST(ForkWithFlagsTest, UpdatesPidCache) { | 1049 TEST(ForkWithFlagsTest, UpdatesPidCache) { |
1048 // The libc clone function, which allows ForkWithFlags to keep the pid cache | 1050 // The libc clone function, which allows ForkWithFlags to keep the pid cache |
1049 // up to date, does not work on Valgrind. | 1051 // up to date, does not work on Valgrind. |
1050 if (RunningOnValgrind()) { | 1052 if (RunningOnValgrind()) { |
1051 return; | 1053 return; |
1052 } | 1054 } |
1053 | 1055 |
1054 // Warm up the libc pid cache, if there is one. | 1056 // Warm up the libc pid cache, if there is one. |
1055 ASSERT_EQ(syscall(__NR_getpid), getpid()); | 1057 ASSERT_EQ(syscall(__NR_getpid), getpid()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 options.current_directory = base::FilePath("/dev/null"); | 1105 options.current_directory = base::FilePath("/dev/null"); |
1104 | 1106 |
1105 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); | 1107 base::Process process(SpawnChildWithOptions("SimpleChildProcess", options)); |
1106 ASSERT_TRUE(process.IsValid()); | 1108 ASSERT_TRUE(process.IsValid()); |
1107 | 1109 |
1108 int exit_code = kSuccess; | 1110 int exit_code = kSuccess; |
1109 EXPECT_TRUE(process.WaitForExit(&exit_code)); | 1111 EXPECT_TRUE(process.WaitForExit(&exit_code)); |
1110 EXPECT_NE(kSuccess, exit_code); | 1112 EXPECT_NE(kSuccess, exit_code); |
1111 } | 1113 } |
1112 #endif | 1114 #endif |
OLD | NEW |