OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
6 #include <gtest/gtest-spi.h> | 6 #include <gtest/gtest-spi.h> |
7 | 7 |
8 #include "update_engine/terminator.h" | 8 #include "update_engine/terminator.h" |
9 | 9 |
10 using std::string; | 10 using std::string; |
(...skipping 16 matching lines...) Expand all Loading... |
27 }; | 27 }; |
28 | 28 |
29 typedef TerminatorTest TerminatorDeathTest; | 29 typedef TerminatorTest TerminatorDeathTest; |
30 | 30 |
31 namespace { | 31 namespace { |
32 void UnblockExitThroughUnblocker() { | 32 void UnblockExitThroughUnblocker() { |
33 ScopedTerminatorExitUnblocker unblocker = ScopedTerminatorExitUnblocker(); | 33 ScopedTerminatorExitUnblocker unblocker = ScopedTerminatorExitUnblocker(); |
34 } | 34 } |
35 | 35 |
36 void RaiseSIGTERM() { | 36 void RaiseSIGTERM() { |
37 ASSERT_EXIT(raise(SIGTERM), ExitedWithCode(0), ""); | 37 ASSERT_EXIT(raise(SIGTERM), ExitedWithCode(1), ""); |
38 } | 38 } |
39 } // namespace {} | 39 } // namespace {} |
40 | 40 |
41 TEST_F(TerminatorTest, HandleSignalTest) { | 41 TEST_F(TerminatorTest, HandleSignalTest) { |
42 Terminator::set_exit_blocked(true); | 42 Terminator::set_exit_blocked(true); |
43 Terminator::HandleSignal(SIGTERM); | 43 Terminator::HandleSignal(SIGTERM); |
44 ASSERT_TRUE(Terminator::exit_requested()); | 44 ASSERT_TRUE(Terminator::exit_requested()); |
45 } | 45 } |
46 | 46 |
47 TEST_F(TerminatorTest, ScopedTerminatorExitUnblockerTest) { | 47 TEST_F(TerminatorTest, ScopedTerminatorExitUnblockerTest) { |
48 Terminator::set_exit_blocked(true); | 48 Terminator::set_exit_blocked(true); |
49 ASSERT_TRUE(Terminator::exit_blocked()); | 49 ASSERT_TRUE(Terminator::exit_blocked()); |
50 ASSERT_FALSE(Terminator::exit_requested()); | 50 ASSERT_FALSE(Terminator::exit_requested()); |
51 UnblockExitThroughUnblocker(); | 51 UnblockExitThroughUnblocker(); |
52 ASSERT_FALSE(Terminator::exit_blocked()); | 52 ASSERT_FALSE(Terminator::exit_blocked()); |
53 ASSERT_FALSE(Terminator::exit_requested()); | 53 ASSERT_FALSE(Terminator::exit_requested()); |
54 } | 54 } |
55 | 55 |
56 TEST_F(TerminatorDeathTest, ExitTest) { | 56 TEST_F(TerminatorDeathTest, ExitTest) { |
57 ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(0), ""); | 57 ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(1), ""); |
58 Terminator::set_exit_blocked(true); | 58 Terminator::set_exit_blocked(true); |
59 ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(0), ""); | 59 ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(1), ""); |
60 } | 60 } |
61 | 61 |
62 TEST_F(TerminatorDeathTest, RaiseSignalTest) { | 62 TEST_F(TerminatorDeathTest, RaiseSignalTest) { |
63 RaiseSIGTERM(); | 63 RaiseSIGTERM(); |
64 Terminator::set_exit_blocked(true); | 64 Terminator::set_exit_blocked(true); |
65 EXPECT_FATAL_FAILURE(RaiseSIGTERM(), ""); | 65 EXPECT_FATAL_FAILURE(RaiseSIGTERM(), ""); |
66 } | 66 } |
67 | 67 |
68 TEST_F(TerminatorDeathTest, ScopedTerminatorExitUnblockerExitTest) { | 68 TEST_F(TerminatorDeathTest, ScopedTerminatorExitUnblockerExitTest) { |
69 Terminator::set_exit_blocked(true); | 69 Terminator::set_exit_blocked(true); |
70 Terminator::exit_requested_ = 1; | 70 Terminator::exit_requested_ = 1; |
71 ASSERT_EXIT(UnblockExitThroughUnblocker(), ExitedWithCode(0), ""); | 71 ASSERT_EXIT(UnblockExitThroughUnblocker(), ExitedWithCode(1), ""); |
72 } | 72 } |
73 | 73 |
74 } // namespace chromeos_update_engine | 74 } // namespace chromeos_update_engine |
OLD | NEW |