OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "util/mac/service_management.h" | 15 #include "util/mac/service_management.h" |
16 | 16 |
17 #import <Foundation/Foundation.h> | 17 #import <Foundation/Foundation.h> |
18 #include <launch.h> | 18 #include <launch.h> |
19 | 19 |
20 #include <string> | 20 #include <string> |
21 #include <vector> | 21 #include <vector> |
22 | 22 |
23 #include "base/mac/foundation_util.h" | 23 #include "base/mac/foundation_util.h" |
24 #include "base/mac/scoped_cftyperef.h" | 24 #include "base/mac/scoped_cftyperef.h" |
25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
26 #include "base/strings/sys_string_conversions.h" | 26 #include "base/strings/sys_string_conversions.h" |
27 #include "base/rand_util.h" | |
28 #include "gtest/gtest.h" | 27 #include "gtest/gtest.h" |
29 #include "util/misc/clock.h" | 28 #include "util/misc/clock.h" |
| 29 #include "util/misc/random_string.h" |
30 #include "util/posix/process_info.h" | 30 #include "util/posix/process_info.h" |
31 #include "util/stdlib/objc.h" | 31 #include "util/stdlib/objc.h" |
32 | 32 |
33 namespace crashpad { | 33 namespace crashpad { |
34 namespace test { | 34 namespace test { |
35 namespace { | 35 namespace { |
36 | 36 |
37 // Ensures that the process with the specified PID is running, identifying it by | 37 // Ensures that the process with the specified PID is running, identifying it by |
38 // requiring that its argv[argc - 1] compare equal to last_arg. | 38 // requiring that its argv[argc - 1] compare equal to last_arg. |
39 void ExpectProcessIsRunning(pid_t pid, std::string& last_arg) { | 39 void ExpectProcessIsRunning(pid_t pid, std::string& last_arg) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 SleepNanoseconds(1E6); // 1 millisecond | 101 SleepNanoseconds(1E6); // 1 millisecond |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 ASSERT_FALSE(job_argv.empty()); | 105 ASSERT_FALSE(job_argv.empty()); |
106 EXPECT_NE(last_arg, job_argv.back()); | 106 EXPECT_NE(last_arg, job_argv.back()); |
107 } | 107 } |
108 | 108 |
109 TEST(ServiceManagement, SubmitRemoveJob) { | 109 TEST(ServiceManagement, SubmitRemoveJob) { |
110 @autoreleasepool { | 110 @autoreleasepool { |
111 std::string cookie; | 111 const std::string cookie = RandomString(); |
112 for (int index = 0; index < 16; ++index) { | |
113 cookie.append(1, base::RandInt('A', 'Z')); | |
114 } | |
115 | 112 |
116 std::string shell_script = | 113 std::string shell_script = |
117 base::StringPrintf("sleep 10; echo %s", cookie.c_str()); | 114 base::StringPrintf("sleep 10; echo %s", cookie.c_str()); |
118 NSString* shell_script_ns = base::SysUTF8ToNSString(shell_script); | 115 NSString* shell_script_ns = base::SysUTF8ToNSString(shell_script); |
119 | 116 |
120 const char kJobLabel[] = "org.chromium.crashpad.test.service_management"; | 117 const char kJobLabel[] = "org.chromium.crashpad.test.service_management"; |
121 NSDictionary* job_dictionary_ns = @{ | 118 NSDictionary* job_dictionary_ns = @{ |
122 @LAUNCH_JOBKEY_LABEL : @"org.chromium.crashpad.test.service_management", | 119 @LAUNCH_JOBKEY_LABEL : @"org.chromium.crashpad.test.service_management", |
123 @LAUNCH_JOBKEY_RUNATLOAD : @YES, | 120 @LAUNCH_JOBKEY_RUNATLOAD : @YES, |
124 @LAUNCH_JOBKEY_PROGRAMARGUMENTS : | 121 @LAUNCH_JOBKEY_PROGRAMARGUMENTS : |
(...skipping 29 matching lines...) Expand all Loading... |
154 // an error. | 151 // an error. |
155 EXPECT_FALSE(ServiceManagementRemoveJob(kJobLabel, false)); | 152 EXPECT_FALSE(ServiceManagementRemoveJob(kJobLabel, false)); |
156 | 153 |
157 ExpectProcessIsNotRunning(job_pid, shell_script); | 154 ExpectProcessIsNotRunning(job_pid, shell_script); |
158 } | 155 } |
159 } | 156 } |
160 | 157 |
161 } // namespace | 158 } // namespace |
162 } // namespace test | 159 } // namespace test |
163 } // namespace crashpad | 160 } // namespace crashpad |
OLD | NEW |