Skip to content

Commit 88c3fb6

Browse files
glemcosmb49
authored andcommitted
verification/dot2: Improve dot parser robustness
BugLink: https://bugs.launchpad.net/bugs/2102118 [ Upstream commit 571f8b3 ] This patch makes the dot parser used by dot2c and dot2k slightly more robust, namely: * allows parsing files with the gv extension (GraphViz) * correctly parses edges with any indentation * used to work only with a single character (e.g. '\t') Additionally it fixes a couple of warnings reported by pylint such as wrong indentation and comparison to False instead of `not ...` Link: https://lore.kernel.org/[email protected] Signed-off-by: Gabriele Monaco <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Koichiro Den <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent efb69e0 commit 88c3fb6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tools/verification/dot2/automata.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def __init__(self, file_path):
2929

3030
def __get_model_name(self):
3131
basename = ntpath.basename(self.__dot_path)
32-
if basename.endswith(".dot") == False:
32+
if not basename.endswith(".dot") and not basename.endswith(".gv"):
3333
print("not a dot file")
3434
raise Exception("not a dot file: %s" % self.__dot_path)
3535

36-
model_name = basename[0:-4]
36+
model_name = ntpath.splitext(basename)[0]
3737
if model_name.__len__() == 0:
3838
raise Exception("not a dot file: %s" % self.__dot_path)
3939

@@ -68,9 +68,9 @@ def __get_cursor_begin_states(self):
6868
def __get_cursor_begin_events(self):
6969
cursor = 0
7070
while self.__dot_lines[cursor].split()[0] != "{node":
71-
cursor += 1
71+
cursor += 1
7272
while self.__dot_lines[cursor].split()[0] == "{node":
73-
cursor += 1
73+
cursor += 1
7474
# skip initial state transition
7575
cursor += 1
7676
return cursor
@@ -94,11 +94,11 @@ def __get_state_variables(self):
9494
initial_state = state[7:]
9595
else:
9696
states.append(state)
97-
if self.__dot_lines[cursor].__contains__("doublecircle") == True:
97+
if "doublecircle" in self.__dot_lines[cursor]:
9898
final_states.append(state)
9999
has_final_states = True
100100

101-
if self.__dot_lines[cursor].__contains__("ellipse") == True:
101+
if "ellipse" in self.__dot_lines[cursor]:
102102
final_states.append(state)
103103
has_final_states = True
104104

@@ -110,7 +110,7 @@ def __get_state_variables(self):
110110
# Insert the initial state at the bein og the states
111111
states.insert(0, initial_state)
112112

113-
if has_final_states == False:
113+
if not has_final_states:
114114
final_states.append(initial_state)
115115

116116
return states, initial_state, final_states
@@ -120,7 +120,7 @@ def __get_event_variables(self):
120120
cursor = self.__get_cursor_begin_events()
121121

122122
events = []
123-
while self.__dot_lines[cursor][1] == '"':
123+
while self.__dot_lines[cursor].lstrip()[0] == '"':
124124
# transitions have the format:
125125
# "all_fired" -> "both_fired" [ label = "disable_irq" ];
126126
# ------------ event is here ------------^^^^^
@@ -161,7 +161,7 @@ def __create_matrix(self):
161161
# and we are back! Let's fill the matrix
162162
cursor = self.__get_cursor_begin_events()
163163

164-
while self.__dot_lines[cursor][1] == '"':
164+
while self.__dot_lines[cursor].lstrip()[0] == '"':
165165
if self.__dot_lines[cursor].split()[1] == "->":
166166
line = self.__dot_lines[cursor].split()
167167
origin_state = line[0].replace('"','').replace(',','_')

0 commit comments

Comments
 (0)