OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "update_engine/filesystem_copier_action.h" | 10 #include "update_engine/filesystem_copier_action.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 processor.EnqueueAction(&collector_action); | 130 processor.EnqueueAction(&collector_action); |
131 | 131 |
132 copier_action.set_copy_source(TestDir() + "/mnt"); | 132 copier_action.set_copy_source(TestDir() + "/mnt"); |
133 feeder_action.set_obj(install_plan); | 133 feeder_action.set_obj(install_plan); |
134 | 134 |
135 g_timeout_add(0, &StartProcessorInRunLoop, &processor); | 135 g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
136 g_main_loop_run(loop); | 136 g_main_loop_run(loop); |
137 g_main_loop_unref(loop); | 137 g_main_loop_unref(loop); |
138 | 138 |
139 EXPECT_EQ(0, System(string("losetup -d ") + dev)); | 139 EXPECT_EQ(0, System(string("losetup -d ") + dev)); |
140 EXPECT_EQ(0, System(string("umount ") + TestDir() + "/mnt/some_dir/mnt")); | 140 EXPECT_EQ(0, System(string("umount -d ") + TestDir() + "/mnt/some_dir/mnt")); |
141 EXPECT_EQ(0, System(string("umount ") + TestDir() + "/mnt")); | 141 EXPECT_EQ(0, System(string("umount -d ") + TestDir() + "/mnt")); |
142 EXPECT_EQ(0, unlink(a_image.c_str())); | 142 EXPECT_EQ(0, unlink(a_image.c_str())); |
143 EXPECT_EQ(0, unlink(b_image.c_str())); | 143 EXPECT_EQ(0, unlink(b_image.c_str())); |
144 | 144 |
145 EXPECT_TRUE(delegate.ran()); | 145 EXPECT_TRUE(delegate.ran()); |
146 if (run_out_of_space) { | 146 if (run_out_of_space) { |
147 EXPECT_FALSE(delegate.success()); | 147 EXPECT_FALSE(delegate.success()); |
148 EXPECT_EQ(0, unlink(out_image.c_str())); | 148 EXPECT_EQ(0, unlink(out_image.c_str())); |
149 EXPECT_EQ(0, rmdir((TestDir() + "/mnt").c_str())); | 149 EXPECT_EQ(0, rmdir((TestDir() + "/mnt").c_str())); |
150 return; | 150 return; |
151 } | 151 } |
152 EXPECT_TRUE(delegate.success()); | 152 EXPECT_TRUE(delegate.success()); |
153 | 153 |
154 EXPECT_EQ(0, System(string("mount -o loop ") + out_image + " " + | 154 EXPECT_EQ(0, System(string("mount -o loop ") + out_image + " " + |
155 TestDir() + "/mnt")); | 155 TestDir() + "/mnt")); |
156 // Make sure everything in the out_image is there | 156 // Make sure everything in the out_image is there |
157 expected_paths_vector.push_back("/update_engine_copy_success"); | 157 expected_paths_vector.push_back("/update_engine_copy_success"); |
158 for (vector<string>::iterator it = expected_paths_vector.begin(); | 158 for (vector<string>::iterator it = expected_paths_vector.begin(); |
159 it != expected_paths_vector.end(); ++it) { | 159 it != expected_paths_vector.end(); ++it) { |
160 *it = TestDir() + "/mnt" + *it; | 160 *it = TestDir() + "/mnt" + *it; |
161 } | 161 } |
162 set<string> expected_paths(expected_paths_vector.begin(), | 162 set<string> expected_paths(expected_paths_vector.begin(), |
163 expected_paths_vector.end()); | 163 expected_paths_vector.end()); |
164 VerifyAllPaths(TestDir() + "/mnt", expected_paths); | 164 VerifyAllPaths(TestDir() + "/mnt", expected_paths); |
165 string file_data; | 165 string file_data; |
166 EXPECT_TRUE(utils::ReadFileToString(TestDir() + "/mnt/hi", &file_data)); | 166 EXPECT_TRUE(utils::ReadFileToString(TestDir() + "/mnt/hi", &file_data)); |
167 EXPECT_EQ("hi\n", file_data); | 167 EXPECT_EQ("hi\n", file_data); |
168 EXPECT_TRUE(utils::ReadFileToString(TestDir() + "/mnt/hello", &file_data)); | 168 EXPECT_TRUE(utils::ReadFileToString(TestDir() + "/mnt/hello", &file_data)); |
169 EXPECT_EQ("hello\n", file_data); | 169 EXPECT_EQ("hello\n", file_data); |
170 EXPECT_EQ("/some/target", Readlink(TestDir() + "/mnt/sym")); | 170 EXPECT_EQ("/some/target", Readlink(TestDir() + "/mnt/sym")); |
171 EXPECT_EQ(0, System(string("umount ") + TestDir() + "/mnt")); | 171 EXPECT_EQ(0, System(string("umount -d ") + TestDir() + "/mnt")); |
172 | 172 |
173 EXPECT_EQ(0, unlink(out_image.c_str())); | 173 EXPECT_EQ(0, unlink(out_image.c_str())); |
174 EXPECT_EQ(0, rmdir((TestDir() + "/mnt").c_str())); | 174 EXPECT_EQ(0, rmdir((TestDir() + "/mnt").c_str())); |
175 | 175 |
176 EXPECT_FALSE(copier_action.skipped_copy()); | 176 EXPECT_FALSE(copier_action.skipped_copy()); |
177 LOG(INFO) << "collected plan:"; | 177 LOG(INFO) << "collected plan:"; |
178 collector_action.object().Dump(); | 178 collector_action.object().Dump(); |
179 LOG(INFO) << "expected plan:"; | 179 LOG(INFO) << "expected plan:"; |
180 install_plan.Dump(); | 180 install_plan.Dump(); |
181 EXPECT_TRUE(collector_action.object() == install_plan); | 181 EXPECT_TRUE(collector_action.object() == install_plan); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 ASSERT_EQ(0, getuid()); | 266 ASSERT_EQ(0, getuid()); |
267 DoTest(true, false); | 267 DoTest(true, false); |
268 } | 268 } |
269 | 269 |
270 TEST_F(FilesystemCopierActionTest, RunAsRootNoSpaceTest) { | 270 TEST_F(FilesystemCopierActionTest, RunAsRootNoSpaceTest) { |
271 ASSERT_EQ(0, getuid()); | 271 ASSERT_EQ(0, getuid()); |
272 DoTest(false, true); | 272 DoTest(false, true); |
273 } | 273 } |
274 | 274 |
275 } // namespace chromeos_update_engine | 275 } // namespace chromeos_update_engine |
OLD | NEW |