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