OLD | NEW |
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium OS 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 <chromeos/process.h> | 5 #include <chromeos/process.h> |
6 #include <chromeos/process_mock.h> | 6 #include <chromeos/process_mock.h> |
7 #include <chromeos/test_helpers.h> | 7 #include <chromeos/test_helpers.h> |
8 | 8 |
9 #include <base/file_util.h> | 9 #include <base/file_util.h> |
10 #include <gtest/gtest.h> | 10 #include <gtest/gtest.h> |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 EXPECT_TRUE(process_.Start()); | 189 EXPECT_TRUE(process_.Start()); |
190 int write_fd = process_.GetPipe(STDIN_FILENO); | 190 int write_fd = process_.GetPipe(STDIN_FILENO); |
191 EXPECT_EQ(-1, process_.GetPipe(STDERR_FILENO)); | 191 EXPECT_EQ(-1, process_.GetPipe(STDERR_FILENO)); |
192 EXPECT_TRUE(file_util::WriteFile(GetFdPath(write_fd), kMessage, | 192 EXPECT_TRUE(file_util::WriteFile(GetFdPath(write_fd), kMessage, |
193 strlen(kMessage))); | 193 strlen(kMessage))); |
194 close(write_fd); | 194 close(write_fd); |
195 EXPECT_EQ(0, process_.Wait()); | 195 EXPECT_EQ(0, process_.Wait()); |
196 ExpectFileEquals(kMessage, output_file_.c_str()); | 196 ExpectFileEquals(kMessage, output_file_.c_str()); |
197 } | 197 } |
198 | 198 |
| 199 TEST_F(ProcessTest, WithSameUid) { |
| 200 gid_t uid = geteuid(); |
| 201 process_.AddArg(kBinEcho); |
| 202 process_.SetUid(uid); |
| 203 EXPECT_EQ(0, process_.Run()); |
| 204 } |
| 205 |
| 206 TEST_F(ProcessTest, WithSameGid) { |
| 207 gid_t gid = getegid(); |
| 208 process_.AddArg(kBinEcho); |
| 209 process_.SetGid(gid); |
| 210 EXPECT_EQ(0, process_.Run()); |
| 211 } |
| 212 |
| 213 TEST_F(ProcessTest, WithIllegalUid) { |
| 214 ASSERT_NE(0, geteuid()); |
| 215 process_.AddArg(kBinEcho); |
| 216 process_.SetUid(0); |
| 217 EXPECT_EQ(127, process_.Run()); |
| 218 std::string contents; |
| 219 EXPECT_TRUE(file_util::ReadFileToString(FilePath(output_file_), |
| 220 &contents)); |
| 221 EXPECT_NE(std::string::npos, |
| 222 contents.find("Unable to set UID to 0: 1\n")); |
| 223 } |
| 224 |
| 225 TEST_F(ProcessTest, WithIllegalGid) { |
| 226 ASSERT_NE(0, getegid()); |
| 227 process_.AddArg(kBinEcho); |
| 228 process_.SetGid(0); |
| 229 EXPECT_EQ(127, process_.Run()); |
| 230 std::string contents; |
| 231 EXPECT_TRUE(file_util::ReadFileToString(FilePath(output_file_), |
| 232 &contents)); |
| 233 EXPECT_NE(std::string::npos, |
| 234 contents.find("Unable to set GID to 0: 1\n")); |
| 235 } |
| 236 |
199 TEST_F(ProcessTest, NoParams) { | 237 TEST_F(ProcessTest, NoParams) { |
200 EXPECT_EQ(127, process_.Run()); | 238 EXPECT_EQ(127, process_.Run()); |
201 } | 239 } |
202 | 240 |
203 TEST_F(ProcessTest, SegFaultHandling) { | 241 TEST_F(ProcessTest, SegFaultHandling) { |
204 process_.AddArg(kBinBash); | 242 process_.AddArg(kBinBash); |
205 process_.AddArg("-c"); | 243 process_.AddArg("-c"); |
206 process_.AddArg("kill -SEGV $$"); | 244 process_.AddArg("kill -SEGV $$"); |
207 EXPECT_EQ(-1, process_.Run()); | 245 EXPECT_EQ(-1, process_.Run()); |
208 EXPECT_TRUE(FindLog("did not exit normally: 11")); | 246 EXPECT_TRUE(FindLog("did not exit normally: 11")); |
(...skipping 27 matching lines...) Expand all Loading... |
236 EXPECT_TRUE(process_.Kill(SIGTERM, 1)); | 274 EXPECT_TRUE(process_.Kill(SIGTERM, 1)); |
237 EXPECT_EQ(0, process_.pid()); | 275 EXPECT_EQ(0, process_.pid()); |
238 } | 276 } |
239 | 277 |
240 TEST_F(ProcessTest, Reset) { | 278 TEST_F(ProcessTest, Reset) { |
241 process_.AddArg(kBinFalse); | 279 process_.AddArg(kBinFalse); |
242 process_.Reset(0); | 280 process_.Reset(0); |
243 process_.AddArg(kBinEcho); | 281 process_.AddArg(kBinEcho); |
244 EXPECT_EQ(0, process_.Run()); | 282 EXPECT_EQ(0, process_.Run()); |
245 } | 283 } |
OLD | NEW |