OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 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 cbuildbot. Needs to be run inside of chroot for mox.""" | 7 """Unittests for cbuildbot. 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 posix | 12 import posix |
13 import shutil | 13 import shutil |
14 import tempfile | |
14 import unittest | 15 import unittest |
15 | 16 |
16 # Fixes circular dependency error. | 17 # Fixes circular dependency error. |
17 import cbuildbot_comm | 18 import cbuildbot_comm |
18 import cbuildbot | 19 import cbuildbot |
19 from cros_build_lib import ReinterpretPathForChroot | 20 from cros_build_lib import ReinterpretPathForChroot |
20 | 21 |
22 | |
21 class CBuildBotTest(mox.MoxTestBase): | 23 class CBuildBotTest(mox.MoxTestBase): |
22 | 24 |
23 def setUp(self): | 25 def setUp(self): |
24 mox.MoxTestBase.setUp(self) | 26 mox.MoxTestBase.setUp(self) |
25 # Always stub RunCommmand out as we use it in every method. | 27 # Always stub RunCommmand out as we use it in every method. |
26 self.mox.StubOutWithMock(cbuildbot, 'RunCommand') | 28 self.mox.StubOutWithMock(cbuildbot, 'RunCommand') |
27 self.tracking_branch = 'cros/master' | 29 self.tracking_branch = 'cros/master' |
28 self._test_repos = [['kernel', 'third_party/kernel/files'], | 30 self._test_repos = [['kernel', 'third_party/kernel/files'], |
29 ['login_manager', 'platform/login_manager'] | 31 ['login_manager', 'platform/login_manager'] |
30 ] | 32 ] |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 # cbuildbot._UprevPackages(self._buildroot, self._revision_file, | 112 # cbuildbot._UprevPackages(self._buildroot, self._revision_file, |
111 # self._test_board) | 113 # self._test_board) |
112 # self.mox.VerifyAll() | 114 # self.mox.VerifyAll() |
113 | 115 |
114 def testArchiveTestResults(self): | 116 def testArchiveTestResults(self): |
115 """Test if we can archive the latest results dir to Google Storage.""" | 117 """Test if we can archive the latest results dir to Google Storage.""" |
116 # Set vars for call. | 118 # Set vars for call. |
117 buildroot = '/fake_dir' | 119 buildroot = '/fake_dir' |
118 board = 'fake-board' | 120 board = 'fake-board' |
119 test_results_dir = 'fake_results_dir' | 121 test_results_dir = 'fake_results_dir' |
120 gsutil_path='/fake/gsutil/path' | 122 gsutil_path = '/fake/gsutil/path' |
121 archive_dir = 1234 | 123 archive_dir = 1234 |
122 acl = 'fake_acl' | 124 acl = 'fake_acl' |
123 num_retries = 5 | 125 num_retries = 5 |
124 | 126 |
125 # Convenience variables to make archive easier to understand. | 127 # Convenience variables to make archive easier to understand. |
126 path_to_results = os.path.join(buildroot, 'chroot', test_results_dir) | 128 path_to_results = os.path.join(buildroot, 'chroot', test_results_dir) |
127 path_to_image = os.path.join(buildroot, 'src', 'build', 'images', board, | 129 path_to_image = os.path.join(buildroot, 'src', 'build', 'images', board, |
128 'latest', 'chromiumos_qemu_image.bin') | 130 'latest', 'chromiumos_qemu_image.bin') |
129 | 131 |
130 cbuildbot.RunCommand(['sudo', 'chmod', '-R', '+r', path_to_results]) | 132 cbuildbot.RunCommand(['sudo', 'chmod', '-R', '+r', path_to_results]) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 binhost = 'http://www.example.com' | 225 binhost = 'http://www.example.com' |
224 binhosts = [binhost, None] | 226 binhosts = [binhost, None] |
225 check = mox.And(mox.IsA(list), mox.In(binhost), mox.Not(mox.In(None)), | 227 check = mox.And(mox.IsA(list), mox.In(binhost), mox.Not(mox.In(None)), |
226 mox.In('chromeos-images:/var/www/prebuilt/')) | 228 mox.In('chromeos-images:/var/www/prebuilt/')) |
227 cbuildbot.RunCommand(check, cwd='%s/src/scripts' % self._buildroot) | 229 cbuildbot.RunCommand(check, cwd='%s/src/scripts' % self._buildroot) |
228 self.mox.ReplayAll() | 230 self.mox.ReplayAll() |
229 cbuildbot._UploadPrebuilts(self._buildroot, self._test_board, 'private', | 231 cbuildbot._UploadPrebuilts(self._buildroot, self._test_board, 'private', |
230 binhosts) | 232 binhosts) |
231 self.mox.VerifyAll() | 233 self.mox.VerifyAll() |
232 | 234 |
235 def testGetChromeOSVersion(self): | |
236 """Tests that we can parse the correct chromeos version using method.""" | |
237 fake_data = '\n'.join(['ChromeOS version information:', | |
238 ' SOME_OTHER_DATA=blah', | |
239 ' CHROMEOS_VERSION_STRING=9.0.232.1', | |
240 ' CHROMEOS_VERSION_CODENAME=test-bot', | |
241 ]) | |
242 cbuildbot.RunCommand('./chromeos_version.sh', | |
243 cwd='src/scripts', | |
244 redirect_stderr=True, | |
245 redirect_stdout=True).AndReturn(fake_data) | |
246 self.mox.ReplayAll() | |
247 return_tuple = cbuildbot._GetChromeOSVersion('') | |
248 self.assertEquals('.'.join(return_tuple), '9.0.232.1') | |
249 self.mox.VerifyAll() | |
250 | |
251 def testGetManifestPath(self): | |
252 """Tests whether our logic to get the manifest path is correct.""" | |
253 self.mox.StubOutWithMock(cbuildbot, '_GetChromeOSVersion') | |
254 return_tuple = cbuildbot._GetChromeOSVersion('').AndReturn( | |
255 ('9', '0', '232', '1')) | |
256 self.mox.ReplayAll() | |
257 relative_path = cbuildbot._GetManifestPath('') | |
258 self.assertEquals(relative_path, '9.0/9.0.232.1.xml') | |
259 self.mox.VerifyAll() | |
260 | |
261 def _CommonManifestTest(self, url, overlay_no_buildroot): | |
262 """Common method for dump manifest tests.""" | |
263 self.mox.StubOutWithMock(cbuildbot, '_GetManifestPath') | |
264 self.mox.StubOutWithMock(shutil, 'copy') | |
265 self.mox.StubOutWithMock(os, 'symlink') | |
266 temp_root = tempfile.mkdtemp('_unittest') | |
267 | |
268 overlay = overlay_no_buildroot % { 'buildroot': temp_root } | |
scottz
2010/12/11 00:01:53
{'
sosa
2010/12/13 18:46:39
Done.
| |
269 relative_path = 'fake/manifest/path.xml' | |
270 full_path = os.path.join(overlay, 'manifests', relative_path) | |
271 | |
272 cbuildbot._GetManifestPath(temp_root).AndReturn(relative_path) | |
273 cbuildbot.RunCommand(['repo', 'manifest', '-r', '-o', full_path], | |
274 cwd=temp_root) | |
275 os.symlink(relative_path, os.path.join(overlay, 'manifests', 'LATEST')) | |
276 cbuildbot.RunCommand(['git', 'add', 'manifests/' + relative_path], | |
277 cwd=overlay) | |
278 cbuildbot.RunCommand(['git', 'add', 'manifests/LATEST'], cwd=overlay) | |
279 shutil.copy(full_path, '/dev/stderr') | |
280 | |
281 self.mox.ReplayAll() | |
282 cbuildbot._DumpManifest(temp_root, url) | |
283 self.mox.VerifyAll() | |
284 | |
285 shutil.rmtree(temp_root) | |
286 | |
287 def testDumpManifestPublic(self): | |
288 """Tests whether we push the manifest to the public overlay correctly.""" | |
289 self._CommonManifestTest('http://some_url/manifest', | |
290 cbuildbot.PUBLIC_OVERLAY) | |
291 | |
292 def testDumpManifestPrivate(self): | |
293 """Tests whether we push the manifest to the private overlay correctly.""" | |
294 self._CommonManifestTest('http://some_url/manifest-internal', | |
295 cbuildbot.PRIVATE_OVERLAY) | |
296 | |
233 | 297 |
234 if __name__ == '__main__': | 298 if __name__ == '__main__': |
235 unittest.main() | 299 unittest.main() |
OLD | NEW |