From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F412225761; Wed, 4 Dec 2024 17:02:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733331776; cv=none; b=e34/kthtXKZDN9R1kcaC9reTcCUmGBvAePMP0OUt3+l712/mq/oUT5BbXy1v8r9vADFRt1crH2Lmz4eUiTx8DXFaQQ1ZIQiN7AerTAkJq1SEDPzUGJ4KXDZPsP7g3LxIEnVZ8DwzPj5qSPnl72SNRCSalPOMxAJwXugLC7EgCs4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733331776; c=relaxed/simple; bh=oDKrhmkhEDIgHaXI1MH3VxbvBxyG9qAbuFJiKqPcUpY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bvaqNtHz6AJiypjgRU+J3n+3uOBnMV4LQIgFZaJXqbbCQ7szuSYiaqBCa3VH2CHhqSObMZRadlF2XrTYEOtb4O3zj3MkPntwUHiYg3SB05a0QOFNQNzWW1SscZ0JZyGx4Ss3EJuew0DnS30Zf78re6srv7G5yrcbMsMCPvgH56s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KndTVd65; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KndTVd65" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A13C5C4CECD; Wed, 4 Dec 2024 17:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733331776; bh=oDKrhmkhEDIgHaXI1MH3VxbvBxyG9qAbuFJiKqPcUpY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KndTVd65RhjB6f6f9T/McUINRIIeW2GBGFWyEN6rIwxBJj2p9oD4eBYF5TiMhAfce JNGgz8ZDl5H9hYwpxcdVsX9zXxm68BmwDTpWEULWibzwcIR00YE1+2t8ord71+I6f7 8LiXga5V85CSvcWCWUxtwG6sbAohE691T4XenCUBxuxuGGPkCtdmRr7nEJBxvVoRGR WFphtTBMBpV1BSRWWaj0Gb4g6KQjxMKBP8/pcsfRGT+ols6CY6erpea3wpSvS3NwC9 wjrso3GfxAx7djaOCgjJ1aLlNrMJRXu4hkWgSO3Sz7pMvm+uscKLxg2+hM108FwRaK C+NQuxYvZwLYA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Gabriele Monaco , Steven Rostedt , Sasha Levin , linux-trace-kernel@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 15/15] verification/dot2: Improve dot parser robustness Date: Wed, 4 Dec 2024 10:50:54 -0500 Message-ID: <20241204155105.2214350-15-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241204155105.2214350-1-sashal@kernel.org> References: <20241204155105.2214350-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.119 Content-Transfer-Encoding: 8bit From: Gabriele Monaco [ Upstream commit 571f8b3f866a6d990a50fe5c89fe0ea78784d70b ] 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/20241017064238.41394-2-gmonaco@redhat.com Signed-off-by: Gabriele Monaco Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin --- tools/verification/dot2/automata.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/verification/dot2/automata.py b/tools/verification/dot2/automata.py index baffeb960ff0b..bdeb98baa8b06 100644 --- a/tools/verification/dot2/automata.py +++ b/tools/verification/dot2/automata.py @@ -29,11 +29,11 @@ class Automata: 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) @@ -68,9 +68,9 @@ class Automata: 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 @@ -94,11 +94,11 @@ class Automata: 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 @@ -110,7 +110,7 @@ class Automata: # 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 @@ -120,7 +120,7 @@ class Automata: 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 ------------^^^^^ @@ -161,7 +161,7 @@ class Automata: # 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(',','_') -- 2.43.0