コード例 #1
0
ファイル: cros_run_unit_tests.py プロジェクト: sjg20/chromite
def main(argv):
    opts = ParseArgs(argv)

    cros_build_lib.AssertInsideChroot()

    sysroot = opts.sysroot or cros_build_lib.GetSysroot(opts.board)
    package_blacklist = portage_util.UNITTEST_PACKAGE_BLACKLIST
    if opts.package_blacklist:
        package_blacklist |= set(opts.package_blacklist.split())

    packages = set()
    # The list of packages to test can be passed as a file containing a
    # space-separated list of package names.
    # This is used by the builder to test only the packages that were upreved.
    if opts.package_file and os.path.exists(opts.package_file):
        packages = set(osutils.ReadFile(opts.package_file).split())

    if opts.packages:
        packages |= set(opts.packages.split())

    # If no packages were specified, use all testable packages.
    if not (opts.packages or opts.package_file):
        workon = workon_helper.WorkonHelper(sysroot)
        packages = (workon.InstalledWorkonAtoms()
                    if opts.installed else workon.ListAtoms(use_all=True))

    for cp in packages & package_blacklist:
        logging.info('Skipping blacklisted package %s.', cp)

    packages = packages - package_blacklist
    pkg_with_test = portage_util.PackagesWithTest(sysroot, packages)

    if packages - pkg_with_test:
        logging.warning('The following packages do not have tests:')
        logging.warning('\n'.join(sorted(packages - pkg_with_test)))

    if opts.pretend:
        print('\n'.join(sorted(pkg_with_test)))
        return

    env = None
    if opts.nowithdebug:
        use_flags = os.environ.get('USE', '')
        use_flags += ' -cros-debug'
        env = {'USE': use_flags}

    try:
        chroot_util.RunUnittests(sysroot,
                                 pkg_with_test,
                                 extra_env=env,
                                 jobs=min(10, multiprocessing.cpu_count()))
    except cros_build_lib.RunCommandError:
        logging.error('Unittests failed.')
        raise
コード例 #2
0
def main(argv):
    opts = ParseArgs(argv)

    cros_build_lib.AssertInsideChroot()

    sysroot = opts.sysroot or cros_build_lib.GetSysroot(opts.board)
    package_blacklist = set()
    if opts.package_blacklist:
        package_blacklist |= set(opts.package_blacklist.split())

    packages = set()
    # The list of packages to test can be passed as a file containing a
    # space-separated list of package names.
    # This is used by the builder to test only the packages that were upreved.
    if opts.package_file and os.path.exists(opts.package_file):
        packages = set(osutils.ReadFile(opts.package_file).split())

    if opts.packages:
        packages |= set(opts.packages.split())

    # If no packages were specified, use all testable packages.
    if not (opts.packages or opts.package_file) and not opts.empty_sysroot:
        workon = workon_helper.WorkonHelper(sysroot)
        packages = (workon.InstalledWorkonAtoms() if opts.installed else set(
            workon.ListAtoms(use_all=True)))

    if opts.empty_sysroot:
        packages |= determine_board_packages(sysroot, BOARD_VIRTUAL_PACKAGES)
        workon = workon_helper.WorkonHelper(sysroot)
        workon_packages = set(workon.ListAtoms(use_all=True))
        packages &= workon_packages

    for cp in packages & package_blacklist:
        logging.info('Skipping blacklisted package %s.', cp)

    packages = packages - package_blacklist
    pkg_with_test = portage_util.PackagesWithTest(sysroot, packages)

    if packages - pkg_with_test:
        logging.warning('The following packages do not have tests:\n  %s',
                        '\n  '.join(sorted(packages - pkg_with_test)))

    if not pkg_with_test:
        if opts.testable_packages_optional:
            logging.warning('No testable packages found!')
            return 0
        logging.error('No testable packages found!')
        return 1

    if opts.pretend:
        print('\n'.join(sorted(pkg_with_test)))
        return 0

    env = None
    if opts.nowithdebug:
        use_flags = os.environ.get('USE', '')
        use_flags += ' -cros-debug'
        env = {'USE': use_flags}

    if opts.empty_sysroot:
        try:
            chroot_util.Emerge(list(IMPLICIT_TEST_DEPS),
                               sysroot,
                               rebuild_deps=False,
                               use_binary=False)
            chroot_util.Emerge(list(pkg_with_test),
                               sysroot,
                               rebuild_deps=False,
                               use_binary=False)
        except cros_build_lib.RunCommandError:
            logging.error('Failed building dependencies for unittests.')
            return 1

    try:
        chroot_util.RunUnittests(sysroot,
                                 pkg_with_test,
                                 extra_env=env,
                                 jobs=opts.jobs)
    except cros_build_lib.RunCommandError:
        logging.error('Unittests failed.')
        return 1