Exemplo n.º 1
0
    def testFindSuiteSyntaxErrors(self):
        """Check all control files for syntax errors.

        This test actually parses all control files in the autotest directory
        for syntax errors, by using the un-forgiving parser and pretending to
        look for all control files with the suite attribute.
        """
        autodir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', '..', '..'))
        fs_getter = SuiteBase.create_fs_getter(autodir)
        predicate = lambda t: hasattr(t, 'suite')
        SuiteBase.find_and_parse_tests(fs_getter, predicate,
                                       forgiving_parser=False)
Exemplo n.º 2
0
    def __init__(self, config, test_dir):
        """Init WrapperTestRunner.

        The test to run inside the wrapper test is usually a client side
        autotest. Look up the control file of the inner test, and then prepend
        the args to to the control file to pass the args to the inner test.

        @param config: the args argument from test_that in a dict, contains the
                       test to look up in the autotest directory and the args to
                       prepend to the control file.
                       required data: {'test': 'test_TestName.tag'}
        @param test_dir: the directory to retrieve the test from.
        """
        if not config:
            msg = 'Wrapper test must run with args input.'
            raise error.TestNAError(msg)
        if 'test' not in config:
            msg = 'User did not specify client side test to run in wrapper.'
            raise error.TestNAError(msg)
        # test_name is tagged test name.
        self._test_name = config['test']

        # Find the test in autotest file system.
        fs_getter = suite.create_fs_getter(test_dir)
        predicate = suite.test_name_equals_predicate(self._test_name)
        test = suite.find_and_parse_tests(fs_getter, predicate)
        if not test:
            msg = '%s is not a valid test name.' % self._test_name
            raise error.TestNAError(msg)

        # If multiple tests with the same name are found, run the first one.
        if len(test) > 1:
            logging.warning(
                'Found %d tests with name %s, running the first '
                'one.', len(test), self._test_name)
        control_file_no_args = test[0].text

        # Prepend the args.
        args_list = ['='.join((k, str(v))) for k, v in config.iteritems()]
        args_string = 'args = ' + json.dumps(args_list)
        args_dict_string = 'args_dict = ' + json.dumps(config)
        control_file_list = [args_string, args_dict_string]
        control_file_list.extend(
            ['%s = "%s"' % (k, str(v)) for k, v in config.iteritems()])
        control_file_list.append(control_file_no_args)

        self._test_control_file = '\n'.join(control_file_list)
Exemplo n.º 3
0
def _control_path_on_disk(control_name):
    """Find the control file corresponding to the given control name, on disk.

    @param control_name: NAME attribute of the control file to fetch.
    @return: Path to the control file.
    """
    cf_getter = suite.create_fs_getter(_AUTOTEST_ROOT)
    control_name_predicate = suite.test_name_matches_pattern_predicate(
        '^%s$' % control_name)
    tests = suite.find_and_parse_tests(cf_getter, control_name_predicate)
    if not tests:
        raise error.AutoservError(
            'Failed to find any control files with NAME %s' % control_name)
    if len(tests) > 1:
        logging.error('Found more than one control file with NAME %s: %s',
                      control_name, [t.path for t in tests])
        raise error.AutoservError(
            'Found more than one control file with NAME %s' % control_name)
    return tests[0].path
Exemplo n.º 4
0
def fetch_local_suite(autotest_path,
                      suite_predicate,
                      afe,
                      test_arg,
                      remote,
                      build=NO_BUILD,
                      board=NO_BOARD,
                      results_directory=None,
                      no_experimental=False,
                      ignore_deps=True):
    """Create a suite from the given suite predicate.

    Satisfaction of dependencies is enforced by Suite.schedule() if
    ignore_deps is False. Note that this method assumes only one host,
    i.e. |remote|, was added to afe. Suite.schedule() will not
    schedule a job if none of the hosts in the afe (in our case,
    just one host |remote|) has a label that matches a requested
    test dependency.

    @param autotest_path: Absolute path to autotest (in sysroot or
                          custom autotest directory set by --autotest_dir).
    @param suite_predicate: callable that takes ControlData objects, and
                            returns True on those that should be in suite
    @param afe: afe object to schedule against (typically a directAFE)
    @param test_arg: String. An individual TEST command line argument, e.g.
                     'login_CryptohomeMounted' or 'suite:smoke'.
    @param remote: String representing the IP of the remote host.
    @param build: Build to schedule suite for.
    @param board: Board to schedule suite for.
    @param results_directory: Absolute path of directory to store results in.
                              (results will be stored in subdirectory of this).
    @param no_experimental: Skip experimental tests when scheduling a suite.
    @param ignore_deps: If True, test dependencies will be ignored.

    @returns: A LocalSuite object.

    """
    fs_getter = suite.create_fs_getter(autotest_path)
    devserver = dev_server.ImageServer('')
    my_suite = LocalSuite.create_from_predicates(
        [suite_predicate], {provision.CROS_VERSION_PREFIX: build},
        constants.BOARD_PREFIX + board,
        devserver,
        fs_getter,
        afe=afe,
        ignore_deps=ignore_deps,
        results_dir=results_directory,
        forgiving_parser=False,
        job_retry=True)
    if len(my_suite.tests) == 0:
        (similarity_predicate, similarity_description) = (
            get_predicate_for_possible_test_arg(test_arg))
        logging.error('No test found, searching for possible tests with %s',
                      similarity_description)
        possible_tests = suite.find_possible_tests(fs_getter,
                                                   similarity_predicate)
        raise ValueError('Found no tests. Check your suite name, test name, '
                         'or test matching wildcard.\nDid you mean any of '
                         'following tests?\n  %s' %
                         '\n  '.join(possible_tests))

    if not ignore_deps:
        # Log tests whose dependencies can't be satisfied.
        labels = [
            label.name for label in afe.get_labels(host__hostname=remote)
        ]
        for test in my_suite.tests:
            if test.experimental and no_experimental:
                continue
            unsatisfiable_deps = set(test.dependencies).difference(labels)
            if unsatisfiable_deps:
                logging.warning(
                    '%s will be skipped, unsatisfiable '
                    'test dependencies: %s', test.name, unsatisfiable_deps)
    return my_suite