-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathlogreaderUtils.py
105 lines (92 loc) · 3.32 KB
/
logreaderUtils.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
from __future__ import print_function
import json
import re
# Improvised enum
class ResultTypeEnum(object):
TEST = "Tests"
ISSUE = "Issues"
# Do not forget to include to list if ResultTypeEnum is updated
# Will be same ordering as in Log reader interface
all_controls = [ResultTypeEnum.ISSUE, ResultTypeEnum.TEST]
def add_exception_to_config(line, index, config_list, custom_rule_list=None):
if custom_rule_list is None:
custom_rule_list = []
default_rules_list = [
{
# will ignore " IgnoreCompletely" messages
"str_to_match": "Begin(?! IgnoreCompletely)(.*Exception)",
"name": "{0}",
"control_type": ResultTypeEnum.ISSUE,
},
{
"str_to_match": "edm::service::InitRootHandlers",
"name": "Segmentation fault",
"control_type": ResultTypeEnum.ISSUE,
},
{
"str_to_match": "sig_dostack_then_abort",
"name": "sig_dostack_then_abort",
"control_type": ResultTypeEnum.ISSUE,
},
{
"str_to_match": ": runtime error:",
"name": "Runtime error",
"control_type": ResultTypeEnum.ISSUE,
},
{
"str_to_match": ": Assertion .* failed",
"name": "Assertion failure",
"control_type": ResultTypeEnum.ISSUE,
},
{
"str_to_match": "==ERROR: AddressSanitizer:",
"name": "Address Sanitizer error",
"control_type": ResultTypeEnum.ISSUE,
},
{
"str_to_match": "mount hook function failure",
"name": "Mount failure",
"control_type": ResultTypeEnum.ISSUE,
},
]
line_nr = index + 1
for rule in default_rules_list + custom_rule_list:
match = re.search(rule["str_to_match"], line, re.IGNORECASE)
if match:
try:
name = rule["name"].format(*match.groups())
except:
name = rule["name"]
new_exception_config = {
"lineStart": line_nr,
"lineEnd": line_nr,
"name": name + " at line #" + str(line_nr),
"control_type": rule["control_type"],
}
config_list.append(new_exception_config)
return config_list
return config_list
def transform_and_write_config_file(log_reader_config_path, config_list):
"""
Dumps config object as JSON file. It is used with for logreader web interface to mark particular issues in log file.
Before dumping, tansform to suitable format.
:param log_reader_config_path:
:param config_list:
:return:
"""
def transform_config(config_list):
show_controls = []
for control_type in all_controls:
issue_list = []
for issue in config_list:
if issue["control_type"] == control_type:
issue_list.append(issue)
if len(issue_list) > 0:
show_controls.append({"name": control_type, "list": issue_list})
return show_controls
try:
log_reader_config_f = open(log_reader_config_path, "w")
json.dump({"show_controls": transform_config(config_list)}, log_reader_config_f)
log_reader_config_f.close()
except:
print("Error writing exception file.")