| 1 |
########################################################################## |
| 2 |
# # |
| 3 |
# This file is part of Frama-C. # |
| 4 |
# # |
| 5 |
# Copyright (C) 2007-2022 # |
| 6 |
# CEA (Commissariat à l'énergie atomique et aux énergies # |
| 7 |
# alternatives) # |
| 8 |
# # |
| 9 |
# you can redistribute it and/or modify it under the terms of the GNU # |
| 10 |
# Lesser General Public License as published by the Free Software # |
| 11 |
# Foundation, version 2.1. # |
| 12 |
# # |
| 13 |
# It is distributed in the hope that it will be useful, # |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 16 |
# GNU Lesser General Public License for more details. # |
| 17 |
# # |
| 18 |
# See the GNU Lesser General Public License version 2.1 # |
| 19 |
# for more details (enclosed in the file licenses/LGPLv2.1). # |
| 20 |
# # |
| 21 |
########################################################################## |
| 22 |
|
| 23 |
import re |
| 24 |
|
| 25 |
stat_file_re = re.compile("^([^=]*)=(.*)$", re.MULTILINE) |
| 26 |
|
| 27 |
|
| 28 |
def load(filename): |
| 29 |
data = {} |
| 30 |
try: |
| 31 |
with open(filename, "r") as file: |
| 32 |
content = file.read() |
| 33 |
for (key, value) in stat_file_re.findall(content): |
| 34 |
data[key] = value |
| 35 |
except OSError: |
| 36 |
pass |
| 37 |
return data |
| 38 |
|
| 39 |
|
| 40 |
re_escape_space = re.compile(r"\\ ") |
| 41 |
|
| 42 |
|
| 43 |
def convert(data, key, to_type, default=None): |
| 44 |
try: |
| 45 |
value = data[key].strip() |
| 46 |
if to_type is str: |
| 47 |
value = re.sub(r"\\ ", " ", value) |
| 48 |
value = re.sub(r"\\,", ",", value) |
| 49 |
return value |
| 50 |
else: |
| 51 |
return to_type(value) |
| 52 |
except (ValueError, TypeError, KeyError): |
| 53 |
return default |
| 54 |
|
| 55 |
|
| 56 |
def parse(data): |
| 57 |
result = {} |
| 58 |
result["timestamp"] = convert(data, "timestamp", str) |
| 59 |
result["sem_reach_fun"] = convert(data, "sem_reach_fun", int) |
| 60 |
result["syn_reach_fun"] = convert(data, "syn_reach_fun", int) |
| 61 |
result["total_fun"] = convert(data, "total_fun", int) |
| 62 |
result["sem_reach_stmt"] = convert(data, "sem_reach_stmt", int) |
| 63 |
result["syn_reach_stmt"] = convert(data, "syn_reach_stmt", int) |
| 64 |
result["alarms"] = convert(data, "alarms", int) |
| 65 |
result["warnings"] = convert(data, "warnings", int) |
| 66 |
result["user_time"] = convert(data, "user_time", float) |
| 67 |
result["memory"] = convert(data, "memory", int) |
| 68 |
result["cmd_args"] = convert(data, "cmd_args", str) |
| 69 |
result["benchmark_tag"] = convert(data, "benchmark_tag", str) |
| 70 |
if result["sem_reach_stmt"] is not None and result["syn_reach_stmt"] is not None: |
| 71 |
result["coverage"] = result["sem_reach_stmt"] / result["syn_reach_stmt"] |
| 72 |
else: |
| 73 |
result["coverage"] = None |
| 74 |
return result |
| 75 |
|
| 76 |
|
| 77 |
def read(filename): |
| 78 |
return parse(load(filename)) |