From nobody Tue Nov 26 17:41:52 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 37A14209F29 for ; Wed, 16 Oct 2024 13:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729087105; cv=none; b=CnR5N7VErrf9qVlvgS/HoDtPSlXH/DmrkpKIAgJqtFvI6yd76ypmcAA0QVyDmQ1Aizm1eUo6omRNNQKB4QwmHc26ExT1lmnVYrniKNeNN7xt4wrxx0R4gnvRExvwDvmMClm3uVhDq3zcPKJllH/6Q6QUqesTJDjTXR46a8zvW7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729087105; c=relaxed/simple; bh=Z4TjoCMH9PRPDw2uOwXm1Dd+eYyQXGwlDJ8FviYm59Q=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=twawm6M6BpGARhEosbM1UWahQH2h8kYm12CY1FI6BH4CFYcRHyyK4abI+1wtcc7eoKVOI49dqrkfyKW35F/KkJgvrKLt2W7MTqxAM5nqu91OxW3bGjNajcrOk7GP5y7gaJxqBJmSrzfltFbQzSCvO4CkzQbcjMHKlQ7+FEx735o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LwU8tC7f; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LwU8tC7f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729087102; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=oAKVska2/oBebQjO+wukHO9XQB/mkPF/9mcuDaF4jWA=; b=LwU8tC7fC99/81tGRXxd9Uz13XkQmdJ9woTLrsFucXiOdP6fn5qB/nMr6D2qBsy8Ysrr0w yY+6Nq9zTTKKP9CM6yo3h8G+Xb8blOr8D1ke0bNlNILcLVUKTagUXQiWpa+TCeoOVbsn/1 sVGNQ2IMabfqwixmLFEpvf5QMlJDssA= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-iff35SGPMK-38-86S4ximw-1; Wed, 16 Oct 2024 09:58:19 -0400 X-MC-Unique: iff35SGPMK-38-86S4ximw-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DAD681955D91; Wed, 16 Oct 2024 13:58:17 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.39.194.13]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4133C19560A2; Wed, 16 Oct 2024 13:58:15 +0000 (UTC) From: Gabriele Monaco To: Steven Rostedt , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Gabriele Monaco Subject: [PATCH] verification/dot2: Improve dot parser robustness Date: Wed, 16 Oct 2024 15:58:12 +0200 Message-ID: <20241016135812.59296-1-gmonaco@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" 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 ...` Signed-off-by: Gabriele Monaco --- tools/verification/dot2/automata.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/verification/dot2/automata.py b/tools/verification/dot2/= automata.py index baffeb960ff0..6eec09bbefdc 100644 --- a/tools/verification/dot2/automata.py +++ b/tools/verification/dot2/automata.py @@ -29,7 +29,7 @@ class Automata: =20 def __get_model_name(self): basename =3D ntpath.basename(self.__dot_path) - if basename.endswith(".dot") =3D=3D 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) =20 @@ -68,9 +68,9 @@ class Automata: def __get_cursor_begin_events(self): cursor =3D 0 while self.__dot_lines[cursor].split()[0] !=3D "{node": - cursor +=3D 1 + cursor +=3D 1 while self.__dot_lines[cursor].split()[0] =3D=3D "{node": - cursor +=3D 1 + cursor +=3D 1 # skip initial state transition cursor +=3D 1 return cursor @@ -94,11 +94,11 @@ class Automata: initial_state =3D state[7:] else: states.append(state) - if self.__dot_lines[cursor].__contains__("doublecircle") = =3D=3D True: + if "doublecircle" in self.__dot_lines[cursor]: final_states.append(state) has_final_states =3D True =20 - if self.__dot_lines[cursor].__contains__("ellipse") =3D=3D= True: + if "ellipse" in self.__dot_lines[cursor]: final_states.append(state) has_final_states =3D True =20 @@ -110,7 +110,7 @@ class Automata: # Insert the initial state at the bein og the states states.insert(0, initial_state) =20 - if has_final_states =3D=3D False: + if not has_final_states: final_states.append(initial_state) =20 return states, initial_state, final_states @@ -120,7 +120,7 @@ class Automata: cursor =3D self.__get_cursor_begin_events() =20 events =3D [] - while self.__dot_lines[cursor][1] =3D=3D '"': + while self.__dot_lines[cursor].lstrip()[0] =3D=3D '"': # transitions have the format: # "all_fired" -> "both_fired" [ label =3D "disable_irq" ]; # ------------ event is here ------------^^^^^ @@ -161,7 +161,7 @@ class Automata: # and we are back! Let's fill the matrix cursor =3D self.__get_cursor_begin_events() =20 - while self.__dot_lines[cursor][1] =3D=3D '"': + while self.__dot_lines[cursor].lstrip()[0] =3D=3D '"': if self.__dot_lines[cursor].split()[1] =3D=3D "->": line =3D self.__dot_lines[cursor].split() origin_state =3D line[0].replace('"','').replace(',','_') base-commit: 2f87d0916ce0d2925cedbc9e8f5d6291ba2ac7b2 --=20 2.47.0