コード例 #1
0
    def _get_test_funcs(self, test_names):
        """Obtain the actual functions of test cases based on test names.

        Args:
            test_names: A list of strings, each string is a test case name.

        Returns:
            A list of tuples of (string, function). String is the test case
            name, function is the actual test case function.

        Raises:
            errors.USERError is raised if the test name does not follow
            naming convention "test_*". This can only be caused by user input
            here.
        """
        test_funcs = []
        for test_name in test_names:
            if not hasattr(self, test_name):
                logging.warning("%s does not have test case %s.",
                                self.test_module_name, test_name)
            elif (test_name.startswith(STR_TEST)
                  or test_name.startswith(STR_GENERATE)):
                test_funcs.append((test_name, getattr(self, test_name)))
            else:
                msg = ("Test case name %s does not follow naming convention "
                       "test*, abort.") % test_name
                raise errors.USERError(msg)

        return test_funcs
コード例 #2
0
ファイル: mirror_tracker.py プロジェクト: SATYAM86400/VTS
    def GetTargetVersion(self, target_version, target_version_major,
                         target_version_minor):
        """Get the actual target version provided by the host.

        If the host provides major and minor versions separately, directly return them.
        Otherwise, manually parse it from the float version.
        If all of them are None, raise a user error.

        Args:
            target_version: float, the target component HAL version (e.g. 1.0).
            target_version_major:
                int, the target component HAL major version (e.g. 1.0 -> 1).
            target_version_minor:
                int, the target component HAL minor version (e.g. 1.0 -> 0).

        Returns:
            two integers, actual major and minor HAL versions.

        Raises: user error, if no version is provided.
        """
        # Check if host provides major and minor versions separately
        if (target_version_minor != None and target_version_minor != None):
            return target_version_major, target_version_minor

        # If not, manually parse it from float version
        if (target_version != None):
            target_version_str = str(target_version)
            [target_version_major,
             target_version_minor] = target_version_str.split(".")
            return int(target_version_major), int(target_version_minor)

        raise errors.USERError("User has to provide a target version.")
コード例 #3
0
ファイル: config_parser.py プロジェクト: SATYAM86400/VTS
def _validate_testbed_name(name):
    """Validates the name of a test bed.

    Since test bed names are used as part of the test run id, it needs to meet
    certain requirements.

    Args:
        name: The test bed's name specified in config file.

    Raises:
        If the name does not meet any criteria, errors.USERError is raised.
    """
    if not name:
        raise errors.USERError("Test bed names can't be empty.")
    if not isinstance(name, str) and not isinstance(name, basestring):
        raise errors.USERError("Test bed names have to be string. Found: %s" %
                               type(name))
    for l in name:
        if l not in utils.valid_filename_chars:
            raise errors.USERError(
                "Char '%s' is not allowed in test bed names." % l)
コード例 #4
0
ファイル: config_parser.py プロジェクト: SATYAM86400/VTS
def _parse_one_test_specifier(item):
    """Parse one test specifier from command line input.

    This also verifies that the test class name and test case names follow
    ACTS's naming conventions. A test class name has to end with "Test"; a test
    case name has to start with "test".

    Args:
        item: A string that specifies a test class or test cases in one test
            class to run.

    Returns:
        A tuple of a string and a list of strings. The string is the test class
        name, the list of strings is a list of test case names. The list can be
        None.
    """
    tokens = item.split(':')
    if len(tokens) > 2:
        raise errors.USERError("Syntax error in test specifier %s" % item)
    if len(tokens) == 1:
        # This should be considered a test class name
        test_cls_name = tokens[0]
        _validate_test_class_name(test_cls_name)
        return (test_cls_name, None)
    elif len(tokens) == 2:
        # This should be considered a test class name followed by
        # a list of test case names.
        test_cls_name, test_case_names = tokens
        clean_names = []
        _validate_test_class_name(test_cls_name)
        for elem in test_case_names.split(','):
            test_case_name = elem.strip()
            if not test_case_name.startswith("test_"):
                raise errors.USERError(
                    ("Requested test case '%s' in test class "
                     "'%s' does not follow the test case "
                     "naming convention test_*.") %
                    (test_case_name, test_cls_name))
            clean_names.append(test_case_name)
        return (test_cls_name, clean_names)
コード例 #5
0
ファイル: config_parser.py プロジェクト: SATYAM86400/VTS
def _validate_test_class_name(test_cls_name):
    """Checks if a string follows the test class name convention.

    Args:
        test_cls_name: A string that should be a test class name.

    Raises:
        errors.USERError is raised if the input does not follow test class
        naming convention.
    """
    if not test_cls_name.endswith("Test"):
        raise errors.USERError(
            ("Requested test class '%s' does not follow the test "
             "class naming convention *Test.") % test_cls_name)
コード例 #6
0
ファイル: config_parser.py プロジェクト: SATYAM86400/VTS
def _validate_test_config(test_config):
    """Validates the raw configuration loaded from the config file.

    Making sure all the required keys exist.

    Args:
        test_config: A dict that is the config to validate.

    Raises:
        errors.USERError is raised if any required key is missing from the
        config.
    """
    for k in keys.ConfigKeys.RESERVED_KEYS:
        if k not in test_config:
            raise errors.USERError(("Required key {} missing in test "
                                    "config.").format(k))
コード例 #7
0
ファイル: config_parser.py プロジェクト: SATYAM86400/VTS
def _validate_testbed_configs(testbed_configs):
    """Validates the testbed configurations.

    Args:
        testbed_configs: A list of testbed configuration json objects.

    Raises:
        If any part of the configuration is invalid, errors.USERError is raised.
    """
    seen_names = set()
    # Cross checks testbed configs for resource conflicts.
    for config in testbed_configs:
        # Check for conflicts between multiple concurrent testbed configs.
        # No need to call it if there's only one testbed config.
        name = config[keys.ConfigKeys.KEY_TESTBED_NAME]
        _validate_testbed_name(name)
        # Test bed names should be unique.
        if name in seen_names:
            raise errors.USERError(
                "Duplicate testbed name {} found.".format(name))
        seen_names.add(name)