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 import optparse | 7 import optparse |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 import unittest | 10 import unittest |
11 | 11 |
12 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) | 12 sys.path.append(os.path.join(os.path.dirname(__file__), '../lib')) |
13 from cros_build_lib import Die | 13 from cros_build_lib import Die |
14 from cros_build_lib import Info | 14 from cros_build_lib import Info |
15 from cros_build_lib import ReinterpretPathForChroot | 15 from cros_build_lib import ReinterpretPathForChroot |
16 from cros_build_lib import RunCommand | 16 from cros_build_lib import RunCommand |
17 from cros_build_lib import Warning | 17 from cros_build_lib import Warning |
18 | 18 |
19 | 19 # VM Constants. |
20 _KVM_PID_FILE = '/tmp/harness_pid' | |
21 _FULL_VDISK_SIZE = 6072 | 20 _FULL_VDISK_SIZE = 6072 |
22 _FULL_STATEFULFS_SIZE = 3074 | 21 _FULL_STATEFULFS_SIZE = 3074 |
| 22 _KVM_PID_FILE = '/tmp/harness_pid' |
| 23 _VERIFY_SUITE = 'suite_Smoke' |
23 | 24 |
24 # Globals to communicate options to unit tests. | 25 # Globals to communicate options to unit tests. |
25 global base_image_path | 26 global base_image_path |
26 global board | 27 global board |
27 global remote | 28 global remote |
28 global target_image_path | 29 global target_image_path |
29 global vm_graphics_flag | 30 global vm_graphics_flag |
30 | 31 |
31 | 32 |
32 _VERIFY_SUITE = 'suite_Smoke' | |
33 | |
34 class AUTest(object): | 33 class AUTest(object): |
35 """Abstract interface that defines an Auto Update test.""" | 34 """Abstract interface that defines an Auto Update test.""" |
36 source_image = '' | 35 source_image = '' |
37 use_delta_updates = False | 36 use_delta_updates = False |
38 | 37 |
39 def setUp(self): | 38 def setUp(self): |
40 unittest.TestCase.setUp(self) | 39 unittest.TestCase.setUp(self) |
41 # Set these up as they are used often. | 40 # Set these up as they are used often. |
42 self.crosutils = os.path.join(os.path.dirname(__file__), '..') | 41 self.crosutils = os.path.join(os.path.dirname(__file__), '..') |
43 self.crosutilsbin = os.path.join(os.path.dirname(__file__)) | 42 self.crosutilsbin = os.path.join(os.path.dirname(__file__)) |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 enter_chroot=False) | 241 enter_chroot=False) |
243 RunCommand(['sudo', 'rm', pid_file], enter_chroot=False) | 242 RunCommand(['sudo', 'rm', pid_file], enter_chroot=False) |
244 | 243 |
245 def setUp(self): | 244 def setUp(self): |
246 """Unit test overriden method. Is called before every test.""" | 245 """Unit test overriden method. Is called before every test.""" |
247 AUTest.setUp(self) | 246 AUTest.setUp(self) |
248 self._KillExistingVM(_KVM_PID_FILE) | 247 self._KillExistingVM(_KVM_PID_FILE) |
249 | 248 |
250 def PrepareBase(self): | 249 def PrepareBase(self): |
251 """Creates an update-able VM based on base image.""" | 250 """Creates an update-able VM based on base image.""" |
| 251 self.vm_image_path = '%s/chromiumos_qemu_image.bin' % os.path.dirname( |
| 252 base_image_path) |
252 | 253 |
253 self.vm_image_path = ('%s/chromiumos_qemu_image.bin' % os.path.dirname( | |
254 base_image_path)) | |
255 if not os.path.exists(self.vm_image_path): | 254 if not os.path.exists(self.vm_image_path): |
256 Info('Qemu image not found, creating one.') | 255 Info('Qemu image %s not found, creating one.' % self.vm_image_path) |
257 RunCommand(['%s/image_to_vm.sh' % self.crosutils, | 256 RunCommand(['%s/image_to_vm.sh' % self.crosutils, |
258 '--full', | 257 '--full', |
259 '--from=%s' % ReinterpretPathForChroot( | 258 '--from=%s' % ReinterpretPathForChroot( |
260 os.path.dirname(base_image_path)), | 259 os.path.dirname(base_image_path)), |
261 '--vdisk_size=%s' % _FULL_VDISK_SIZE, | 260 '--vdisk_size=%s' % _FULL_VDISK_SIZE, |
262 '--statefulfs_size=%s' % _FULL_STATEFULFS_SIZE, | 261 '--statefulfs_size=%s' % _FULL_STATEFULFS_SIZE, |
263 '--board=%s' % board, | 262 '--board=%s' % board, |
264 '--test_image'], enter_chroot=True) | 263 '--test_image'], enter_chroot=True) |
265 else: | 264 else: |
266 Info('Using existing VM image') | 265 Info('Using existing VM image %s' % self.vm_image_path) |
267 | 266 |
268 self.assertTrue(os.path.exists(self.vm_image_path)) | 267 self.assertTrue(os.path.exists(self.vm_image_path)) |
269 | 268 |
270 def UpdateImage(self, image_path, stateful_change='old'): | 269 def UpdateImage(self, image_path, stateful_change='old'): |
271 """Updates VM image with image_path.""" | 270 """Updates VM image with image_path.""" |
272 stateful_change_flag = self.GetStatefulChangeFlag(stateful_change) | 271 stateful_change_flag = self.GetStatefulChangeFlag(stateful_change) |
273 if self.source_image == base_image_path: | 272 if self.source_image == base_image_path: |
274 self.source_image = self.vm_image_path | 273 self.source_image = self.vm_image_path |
275 | 274 |
276 RunCommand(['%s/cros_run_vm_update' % self.crosutilsbin, | 275 RunCommand(['%s/cros_run_vm_update' % self.crosutilsbin, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 help='board for the images.') | 309 help='board for the images.') |
311 parser.add_option('-p', '--type', default='vm', | 310 parser.add_option('-p', '--type', default='vm', |
312 help='type of test to run: [vm, real]. Default: vm.') | 311 help='type of test to run: [vm, real]. Default: vm.') |
313 parser.add_option('-m', '--remote', | 312 parser.add_option('-m', '--remote', |
314 help='Remote address for real test.') | 313 help='Remote address for real test.') |
315 parser.add_option('--no_graphics', action='store_true', | 314 parser.add_option('--no_graphics', action='store_true', |
316 help='Disable graphics for the vm test.') | 315 help='Disable graphics for the vm test.') |
317 parser.add_option('--no_delta', action='store_false', default=True, | 316 parser.add_option('--no_delta', action='store_false', default=True, |
318 dest='delta', | 317 dest='delta', |
319 help='Disable using delta updates.') | 318 help='Disable using delta updates.') |
| 319 parser.add_option('-q', '--quick_test', default=False, action='store_true', |
| 320 help='Use a basic test to verify image.') |
320 # Set the usage to include flags. | 321 # Set the usage to include flags. |
321 parser.set_usage(parser.format_help()) | 322 parser.set_usage(parser.format_help()) |
322 # Parse existing sys.argv so we can pass rest to unittest.main. | 323 # Parse existing sys.argv so we can pass rest to unittest.main. |
323 (options, sys.argv) = parser.parse_args(sys.argv) | 324 (options, sys.argv) = parser.parse_args(sys.argv) |
324 | 325 |
325 base_image_path = options.base_image | 326 base_image_path = options.base_image |
326 target_image_path = options.target_image | 327 target_image_path = options.target_image |
327 board = options.board | 328 board = options.board |
328 | 329 |
329 if not base_image_path: | 330 if not base_image_path: |
330 parser.error('Need path to base image for vm.') | 331 parser.error('Need path to base image for vm.') |
331 elif not os.path.exists(base_image_path): | 332 elif not os.path.exists(base_image_path): |
332 Die('%s does not exist' % base_image_path) | 333 Die('%s does not exist' % base_image_path) |
333 | 334 |
334 if not target_image_path: | 335 if not target_image_path: |
335 parser.error('Need path to target image to update with.') | 336 parser.error('Need path to target image to update with.') |
336 elif not os.path.exists(target_image_path): | 337 elif not os.path.exists(target_image_path): |
337 Die('%s does not exist' % target_image_path) | 338 Die('%s does not exist' % target_image_path) |
338 | 339 |
339 if not board: | 340 if not board: |
340 parser.error('Need board to convert base image to vm.') | 341 parser.error('Need board to convert base image to vm.') |
341 | 342 |
342 # Communicate flags to tests. | 343 # Communicate flags to tests. |
343 vm_graphics_flag = '' | 344 vm_graphics_flag = '' |
344 if options.no_graphics: vm_graphics_flag = '--no_graphics' | 345 if options.no_graphics: vm_graphics_flag = '--no_graphics' |
345 | 346 if options.quick_test: _VERIFY_SUITE = 'build_RootFilesystemSize' |
346 AUTest.use_delta_updates = options.delta | 347 AUTest.use_delta_updates = options.delta |
347 | 348 |
348 # Only run the test harness we care about. | 349 # Only run the test harness we care about. |
349 if options.type == 'vm': | 350 if options.type == 'vm': |
350 suite = unittest.TestLoader().loadTestsFromTestCase(VirtualAUTest) | 351 suite = unittest.TestLoader().loadTestsFromTestCase(VirtualAUTest) |
351 test_result = unittest.TextTestRunner(verbosity=2).run(suite) | 352 test_result = unittest.TextTestRunner(verbosity=2).run(suite) |
352 elif options.type == 'real': | 353 elif options.type == 'real': |
353 if not options.remote: | 354 if not options.remote: |
354 parser.error('Real tests require a remote test machine.') | 355 parser.error('Real tests require a remote test machine.') |
355 else: | 356 else: |
356 remote = options.remote | 357 remote = options.remote |
357 | 358 |
358 suite = unittest.TestLoader().loadTestsFromTestCase(RealAUTest) | 359 suite = unittest.TestLoader().loadTestsFromTestCase(RealAUTest) |
359 test_result = unittest.TextTestRunner(verbosity=2).run(suite) | 360 test_result = unittest.TextTestRunner(verbosity=2).run(suite) |
360 else: | 361 else: |
361 parser.error('Could not parse harness type %s.' % options.type) | 362 parser.error('Could not parse harness type %s.' % options.type) |
362 | 363 |
363 if not test_result.wasSuccessful(): | 364 if not test_result.wasSuccessful(): |
364 Die('Test harness was not successful') | 365 Die('Test harness was not successful') |
OLD | NEW |