Exemplo n.º 1
0
def parse_json_function_return(step, root=None):
    """Parse a function return step of a json trace."""

    return {
        'kind': 'function-return',
        'location': srcloct.json_srcloc(step.get('sourceLocation'), root),
        'detail': {
            'name':
            step['function']['displayName'],
            'location':
            srcloct.json_srcloc(step['function']['sourceLocation'], root)
        }
    }
def load_cbmc_json(json_file, root):
    """Load json file produced by cbmc --cover location --json-ui."""

    json_data = parse.parse_json_file(json_file, fail=True)
    if not json_data:
        logging.info("Expected coverage data in json file %s, found none",
                     json_file)
        return None

    goal_list = [entry for entry in json_data if 'goals' in entry]
    if len(goal_list) != 1:
        logging.info("Expected 1 block of goal data in json file %s, found %s",
                     json_file, len(goal_list))
        return None
    goals = goal_list[0]

    coverage = {}
    for goal in goals["goals"]:
        description = goal["description"]
        status = goal["status"]
        location = goal["sourceLocation"]
        srcloc = srcloct.json_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 json coverage data: {}: {}"
                          .format(json_file, error))
    return coverage
Exemplo n.º 3
0
def parse_json_assignment(step, root=None):
    """Parse an assignment step of a json trace."""

    akind = step.get('assignmentType')
    kind = ('variable-assignment' if akind == 'variable' else
            'parameter-assignment' if akind == 'actual-parameter' else None)
    if kind is None:
        raise UserWarning("Unknown json assignment type: {}".format(akind))

    # &v is represented as {name: pointer, data: v}
    # NULL is represented as {name: pointer, data:{(basetype *)NULL)}
    data = step['value'].get('data')
    if step['value'].get('name') == 'pointer' and data and 'NULL' not in data:
        data = '&{}'.format(data)

    return {
        'kind': kind,
        'location': srcloct.json_srcloc(step.get('sourceLocation'), root),
        'detail': {
            'lhs': step['lhs'],
            'lhs-lexical-scope': None,
            'rhs-value': data or json.dumps(step['value']),
            'rhs-binary': binary_as_bytes(step['value'].get('binary'))
        }
    }
Exemplo n.º 4
0
def parse_json_failure(step, root=None):
    """Parse a failure step of a json trace."""

    return {
        'kind': 'failure',
        'location': srcloct.json_srcloc(step.get('sourceLocation'), root),
        'detail': {
            'property': step.get('property'),
            'reason': step.get('reason')
        }
    }
Exemplo n.º 5
0
def parse_cbmc_json(json_data, root):
    """Parse the json output of cbmc --show-loops --json-ui."""

    # Search cbmc output for {"loops": [ LOOP ]}
    loops = [json_map for json_map in json_data if "loops" in json_map]
    if len(loops) != 1:
        raise UserWarning(
            "Expected 1 set of loops in cbmc output, found {}".format(
                len(loops)))

    # Each LOOP is a dict that gives a loop name and location.
    root = srcloct.abspath(root)
    return {
        loop['name']: srcloct.json_srcloc(loop['sourceLocation'], root)
        for loop in loops[0]["loops"]
    }
def load_cbmc_json(jsonfile, root):
    """Load a json file produced by cbmc --show-properties --json-ui."""

    json_data = parse.parse_json_file(jsonfile, fail=True)
    assert json_data is not None

    # Search cbmc output for {"properties": [ PROPERTY ]}
    asserts = [json_map for json_map in json_data if "properties" in json_map]
    if len(asserts) != 1:
        raise UserWarning("Expected 1 set of properties in cbmc output, "
                          "found {}".format(len(asserts)))

    # Each PROPERTY a loop property and definition
    root = srcloct.abspath(root)
    return {
        property['name']: {
            'class': property['class'],
            'description': property['description'],
            'expression': property['expression'],
            'location': srcloct.json_srcloc(property['sourceLocation'], root)
        }
        for property in asserts[0]["properties"]
    }