Ejemplo n.º 1
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)
    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
Ejemplo n.º 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'
    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
Ejemplo n.º 3
0
    def setUp(self):
        self.git_dir = os.path.join(self.tempdir, '.git')

        devnull = open(os.devnull, 'w')
        self.addCleanup(devnull.close)

        def call(args, **kwargs):
            subprocess.check_call(args,
                                  stdout=devnull,
                                  stderr=devnull,
                                  **kwargs)

        with osutils.ChdirContext(self.tempdir):
            call(['git', 'init'])
            call(['git', 'config', 'user.name', 'John Doe'])
            call(['git', 'config', 'user.email', '*****@*****.**'])
            with open('foo', 'w') as f:
                f.write('a\nb\nc\n')
            call(['git', 'add', 'foo'])
            env = os.environ.copy()
            env['GIT_AUTHOR_DATE'] = '2017-01-01T00:00:00Z'
            env['GIT_COMMITTER_DATE'] = '2017-01-01T00:00:00Z'
            call(['git', 'commit', '-m', 'Initial commit'], env=env)
Ejemplo n.º 4
0
 def testChdir(self):
   current_dir = os.getcwd()
   self.assertNotEqual(self.tempdir, os.getcwd())
   with osutils.ChdirContext(self.tempdir):
     self.assertEqual(self.tempdir, os.getcwd())
   self.assertEqual(current_dir, os.getcwd())