Skip to content

Commit

Permalink
add option to print +mutant inputs and the mutants they kill
Browse files Browse the repository at this point in the history
  • Loading branch information
keltono committed Jun 7, 2022
1 parent c7c42a7 commit c71d6b1
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions scripts/graph_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
def parseFile(file_name):
source_info = {}
reason_info = {}
mutant_info = {}
with open(file_name, 'r') as file:
for line in file.readlines():
#takes all relevant information (id, source, reasons) and places them into capture groups
res = re.search(r"Saved - .*id_(\d+) src:(\d+),havoc:\d+ ((?:\+[a-zA-Z]*(?: |$))*)(?:$|\+\d+ (mutants))",line)
#takes all relevant information (id, source, reasons, mutants) and places them into capture groups
res = re.search(r"Saved - .*id_(\d+) src:(\d+),havoc:\d+ ((?:\+[a-zA-Z]*(?: |$))*)(?:$|\+\d+ (mutants) \[(\(.*\))\])",line)
if res is not None:
info = res.groups()
try:
Expand All @@ -25,12 +26,15 @@ def parseFile(file_name):
#if one of the reasons is killed mutants
if info[3] is not None:
reasons+= "+mutants"
#collect mutants
mutants = re.findall(r"\(([^,]*),[^\)]*\)",info[4])
mutant_info[int(info[0])] = mutants
try:
reason_info[reasons].append(int(info[0]))
except KeyError:
reason_info[reasons] = [int(info[0])]

return source_info, reason_info
return source_info, reason_info, mutant_info

def emit_dot(data,dot_file,out_file):
with open(dot_file,"w") as file:
Expand All @@ -44,6 +48,18 @@ def emit_dot(data,dot_file,out_file):
except FileNotFoundError:
print("ERROR: graphviz dot does not appear to be installed")

def emit_inputs(reasons,mutants,repro):
print("listing all +mutants inputs and the mutants they kill")
pm = reasons["+mutants"]
for i in pm:
print(f"input {i} is")
with open(f"{repro if repro[-1]=='/' else repro+'/'}id_{str(i).zfill(6)}.0","r") as file:
for line in file.readlines():
print(line)
print(f"input {i} kills the following mutants:")
for mut in mutants[i]:
print(mut)

def plot_freq_data(sources,reasons,out_file):
reason_total_children = dict.fromkeys(reasons.keys(),0)
for key in reasons:
Expand All @@ -56,7 +72,6 @@ def plot_freq_data(sources,reasons,out_file):
children_per_reason = list(reason_total_children.values())
inputs_per_reason = list(map(len,reasons.values()))
x = list(np.arange(len(labels)))
print(inputs_per_reason)
plt.figure(figsize=(12,3))
plt.bar(list(map(lambda y: y-0.20,x)),children_per_reason, width=0.4,label='Number of children inputs generated with this reason have')
plt.bar(list(map(lambda y: y+0.20,x)),inputs_per_reason, width=0.4,label='Number inputs saved for this reason')
Expand All @@ -74,9 +89,13 @@ def plot_freq_data(sources,reasons,out_file):
parser.add_argument('-oc', '--chartout', nargs='?', const='chart.png', default="chart.png", help='output for the bar chart representation of the logs')
parser.add_argument('-og', '--graphout', nargs='?', const='graph.png', help='output for digraph representation of the logs')
parser.add_argument('-od', '--dotout', nargs='?', const='/tmp/graph.dot', help='intermediate output for graphiv dot representation of the logs')
parser.add_argument('-r', '--reproout', nargs='?', const='arg_corpus', help='The directory of the result of calling repro. Used for showing the inputs that killed mutants.')
args = parser.parse_args()

sources,reasons = parseFile(args.input_log)
sources,reasons, mutants = parseFile(args.input_log)
if args.graphout is not None or args.dotout is not None:
emit_dot(sources,args.dotout,args.graphout)

if args.reproout is not None:
emit_inputs(reasons,mutants,args.reproout)
plot_freq_data(sources,reasons,args.chartout)

0 comments on commit c71d6b1

Please sign in to comment.