OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Unittests for commands. Needs to be run inside of chroot for mox.""" | 7 """Unittests for commands. Needs to be run inside of chroot for mox.""" |
8 | 8 |
9 import __builtin__ | 9 import __builtin__ |
10 import mox | 10 import mox |
11 import os | 11 import os |
12 import shutil | 12 import shutil |
13 import sys | 13 import sys |
14 import unittest | 14 import unittest |
15 | 15 |
16 import constants | 16 import constants |
17 sys.path.append(constants.SOURCE_ROOT) | 17 sys.path.append(constants.SOURCE_ROOT) |
18 import chromite.buildbot.cbuildbot_commands as commands | 18 import chromite.buildbot.cbuildbot_commands as commands |
19 import chromite.lib.cros_build_lib as cros_lib | 19 import chromite.lib.cros_build_lib as cros_lib |
20 | 20 |
21 class CBuildBotTest(mox.MoxTestBase): | 21 class CBuildBotTest(mox.MoxTestBase): |
22 | 22 |
23 def setUp(self): | 23 def setUp(self): |
24 mox.MoxTestBase.setUp(self) | 24 mox.MoxTestBase.setUp(self) |
25 # Always stub RunCommmand out as we use it in every method. | 25 # Always stub RunCommmand out as we use it in every method. |
26 self.mox.StubOutWithMock(cros_lib, 'OldRunCommand') | 26 self.mox.StubOutWithMock(cros_lib, 'OldRunCommand') |
| 27 self.mox.StubOutWithMock(cros_lib, 'RunCommand') |
27 self.tracking_branch = 'cros/master' | 28 self.tracking_branch = 'cros/master' |
28 self._test_repos = [['kernel', 'third_party/kernel/files'], | 29 self._test_repos = [['kernel', 'third_party/kernel/files'], |
29 ['login_manager', 'platform/login_manager'] | 30 ['login_manager', 'platform/login_manager'] |
30 ] | 31 ] |
31 self._test_cros_workon_packages = ( | 32 self._test_cros_workon_packages = ( |
32 'chromeos-base/kernel\nchromeos-base/chromeos-login\n') | 33 'chromeos-base/kernel\nchromeos-base/chromeos-login\n') |
33 self._test_board = 'test-board' | 34 self._test_board = 'test-board' |
34 self._buildroot = '.' | 35 self._buildroot = '.' |
35 self._test_dict = {'kernel': ['chromos-base/kernel', 'dev-util/perf'], | 36 self._test_dict = {'kernel': ['chromos-base/kernel', 'dev-util/perf'], |
36 'cros': ['chromos-base/libcros'] | 37 'cros': ['chromos-base/libcros'] |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 the second time.""" | 151 the second time.""" |
151 cros_lib.OldRunCommand(mox.In('sync'), | 152 cros_lib.OldRunCommand(mox.In('sync'), |
152 cwd=self._buildroot).AndRaise(Exception("failed")) | 153 cwd=self._buildroot).AndRaise(Exception("failed")) |
153 cros_lib.OldRunCommand(mox.In('sync'), cwd=self._buildroot) | 154 cros_lib.OldRunCommand(mox.In('sync'), cwd=self._buildroot) |
154 cros_lib.OldRunCommand(mox.In('forall'), cwd=self._buildroot) | 155 cros_lib.OldRunCommand(mox.In('forall'), cwd=self._buildroot) |
155 cros_lib.OldRunCommand(mox.In('manifest'), cwd=self._buildroot) | 156 cros_lib.OldRunCommand(mox.In('manifest'), cwd=self._buildroot) |
156 self.mox.ReplayAll() | 157 self.mox.ReplayAll() |
157 commands._RepoSync(self._buildroot, retries=2) | 158 commands._RepoSync(self._buildroot, retries=2) |
158 self.mox.VerifyAll() | 159 self.mox.VerifyAll() |
159 | 160 |
| 161 def testBuildIncremental(self): |
| 162 """Base case where Build is called.""" |
| 163 buildroot = '/bob/' |
| 164 cros_lib.RunCommand(mox.IgnoreArg(), cwd=mox.StrContains(buildroot), |
| 165 enter_chroot=True, extra_env=mox.IgnoreArg()) |
| 166 self.mox.ReplayAll() |
| 167 commands.Build(buildroot, False) |
| 168 self.mox.VerifyAll() |
| 169 |
| 170 def testBuildClobber(self): |
| 171 """Base case where Build with emptytree is called.""" |
| 172 buildroot = '/bob/' |
| 173 cros_lib.RunCommand(mox.IgnoreArg(), cwd=mox.StrContains(buildroot), |
| 174 enter_chroot=True, |
| 175 extra_env=mox.ContainsKeyValue('EXTRA_BOARD_FLAGS','--emptytree')) |
| 176 self.mox.ReplayAll() |
| 177 commands.Build(buildroot, True) |
| 178 self.mox.VerifyAll() |
| 179 |
| 180 def testBuildWithEnv(self): |
| 181 """Case where Build is called with a custom environment.""" |
| 182 buildroot = '/bob/' |
| 183 extra = {'A' :'Av', 'B' : 'Bv'} |
| 184 cros_lib.RunCommand( mox.IgnoreArg(), cwd=mox.StrContains(buildroot), |
| 185 enter_chroot=True,extra_env=mox.And( |
| 186 mox.ContainsKeyValue('A','Av'), mox.ContainsKeyValue('B','Bv'))) |
| 187 self.mox.ReplayAll() |
| 188 commands.Build(buildroot, True, extra_env=extra) |
| 189 self.mox.VerifyAll() |
| 190 |
| 191 |
160 | 192 |
161 if __name__ == '__main__': | 193 if __name__ == '__main__': |
162 unittest.main() | 194 unittest.main() |
OLD | NEW |