blob: a1d5233aa30390ba0cb7ce44e1495da632f59664 [file] [log] [blame]
Mike Frysinger8155d082012-04-06 15:23:18 -04001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
adlr@google.com3defe6a2009-12-04 20:57:17 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Darin Petkov698d0412010-10-13 10:59:44 -07005#include <fcntl.h>
6
adlr@google.com3defe6a2009-12-04 20:57:17 +00007#include <set>
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -08008#include <string>
adlr@google.com3defe6a2009-12-04 20:57:17 +00009#include <vector>
Darin Petkov698d0412010-10-13 10:59:44 -070010
11#include <base/eintr_wrapper.h>
Gilad Arnoldae236702012-05-17 09:33:20 -070012// TODO(garnold) remove this include, here for debugging purposes
13#include <base/rand_util.h>
Darin Petkov698d0412010-10-13 10:59:44 -070014#include <base/string_util.h>
Mike Frysinger8155d082012-04-06 15:23:18 -040015#include <base/stringprintf.h>
Darin Petkov698d0412010-10-13 10:59:44 -070016#include <glib.h>
adlr@google.com3defe6a2009-12-04 20:57:17 +000017#include <gtest/gtest.h>
Darin Petkov698d0412010-10-13 10:59:44 -070018
adlr@google.com3defe6a2009-12-04 20:57:17 +000019#include "update_engine/filesystem_copier_action.h"
20#include "update_engine/filesystem_iterator.h"
21#include "update_engine/omaha_hash_calculator.h"
22#include "update_engine/test_utils.h"
23#include "update_engine/utils.h"
24
25using std::set;
Andrew de los Reyes4fe15d02009-12-10 19:01:36 -080026using std::string;
adlr@google.com3defe6a2009-12-04 20:57:17 +000027using std::vector;
28
29namespace chromeos_update_engine {
30
31class FilesystemCopierActionTest : public ::testing::Test {
32 protected:
Darin Petkov3aefa862010-12-07 14:45:00 -080033 // |verify_hash|: 0 - no hash verification, 1 -- successful hash verification,
34 // 2 -- hash verification failure.
Gilad Arnoldae236702012-05-17 09:33:20 -070035 // Returns true iff test has completed successfully.
36 // TODO(garnold) we temporarily add an |is_debug_random_loop_file_size| to try
37 // copying with different file sizes, in attempt to expose circumstances that
38 // lead to a certain unit test failure. The second variant preserves the
39 // original behavior. This code needs to be reverted.
40 bool DoTest(bool run_out_of_space,
Andrew de los Reyesf9185172010-05-03 11:07:05 -070041 bool terminate_early,
Darin Petkov3aefa862010-12-07 14:45:00 -080042 bool use_kernel_partition,
Gilad Arnoldae236702012-05-17 09:33:20 -070043 int verify_hash,
44 bool is_debug_random_loop_file_size);
45 inline bool DoTest(bool run_out_of_space,
46 bool terminate_early,
47 bool use_kernel_partition,
48 int verify_hash) {
49 return DoTest(run_out_of_space, terminate_early, use_kernel_partition,
50 verify_hash, false);
51 }
adlr@google.com3defe6a2009-12-04 20:57:17 +000052 void SetUp() {
adlr@google.com3defe6a2009-12-04 20:57:17 +000053 }
54 void TearDown() {
adlr@google.com3defe6a2009-12-04 20:57:17 +000055 }
56};
57
58class FilesystemCopierActionTestDelegate : public ActionProcessorDelegate {
59 public:
Darin Petkovc1a8b422010-07-19 11:34:49 -070060 FilesystemCopierActionTestDelegate() : ran_(false), code_(kActionCodeError) {}
Andrew de los Reyesc7020782010-04-28 10:46:04 -070061 void ExitMainLoop() {
62 while (g_main_context_pending(NULL)) {
63 g_main_context_iteration(NULL, false);
64 }
adlr@google.com3defe6a2009-12-04 20:57:17 +000065 g_main_loop_quit(loop_);
66 }
Darin Petkovc1a8b422010-07-19 11:34:49 -070067 void ProcessingDone(const ActionProcessor* processor, ActionExitCode code) {
Andrew de los Reyesc7020782010-04-28 10:46:04 -070068 ExitMainLoop();
69 }
70 void ProcessingStopped(const ActionProcessor* processor) {
71 ExitMainLoop();
72 }
adlr@google.com3defe6a2009-12-04 20:57:17 +000073 void ActionCompleted(ActionProcessor* processor,
74 AbstractAction* action,
Darin Petkovc1a8b422010-07-19 11:34:49 -070075 ActionExitCode code) {
adlr@google.com3defe6a2009-12-04 20:57:17 +000076 if (action->Type() == FilesystemCopierAction::StaticType()) {
77 ran_ = true;
Darin Petkovc1a8b422010-07-19 11:34:49 -070078 code_ = code;
adlr@google.com3defe6a2009-12-04 20:57:17 +000079 }
80 }
81 void set_loop(GMainLoop* loop) {
82 loop_ = loop;
83 }
84 bool ran() { return ran_; }
Darin Petkovc1a8b422010-07-19 11:34:49 -070085 ActionExitCode code() { return code_; }
adlr@google.com3defe6a2009-12-04 20:57:17 +000086 private:
87 GMainLoop* loop_;
88 bool ran_;
Darin Petkovc1a8b422010-07-19 11:34:49 -070089 ActionExitCode code_;
adlr@google.com3defe6a2009-12-04 20:57:17 +000090};
91
Andrew de los Reyesc7020782010-04-28 10:46:04 -070092struct StartProcessorCallbackArgs {
93 ActionProcessor* processor;
94 FilesystemCopierAction* filesystem_copier_action;
95 bool terminate_early;
96};
97
adlr@google.com3defe6a2009-12-04 20:57:17 +000098gboolean StartProcessorInRunLoop(gpointer data) {
Andrew de los Reyesc7020782010-04-28 10:46:04 -070099 StartProcessorCallbackArgs* args =
100 reinterpret_cast<StartProcessorCallbackArgs*>(data);
101 ActionProcessor* processor = args->processor;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000102 processor->StartProcessing();
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700103 if (args->terminate_early) {
104 EXPECT_TRUE(args->filesystem_copier_action);
105 args->processor->StopProcessing();
106 }
adlr@google.com3defe6a2009-12-04 20:57:17 +0000107 return FALSE;
108}
109
110TEST_F(FilesystemCopierActionTest, RunAsRootSimpleTest) {
111 ASSERT_EQ(0, getuid());
Gilad Arnoldae236702012-05-17 09:33:20 -0700112 EXPECT_TRUE(DoTest(false, false, false, 0, true));
113 EXPECT_TRUE(DoTest(false, false, true, 0, true));
adlr@google.com3defe6a2009-12-04 20:57:17 +0000114}
Darin Petkov3aefa862010-12-07 14:45:00 -0800115
Gilad Arnoldae236702012-05-17 09:33:20 -0700116bool FilesystemCopierActionTest::DoTest(bool run_out_of_space,
Andrew de los Reyesf9185172010-05-03 11:07:05 -0700117 bool terminate_early,
Darin Petkov3aefa862010-12-07 14:45:00 -0800118 bool use_kernel_partition,
Gilad Arnoldae236702012-05-17 09:33:20 -0700119 int verify_hash,
120 bool is_debug_random_loop_file_size) {
adlr@google.com3defe6a2009-12-04 20:57:17 +0000121 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
122
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700123 string a_loop_file;
124 string b_loop_file;
Darin Petkovc1a8b422010-07-19 11:34:49 -0700125
Gilad Arnoldae236702012-05-17 09:33:20 -0700126 if (!(utils::MakeTempFile("/tmp/a_loop_file.XXXXXX", &a_loop_file, NULL) &&
127 utils::MakeTempFile("/tmp/b_loop_file.XXXXXX", &b_loop_file, NULL))) {
128 ADD_FAILURE();
129 return false;
130 }
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700131 ScopedPathUnlinker a_loop_file_unlinker(a_loop_file);
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700132 ScopedPathUnlinker b_loop_file_unlinker(b_loop_file);
Darin Petkovc1a8b422010-07-19 11:34:49 -0700133
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700134 // Make random data for a, zero filled data for b.
Gilad Arnoldae236702012-05-17 09:33:20 -0700135 // TODO(garnold) eliminate the random choice, here for debugging purposes of
136 // unittest failures. We're testing the hypothesis that the particular file
137 // size causes this nondeterministic problem.
138 size_t randomLoopFileSize = 10 * 1024 * 1024 + 512; // original value
139 if (is_debug_random_loop_file_size) {
140 int debugRandomChoice = base::RandInt(0, 4);
141 switch (debugRandomChoice) {
142 case 0:
143 break; // keep default value
144 case 1:
145 randomLoopFileSize = 10 * 1024 * 1024; // exactly 10 MB
146 break;
147 case 2:
148 randomLoopFileSize = (10 * 1024 + 128) * 1024; // 10 MB + 128 KB
149 break;
150 case 3:
151 randomLoopFileSize = 30 * 1024 * 1024; // exactly 30 MB
152 break;
153 case 4:
154 randomLoopFileSize = 30 * 1024 * 1024 + 512; // 10 MB + 512 bytes
155 break;
156 default:
157 ADD_FAILURE();
158 return false;
159 }
160 LOG(INFO) << "(debug) randomLoopFileSize=" << randomLoopFileSize
161 << " (option " << debugRandomChoice << ")";
162 }
163 const size_t kLoopFileSize = randomLoopFileSize;
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700164 vector<char> a_loop_data(kLoopFileSize);
165 FillWithData(&a_loop_data);
166 vector<char> b_loop_data(run_out_of_space ?
167 (kLoopFileSize - 1) :
168 kLoopFileSize,
169 '\0'); // Fill with 0s
adlr@google.com3defe6a2009-12-04 20:57:17 +0000170
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700171 // Write data to disk
Gilad Arnoldae236702012-05-17 09:33:20 -0700172 if (!(WriteFileVector(a_loop_file, a_loop_data) &&
173 WriteFileVector(b_loop_file, b_loop_data))) {
174 ADD_FAILURE();
175 return false;
176 }
adlr@google.com3defe6a2009-12-04 20:57:17 +0000177
Don Garrett58e8b1f2012-01-31 16:38:16 -0800178 // Attach loop devices to the files
179 string a_dev;
180 string b_dev;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000181
Don Garrett58e8b1f2012-01-31 16:38:16 -0800182 ScopedLoopbackDeviceBinder a_dev_releaser(a_loop_file, &a_dev);
183 ScopedLoopbackDeviceBinder b_dev_releaser(b_loop_file, &b_dev);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000184
Gilad Arnoldae236702012-05-17 09:33:20 -0700185 bool success = true;
186
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700187 // Set up the action objects
adlr@google.com3defe6a2009-12-04 20:57:17 +0000188 InstallPlan install_plan;
Darin Petkov3aefa862010-12-07 14:45:00 -0800189 if (verify_hash) {
190 if (use_kernel_partition) {
191 install_plan.kernel_install_path = a_dev;
192 install_plan.kernel_size =
193 kLoopFileSize - ((verify_hash == 2) ? 1 : 0);
Gilad Arnoldae236702012-05-17 09:33:20 -0700194 if (!OmahaHashCalculator::RawHashOfData(a_loop_data,
195 &install_plan.kernel_hash)) {
196 ADD_FAILURE();
197 success = false;
198 }
Darin Petkov3aefa862010-12-07 14:45:00 -0800199 } else {
200 install_plan.install_path = a_dev;
201 install_plan.rootfs_size =
202 kLoopFileSize - ((verify_hash == 2) ? 1 : 0);
Gilad Arnoldae236702012-05-17 09:33:20 -0700203 if (!OmahaHashCalculator::RawHashOfData(a_loop_data,
204 &install_plan.rootfs_hash)) {
205 ADD_FAILURE();
206 success = false;
207 }
Darin Petkov3aefa862010-12-07 14:45:00 -0800208 }
209 } else {
210 if (use_kernel_partition) {
211 install_plan.kernel_install_path = b_dev;
212 } else {
213 install_plan.install_path = b_dev;
214 }
215 }
adlr@google.com3defe6a2009-12-04 20:57:17 +0000216
217 ActionProcessor processor;
218 FilesystemCopierActionTestDelegate delegate;
219 delegate.set_loop(loop);
220 processor.set_delegate(&delegate);
221
222 ObjectFeederAction<InstallPlan> feeder_action;
Darin Petkov3aefa862010-12-07 14:45:00 -0800223 FilesystemCopierAction copier_action(use_kernel_partition,
224 verify_hash != 0);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000225 ObjectCollectorAction<InstallPlan> collector_action;
226
227 BondActions(&feeder_action, &copier_action);
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700228 BondActions(&copier_action, &collector_action);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000229
230 processor.EnqueueAction(&feeder_action);
231 processor.EnqueueAction(&copier_action);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000232 processor.EnqueueAction(&collector_action);
233
Darin Petkov3aefa862010-12-07 14:45:00 -0800234 if (!verify_hash) {
235 copier_action.set_copy_source(a_dev);
236 }
adlr@google.com3defe6a2009-12-04 20:57:17 +0000237 feeder_action.set_obj(install_plan);
238
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700239 StartProcessorCallbackArgs start_callback_args;
240 start_callback_args.processor = &processor;
241 start_callback_args.filesystem_copier_action = &copier_action;
242 start_callback_args.terminate_early = terminate_early;
243
244 g_timeout_add(0, &StartProcessorInRunLoop, &start_callback_args);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000245 g_main_loop_run(loop);
246 g_main_loop_unref(loop);
247
Gilad Arnoldae236702012-05-17 09:33:20 -0700248 if (!terminate_early) {
249 bool is_delegate_ran = delegate.ran();
250 EXPECT_TRUE(is_delegate_ran);
251 success = success && is_delegate_ran;
252 }
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700253 if (run_out_of_space || terminate_early) {
Darin Petkovc1a8b422010-07-19 11:34:49 -0700254 EXPECT_EQ(kActionCodeError, delegate.code());
Gilad Arnoldae236702012-05-17 09:33:20 -0700255 return (kActionCodeError == delegate.code());
adlr@google.com3defe6a2009-12-04 20:57:17 +0000256 }
Darin Petkov3aefa862010-12-07 14:45:00 -0800257 if (verify_hash == 2) {
Gilad Arnoldae236702012-05-17 09:33:20 -0700258 ActionExitCode expected_exit_code =
259 (use_kernel_partition ?
260 kActionCodeNewKernelVerificationError :
261 kActionCodeNewRootfsVerificationError);
262 EXPECT_EQ(expected_exit_code, delegate.code());
263 return (expected_exit_code == delegate.code());
Darin Petkov3aefa862010-12-07 14:45:00 -0800264 }
Darin Petkovc1a8b422010-07-19 11:34:49 -0700265 EXPECT_EQ(kActionCodeSuccess, delegate.code());
adlr@google.com3defe6a2009-12-04 20:57:17 +0000266
adlr@google.com3defe6a2009-12-04 20:57:17 +0000267 // Make sure everything in the out_image is there
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700268 vector<char> a_out;
Gilad Arnoldae236702012-05-17 09:33:20 -0700269 if (!utils::ReadFile(a_dev, &a_out)) {
270 ADD_FAILURE();
271 return false;
272 }
273 success = success && ExpectVectorsEq(a_loop_data, a_out);
Darin Petkov3aefa862010-12-07 14:45:00 -0800274 if (!verify_hash) {
275 vector<char> b_out;
Gilad Arnoldae236702012-05-17 09:33:20 -0700276 if (!utils::ReadFile(b_dev, &b_out)) {
277 ADD_FAILURE();
278 return false;
279 }
280 success = success && ExpectVectorsEq(a_out, b_out);
Darin Petkov3aefa862010-12-07 14:45:00 -0800281 }
adlr@google.com3defe6a2009-12-04 20:57:17 +0000282
Gilad Arnoldae236702012-05-17 09:33:20 -0700283 bool is_install_plan_eq = (collector_action.object() == install_plan);
284 EXPECT_TRUE(is_install_plan_eq);
285 success = success && is_install_plan_eq;
286
287 return success;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000288}
289
290class FilesystemCopierActionTest2Delegate : public ActionProcessorDelegate {
291 public:
292 void ActionCompleted(ActionProcessor* processor,
293 AbstractAction* action,
Darin Petkovc1a8b422010-07-19 11:34:49 -0700294 ActionExitCode code) {
adlr@google.com3defe6a2009-12-04 20:57:17 +0000295 if (action->Type() == FilesystemCopierAction::StaticType()) {
296 ran_ = true;
Darin Petkovc1a8b422010-07-19 11:34:49 -0700297 code_ = code;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000298 }
299 }
300 GMainLoop *loop_;
301 bool ran_;
Darin Petkovc1a8b422010-07-19 11:34:49 -0700302 ActionExitCode code_;
adlr@google.com3defe6a2009-12-04 20:57:17 +0000303};
304
305TEST_F(FilesystemCopierActionTest, MissingInputObjectTest) {
306 ActionProcessor processor;
307 FilesystemCopierActionTest2Delegate delegate;
308
309 processor.set_delegate(&delegate);
310
Darin Petkov3aefa862010-12-07 14:45:00 -0800311 FilesystemCopierAction copier_action(false, false);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000312 ObjectCollectorAction<InstallPlan> collector_action;
313
314 BondActions(&copier_action, &collector_action);
315
316 processor.EnqueueAction(&copier_action);
317 processor.EnqueueAction(&collector_action);
318 processor.StartProcessing();
319 EXPECT_FALSE(processor.IsRunning());
320 EXPECT_TRUE(delegate.ran_);
Darin Petkovc1a8b422010-07-19 11:34:49 -0700321 EXPECT_EQ(kActionCodeError, delegate.code_);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000322}
323
Darin Petkov9b230572010-10-08 10:20:09 -0700324TEST_F(FilesystemCopierActionTest, ResumeTest) {
325 ActionProcessor processor;
326 FilesystemCopierActionTest2Delegate delegate;
327
328 processor.set_delegate(&delegate);
329
330 ObjectFeederAction<InstallPlan> feeder_action;
331 const char* kUrl = "http://some/url";
Darin Petkov7ed561b2011-10-04 02:59:03 -0700332 InstallPlan install_plan(true, kUrl, 0, "", "", "");
Darin Petkov9b230572010-10-08 10:20:09 -0700333 feeder_action.set_obj(install_plan);
Darin Petkov3aefa862010-12-07 14:45:00 -0800334 FilesystemCopierAction copier_action(false, false);
Darin Petkov9b230572010-10-08 10:20:09 -0700335 ObjectCollectorAction<InstallPlan> collector_action;
336
337 BondActions(&feeder_action, &copier_action);
338 BondActions(&copier_action, &collector_action);
339
340 processor.EnqueueAction(&feeder_action);
341 processor.EnqueueAction(&copier_action);
342 processor.EnqueueAction(&collector_action);
343 processor.StartProcessing();
344 EXPECT_FALSE(processor.IsRunning());
345 EXPECT_TRUE(delegate.ran_);
346 EXPECT_EQ(kActionCodeSuccess, delegate.code_);
347 EXPECT_EQ(kUrl, collector_action.object().download_url);
348}
349
adlr@google.com3defe6a2009-12-04 20:57:17 +0000350TEST_F(FilesystemCopierActionTest, NonExistentDriveTest) {
351 ActionProcessor processor;
352 FilesystemCopierActionTest2Delegate delegate;
353
354 processor.set_delegate(&delegate);
355
356 ObjectFeederAction<InstallPlan> feeder_action;
Darin Petkov0406e402010-10-06 21:33:11 -0700357 InstallPlan install_plan(false,
Darin Petkov0406e402010-10-06 21:33:11 -0700358 "",
359 0,
360 "",
361 "/no/such/file",
362 "/no/such/file");
adlr@google.com3defe6a2009-12-04 20:57:17 +0000363 feeder_action.set_obj(install_plan);
Darin Petkov3aefa862010-12-07 14:45:00 -0800364 FilesystemCopierAction copier_action(false, false);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000365 ObjectCollectorAction<InstallPlan> collector_action;
366
367 BondActions(&copier_action, &collector_action);
368
369 processor.EnqueueAction(&feeder_action);
370 processor.EnqueueAction(&copier_action);
371 processor.EnqueueAction(&collector_action);
372 processor.StartProcessing();
373 EXPECT_FALSE(processor.IsRunning());
374 EXPECT_TRUE(delegate.ran_);
Darin Petkovc1a8b422010-07-19 11:34:49 -0700375 EXPECT_EQ(kActionCodeError, delegate.code_);
adlr@google.com3defe6a2009-12-04 20:57:17 +0000376}
377
Darin Petkov3aefa862010-12-07 14:45:00 -0800378TEST_F(FilesystemCopierActionTest, RunAsRootVerifyHashTest) {
379 ASSERT_EQ(0, getuid());
Gilad Arnoldae236702012-05-17 09:33:20 -0700380 EXPECT_TRUE(DoTest(false, false, false, 1));
381 EXPECT_TRUE(DoTest(false, false, true, 1));
Darin Petkov3aefa862010-12-07 14:45:00 -0800382}
383
384TEST_F(FilesystemCopierActionTest, RunAsRootVerifyHashFailTest) {
385 ASSERT_EQ(0, getuid());
Gilad Arnoldae236702012-05-17 09:33:20 -0700386 EXPECT_TRUE(DoTest(false, false, false, 2));
387 EXPECT_TRUE(DoTest(false, false, true, 2));
Darin Petkov3aefa862010-12-07 14:45:00 -0800388}
389
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700390TEST_F(FilesystemCopierActionTest, RunAsRootNoSpaceTest) {
adlr@google.com3defe6a2009-12-04 20:57:17 +0000391 ASSERT_EQ(0, getuid());
Gilad Arnoldae236702012-05-17 09:33:20 -0700392 EXPECT_TRUE(DoTest(true, false, false, 0));
adlr@google.com3defe6a2009-12-04 20:57:17 +0000393}
394
Andrew de los Reyesc7020782010-04-28 10:46:04 -0700395TEST_F(FilesystemCopierActionTest, RunAsRootTerminateEarlyTest) {
adlr@google.com3defe6a2009-12-04 20:57:17 +0000396 ASSERT_EQ(0, getuid());
Gilad Arnoldae236702012-05-17 09:33:20 -0700397 EXPECT_TRUE(DoTest(false, true, false, 0));
adlr@google.com3defe6a2009-12-04 20:57:17 +0000398}
399
Darin Petkov698d0412010-10-13 10:59:44 -0700400TEST_F(FilesystemCopierActionTest, RunAsRootDetermineFilesystemSizeTest) {
401 string img;
402 EXPECT_TRUE(utils::MakeTempFile("/tmp/img.XXXXXX", &img, NULL));
403 ScopedPathUnlinker img_unlinker(img);
404 CreateExtImageAtPath(img, NULL);
405 // Extend the "partition" holding the file system from 10MiB to 20MiB.
406 EXPECT_EQ(0, System(StringPrintf(
407 "dd if=/dev/zero of=%s seek=20971519 bs=1 count=1",
408 img.c_str())));
409 EXPECT_EQ(20 * 1024 * 1024, utils::FileSize(img));
410
411 for (int i = 0; i < 2; ++i) {
412 bool is_kernel = i == 1;
Darin Petkov3aefa862010-12-07 14:45:00 -0800413 FilesystemCopierAction action(is_kernel, false);
Darin Petkov698d0412010-10-13 10:59:44 -0700414 EXPECT_EQ(kint64max, action.filesystem_size_);
415 {
416 int fd = HANDLE_EINTR(open(img.c_str(), O_RDONLY));
417 EXPECT_TRUE(fd > 0);
418 ScopedFdCloser fd_closer(&fd);
419 action.DetermineFilesystemSize(fd);
420 }
421 EXPECT_EQ(is_kernel ? kint64max : 10 * 1024 * 1024,
422 action.filesystem_size_);
423 }
424}
425
426
adlr@google.com3defe6a2009-12-04 20:57:17 +0000427} // namespace chromeos_update_engine