Darin Petkov | 7ed561b | 2011-10-04 02:59:03 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 5 | #include <fcntl.h> |
| 6 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 7 | #include <set> |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 8 | #include <string> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 9 | #include <vector> |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 10 | |
| 11 | #include <base/eintr_wrapper.h> |
| 12 | #include <base/string_util.h> |
| 13 | #include <glib.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 14 | #include <gtest/gtest.h> |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 15 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 | #include "update_engine/filesystem_copier_action.h" |
| 17 | #include "update_engine/filesystem_iterator.h" |
| 18 | #include "update_engine/omaha_hash_calculator.h" |
| 19 | #include "update_engine/test_utils.h" |
| 20 | #include "update_engine/utils.h" |
| 21 | |
| 22 | using std::set; |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 23 | using std::string; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 24 | using std::vector; |
| 25 | |
| 26 | namespace chromeos_update_engine { |
| 27 | |
| 28 | class FilesystemCopierActionTest : public ::testing::Test { |
| 29 | protected: |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 30 | // |verify_hash|: 0 - no hash verification, 1 -- successful hash verification, |
| 31 | // 2 -- hash verification failure. |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 32 | void DoTest(bool run_out_of_space, |
| 33 | bool terminate_early, |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 34 | bool use_kernel_partition, |
| 35 | int verify_hash); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 | void SetUp() { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 37 | } |
| 38 | void TearDown() { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 39 | } |
| 40 | }; |
| 41 | |
| 42 | class FilesystemCopierActionTestDelegate : public ActionProcessorDelegate { |
| 43 | public: |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 44 | FilesystemCopierActionTestDelegate() : ran_(false), code_(kActionCodeError) {} |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 45 | void ExitMainLoop() { |
| 46 | while (g_main_context_pending(NULL)) { |
| 47 | g_main_context_iteration(NULL, false); |
| 48 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 49 | g_main_loop_quit(loop_); |
| 50 | } |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 51 | void ProcessingDone(const ActionProcessor* processor, ActionExitCode code) { |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 52 | ExitMainLoop(); |
| 53 | } |
| 54 | void ProcessingStopped(const ActionProcessor* processor) { |
| 55 | ExitMainLoop(); |
| 56 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 57 | void ActionCompleted(ActionProcessor* processor, |
| 58 | AbstractAction* action, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 59 | ActionExitCode code) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 60 | if (action->Type() == FilesystemCopierAction::StaticType()) { |
| 61 | ran_ = true; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 62 | code_ = code; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | void set_loop(GMainLoop* loop) { |
| 66 | loop_ = loop; |
| 67 | } |
| 68 | bool ran() { return ran_; } |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 69 | ActionExitCode code() { return code_; } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 70 | private: |
| 71 | GMainLoop* loop_; |
| 72 | bool ran_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 73 | ActionExitCode code_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 76 | struct StartProcessorCallbackArgs { |
| 77 | ActionProcessor* processor; |
| 78 | FilesystemCopierAction* filesystem_copier_action; |
| 79 | bool terminate_early; |
| 80 | }; |
| 81 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 82 | gboolean StartProcessorInRunLoop(gpointer data) { |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 83 | StartProcessorCallbackArgs* args = |
| 84 | reinterpret_cast<StartProcessorCallbackArgs*>(data); |
| 85 | ActionProcessor* processor = args->processor; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 86 | processor->StartProcessing(); |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 87 | if (args->terminate_early) { |
| 88 | EXPECT_TRUE(args->filesystem_copier_action); |
| 89 | args->processor->StopProcessing(); |
| 90 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 91 | return FALSE; |
| 92 | } |
| 93 | |
| 94 | TEST_F(FilesystemCopierActionTest, RunAsRootSimpleTest) { |
| 95 | ASSERT_EQ(0, getuid()); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 96 | DoTest(false, false, false, 0); |
| 97 | DoTest(false, false, true, 0); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 98 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 99 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 100 | void FilesystemCopierActionTest::DoTest(bool run_out_of_space, |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 101 | bool terminate_early, |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 102 | bool use_kernel_partition, |
| 103 | int verify_hash) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 104 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 105 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 106 | string a_loop_file; |
| 107 | string b_loop_file; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 108 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 109 | EXPECT_TRUE(utils::MakeTempFile("/tmp/a_loop_file.XXXXXX", |
| 110 | &a_loop_file, |
| 111 | NULL)); |
| 112 | ScopedPathUnlinker a_loop_file_unlinker(a_loop_file); |
| 113 | EXPECT_TRUE(utils::MakeTempFile("/tmp/b_loop_file.XXXXXX", |
| 114 | &b_loop_file, |
| 115 | NULL)); |
| 116 | ScopedPathUnlinker b_loop_file_unlinker(b_loop_file); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 117 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 118 | // Make random data for a, zero filled data for b. |
| 119 | const size_t kLoopFileSize = 10 * 1024 * 1024 + 512; |
| 120 | vector<char> a_loop_data(kLoopFileSize); |
| 121 | FillWithData(&a_loop_data); |
| 122 | vector<char> b_loop_data(run_out_of_space ? |
| 123 | (kLoopFileSize - 1) : |
| 124 | kLoopFileSize, |
| 125 | '\0'); // Fill with 0s |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 126 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 127 | // Write data to disk |
| 128 | EXPECT_TRUE(WriteFileVector(a_loop_file, a_loop_data)); |
| 129 | EXPECT_TRUE(WriteFileVector(b_loop_file, b_loop_data)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 130 | |
Don Garrett | 58e8b1f | 2012-01-31 16:38:16 -0800 | [diff] [blame] | 131 | // Attach loop devices to the files |
| 132 | string a_dev; |
| 133 | string b_dev; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 134 | |
Don Garrett | 58e8b1f | 2012-01-31 16:38:16 -0800 | [diff] [blame] | 135 | ScopedLoopbackDeviceBinder a_dev_releaser(a_loop_file, &a_dev); |
| 136 | ScopedLoopbackDeviceBinder b_dev_releaser(b_loop_file, &b_dev); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 137 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 138 | // Set up the action objects |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 139 | InstallPlan install_plan; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 140 | if (verify_hash) { |
| 141 | if (use_kernel_partition) { |
| 142 | install_plan.kernel_install_path = a_dev; |
| 143 | install_plan.kernel_size = |
| 144 | kLoopFileSize - ((verify_hash == 2) ? 1 : 0); |
| 145 | EXPECT_TRUE(OmahaHashCalculator::RawHashOfData( |
| 146 | a_loop_data, |
| 147 | &install_plan.kernel_hash)); |
| 148 | } else { |
| 149 | install_plan.install_path = a_dev; |
| 150 | install_plan.rootfs_size = |
| 151 | kLoopFileSize - ((verify_hash == 2) ? 1 : 0); |
| 152 | EXPECT_TRUE(OmahaHashCalculator::RawHashOfData( |
| 153 | a_loop_data, |
| 154 | &install_plan.rootfs_hash)); |
| 155 | } |
| 156 | } else { |
| 157 | if (use_kernel_partition) { |
| 158 | install_plan.kernel_install_path = b_dev; |
| 159 | } else { |
| 160 | install_plan.install_path = b_dev; |
| 161 | } |
| 162 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 163 | |
| 164 | ActionProcessor processor; |
| 165 | FilesystemCopierActionTestDelegate delegate; |
| 166 | delegate.set_loop(loop); |
| 167 | processor.set_delegate(&delegate); |
| 168 | |
| 169 | ObjectFeederAction<InstallPlan> feeder_action; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 170 | FilesystemCopierAction copier_action(use_kernel_partition, |
| 171 | verify_hash != 0); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 172 | ObjectCollectorAction<InstallPlan> collector_action; |
| 173 | |
| 174 | BondActions(&feeder_action, &copier_action); |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 175 | BondActions(&copier_action, &collector_action); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 176 | |
| 177 | processor.EnqueueAction(&feeder_action); |
| 178 | processor.EnqueueAction(&copier_action); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 179 | processor.EnqueueAction(&collector_action); |
| 180 | |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 181 | if (!verify_hash) { |
| 182 | copier_action.set_copy_source(a_dev); |
| 183 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 184 | feeder_action.set_obj(install_plan); |
| 185 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 186 | StartProcessorCallbackArgs start_callback_args; |
| 187 | start_callback_args.processor = &processor; |
| 188 | start_callback_args.filesystem_copier_action = &copier_action; |
| 189 | start_callback_args.terminate_early = terminate_early; |
| 190 | |
| 191 | g_timeout_add(0, &StartProcessorInRunLoop, &start_callback_args); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 192 | g_main_loop_run(loop); |
| 193 | g_main_loop_unref(loop); |
| 194 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 195 | if (!terminate_early) |
| 196 | EXPECT_TRUE(delegate.ran()); |
| 197 | if (run_out_of_space || terminate_early) { |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 198 | EXPECT_EQ(kActionCodeError, delegate.code()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 199 | return; |
| 200 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 201 | if (verify_hash == 2) { |
| 202 | EXPECT_EQ(use_kernel_partition ? |
| 203 | kActionCodeNewKernelVerificationError : |
| 204 | kActionCodeNewRootfsVerificationError, |
| 205 | delegate.code()); |
| 206 | return; |
| 207 | } |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 208 | EXPECT_EQ(kActionCodeSuccess, delegate.code()); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 209 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 210 | // Make sure everything in the out_image is there |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 211 | vector<char> a_out; |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 212 | EXPECT_TRUE(utils::ReadFile(a_dev, &a_out)); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 213 | if (!verify_hash) { |
| 214 | vector<char> b_out; |
| 215 | EXPECT_TRUE(utils::ReadFile(b_dev, &b_out)); |
| 216 | EXPECT_TRUE(ExpectVectorsEq(a_out, b_out)); |
| 217 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 218 | EXPECT_TRUE(ExpectVectorsEq(a_loop_data, a_out)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 219 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 220 | EXPECT_TRUE(collector_action.object() == install_plan); |
| 221 | } |
| 222 | |
| 223 | class FilesystemCopierActionTest2Delegate : public ActionProcessorDelegate { |
| 224 | public: |
| 225 | void ActionCompleted(ActionProcessor* processor, |
| 226 | AbstractAction* action, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 227 | ActionExitCode code) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 228 | if (action->Type() == FilesystemCopierAction::StaticType()) { |
| 229 | ran_ = true; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 230 | code_ = code; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | GMainLoop *loop_; |
| 234 | bool ran_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 235 | ActionExitCode code_; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | TEST_F(FilesystemCopierActionTest, MissingInputObjectTest) { |
| 239 | ActionProcessor processor; |
| 240 | FilesystemCopierActionTest2Delegate delegate; |
| 241 | |
| 242 | processor.set_delegate(&delegate); |
| 243 | |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 244 | FilesystemCopierAction copier_action(false, false); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 245 | ObjectCollectorAction<InstallPlan> collector_action; |
| 246 | |
| 247 | BondActions(&copier_action, &collector_action); |
| 248 | |
| 249 | processor.EnqueueAction(&copier_action); |
| 250 | processor.EnqueueAction(&collector_action); |
| 251 | processor.StartProcessing(); |
| 252 | EXPECT_FALSE(processor.IsRunning()); |
| 253 | EXPECT_TRUE(delegate.ran_); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 254 | EXPECT_EQ(kActionCodeError, delegate.code_); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 257 | TEST_F(FilesystemCopierActionTest, ResumeTest) { |
| 258 | ActionProcessor processor; |
| 259 | FilesystemCopierActionTest2Delegate delegate; |
| 260 | |
| 261 | processor.set_delegate(&delegate); |
| 262 | |
| 263 | ObjectFeederAction<InstallPlan> feeder_action; |
| 264 | const char* kUrl = "http://some/url"; |
Darin Petkov | 7ed561b | 2011-10-04 02:59:03 -0700 | [diff] [blame] | 265 | InstallPlan install_plan(true, kUrl, 0, "", "", ""); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 266 | feeder_action.set_obj(install_plan); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 267 | FilesystemCopierAction copier_action(false, false); |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 268 | ObjectCollectorAction<InstallPlan> collector_action; |
| 269 | |
| 270 | BondActions(&feeder_action, &copier_action); |
| 271 | BondActions(&copier_action, &collector_action); |
| 272 | |
| 273 | processor.EnqueueAction(&feeder_action); |
| 274 | processor.EnqueueAction(&copier_action); |
| 275 | processor.EnqueueAction(&collector_action); |
| 276 | processor.StartProcessing(); |
| 277 | EXPECT_FALSE(processor.IsRunning()); |
| 278 | EXPECT_TRUE(delegate.ran_); |
| 279 | EXPECT_EQ(kActionCodeSuccess, delegate.code_); |
| 280 | EXPECT_EQ(kUrl, collector_action.object().download_url); |
| 281 | } |
| 282 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 283 | TEST_F(FilesystemCopierActionTest, NonExistentDriveTest) { |
| 284 | ActionProcessor processor; |
| 285 | FilesystemCopierActionTest2Delegate delegate; |
| 286 | |
| 287 | processor.set_delegate(&delegate); |
| 288 | |
| 289 | ObjectFeederAction<InstallPlan> feeder_action; |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 290 | InstallPlan install_plan(false, |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 291 | "", |
| 292 | 0, |
| 293 | "", |
| 294 | "/no/such/file", |
| 295 | "/no/such/file"); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 296 | feeder_action.set_obj(install_plan); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 297 | FilesystemCopierAction copier_action(false, false); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 298 | ObjectCollectorAction<InstallPlan> collector_action; |
| 299 | |
| 300 | BondActions(&copier_action, &collector_action); |
| 301 | |
| 302 | processor.EnqueueAction(&feeder_action); |
| 303 | processor.EnqueueAction(&copier_action); |
| 304 | processor.EnqueueAction(&collector_action); |
| 305 | processor.StartProcessing(); |
| 306 | EXPECT_FALSE(processor.IsRunning()); |
| 307 | EXPECT_TRUE(delegate.ran_); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 308 | EXPECT_EQ(kActionCodeError, delegate.code_); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 311 | TEST_F(FilesystemCopierActionTest, RunAsRootVerifyHashTest) { |
| 312 | ASSERT_EQ(0, getuid()); |
| 313 | DoTest(false, false, false, 1); |
| 314 | DoTest(false, false, true, 1); |
| 315 | } |
| 316 | |
| 317 | TEST_F(FilesystemCopierActionTest, RunAsRootVerifyHashFailTest) { |
| 318 | ASSERT_EQ(0, getuid()); |
| 319 | DoTest(false, false, false, 2); |
| 320 | DoTest(false, false, true, 2); |
| 321 | } |
| 322 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 323 | TEST_F(FilesystemCopierActionTest, RunAsRootNoSpaceTest) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 324 | ASSERT_EQ(0, getuid()); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 325 | DoTest(true, false, false, 0); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 328 | TEST_F(FilesystemCopierActionTest, RunAsRootTerminateEarlyTest) { |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 329 | ASSERT_EQ(0, getuid()); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 330 | DoTest(false, true, false, 0); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 333 | TEST_F(FilesystemCopierActionTest, RunAsRootDetermineFilesystemSizeTest) { |
| 334 | string img; |
| 335 | EXPECT_TRUE(utils::MakeTempFile("/tmp/img.XXXXXX", &img, NULL)); |
| 336 | ScopedPathUnlinker img_unlinker(img); |
| 337 | CreateExtImageAtPath(img, NULL); |
| 338 | // Extend the "partition" holding the file system from 10MiB to 20MiB. |
| 339 | EXPECT_EQ(0, System(StringPrintf( |
| 340 | "dd if=/dev/zero of=%s seek=20971519 bs=1 count=1", |
| 341 | img.c_str()))); |
| 342 | EXPECT_EQ(20 * 1024 * 1024, utils::FileSize(img)); |
| 343 | |
| 344 | for (int i = 0; i < 2; ++i) { |
| 345 | bool is_kernel = i == 1; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 346 | FilesystemCopierAction action(is_kernel, false); |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 347 | EXPECT_EQ(kint64max, action.filesystem_size_); |
| 348 | { |
| 349 | int fd = HANDLE_EINTR(open(img.c_str(), O_RDONLY)); |
| 350 | EXPECT_TRUE(fd > 0); |
| 351 | ScopedFdCloser fd_closer(&fd); |
| 352 | action.DetermineFilesystemSize(fd); |
| 353 | } |
| 354 | EXPECT_EQ(is_kernel ? kint64max : 10 * 1024 * 1024, |
| 355 | action.filesystem_size_); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 360 | } // namespace chromeos_update_engine |