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

Side by Side Diff: postinstall_runner_action_unittest.cc

Issue 4690006: AU: Execute postinst asynchronously so that the D-Bus service is not blocked. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: address review comments Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « postinstall_runner_action.cc ('k') | subprocess.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 #include <gtest/gtest.h> 10 #include <gtest/gtest.h>
11 #include "update_engine/postinstall_runner_action.h" 11 #include "update_engine/postinstall_runner_action.h"
12 #include "update_engine/test_utils.h" 12 #include "update_engine/test_utils.h"
13 #include "update_engine/utils.h" 13 #include "update_engine/utils.h"
14 14
15 using std::string; 15 using std::string;
16 using std::vector; 16 using std::vector;
17 17
18 namespace chromeos_update_engine { 18 namespace chromeos_update_engine {
19 19
20 namespace {
21 gboolean StartProcessorInRunLoop(gpointer data) {
22 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data);
23 processor->StartProcessing();
24 return FALSE;
25 }
26 } // namespace
27
20 class PostinstallRunnerActionTest : public ::testing::Test { 28 class PostinstallRunnerActionTest : public ::testing::Test {
21 public: 29 public:
22 void DoTest(bool do_losetup, bool do_err_script); 30 void DoTest(bool do_losetup, bool do_err_script);
23 }; 31 };
24 32
25 class PostinstActionProcessorDelegate : public ActionProcessorDelegate { 33 class PostinstActionProcessorDelegate : public ActionProcessorDelegate {
26 public: 34 public:
27 PostinstActionProcessorDelegate() 35 PostinstActionProcessorDelegate()
28 : code_(kActionCodeError), 36 : loop_(NULL),
37 code_(kActionCodeError),
29 code_set_(false) {} 38 code_set_(false) {}
39 void ProcessingDone(const ActionProcessor* processor,
40 ActionExitCode code) {
41 ASSERT_TRUE(loop_);
42 g_main_loop_quit(loop_);
43 }
30 void ActionCompleted(ActionProcessor* processor, 44 void ActionCompleted(ActionProcessor* processor,
31 AbstractAction* action, 45 AbstractAction* action,
32 ActionExitCode code) { 46 ActionExitCode code) {
33 if (action->Type() == PostinstallRunnerAction::StaticType()) { 47 if (action->Type() == PostinstallRunnerAction::StaticType()) {
34 code_ = code; 48 code_ = code;
35 code_set_ = true; 49 code_set_ = true;
36 } 50 }
37 } 51 }
52 GMainLoop* loop_;
38 ActionExitCode code_; 53 ActionExitCode code_;
39 bool code_set_; 54 bool code_set_;
40 }; 55 };
41 56
42 TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) { 57 TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) {
43 ASSERT_EQ(0, getuid()); 58 ASSERT_EQ(0, getuid());
44 DoTest(true, false); 59 DoTest(true, false);
45 } 60 }
46 61
47 TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) { 62 TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 feeder_action.set_obj(install_plan); 133 feeder_action.set_obj(install_plan);
119 PostinstallRunnerAction runner_action; 134 PostinstallRunnerAction runner_action;
120 BondActions(&feeder_action, &runner_action); 135 BondActions(&feeder_action, &runner_action);
121 ObjectCollectorAction<InstallPlan> collector_action; 136 ObjectCollectorAction<InstallPlan> collector_action;
122 BondActions(&runner_action, &collector_action); 137 BondActions(&runner_action, &collector_action);
123 PostinstActionProcessorDelegate delegate; 138 PostinstActionProcessorDelegate delegate;
124 processor.EnqueueAction(&feeder_action); 139 processor.EnqueueAction(&feeder_action);
125 processor.EnqueueAction(&runner_action); 140 processor.EnqueueAction(&runner_action);
126 processor.EnqueueAction(&collector_action); 141 processor.EnqueueAction(&collector_action);
127 processor.set_delegate(&delegate); 142 processor.set_delegate(&delegate);
128 processor.StartProcessing(); 143
129 ASSERT_FALSE(processor.IsRunning()) 144 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
130 << "Update test to handle non-asynch actions"; 145 delegate.loop_ = loop;
146 g_timeout_add(0, &StartProcessorInRunLoop, &processor);
147 g_main_loop_run(loop);
148 g_main_loop_unref(loop);
149 ASSERT_FALSE(processor.IsRunning());
131 150
132 EXPECT_TRUE(delegate.code_set_); 151 EXPECT_TRUE(delegate.code_set_);
133 EXPECT_EQ(do_losetup && !do_err_script, delegate.code_ == kActionCodeSuccess); 152 EXPECT_EQ(do_losetup && !do_err_script, delegate.code_ == kActionCodeSuccess);
134 EXPECT_EQ(do_losetup && !do_err_script, 153 EXPECT_EQ(do_losetup && !do_err_script,
135 !collector_action.object().install_path.empty()); 154 !collector_action.object().install_path.empty());
136 if (do_losetup && !do_err_script) { 155 if (do_losetup && !do_err_script) {
137 EXPECT_TRUE(install_plan == collector_action.object()); 156 EXPECT_TRUE(install_plan == collector_action.object());
138 } 157 }
139 158
140 struct stat stbuf; 159 struct stat stbuf;
(...skipping 11 matching lines...) Expand all
152 171
153 // Death tests don't seem to be working on Hardy 172 // Death tests don't seem to be working on Hardy
154 TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) { 173 TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) {
155 ASSERT_EQ(0, getuid()); 174 ASSERT_EQ(0, getuid());
156 PostinstallRunnerAction runner_action; 175 PostinstallRunnerAction runner_action;
157 ASSERT_DEATH({ runner_action.TerminateProcessing(); }, 176 ASSERT_DEATH({ runner_action.TerminateProcessing(); },
158 "postinstall_runner_action.h:.*] Check failed"); 177 "postinstall_runner_action.h:.*] Check failed");
159 } 178 }
160 179
161 } // namespace chromeos_update_engine 180 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « postinstall_runner_action.cc ('k') | subprocess.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698