예제 #1
0
def check_platform_specs(platform_spec,
                         work_dir,
                         logging=False,
                         no_anchors=False):
    foo = platform_spec
    schema = constants.platform_schema
    if logging:
        logger.info('Input-Platform file')
    """
      Read the input-platform foo (yaml file) and validate with schema-platform for feature values
      and constraints
    """
    # Load input YAML file
    if logging:
        logger.info('Loading input file: ' + str(foo))
    inp_yaml = utils.load_yaml(foo, no_anchors)
    if inp_yaml is None:
        inp_yaml = {'mtime': {'implemented': False}}

    # instantiate validator
    if logging:
        logger.info('Load Schema ' + str(schema))
    schema_yaml = utils.load_yaml(schema, no_anchors)
    validator = schemaValidator(schema_yaml, xlen=[])
    validator.allow_unknown = False
    validator.purge_readonly = True
    normalized = validator.normalized(inp_yaml, schema_yaml)

    # Perform Validation
    if logging:
        logger.info('Initiating Validation')
    valid = validator.validate(normalized)

    # Print out errors
    if valid:
        if logging:
            logger.info('No Syntax errors in Input Platform Yaml. :)')
    else:
        error_list = validator.errors
        raise ValidationError("Error in " + foo + ".", error_list)

    file_name = os.path.split(foo)
    file_name_split = file_name[1].split('.')
    output_filename = os.path.join(
        work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
    pfile = output_filename
    outfile = open(output_filename, 'w')
    if logging:
        logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
    utils.dump_yaml(trim(normalized), outfile, no_anchors)

    return pfile
예제 #2
0
def check_specs(isa_spec, platform_spec, work_dir):
    ''' 
        Function to perform ensure that the isa and platform specifications confirm
        to their schemas. The :py:mod:`Cerberus` module is used to validate that the
        specifications confirm to their respective schemas.

        :param isa_spec: The path to the DUT isa specification yaml file. 

        :param platform_spec: The path to the DUT platform specification yaml file.
        
        :type isa_spec: str

        :type platform_spec: str

        :raise ValidationError: It is raised when the specifications violate the 
            schema rules.
        
        :return: A tuple with the first entry being the path to normalized isa file 
            and the second being path to the platform spec file.
    '''
    global inp_yaml

    logger.info('Input-ISA file')

    foo = isa_spec
    schema = constants.isa_schema
    """
      Read the input-isa foo (yaml file) and validate with schema-isa for feature values
      and constraints
    """
    # Load input YAML file
    logger.info('Loading input file: ' + str(foo))
    inp_yaml = utils.load_yaml(foo)

    # instantiate validator
    logger.info('Load Schema ' + str(schema))
    schema_yaml = utils.load_yaml(schema)

    #Extract xlen
    xlen = findxlen()

    schema_yaml = add_def_setters(schema_yaml)
    validator = schemaValidator(schema_yaml, xlen=xlen)
    validator.allow_unknown = False
    validator.purge_readonly = True
    normalized = validator.normalized(inp_yaml, schema_yaml)

    # Perform Validation
    logger.info('Initiating Validation')
    valid = validator.validate(inp_yaml)

    # Print out errors
    if valid:
        logger.info('No Syntax errors in Input ISA Yaml. :)')
    else:
        error_list = validator.errors
        logger.error("Error in " + foo + "\n" + errPrint(error_list))
        raise ValidationError(
            "Error in ISA Yaml. Refer to logs for more details.")

    file_name = os.path.split(foo)
    file_name_split = file_name[1].split('.')
    output_filename = os.path.join(
        work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
    ifile = output_filename
    outfile = open(output_filename, 'w')
    logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
    yaml.dump(imp_normalise(normalized), outfile)

    logger.info('Input-Platform file')

    foo = platform_spec
    schema = constants.platform_schema
    """
      Read the input-platform foo (yaml file) and validate with schema-platform for feature values
      and constraints
    """
    # Load input YAML file
    logger.info('Loading input file: ' + str(foo))
    inp_yaml = utils.load_yaml(foo)
    if inp_yaml is None:
        inp_yaml = {'mtime': {'implemented': False}}

    # instantiate validator
    logger.info('Load Schema ' + str(schema))
    schema_yaml = utils.load_yaml(schema)

    validator = schemaValidator(schema_yaml, xlen=xlen)
    validator.allow_unknown = False
    validator.purge_readonly = True
    normalized = validator.normalized(inp_yaml, schema_yaml)

    # Perform Validation
    logger.info('Initiating Validation')
    valid = validator.validate(inp_yaml)

    # Print out errors
    if valid:
        logger.info('No Syntax errors in Input Platform Yaml. :)')
    else:
        error_list = validator.errors
        logger.error("Error in " + foo + "\n" + errPrint(error_list))
        raise ValidationError("Error in Platform\
             Yaml. Refer to logs for more details.")

    file_name = os.path.split(foo)
    file_name_split = file_name[1].split('.')
    output_filename = os.path.join(
        work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
    pfile = output_filename
    outfile = open(output_filename, 'w')
    logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
    yaml.dump(imp_normalise(normalized), outfile)
    return (ifile, pfile)
예제 #3
0
def check_specs(isa_spec, platform_spec, work_dir, logging=False):
    '''
        Function to perform ensure that the isa and platform specifications confirm
        to their schemas. The :py:mod:`Cerberus` module is used to validate that the
        specifications confirm to their respective schemas.

        :param isa_spec: The path to the DUT isa specification yaml file.

        :param platform_spec: The path to the DUT platform specification yaml file.

        :param logging: A boolean to indicate whether log is to be printed.

        :type logging: bool

        :type isa_spec: str

        :type platform_spec: str

        :raise ValidationError: It is raised when the specifications violate the
            schema rules. It also contains the specific errors in each of the fields.

        :return: A tuple with the first entry being the absolute path to normalized isa file
            and the second being the absolute path to the platform spec file.
    '''
    global inp_yaml

    if logging:
        logger.info('Input-ISA file')

    foo = isa_spec
    schema = constants.isa_schema
    """
      Read the input-isa foo (yaml file) and validate with schema-isa for feature values
      and constraints
    """
    # Load input YAML file
    if logging:
        logger.info('Loading input file: ' + str(foo))
    inp_yaml = utils.load_yaml(foo)

    # instantiate validator
    if logging:
        logger.info('Load Schema ' + str(schema))
    schema_yaml = add_def_setters(utils.load_yaml(schema))

    #Extract xlen
    xlen = inp_yaml['supported_xlen']

    # schema_yaml = add_def_setters(schema_yaml)
    validator = schemaValidator(schema_yaml, xlen=xlen)
    validator.allow_unknown = False
    validator.purge_readonly = True
    normalized = validator.normalized(inp_yaml, schema_yaml)

    # Perform Validation
    if logging:
        logger.info('Initiating Validation')
    valid = validator.validate(normalized)

    # Print out errors
    if valid:
        if logging:
            logger.info('No Syntax errors in Input ISA Yaml. :)')
    else:
        error_list = validator.errors
        raise ValidationError("Error in " + foo + ".", error_list)
    logger.info("Initiating post processing and reset value checks.")
    normalized, errors = check_reset_fill_fields(normalized)
    if errors:
        raise ValidationError("Error in " + foo + ".", errors)
    file_name = os.path.split(foo)
    file_name_split = file_name[1].split('.')
    output_filename = os.path.join(
        work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
    ifile = output_filename
    outfile = open(output_filename, 'w')
    if logging:
        logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
    yaml.dump(trim(normalized), outfile)

    if logging:
        logger.info('Input-Platform file')

    foo = platform_spec
    schema = constants.platform_schema
    """
      Read the input-platform foo (yaml file) and validate with schema-platform for feature values
      and constraints
    """
    # Load input YAML file
    if logging:
        logger.info('Loading input file: ' + str(foo))
    inp_yaml = utils.load_yaml(foo)
    if inp_yaml is None:
        inp_yaml = {'mtime': {'implemented': False}}

    # instantiate validator
    if logging:
        logger.info('Load Schema ' + str(schema))
    schema_yaml = utils.load_yaml(schema)

    validator = schemaValidator(schema_yaml, xlen=xlen)
    validator.allow_unknown = False
    validator.purge_readonly = True
    normalized = validator.normalized(inp_yaml, schema_yaml)

    # Perform Validation
    if logging:
        logger.info('Initiating Validation')
    valid = validator.validate(normalized)

    # Print out errors
    if valid:
        if logging:
            logger.info('No Syntax errors in Input Platform Yaml. :)')
    else:
        error_list = validator.errors
        raise ValidationError("Error in " + foo + ".", error_list)

    file_name = os.path.split(foo)
    file_name_split = file_name[1].split('.')
    output_filename = os.path.join(
        work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
    pfile = output_filename
    outfile = open(output_filename, 'w')
    if logging:
        logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
    yaml.dump(trim(normalized), outfile)
    return (ifile, pfile)
예제 #4
0
def check_isa_specs(isa_spec, work_dir, logging=False, no_anchors=False):
    '''
        Function to perform ensure that the isa and platform specifications confirm
        to their schemas. The :py:mod:`Cerberus` module is used to validate that the
        specifications confirm to their respective schemas.

        :param isa_spec: The path to the DUT isa specification yaml file.

        :param logging: A boolean to indicate whether log is to be printed.

        :type logging: bool

        :type isa_spec: str

        :raise ValidationError: It is raised when the specifications violate the
            schema rules. It also contains the specific errors in each of the fields.

        :return: A tuple with the first entry being the absolute path to normalized isa file
            and the second being the absolute path to the platform spec file.
    '''
    global inp_yaml

    if logging:
        logger.info('Input-ISA file')

    foo = isa_spec
    schema = constants.isa_schema
    """
      Read the input-isa foo (yaml file) and validate with schema-isa for feature values
      and constraints
    """
    # Load input YAML file
    if logging:
        logger.info('Loading input file: ' + str(foo))
    master_inp_yaml = utils.load_yaml(foo, no_anchors)

    # instantiate validator
    if logging:
        logger.info('Load Schema ' + str(schema))
    master_schema_yaml = utils.load_yaml(schema, no_anchors)

    outyaml = copy.deepcopy(master_inp_yaml)
    for x in master_inp_yaml['hart_ids']:
        if logging:
            logger.info('Processing Hart: hart' + str(x))
        inp_yaml = master_inp_yaml['hart' + str(x)]
        schema_yaml = add_def_setters(
            master_schema_yaml['hart_schema']['schema'])
        #Extract xlen
        xlen = inp_yaml['supported_xlen']

        validator = schemaValidator(schema_yaml, xlen=xlen)
        validator.allow_unknown = False
        validator.purge_readonly = True
        normalized = validator.normalized(inp_yaml, schema_yaml)

        # Perform Validation
        if logging:
            logger.info('Initiating Validation')
        valid = validator.validate(normalized)

        # Print out errors
        if valid:
            if logging:
                logger.info('No errors for Hart: ' + str(x) + ' :)')
        else:
            error_list = validator.errors
            raise ValidationError("Error in " + foo + ".", error_list)
        if logging:
            logger.info("Initiating post processing and reset value checks.")
        normalized, errors = check_reset_fill_fields(normalized, logging)
        if errors:
            raise ValidationError("Error in " + foo + ".", errors)
        if normalized['mhartid']['reset-val'] != x:
            raise ValidationError(
                'Error in ' + foo + ".",
                {'mhartid': ['wrong reset-val of for hart' + str(x)]})
        errors = check_shadows(normalized, logging)
        if errors:
            raise ValidationError("Error in " + foo + ".", errors)
        outyaml['hart' + str(x)] = trim(normalized)
    file_name = os.path.split(foo)
    file_name_split = file_name[1].split('.')
    output_filename = os.path.join(
        work_dir, file_name_split[0] + '_checked.' + file_name_split[1])
    ifile = output_filename
    outfile = open(output_filename, 'w')
    if logging:
        logger.info('Dumping out Normalized Checked YAML: ' + output_filename)
    utils.dump_yaml(outyaml, outfile, no_anchors)
    return ifile