forked from TrustAI/testRNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readfile.py
executable file
·134 lines (119 loc) · 3.92 KB
/
readfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import numpy as np
import scipy.io as scio
import argparse
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
parser = argparse.ArgumentParser(description='Coverage Updating Plot')
parser.add_argument('--output', dest='filename', default='./log_folder/record.txt', help='')
parser.add_argument('--metrcis', dest='metrics', default='all', help='')
args=parser.parse_args()
filename = args.filename
metrics = args.metrics
lines = open(filename,'r').readlines()
nc = []
SC = []
BC = []
TC_p = []
TC_n = []
for i, line in enumerate(lines):
parts = line.split(' ')
if parts[0] == 'cell':
SC.append(float(parts[2]))
elif parts[0] == 'neuron':
nc.append(float(parts[2]))
elif parts[0] == 'gate':
BC.append(float(parts[2]))
elif parts[0] == 'positive':
TC_p.append(float(parts[3]))
elif parts[0] == 'negative':
TC_n.append(float(parts[3]))
nc = np.array(nc)
SC = np.array(SC)
BC = np.array(BC)
TC_p = np.array(TC_p)
TC_n = np.array(TC_n)
# io.savemat('log_folder/coverage_count_NC.mat', {'coverage_count_NC': nc})
# io.savemat('log_folder/coverage_count_SC.mat', {'coverage_count_SC': SC})
# io.savemat('log_folder/coverage_count_BC.mat', {'coverage_count_BC': BC})
# io.savemat('log_folder/coverage_count_TC_P.mat', {'coverage_count_TC_P': TC_p})
# io.savemat('log_folder/coverage_count_TC_N.mat', {'coverage_count_TC_N': TC_n})
if metrics == 'SC' :
plt.plot(SC)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Cell Coverage Updating')
plt.savefig("log_folder/SC.jpg")
elif metrics == 'NC' :
plt.plot(nc)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Neuron Coverage Updating')
plt.savefig("log_folder/nc.jpg")
elif metrics == 'BC' :
plt.plot(BC)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Gate Coverage Updating')
plt.savefig("log_folder/BC.jpg")
elif metrics == 'TCP' :
plt.plot(TC_p)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Positive Sequence Coverage Updating')
plt.savefig("log_folder/TCp.jpg")
elif metrics == 'TCN' :
plt.plot(TC_n)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Negative Sequence Coverage Updating')
plt.savefig("log_folder/TCn.jpg")
elif metrics == 'all' :
plt.figure()
plt.plot(SC)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Cell Coverage Updating')
plt.savefig("log_folder/SC.jpg")
plt.figure()
plt.plot(nc)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Neuron Coverage Updating')
plt.savefig("log_folder/nc.jpg")
plt.figure()
plt.plot(BC)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Gate Coverage Updating')
plt.savefig("log_folder/BC.jpg")
plt.figure()
plt.plot(TC_p)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Positive Sequence Coverage Updating')
plt.savefig("log_folder/TCp.jpg")
plt.figure()
plt.plot(TC_n)
plt.xlabel('Test Cases')
plt.ylabel('Coverage Rate')
plt.title('Negative Sequence Coverage Updating')
plt.savefig("log_folder/TCn.jpg")
else :
print("Please specify a metrics to plot {NC, SC, BC, TCP, TCN, all}")
data1 = scio.loadmat('./log_folder/feature_count_SC.mat')
feature_count_SC = data1['feature_count_SC']
plt.figure()
plt.bar(range(len(feature_count_SC[0])),feature_count_SC[0])
plt.xlabel('Test Conditions')
plt.ylabel('Covering Times')
plt.title('Cell Coverage Test Conditions Count')
plt.savefig("log_folder/feature_count_SC.jpg")
data2 = scio.loadmat('./log_folder/feature_count_BC.mat')
feature_count_BC = data2['feature_count_BC']
plt.figure()
plt.bar(range(len(feature_count_BC[0])),feature_count_BC[0])
plt.xlabel('Test Conditions')
plt.ylabel('Covering Times')
plt.title('Gate Coverage Test Conditions Count')
plt.savefig("log_folder/feature_count_BC.jpg")