Example #1
0
 def _testWithParts(self, parts, selectors, check_links=True):
   self.PatchObject(cros_build_lib, 'GetImageDiskPartitionInfo',
                    return_value=parts)
   mount_dir = self.PatchObject(osutils, 'MountDir')
   unmount_dir = self.PatchObject(osutils, 'UmountDir')
   rmdir = self.PatchObject(osutils, 'RmDir')
   with osutils.MountImageContext('_ignored', self.tempdir, selectors):
     for _, part in parts.items():
       mount_point = os.path.join(self.tempdir, 'dir-%d' % part.number)
       mount_dir.assert_any_call(
           '_ignored', mount_point, makedirs=True, skip_mtab=False,
           sudo=True,
           mount_opts=['loop', 'offset=0', 'sizelimit=0', 'ro']
       )
       if check_links:
         link = os.path.join(self.tempdir, 'dir-%s' % part.name)
         self.assertTrue(os.path.islink(link))
         self.assertEqual(os.path.basename(mount_point),
                          os.readlink(link))
   for _, part in parts.items():
     mount_point = os.path.join(self.tempdir, 'dir-%d' % part.number)
     unmount_dir.assert_any_call(mount_point, cleanup=False)
     rmdir.assert_any_call(mount_point, sudo=True)
     if check_links:
       link = os.path.join(self.tempdir, 'dir-%s' % part.name)
       self.assertFalse(os.path.lexists(link))
Example #2
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'
    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_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):
                result = runner.run(all_tests)

    if result and not result.wasSuccessful():
        return 1
    return 0
Example #3
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