Skip to content

Commit

Permalink
verification/dot2: Improve dot parser robustness
Browse files Browse the repository at this point in the history
[ 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]>
  • Loading branch information
glemco authored and gregkh committed Dec 14, 2024
1 parent 7a135fd commit 5623341
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tools/verification/dot2/automata.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def __init__(self, file_path):

def __get_model_name(self):
basename = ntpath.basename(self.__dot_path)
if basename.endswith(".dot") == False:
if not basename.endswith(".dot") and not basename.endswith(".gv"):
print("not a dot file")
raise Exception("not a dot file: %s" % self.__dot_path)

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

Expand Down Expand Up @@ -68,9 +68,9 @@ def __get_cursor_begin_states(self):
def __get_cursor_begin_events(self):
cursor = 0
while self.__dot_lines[cursor].split()[0] != "{node":
cursor += 1
cursor += 1
while self.__dot_lines[cursor].split()[0] == "{node":
cursor += 1
cursor += 1
# skip initial state transition
cursor += 1
return cursor
Expand All @@ -94,11 +94,11 @@ def __get_state_variables(self):
initial_state = state[7:]
else:
states.append(state)
if self.__dot_lines[cursor].__contains__("doublecircle") == True:
if "doublecircle" in self.__dot_lines[cursor]:
final_states.append(state)
has_final_states = True

if self.__dot_lines[cursor].__contains__("ellipse") == True:
if "ellipse" in self.__dot_lines[cursor]:
final_states.append(state)
has_final_states = True

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

if has_final_states == False:
if not has_final_states:
final_states.append(initial_state)

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

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

while self.__dot_lines[cursor][1] == '"':
while self.__dot_lines[cursor].lstrip()[0] == '"':
if self.__dot_lines[cursor].split()[1] == "->":
line = self.__dot_lines[cursor].split()
origin_state = line[0].replace('"','').replace(',','_')
Expand Down

0 comments on commit 5623341

Please sign in to comment.