-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinconsistency.py
More file actions
136 lines (113 loc) · 5.86 KB
/
inconsistency.py
File metadata and controls
136 lines (113 loc) · 5.86 KB
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
135
136
import csv
from enum import Enum
from utils.logger import get_logger
from utils.utils import file_name_to_project_name
logger = get_logger(__name__)
# Inconsistency types
class Inconsistency(Enum):
MCDC_NUM_CONDITION = 0
MCDC_GCC_INTERNAL_INCONSISTENCY = 1
MCDC_LLVM_OVER_REPORT = 2
MCDC_GCC_OVER_REPORT = 3
MCDC_GCC_PLURAL_DECISION_A_LINE = 4
MCDC_LLVM_PLURAL_DECISION_A_LINE = 5
LINE_COV = 10
LINE_COV_STEADY = 11
BRANCH_COV_NUM_OUTCOME = 20
BRANCH_COV_COUNT = 21
BRANCH_COV_COUNT_STEADY = 22
# What to do upon inconsistency
class Action(Enum):
SILENT = 0
CONTINUE = 1
ABORT = 2
LEARN = 3
policies: dict[Inconsistency, list[Action]] = {
Inconsistency.MCDC_NUM_CONDITION: [ Action.SILENT, Action.CONTINUE ],
Inconsistency.MCDC_GCC_INTERNAL_INCONSISTENCY: [ Action.SILENT, Action.CONTINUE ],
Inconsistency.MCDC_LLVM_OVER_REPORT: [ Action.SILENT, Action.CONTINUE ],
Inconsistency.MCDC_GCC_OVER_REPORT: [ Action.SILENT, Action.CONTINUE ],
Inconsistency.MCDC_GCC_PLURAL_DECISION_A_LINE: [ Action.SILENT, Action.CONTINUE ],
Inconsistency.MCDC_LLVM_PLURAL_DECISION_A_LINE: [ Action.SILENT, Action.CONTINUE ],
Inconsistency.LINE_COV: [ Action.LEARN, Action.CONTINUE, Action.SILENT ],
Inconsistency.LINE_COV_STEADY: [ Action.LEARN, Action.CONTINUE, Action.SILENT ],
Inconsistency.BRANCH_COV_NUM_OUTCOME: [ Action.CONTINUE ],
Inconsistency.BRANCH_COV_COUNT: [ Action.LEARN, Action.CONTINUE, Action.SILENT ],
Inconsistency.BRANCH_COV_COUNT_STEADY: [ Action.LEARN, Action.CONTINUE, Action.SILENT ],
}
# Count inconsistency by type
inconsistency_count: dict[Inconsistency, int] = {}
inconsistency_count[Inconsistency.MCDC_NUM_CONDITION] = 0
inconsistency_count[Inconsistency.MCDC_GCC_INTERNAL_INCONSISTENCY] = 0
inconsistency_count[Inconsistency.MCDC_LLVM_OVER_REPORT] = 0
inconsistency_count[Inconsistency.MCDC_GCC_OVER_REPORT] = 0
inconsistency_count[Inconsistency.MCDC_GCC_PLURAL_DECISION_A_LINE] = 0
inconsistency_count[Inconsistency.MCDC_LLVM_PLURAL_DECISION_A_LINE] = 0
inconsistency_count[Inconsistency.LINE_COV] = 0
inconsistency_count[Inconsistency.LINE_COV_STEADY] = 0
inconsistency_count[Inconsistency.BRANCH_COV_NUM_OUTCOME] = 0
inconsistency_count[Inconsistency.BRANCH_COV_COUNT] = 0
inconsistency_count[Inconsistency.BRANCH_COV_COUNT_STEADY] = 0
inconsistency_list: list = []
compared_sites = {
'line': 0,
'branch': 0,
'decision': 0,
}
def dump_csv(inconsistency_csv_path, total_num_csv_path):
with open(inconsistency_csv_path, mode='w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
sorted_inconsistency_list = sorted(inconsistency_list, key=lambda elem: (elem[0].name, elem[1], elem[2]))
for f in sorted_inconsistency_list:
failure_type = f[0]
file_name = f[1]
project_name = file_name_to_project_name(file_name)
line_number = f[2]
# Schema
if failure_type == Inconsistency.LINE_COV_STEADY:
gcc_line_result = f[3]
llvm_line_result = f[4]
writer.writerow([project_name,file_name,line_number,failure_type,gcc_line_result,llvm_line_result])
elif failure_type == Inconsistency.BRANCH_COV_COUNT_STEADY:
gcc_branch_result = f[3]
llvm_branch_result = f[4]
writer.writerow([project_name,file_name,line_number,failure_type,gcc_branch_result,llvm_branch_result])
elif failure_type == Inconsistency.BRANCH_COV_NUM_OUTCOME:
gcc_num_outcome = f[3]
llvm_num_outcome = f[4]
writer.writerow([project_name,file_name,line_number,failure_type,gcc_num_outcome,llvm_num_outcome])
elif failure_type == Inconsistency.MCDC_NUM_CONDITION:
gcc_num_outcome = f[3]
llvm_num_outcome = f[4]
writer.writerow([project_name,file_name,line_number,failure_type,gcc_num_outcome,llvm_num_outcome])
elif failure_type == Inconsistency.MCDC_GCC_OVER_REPORT:
writer.writerow([project_name,file_name,line_number,failure_type,True,False])
elif failure_type == Inconsistency.MCDC_LLVM_OVER_REPORT:
writer.writerow([project_name,file_name,line_number,failure_type,False,True])
with open(total_num_csv_path, mode='w', newline='', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerow([compared_sites['line'], compared_sites['branch'], compared_sites['decision']])
# Print inconsistency summary
class Result(Enum):
CONSISTENT = 0
INCONSISTENT = 10
def inconsistency_summary() -> int:
"""
1. Print summary regardless of `Action.SILENT`
2. Return nonzero if there's any inconsistency, but honoring `Action.SILENT`
"""
ret = Result.CONSISTENT
if any(list(inconsistency_count.values())):
logger.warning("")
logger.warning("----------------------------------------------")
logger.warning("Inconsistency type Count")
logger.warning("----------------------------------------------")
inconsistency_type: Inconsistency
for inconsistency_type in inconsistency_count:
count = inconsistency_count[inconsistency_type]
if count:
logger.warning(f"{inconsistency_type.name:<40} {count}")
if Action.SILENT not in policies[inconsistency_type]:
ret = Result.INCONSISTENT
logger.warning("----------------------------------------------")
return ret.value