Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: src/platform/update_engine/filesystem_copier_action_unittest.cc

Issue 1694025: AU: Update Downloader to support our image formats. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: fixes for review Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium 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 <glib.h> 5 #include <glib.h>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 #include <gtest/gtest.h> 9 #include <gtest/gtest.h>
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "update_engine/filesystem_copier_action.h" 11 #include "update_engine/filesystem_copier_action.h"
12 #include "update_engine/filesystem_iterator.h" 12 #include "update_engine/filesystem_iterator.h"
13 #include "update_engine/omaha_hash_calculator.h" 13 #include "update_engine/omaha_hash_calculator.h"
14 #include "update_engine/test_utils.h" 14 #include "update_engine/test_utils.h"
15 #include "update_engine/utils.h" 15 #include "update_engine/utils.h"
16 16
17 using std::set; 17 using std::set;
18 using std::string; 18 using std::string;
19 using std::vector; 19 using std::vector;
20 20
21 namespace chromeos_update_engine { 21 namespace chromeos_update_engine {
22 22
23 class FilesystemCopierActionTest : public ::testing::Test { 23 class FilesystemCopierActionTest : public ::testing::Test {
24 protected: 24 protected:
25 void DoTest(bool run_out_of_space, bool terminate_early); 25 void DoTest(bool run_out_of_space,
26 bool terminate_early,
27 bool use_kernel_partition);
26 void SetUp() { 28 void SetUp() {
27 } 29 }
28 void TearDown() { 30 void TearDown() {
29 } 31 }
30 }; 32 };
31 33
32 class FilesystemCopierActionTestDelegate : public ActionProcessorDelegate { 34 class FilesystemCopierActionTestDelegate : public ActionProcessorDelegate {
33 public: 35 public:
34 FilesystemCopierActionTestDelegate() : ran_(false), success_(false) {} 36 FilesystemCopierActionTestDelegate() : ran_(false), success_(false) {}
35 void ExitMainLoop() { 37 void ExitMainLoop() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 processor->StartProcessing(); 78 processor->StartProcessing();
77 if (args->terminate_early) { 79 if (args->terminate_early) {
78 EXPECT_TRUE(args->filesystem_copier_action); 80 EXPECT_TRUE(args->filesystem_copier_action);
79 args->processor->StopProcessing(); 81 args->processor->StopProcessing();
80 } 82 }
81 return FALSE; 83 return FALSE;
82 } 84 }
83 85
84 TEST_F(FilesystemCopierActionTest, RunAsRootSimpleTest) { 86 TEST_F(FilesystemCopierActionTest, RunAsRootSimpleTest) {
85 ASSERT_EQ(0, getuid()); 87 ASSERT_EQ(0, getuid());
86 DoTest(false, false); 88 DoTest(false, false, false);
89
90 DoTest(false, false, true);
87 } 91 }
88 void FilesystemCopierActionTest::DoTest(bool run_out_of_space, 92 void FilesystemCopierActionTest::DoTest(bool run_out_of_space,
89 bool terminate_early) { 93 bool terminate_early,
94 bool use_kernel_partition) {
90 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 95 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
91 96
92 string a_loop_file; 97 string a_loop_file;
93 string b_loop_file; 98 string b_loop_file;
94 99
95 EXPECT_TRUE(utils::MakeTempFile("/tmp/a_loop_file.XXXXXX", 100 EXPECT_TRUE(utils::MakeTempFile("/tmp/a_loop_file.XXXXXX",
96 &a_loop_file, 101 &a_loop_file,
97 NULL)); 102 NULL));
98 ScopedPathUnlinker a_loop_file_unlinker(a_loop_file); 103 ScopedPathUnlinker a_loop_file_unlinker(a_loop_file);
99 EXPECT_TRUE(utils::MakeTempFile("/tmp/b_loop_file.XXXXXX", 104 EXPECT_TRUE(utils::MakeTempFile("/tmp/b_loop_file.XXXXXX",
(...skipping 25 matching lines...) Expand all
125 string b_dev = GetUnusedLoopDevice(); 130 string b_dev = GetUnusedLoopDevice();
126 EXPECT_FALSE(b_dev.empty()); 131 EXPECT_FALSE(b_dev.empty());
127 EXPECT_EQ(0, System(StringPrintf("losetup %s %s", 132 EXPECT_EQ(0, System(StringPrintf("losetup %s %s",
128 b_dev.c_str(), 133 b_dev.c_str(),
129 b_loop_file.c_str()))); 134 b_loop_file.c_str())));
130 ScopedLoopbackDeviceReleaser b_dev_releaser(b_dev); 135 ScopedLoopbackDeviceReleaser b_dev_releaser(b_dev);
131 136
132 // Set up the action objects 137 // Set up the action objects
133 InstallPlan install_plan; 138 InstallPlan install_plan;
134 install_plan.is_full_update = false; 139 install_plan.is_full_update = false;
135 install_plan.install_path = b_dev; 140 if (use_kernel_partition)
141 install_plan.kernel_install_path = b_dev;
142 else
143 install_plan.install_path = b_dev;
136 144
137 ActionProcessor processor; 145 ActionProcessor processor;
138 FilesystemCopierActionTestDelegate delegate; 146 FilesystemCopierActionTestDelegate delegate;
139 delegate.set_loop(loop); 147 delegate.set_loop(loop);
140 processor.set_delegate(&delegate); 148 processor.set_delegate(&delegate);
141 149
142 ObjectFeederAction<InstallPlan> feeder_action; 150 ObjectFeederAction<InstallPlan> feeder_action;
143 FilesystemCopierAction copier_action; 151 FilesystemCopierAction copier_action(use_kernel_partition);
144 ObjectCollectorAction<InstallPlan> collector_action; 152 ObjectCollectorAction<InstallPlan> collector_action;
145 153
146 BondActions(&feeder_action, &copier_action); 154 BondActions(&feeder_action, &copier_action);
147 BondActions(&copier_action, &collector_action); 155 BondActions(&copier_action, &collector_action);
148 156
149 processor.EnqueueAction(&feeder_action); 157 processor.EnqueueAction(&feeder_action);
150 processor.EnqueueAction(&copier_action); 158 processor.EnqueueAction(&copier_action);
151 processor.EnqueueAction(&collector_action); 159 processor.EnqueueAction(&collector_action);
152 160
153 copier_action.set_copy_source(a_dev); 161 copier_action.set_copy_source(a_dev);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 bool ran_; 203 bool ran_;
196 bool success_; 204 bool success_;
197 }; 205 };
198 206
199 TEST_F(FilesystemCopierActionTest, MissingInputObjectTest) { 207 TEST_F(FilesystemCopierActionTest, MissingInputObjectTest) {
200 ActionProcessor processor; 208 ActionProcessor processor;
201 FilesystemCopierActionTest2Delegate delegate; 209 FilesystemCopierActionTest2Delegate delegate;
202 210
203 processor.set_delegate(&delegate); 211 processor.set_delegate(&delegate);
204 212
205 FilesystemCopierAction copier_action; 213 FilesystemCopierAction copier_action(false);
206 ObjectCollectorAction<InstallPlan> collector_action; 214 ObjectCollectorAction<InstallPlan> collector_action;
207 215
208 BondActions(&copier_action, &collector_action); 216 BondActions(&copier_action, &collector_action);
209 217
210 processor.EnqueueAction(&copier_action); 218 processor.EnqueueAction(&copier_action);
211 processor.EnqueueAction(&collector_action); 219 processor.EnqueueAction(&collector_action);
212 processor.StartProcessing(); 220 processor.StartProcessing();
213 EXPECT_FALSE(processor.IsRunning()); 221 EXPECT_FALSE(processor.IsRunning());
214 EXPECT_TRUE(delegate.ran_); 222 EXPECT_TRUE(delegate.ran_);
215 EXPECT_FALSE(delegate.success_); 223 EXPECT_FALSE(delegate.success_);
216 } 224 }
217 225
218 TEST_F(FilesystemCopierActionTest, FullUpdateTest) { 226 TEST_F(FilesystemCopierActionTest, FullUpdateTest) {
219 ActionProcessor processor; 227 ActionProcessor processor;
220 FilesystemCopierActionTest2Delegate delegate; 228 FilesystemCopierActionTest2Delegate delegate;
221 229
222 processor.set_delegate(&delegate); 230 processor.set_delegate(&delegate);
223 231
224 ObjectFeederAction<InstallPlan> feeder_action; 232 ObjectFeederAction<InstallPlan> feeder_action;
225 InstallPlan install_plan(true, "", "", ""); 233 InstallPlan install_plan(true, "", "", "", "");
226 feeder_action.set_obj(install_plan); 234 feeder_action.set_obj(install_plan);
227 FilesystemCopierAction copier_action; 235 FilesystemCopierAction copier_action(false);
228 ObjectCollectorAction<InstallPlan> collector_action; 236 ObjectCollectorAction<InstallPlan> collector_action;
229 237
230 BondActions(&feeder_action, &copier_action); 238 BondActions(&feeder_action, &copier_action);
231 BondActions(&copier_action, &collector_action); 239 BondActions(&copier_action, &collector_action);
232 240
233 processor.EnqueueAction(&feeder_action); 241 processor.EnqueueAction(&feeder_action);
234 processor.EnqueueAction(&copier_action); 242 processor.EnqueueAction(&copier_action);
235 processor.EnqueueAction(&collector_action); 243 processor.EnqueueAction(&collector_action);
236 processor.StartProcessing(); 244 processor.StartProcessing();
237 EXPECT_FALSE(processor.IsRunning()); 245 EXPECT_FALSE(processor.IsRunning());
238 EXPECT_TRUE(delegate.ran_); 246 EXPECT_TRUE(delegate.ran_);
239 EXPECT_TRUE(delegate.success_); 247 EXPECT_TRUE(delegate.success_);
240 } 248 }
241 249
242 TEST_F(FilesystemCopierActionTest, NonExistentDriveTest) { 250 TEST_F(FilesystemCopierActionTest, NonExistentDriveTest) {
243 ActionProcessor processor; 251 ActionProcessor processor;
244 FilesystemCopierActionTest2Delegate delegate; 252 FilesystemCopierActionTest2Delegate delegate;
245 253
246 processor.set_delegate(&delegate); 254 processor.set_delegate(&delegate);
247 255
248 ObjectFeederAction<InstallPlan> feeder_action; 256 ObjectFeederAction<InstallPlan> feeder_action;
249 InstallPlan install_plan(false, "", "", "/some/missing/file/path"); 257 InstallPlan install_plan(false, "", "", "/no/such/file", "/no/such/file");
250 feeder_action.set_obj(install_plan); 258 feeder_action.set_obj(install_plan);
251 FilesystemCopierAction copier_action; 259 FilesystemCopierAction copier_action(false);
252 ObjectCollectorAction<InstallPlan> collector_action; 260 ObjectCollectorAction<InstallPlan> collector_action;
253 261
254 BondActions(&copier_action, &collector_action); 262 BondActions(&copier_action, &collector_action);
255 263
256 processor.EnqueueAction(&feeder_action); 264 processor.EnqueueAction(&feeder_action);
257 processor.EnqueueAction(&copier_action); 265 processor.EnqueueAction(&copier_action);
258 processor.EnqueueAction(&collector_action); 266 processor.EnqueueAction(&collector_action);
259 processor.StartProcessing(); 267 processor.StartProcessing();
260 EXPECT_FALSE(processor.IsRunning()); 268 EXPECT_FALSE(processor.IsRunning());
261 EXPECT_TRUE(delegate.ran_); 269 EXPECT_TRUE(delegate.ran_);
262 EXPECT_FALSE(delegate.success_); 270 EXPECT_FALSE(delegate.success_);
263 } 271 }
264 272
265 TEST_F(FilesystemCopierActionTest, RunAsRootNoSpaceTest) { 273 TEST_F(FilesystemCopierActionTest, RunAsRootNoSpaceTest) {
266 ASSERT_EQ(0, getuid()); 274 ASSERT_EQ(0, getuid());
267 DoTest(true, false); 275 DoTest(true, false, false);
268 } 276 }
269 277
270 TEST_F(FilesystemCopierActionTest, RunAsRootTerminateEarlyTest) { 278 TEST_F(FilesystemCopierActionTest, RunAsRootTerminateEarlyTest) {
271 ASSERT_EQ(0, getuid()); 279 ASSERT_EQ(0, getuid());
272 DoTest(false, true); 280 DoTest(false, true, false);
273 } 281 }
274 282
275 } // namespace chromeos_update_engine 283 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « src/platform/update_engine/filesystem_copier_action.cc ('k') | src/platform/update_engine/install_plan.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698