Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2012 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 17 | #include "update_engine/postinstall_runner_action.h" |
| 18 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 19 | #include <sys/stat.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <unistd.h> |
Andrew de los Reyes | bfabc30 | 2011-01-31 17:23:50 -0800 | [diff] [blame] | 22 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 23 | #include <memory> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <vector> |
Andrew de los Reyes | bfabc30 | 2011-01-31 17:23:50 -0800 | [diff] [blame] | 26 | |
Ben Chan | 06c76a4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 27 | #include <base/files/file_util.h> |
Alex Deymo | 0b3db6b | 2015-08-10 15:19:37 -0700 | [diff] [blame] | 28 | #include <base/message_loop/message_loop.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 29 | #include <base/strings/string_util.h> |
| 30 | #include <base/strings/stringprintf.h> |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 31 | #include <chromeos/bind_lambda.h> |
Alex Deymo | 0b3db6b | 2015-08-10 15:19:37 -0700 | [diff] [blame] | 32 | #include <chromeos/message_loops/base_message_loop.h> |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 33 | #include <chromeos/message_loops/message_loop_utils.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 34 | #include <gtest/gtest.h> |
Andrew de los Reyes | bfabc30 | 2011-01-31 17:23:50 -0800 | [diff] [blame] | 35 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 36 | #include "update_engine/constants.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 37 | #include "update_engine/test_utils.h" |
| 38 | #include "update_engine/utils.h" |
| 39 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 40 | using chromeos::MessageLoop; |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 41 | using chromeos_update_engine::test_utils::System; |
| 42 | using chromeos_update_engine::test_utils::WriteFileString; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 43 | using std::string; |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 44 | using std::unique_ptr; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 45 | using std::vector; |
| 46 | |
| 47 | namespace chromeos_update_engine { |
| 48 | |
| 49 | class PostinstallRunnerActionTest : public ::testing::Test { |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 50 | protected: |
| 51 | void SetUp() override { |
| 52 | loop_.SetAsCurrent(); |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 53 | async_signal_handler_.Init(); |
| 54 | subprocess_.Init(&async_signal_handler_); |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 57 | // DoTest with various combinations of do_losetup, err_code and |
| 58 | // powerwash_required. |
| 59 | void DoTest(bool do_losetup, int err_code, bool powerwash_required); |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | static const char* kImageMountPointTemplate; |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 63 | |
Alex Deymo | 0b3db6b | 2015-08-10 15:19:37 -0700 | [diff] [blame] | 64 | base::MessageLoopForIO base_loop_; |
| 65 | chromeos::BaseMessageLoop loop_{&base_loop_}; |
Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 66 | chromeos::AsynchronousSignalHandler async_signal_handler_; |
Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 67 | Subprocess subprocess_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | class PostinstActionProcessorDelegate : public ActionProcessorDelegate { |
| 71 | public: |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 72 | PostinstActionProcessorDelegate() |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 73 | : code_(ErrorCode::kError), |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 74 | code_set_(false) {} |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 75 | void ProcessingDone(const ActionProcessor* processor, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 76 | ErrorCode code) { |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 77 | MessageLoop::current()->BreakLoop(); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 78 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 79 | void ActionCompleted(ActionProcessor* processor, |
| 80 | AbstractAction* action, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 81 | ErrorCode code) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 82 | if (action->Type() == PostinstallRunnerAction::StaticType()) { |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 83 | code_ = code; |
| 84 | code_set_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 85 | } |
| 86 | } |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 87 | ErrorCode code_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 88 | bool code_set_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 92 | DoTest(true, 0, false); |
| 93 | } |
| 94 | |
| 95 | TEST_F(PostinstallRunnerActionTest, RunAsRootPowerwashRequiredTest) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 96 | DoTest(true, 0, true); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 100 | DoTest(false, 0, true); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | TEST_F(PostinstallRunnerActionTest, RunAsRootErrScriptTest) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 104 | DoTest(true, 1, false); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Andrew de los Reyes | c1d5c93 | 2011-04-20 17:15:47 -0700 | [diff] [blame] | 107 | TEST_F(PostinstallRunnerActionTest, RunAsRootFirmwareBErrScriptTest) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 108 | DoTest(true, 3, false); |
Andrew de los Reyes | c1d5c93 | 2011-04-20 17:15:47 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Don Garrett | 81018e0 | 2013-07-30 18:46:31 -0700 | [diff] [blame] | 111 | TEST_F(PostinstallRunnerActionTest, RunAsRootFirmwareROErrScriptTest) { |
Don Garrett | 81018e0 | 2013-07-30 18:46:31 -0700 | [diff] [blame] | 112 | DoTest(true, 4, false); |
| 113 | } |
| 114 | |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 115 | const char* PostinstallRunnerActionTest::kImageMountPointTemplate = |
| 116 | "au_destination-XXXXXX"; |
| 117 | |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 118 | void PostinstallRunnerActionTest::DoTest( |
| 119 | bool do_losetup, |
| 120 | int err_code, |
| 121 | bool powerwash_required) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 122 | ASSERT_EQ(0, getuid()) << "Run me as root. Ideally don't run other tests " |
| 123 | << "as root, tho."; |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 124 | // True if the post-install action is expected to succeed. |
| 125 | bool should_succeed = do_losetup && !err_code; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 126 | |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 127 | string orig_cwd; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 128 | { |
| 129 | vector<char> buf(1000); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 130 | ASSERT_EQ(buf.data(), getcwd(buf.data(), buf.size())); |
| 131 | orig_cwd = string(buf.data(), strlen(buf.data())); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 134 | // Create a unique named working directory and chdir into it. |
| 135 | string cwd; |
| 136 | ASSERT_TRUE(utils::MakeTempDirectory( |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 137 | "postinstall_runner_action_unittest-XXXXXX", |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 138 | &cwd)); |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 139 | ASSERT_EQ(0, test_utils::Chdir(cwd)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 140 | |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 141 | // Create a 10MiB sparse file to be used as image; format it as ext2. |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 142 | ASSERT_EQ(0, System( |
Alex Deymo | 1f93d03 | 2015-03-10 18:58:32 -0700 | [diff] [blame] | 143 | "dd if=/dev/zero of=image.dat seek=10485759 bs=1 count=1 " |
| 144 | "status=none")); |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 145 | ASSERT_EQ(0, System("mkfs.ext2 -F image.dat")); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 146 | |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 147 | // Create a uniquely named image mount point, mount the image. |
| 148 | ASSERT_EQ(0, System(string("mkdir -p ") + kStatefulPartition)); |
| 149 | string mountpoint; |
| 150 | ASSERT_TRUE(utils::MakeTempDirectory( |
| 151 | string(kStatefulPartition) + "/" + kImageMountPointTemplate, |
| 152 | &mountpoint)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 153 | ASSERT_EQ(0, System(string("mount -o loop image.dat ") + mountpoint)); |
| 154 | |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 155 | // Generate a fake postinst script inside the image. |
| 156 | string script = (err_code ? |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 157 | base::StringPrintf("#!/bin/bash\nexit %d", err_code) : |
| 158 | base::StringPrintf( |
| 159 | "#!/bin/bash\n" |
| 160 | "mount | grep au_postint_mount | grep ext2\n" |
| 161 | "if [ $? -eq 0 ]; then\n" |
| 162 | " touch %s/postinst_called\n" |
| 163 | "fi\n", |
| 164 | cwd.c_str())); |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 165 | const string script_file_name = mountpoint + "/postinst"; |
| 166 | ASSERT_TRUE(WriteFileString(script_file_name, script)); |
| 167 | ASSERT_EQ(0, System(string("chmod a+x ") + script_file_name)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 168 | |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 169 | // Unmount image; do not remove the uniquely named directory as it will be |
| 170 | // reused during the test. |
Ben Chan | 77a1eba | 2012-10-07 22:54:55 -0700 | [diff] [blame] | 171 | ASSERT_TRUE(utils::UnmountFilesystem(mountpoint)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 172 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 173 | // get a loop device we can use for the install device |
Don Garrett | 58e8b1f | 2012-01-31 16:38:16 -0800 | [diff] [blame] | 174 | string dev = "/dev/null"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 175 | |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 176 | unique_ptr<test_utils::ScopedLoopbackDeviceBinder> loop_releaser; |
Darin Petkov | 56dad72 | 2011-03-03 16:03:56 -0800 | [diff] [blame] | 177 | if (do_losetup) { |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 178 | loop_releaser.reset(new test_utils::ScopedLoopbackDeviceBinder( |
| 179 | cwd + "/image.dat", &dev)); |
Darin Petkov | 56dad72 | 2011-03-03 16:03:56 -0800 | [diff] [blame] | 180 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 181 | |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 182 | // We use a test-specific powerwash marker file, to avoid race conditions. |
| 183 | string powerwash_marker_file = mountpoint + "/factory_install_reset"; |
| 184 | LOG(INFO) << ">>> powerwash_marker_file=" << powerwash_marker_file; |
| 185 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 186 | ActionProcessor processor; |
Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 187 | ObjectFeederAction<InstallPlan> feeder_action; |
| 188 | InstallPlan install_plan; |
| 189 | install_plan.install_path = dev; |
Chris Sosa | 000ecb3 | 2014-04-23 12:21:18 -0700 | [diff] [blame] | 190 | install_plan.download_url = "http://devserver:8080/update"; |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 191 | install_plan.powerwash_required = powerwash_required; |
Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 192 | feeder_action.set_obj(install_plan); |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 193 | PostinstallRunnerAction runner_action(powerwash_marker_file.c_str()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 194 | BondActions(&feeder_action, &runner_action); |
Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 195 | ObjectCollectorAction<InstallPlan> collector_action; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 196 | BondActions(&runner_action, &collector_action); |
| 197 | PostinstActionProcessorDelegate delegate; |
| 198 | processor.EnqueueAction(&feeder_action); |
| 199 | processor.EnqueueAction(&runner_action); |
| 200 | processor.EnqueueAction(&collector_action); |
| 201 | processor.set_delegate(&delegate); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 202 | |
Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 203 | loop_.PostTask(FROM_HERE, |
| 204 | base::Bind([&processor] { processor.StartProcessing(); })); |
| 205 | loop_.Run(); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 206 | ASSERT_FALSE(processor.IsRunning()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 207 | |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 208 | EXPECT_TRUE(delegate.code_set_); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 209 | EXPECT_EQ(should_succeed, delegate.code_ == ErrorCode::kSuccess); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 210 | EXPECT_EQ(should_succeed, !collector_action.object().install_path.empty()); |
| 211 | if (should_succeed) |
Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 212 | EXPECT_TRUE(install_plan == collector_action.object()); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 213 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 214 | const base::FilePath kPowerwashMarkerPath(powerwash_marker_file); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 215 | string actual_cmd; |
| 216 | if (should_succeed && powerwash_required) { |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 217 | EXPECT_TRUE(base::ReadFileToString(kPowerwashMarkerPath, &actual_cmd)); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 218 | EXPECT_EQ(kPowerwashCommand, actual_cmd); |
| 219 | } else { |
| 220 | EXPECT_FALSE( |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 221 | base::ReadFileToString(kPowerwashMarkerPath, &actual_cmd)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 222 | } |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 223 | |
Andrew de los Reyes | c1d5c93 | 2011-04-20 17:15:47 -0700 | [diff] [blame] | 224 | if (err_code == 2) |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 225 | EXPECT_EQ(ErrorCode::kPostinstallBootedFromFirmwareB, delegate.code_); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 226 | |
| 227 | struct stat stbuf; |
| 228 | int rc = lstat((string(cwd) + "/postinst_called").c_str(), &stbuf); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 229 | if (should_succeed) |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 230 | ASSERT_EQ(0, rc); |
| 231 | else |
| 232 | ASSERT_LT(rc, 0); |
| 233 | |
Darin Petkov | 56dad72 | 2011-03-03 16:03:56 -0800 | [diff] [blame] | 234 | if (do_losetup) { |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 235 | loop_releaser.reset(nullptr); |
Darin Petkov | 56dad72 | 2011-03-03 16:03:56 -0800 | [diff] [blame] | 236 | } |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 237 | |
| 238 | // Remove unique stateful directory. |
| 239 | ASSERT_EQ(0, System(string("rm -fr ") + mountpoint)); |
| 240 | |
| 241 | // Remove the temporary work directory. |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 242 | ASSERT_EQ(0, test_utils::Chdir(orig_cwd)); |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 243 | ASSERT_EQ(0, System(string("rm -fr ") + cwd)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // Death tests don't seem to be working on Hardy |
| 247 | TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) { |
| 248 | ASSERT_EQ(0, getuid()); |
Darin Petkov | 6d5dbf6 | 2010-11-08 16:09:55 -0800 | [diff] [blame] | 249 | PostinstallRunnerAction runner_action; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 250 | ASSERT_DEATH({ runner_action.TerminateProcessing(); }, |
| 251 | "postinstall_runner_action.h:.*] Check failed"); |
| 252 | } |
| 253 | |
| 254 | } // namespace chromeos_update_engine |