Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 def load(source_json):
     try:
         source = parse.parse_json_file(source_json)[JSON_TAG]
     except TypeError:
         raise UserWarning("Failed to load sources from {}".format(
             source_json)) from None
     self.validate(source)
     return source
Ejemplo n.º 3
0
    def __init__(self, config_file=None):
        self.file = config_file
        self.missing_functions = []

        if config_file is None:
            return

        config_data = parse.parse_json_file(config_file)
        if config_data:
            self.missing_functions = config_data.get(EXPECTED_MISSING, [])
Ejemplo n.º 4
0
    def load_results(json_file):
        """Load CBMC results from json file"""

        data = parse.parse_json_file(json_file)[JSON_TAG]

        # json uses strings "true" and "false" for True and False keys
        data[RESULT][True] = data[RESULT]["true"]
        data[RESULT][False] = data[RESULT]["false"]
        del data[RESULT]["true"]
        del data[RESULT]["false"]

        return data
Ejemplo n.º 5
0
def parse_json_traces(jsonfile, root=None):
    """Parse a set of json traces."""

    data = parse.parse_json_file(jsonfile)
    if data is None:
        return {}

    results = [entry['result'] for entry in data if 'result' in entry][0]
    traces = {
        result['property']: parse_json_trace(result['trace'], root)
        for result in results if 'trace' in result
    }
    return traces
Ejemplo n.º 6
0
    def parse_results(jsonfile):
        """Parse CBMC results in json output"""

        results = {
            PROGRAM: None,
            STATUS: [],
            WARNING: [],
            RESULT: {
                True: [],
                False: []
            },
            PROVER: None
        }

        data = parse.parse_json_file(jsonfile)
        if data is None:
            return results

        # TODO: handle cbmc --stop-on-fail json output
        for entry in data:
            if JSON_PROGRAM_KEY in entry:
                results[PROGRAM] = entry[JSON_PROGRAM_KEY]
                continue

            if JSON_MESSAGE_TYPE_KEY in entry:
                kind = entry[JSON_MESSAGE_TYPE_KEY]
                text = entry[JSON_MESSAGE_TEXT_KEY]
                if kind == JSON_STATUS_MESSAGE:
                    results[STATUS].append(text)
                    continue
                if kind == JSON_WARNING:
                    results[WARNING].append(text)
                    continue
                raise UserWarning(
                    'Unknown CBMC json message type {}'.format(kind))

            if JSON_RESULT_KEY in entry:
                for result in entry[JSON_RESULT_KEY]:
                    name = result[JSON_PROPERTY_KEY]
                    success = result[JSON_STATUS_KEY] == JSON_SUCCESS
                    results[RESULT][success].append(name)
                continue

            if JSON_PROVER_STATUS_KEY in entry:
                results[PROVER] = entry[JSON_PROVER_STATUS_KEY]
                continue

            raise UserWarning(
                'Unrecognized CBMC json results data: {}'.format(entry))

        return results
Ejemplo n.º 7
0
def load_json(json_file):
    """Load json file produced by make-coverage"""

    json_data = parse.parse_json_file(json_file, fail=True)
    if json_data is None:
        logging.info("Found empty json coverage data.")
        return None

    coverage = repair_json(json_data[JSON_TAG]['coverage'])
    try:
        RAW_COVERAGE_DATA(coverage)
    except voluptuous.error.Error as error:
        raise UserWarning("Error loading json coverage data: {}: {}"
                          .format(json_file, error))
    return coverage
Ejemplo n.º 8
0
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"]
    }
Ejemplo n.º 9
0
 def load(symbol_json):
     return parse.parse_json_file(symbol_json)[JSON_TAG]
Ejemplo n.º 10
0
    def __init__(self, json_files):

        super(PropertyFromJson, self).__init__([
            parse.parse_json_file(json_file)[JSON_TAG]["properties"]
            for json_file in json_files
        ])
Ejemplo n.º 11
0
def load_cbmc_json(json_file, root):
    """Load json file produced by goto-analyzer --reachable-functions --json."""

    json_data = parse.parse_json_file(json_file, fail=True, goto_analyzer=True)
    return parse_cbmc_json(json_data, root)
Ejemplo n.º 12
0
    def __init__(self, json_files):

        super().__init__([
            parse.parse_json_file(json_file, fail=True)[JSON_TAG]["reachable"]
            for json_file in json_files
        ])
Ejemplo n.º 13
0
def load_cbmc_json(json_file, root):
    """Load a json file produced by cbmc --show-loops --json-ui."""

    return parse_cbmc_json(parse.parse_json_file(json_file, fail=True), root)
Ejemplo n.º 14
0
    def __init__(self, json_files):

        super(LoopFromJson, self).__init__([
            parse.parse_json_file(json_file, fail=True)[JSON_TAG]['loops']
            for json_file in json_files
        ])