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 <signal.h> | 5 #include <signal.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <sys/wait.h> | 8 #include <sys/wait.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
| 11 #include "base/logging.h" |
11 #include "base/posix/eintr_wrapper.h" | 12 #include "base/posix/eintr_wrapper.h" |
12 #include "sandbox/linux/tests/unit_tests.h" | 13 #include "sandbox/linux/tests/unit_tests.h" |
13 | 14 |
14 namespace sandbox { | 15 namespace sandbox { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Let's not use any of the "magic" values used internally in unit_tests.cc, | 19 // Let's not use any of the "magic" values used internally in unit_tests.cc, |
19 // such as kExpectedValue. | 20 // such as kExpectedValue. |
20 const int kExpectedExitCode = 100; | 21 const int kExpectedExitCode = 100; |
21 | 22 |
22 SANDBOX_DEATH_TEST(UnitTests, | 23 SANDBOX_DEATH_TEST(UnitTests, |
23 DeathExitCode, | 24 DeathExitCode, |
24 DEATH_EXIT_CODE(kExpectedExitCode)) { | 25 DEATH_EXIT_CODE(kExpectedExitCode)) { |
25 exit(kExpectedExitCode); | 26 exit(kExpectedExitCode); |
26 } | 27 } |
27 | 28 |
28 const int kExpectedSignalNumber = SIGKILL; | 29 const int kExpectedSignalNumber = SIGKILL; |
29 | 30 |
30 SANDBOX_DEATH_TEST(UnitTests, | 31 SANDBOX_DEATH_TEST(UnitTests, |
31 DeathBySignal, | 32 DeathBySignal, |
32 DEATH_BY_SIGNAL(kExpectedSignalNumber)) { | 33 DEATH_BY_SIGNAL(kExpectedSignalNumber)) { |
33 raise(kExpectedSignalNumber); | 34 raise(kExpectedSignalNumber); |
34 } | 35 } |
35 | 36 |
| 37 SANDBOX_TEST_ALLOW_NOISE(UnitTests, NoisyTest) { |
| 38 LOG(ERROR) << "The cow says moo!"; |
| 39 } |
| 40 |
36 // Test that a subprocess can be forked() and can use exit(3) instead of | 41 // Test that a subprocess can be forked() and can use exit(3) instead of |
37 // _exit(2). | 42 // _exit(2). |
38 TEST(UnitTests, SubProcessCanExit) { | 43 TEST(UnitTests, SubProcessCanExit) { |
39 pid_t child = fork(); | 44 pid_t child = fork(); |
40 ASSERT_NE(-1, child); | 45 ASSERT_NE(-1, child); |
41 | 46 |
42 if (!child) { | 47 if (!child) { |
43 exit(kExpectedExitCode); | 48 exit(kExpectedExitCode); |
44 } | 49 } |
45 | 50 |
46 int status = 0; | 51 int status = 0; |
47 pid_t waitpid_ret = HANDLE_EINTR(waitpid(child, &status, 0)); | 52 pid_t waitpid_ret = HANDLE_EINTR(waitpid(child, &status, 0)); |
48 EXPECT_EQ(child, waitpid_ret); | 53 EXPECT_EQ(child, waitpid_ret); |
49 EXPECT_TRUE(WIFEXITED(status)); | 54 EXPECT_TRUE(WIFEXITED(status)); |
50 EXPECT_EQ(kExpectedExitCode, WEXITSTATUS(status)); | 55 EXPECT_EQ(kExpectedExitCode, WEXITSTATUS(status)); |
51 } | 56 } |
52 | 57 |
53 } // namespace | 58 } // namespace |
54 | 59 |
55 } // namespace sandbox | 60 } // namespace sandbox |
OLD | NEW |