def main(args): opts = ParseArgs(args) # Build up test suites. loader = unittest.TestLoader() loader.suiteClass = image_test_lib.ImageTestSuite # We use a different prefix here so that unittest DO NOT pick up the # image tests automatically because they depend on a proper environment. loader.testMethodPrefix = 'Test' tests_namespace = 'chromite.cros.test.image_test' if opts.tests: tests = ['%s.%s' % (tests_namespace, x) for x in opts.tests] else: tests = (tests_namespace, ) all_tests = loader.loadTestsFromNames(tests) # If they just want to see the lists of tests, show them now. if opts.list: def _WalkSuite(suite): for test in suite: if isinstance(test, unittest.BaseTestSuite): for result in _WalkSuite(test): yield result else: yield (test.id()[len(tests_namespace) + 1:], test.shortDescription() or '') test_list = list(_WalkSuite(all_tests)) maxlen = max(len(x[0]) for x in test_list) for name, desc in test_list: print('%-*s %s' % (maxlen, name, desc)) return # Run them in the image directory. runner = image_test_lib.ImageTestRunner() runner.SetBoard(opts.board) runner.SetResultDir(opts.test_results_root) image_file = FindImage(opts.image) tmp_in_chroot = path_util.FromChrootPath('/tmp') with osutils.TempDir(base_dir=tmp_in_chroot) as temp_dir: with image_lib.LoopbackPartitions(image_file, temp_dir) as image: # Due to the lack of mount context, we mount the partitions # but do not reference directly. This will be removed with the # submission of http://crrev/c/1795578 _ = image.Mount((constants.PART_ROOT_A, ))[0] _ = image.Mount((constants.PART_STATE, ))[0] with osutils.ChdirContext(temp_dir): result = runner.run(all_tests) if result and not result.wasSuccessful(): return 1 return 0
def main(args): opts = ParseArgs(args) # Build up test suites. loader = unittest.TestLoader() loader.suiteClass = image_test_lib.ImageTestSuite # We use a different prefix here so that unittest DO NOT pick up the # image tests automatically because they depend on a proper environment. loader.testMethodPrefix = 'Test' all_tests = loader.loadTestsFromName('chromite.cros.test.image_test') forgiving = image_test_lib.ImageTestSuite() non_forgiving = image_test_lib.ImageTestSuite() for suite in all_tests: for test in suite.GetTests(): if test.IsForgiving(): forgiving.addTest(test) else: non_forgiving.addTest(test) # Run them in the image directory. runner = image_test_lib.ImageTestRunner() runner.SetBoard(opts.board) runner.SetResultDir(opts.test_results_root) image_file = FindImage(opts.image_dir) tmp_in_chroot = path_util.FromChrootPath('/tmp') with osutils.TempDir(base_dir=tmp_in_chroot) as temp_dir: with osutils.MountImageContext(image_file, temp_dir): with osutils.ChdirContext(temp_dir): # Run non-forgiving tests first so that exceptions in forgiving tests # do not skip any required tests. logging.info('Running NON-forgiving tests.') result = runner.run(non_forgiving) logging.info('Running forgiving tests.') runner.run(forgiving) if result and not result.wasSuccessful(): return 1 return 0