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

Side by Side Diff: postinstall_runner_action_unittest.cc

Issue 3022008: For actions, switch bool success into an exit code. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: switch to all positive error codes. Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « postinstall_runner_action.cc ('k') | set_bootable_flag_action.cc » ('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) 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 <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 class PostinstallRunnerActionTest : public ::testing::Test { 20 class PostinstallRunnerActionTest : public ::testing::Test {
21 public: 21 public:
22 void DoTest(bool do_losetup, bool do_err_script); 22 void DoTest(bool do_losetup, bool do_err_script);
23 }; 23 };
24 24
25 class PostinstActionProcessorDelegate : public ActionProcessorDelegate { 25 class PostinstActionProcessorDelegate : public ActionProcessorDelegate {
26 public: 26 public:
27 PostinstActionProcessorDelegate() : success_(false), success_set_(false) {} 27 PostinstActionProcessorDelegate()
28 : code_(kActionCodeError),
29 code_set_(false) {}
28 void ActionCompleted(ActionProcessor* processor, 30 void ActionCompleted(ActionProcessor* processor,
29 AbstractAction* action, 31 AbstractAction* action,
30 bool success) { 32 ActionExitCode code) {
31 if (action->Type() == PostinstallRunnerAction::StaticType()) { 33 if (action->Type() == PostinstallRunnerAction::StaticType()) {
32 success_ = success; 34 code_ = code;
33 success_set_ = true; 35 code_set_ = true;
34 } 36 }
35 } 37 }
36 bool success_; 38 ActionExitCode code_;
37 bool success_set_; 39 bool code_set_;
38 }; 40 };
39 41
40 TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) { 42 TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) {
41 ASSERT_EQ(0, getuid()); 43 ASSERT_EQ(0, getuid());
42 DoTest(true, false); 44 DoTest(true, false);
43 } 45 }
44 46
45 TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) { 47 TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) {
46 ASSERT_EQ(0, getuid()); 48 ASSERT_EQ(0, getuid());
47 DoTest(false, false); 49 DoTest(false, false);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 BondActions(&runner_action, &collector_action); 122 BondActions(&runner_action, &collector_action);
121 PostinstActionProcessorDelegate delegate; 123 PostinstActionProcessorDelegate delegate;
122 processor.EnqueueAction(&feeder_action); 124 processor.EnqueueAction(&feeder_action);
123 processor.EnqueueAction(&runner_action); 125 processor.EnqueueAction(&runner_action);
124 processor.EnqueueAction(&collector_action); 126 processor.EnqueueAction(&collector_action);
125 processor.set_delegate(&delegate); 127 processor.set_delegate(&delegate);
126 processor.StartProcessing(); 128 processor.StartProcessing();
127 ASSERT_FALSE(processor.IsRunning()) 129 ASSERT_FALSE(processor.IsRunning())
128 << "Update test to handle non-asynch actions"; 130 << "Update test to handle non-asynch actions";
129 131
130 EXPECT_TRUE(delegate.success_set_); 132 EXPECT_TRUE(delegate.code_set_);
131 EXPECT_EQ(do_losetup && !do_err_script, delegate.success_); 133 EXPECT_EQ(do_losetup && !do_err_script, delegate.code_ == kActionCodeSuccess);
132 EXPECT_EQ(do_losetup && !do_err_script, 134 EXPECT_EQ(do_losetup && !do_err_script,
133 !collector_action.object().install_path.empty()); 135 !collector_action.object().install_path.empty());
134 if (do_losetup && !do_err_script) { 136 if (do_losetup && !do_err_script) {
135 EXPECT_TRUE(install_plan == collector_action.object()); 137 EXPECT_TRUE(install_plan == collector_action.object());
136 } 138 }
137 139
138 struct stat stbuf; 140 struct stat stbuf;
139 int rc = lstat((string(cwd) + "/postinst_called").c_str(), &stbuf); 141 int rc = lstat((string(cwd) + "/postinst_called").c_str(), &stbuf);
140 if (do_losetup && !do_err_script) 142 if (do_losetup && !do_err_script)
141 ASSERT_EQ(0, rc); 143 ASSERT_EQ(0, rc);
142 else 144 else
143 ASSERT_LT(rc, 0); 145 ASSERT_LT(rc, 0);
144 146
145 if (do_losetup) 147 if (do_losetup)
146 ASSERT_EQ(0, System(string("losetup -d ") + dev)); 148 ASSERT_EQ(0, System(string("losetup -d ") + dev));
147 ASSERT_EQ(0, System(string("rm -f ") + cwd + "/postinst_called")); 149 ASSERT_EQ(0, System(string("rm -f ") + cwd + "/postinst_called"));
148 ASSERT_EQ(0, System(string("rm -f ") + cwd + "/image.dat")); 150 ASSERT_EQ(0, System(string("rm -f ") + cwd + "/image.dat"));
149 } 151 }
150 152
151 // Death tests don't seem to be working on Hardy 153 // Death tests don't seem to be working on Hardy
152 TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) { 154 TEST_F(PostinstallRunnerActionTest, DISABLED_RunAsRootDeathTest) {
153 ASSERT_EQ(0, getuid()); 155 ASSERT_EQ(0, getuid());
154 PostinstallRunnerAction runner_action(true); 156 PostinstallRunnerAction runner_action(true);
155 ASSERT_DEATH({ runner_action.TerminateProcessing(); }, 157 ASSERT_DEATH({ runner_action.TerminateProcessing(); },
156 "postinstall_runner_action.h:.*] Check failed"); 158 "postinstall_runner_action.h:.*] Check failed");
157 } 159 }
158 160
159 } // namespace chromeos_update_engine 161 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « postinstall_runner_action.cc ('k') | set_bootable_flag_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698