コード例 #1
0
def parse_xml_function_return(step, root=None):
    """Parse a function return step in an xml trace."""

    return {
        'kind': 'function-return',
        'location': srcloct.xml_srcloc(step.find('location'), root),
        'detail': {
            'name':
            step.find('function').get('display_name'),
            'location':
            srcloct.xml_srcloc(step.find('function').find('location'), root)
        }
    }
コード例 #2
0
def parse_xml_function_call(step, root=None):
    """Parse a function call step in an xml trace."""

    return {
        'kind': 'function-call',
        'location': srcloct.xml_srcloc(step.find('location'), root),
        'detail': {
            'name':
            step.find('function').get('display_name'),
            'name-path':
            step.find('function').get('identifier'),
            'location':
            srcloct.xml_srcloc(step.find('function').find('location'), root)
        }
    }
コード例 #3
0
def parse_cbmc_xml(xml_data, root):
    """Parse the xml output of cbmc --show-loops --xml-ui."""

    # Each loop element contains loop-id and location elements
    root = srcloct.abspath(root)
    return {
        loop.find("loop-id").text: srcloct.xml_srcloc(loop.find("location"),
                                                      root)
        for loop in xml_data.iter("loop")
    }
コード例 #4
0
def parse_xml_failure(step, root=None):
    """Parse a failure step in an xml trace."""

    return {
        'kind': 'failure',
        'location': srcloct.xml_srcloc(step.find('location'), root),
        'detail': {
            'property': step.get('property'),
            'reason': step.get('reason')
        }
    }
コード例 #5
0
def load_cbmc_xml(xmlfile, root):
    """Load a json file produced by cbmc --show-properties --xml-ui."""

    xml_data = parse.parse_xml_file(xmlfile, fail=True)
    assert xml_data is not None

    root = srcloct.abspath(root)
    return {
        property.get("name"): {
            "class": property.get("class"),
            "description": property.find("description").text,
            "expression": property.find("expression").text,
            'location': srcloct.xml_srcloc(property.find("location"), root)
        }
        for property in xml_data.iter("property")
    }
コード例 #6
0
def parse_xml_assignment(step, root=None):
    """Parse an assignment step in an xml trace."""

    akind = step.get('assignment_type')
    kind = ('variable-assignment' if akind == 'state' else
            'parameter-assignment' if akind == 'actual_parameter' else None)
    if kind is None:
        raise UserWarning("Unknown xml assignment type: {}".format(akind))

    return {
        'kind': kind,
        'location': srcloct.xml_srcloc(step.find('location'), root),
        'detail': {
            'lhs': step.find('full_lhs').text,
            'rhs-value': step.find('full_lhs_value').text,
            'rhs-binary': None
        }
    }
コード例 #7
0
def load_cbmc_xml(xml_file, root):
    """Load xml file produced by cbmc --cover location --xml-ui."""

    xml = parse.parse_xml_file(xml_file, fail=True)
    if not xml or xml is None:   # Why is 'xml is None' required?
        logging.info("Expected coverage data in xml file %s, found none",
                     xml_file)
        return None

    coverage = {}
    for goal in xml.iter("goal"):
        description = goal.get("description")
        status = goal.get("status")
        location = goal.find("location")
        srcloc = srcloct.xml_srcloc(location, root)
        coverage = add_coverage_data(coverage, description, status, srcloc)

    try:
        RAW_COVERAGE_DATA(coverage)
    except voluptuous.error.Error as error:
        raise UserWarning("Error loading cbmc xml coverage data: {}: {}"
                          .format(xml_file, error))
    return coverage