-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
config_checker
executable file
·103 lines (84 loc) · 3.22 KB
/
config_checker
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
#!/usr/bin/env python3
import glob
import re
import sys
permitted_properties = []
def usage():
print("Usage: " + sys.argv[0] + " <config_file>")
sys.exit(1)
def check_property(p):
if p in permitted_properties:
return True
return False
def check_file(file_name):
try:
file_ok = True
failed_properties = []
lineno = 0
with open(file_name) as f:
for line in f.readlines():
lineno = lineno + 1
# Check both commented and uncommented lines
line = line.strip().lstrip('#').strip().lower()
# Check if = in the line
if line.find("=") == -1:
continue
p = line.split("=", 1)[0]
# Remove trailing chip name "bcm8869x"
p = re.sub(r"\.bcm8869x(_adapter|_[a-z]\d)?$", "", p)
# Remove trailing chip name "bcm8885x"
p = re.sub(r"\.bcm8885x(_adapter|_[a-z]\d)?$", "", p)
# Remove trailing unit ".<number>$"
p = re.sub(r"\.[0-9]+$", '', p)
# Remove trailing port name
p = re.sub(r"_[cxg][de](\d+)?$", '', p)
# Remove trailing port id "{id/number}"
p = re.sub(r"\{.*\}", '', p)
# Remove trailing port name example
p = re.sub(r"_<port>$", '', p)
# Remove trailing port number
if p != "phy_84752" and p != "phy_84328":
p = re.sub(r"_(port)?\d+$", '', p)
# Remove trailing higig port
p = re.sub(r"_hg$", '', p)
# Remove trailing lane number
p = re.sub(r"_lane\d+$", '', p)
# Remove trailing "{<number>.<number>}$"
p = re.sub(r"{[0-9]+\.[0-9]+}$", '', p)
# Remove trailing phy with number
p = re.sub(r"_phy\d+$", '', p)
# Remove trailing phase of data granularity
p = re.sub(r"_data_granularity_\w\w$", '_data_granularity', p)
# Remove trailing type of port_init_speed
p = re.sub(r"^port_init_speed_\w+$", 'port_init_speed', p)
if not check_property(p):
file_ok = False
print("[line {}] Error: {} is not permitted".format(lineno, p))
if file_ok:
print("Result: " + file_name + " PASSED the config check!")
else:
print("Result: " + file_name + " FAILED the config check!")
return file_ok
except IOError:
print("Error: Cannot open file " + file_name)
return False
def main(argv):
global permitted_properties
if len(argv) > 0 and argv[0] == "-h":
usage()
# Load permitted properties
with open("permitted_list") as f:
permitted_properties = [p.strip().lower() for p in f.readlines()]
# Load target file
if len(argv) == 0:
files = glob.glob('*.config.bcm')
else:
files = argv
all_good = True
for f in files:
good = check_file(f)
all_good = all_good and good
if not all_good:
sys.exit(-1)
if __name__ == "__main__":
main(sys.argv[1:])