OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 <sys/stat.h> | 5 #include <sys/stat.h> |
6 #include <sys/types.h> | 6 #include <sys/types.h> |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 size_t r = fread(dev, 1, sizeof(dev), find_dev_cmd); | 125 size_t r = fread(dev, 1, sizeof(dev), find_dev_cmd); |
126 ASSERT_GT(r, 0); | 126 ASSERT_GT(r, 0); |
127 ASSERT_LT(r, sizeof(dev)); | 127 ASSERT_LT(r, sizeof(dev)); |
128 ASSERT_TRUE(feof(find_dev_cmd)); | 128 ASSERT_TRUE(feof(find_dev_cmd)); |
129 fclose(find_dev_cmd); | 129 fclose(find_dev_cmd); |
130 | 130 |
131 // strip trailing newline on dev | 131 // strip trailing newline on dev |
132 if (dev[strlen(dev) - 1] == '\n') | 132 if (dev[strlen(dev) - 1] == '\n') |
133 dev[strlen(dev) - 1] = '\0'; | 133 dev[strlen(dev) - 1] = '\0'; |
134 | 134 |
135 if (do_losetup) | 135 scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser; |
| 136 if (do_losetup) { |
136 ASSERT_EQ(0, System(string("losetup ") + dev + " " + cwd + "/image.dat")); | 137 ASSERT_EQ(0, System(string("losetup ") + dev + " " + cwd + "/image.dat")); |
| 138 loop_releaser.reset(new ScopedLoopbackDeviceReleaser(dev)); |
| 139 } |
137 | 140 |
138 ActionProcessor processor; | 141 ActionProcessor processor; |
139 ObjectFeederAction<InstallPlan> feeder_action; | 142 ObjectFeederAction<InstallPlan> feeder_action; |
140 InstallPlan install_plan; | 143 InstallPlan install_plan; |
141 install_plan.install_path = dev; | 144 install_plan.install_path = dev; |
142 feeder_action.set_obj(install_plan); | 145 feeder_action.set_obj(install_plan); |
143 PostinstallRunnerAction runner_action; | 146 PostinstallRunnerAction runner_action; |
144 BondActions(&feeder_action, &runner_action); | 147 BondActions(&feeder_action, &runner_action); |
145 ObjectCollectorAction<InstallPlan> collector_action; | 148 ObjectCollectorAction<InstallPlan> collector_action; |
146 BondActions(&runner_action, &collector_action); | 149 BondActions(&runner_action, &collector_action); |
(...skipping 18 matching lines...) Expand all Loading... |
165 EXPECT_TRUE(install_plan == collector_action.object()); | 168 EXPECT_TRUE(install_plan == collector_action.object()); |
166 } | 169 } |
167 | 170 |
168 struct stat stbuf; | 171 struct stat stbuf; |
169 int rc = lstat((string(cwd) + "/postinst_called").c_str(), &stbuf); | 172 int rc = lstat((string(cwd) + "/postinst_called").c_str(), &stbuf); |
170 if (do_losetup && !do_err_script) | 173 if (do_losetup && !do_err_script) |
171 ASSERT_EQ(0, rc); | 174 ASSERT_EQ(0, rc); |
172 else | 175 else |
173 ASSERT_LT(rc, 0); | 176 ASSERT_LT(rc, 0); |
174 | 177 |
175 if (do_losetup) | 178 if (do_losetup) { |
176 ASSERT_EQ(0, System(string("losetup -d ") + dev)); | 179 loop_releaser.reset(NULL); |
| 180 } |
177 ASSERT_EQ(0, System(string("rm -f ") + cwd + "/postinst_called")); | 181 ASSERT_EQ(0, System(string("rm -f ") + cwd + "/postinst_called")); |
178 ASSERT_EQ(0, System(string("rm -f ") + cwd + "/image.dat")); | 182 ASSERT_EQ(0, System(string("rm -f ") + cwd + "/image.dat")); |
179 } | 183 } |
180 | 184 |
181 // Death tests don't seem to be working on Hardy | 185 // Death tests don't seem to be working on Hardy |
182 TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) { | 186 TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) { |
183 ASSERT_EQ(0, getuid()); | 187 ASSERT_EQ(0, getuid()); |
184 PostinstallRunnerAction runner_action; | 188 PostinstallRunnerAction runner_action; |
185 ASSERT_DEATH({ runner_action.TerminateProcessing(); }, | 189 ASSERT_DEATH({ runner_action.TerminateProcessing(); }, |
186 "postinstall_runner_action.h:.*] Check failed"); | 190 "postinstall_runner_action.h:.*] Check failed"); |
187 } | 191 } |
188 | 192 |
189 } // namespace chromeos_update_engine | 193 } // namespace chromeos_update_engine |
OLD | NEW |