[PATCH v2 11/22] verification/rvgen: Prepare the templates for LTL inclusion

Nam Cao
2025-04-11T07:38:11Z

To prepare for the inclusion of linear temporal logic monitor, prepare the
generation template files:

- Rename the directory dot2k_templates to templates
- Move the dot2k-specific files to templates/dot2k
- Move the container-specific files to templates/container

(Kconfig can be shared with LTL, therefore leave it at templates/)

This new structure allows sharing code for reading Kconfig and main.c
templates between DA monitor, container monitor and LTL monitor.

The intention is to add template files for LTL to templates/ltl.

Signed-off-by: Nam Cao <namcao@linutronix.de>
---
tools/verification/rvgen/Makefile | 2 +-
tools/verification/rvgen/rvgen/dot2k.py | 33 +++++++++++++------
.../{dot2k_templates => templates}/Kconfig | 0
.../container/Kconfig} | 0
.../container/main.c} | 0
.../container/main.h} | 0
.../dot2k}/main.c | 0
.../dot2k}/trace.h | 0
8 files changed, 24 insertions(+), 11 deletions(-)
rename tools/verification/rvgen/{dot2k_templates => templates}/Kconfig (100%)
rename tools/verification/rvgen/{dot2k_templates/Kconfig_container => templates/container/Kconfig} (100%)
rename tools/verification/rvgen/{dot2k_templates/main_container.c => templates/container/main.c} (100%)
rename tools/verification/rvgen/{dot2k_templates/main_container.h => templates/container/main.h} (100%)
rename tools/verification/rvgen/{dot2k_templates => templates/dot2k}/main.c (100%)
rename tools/verification/rvgen/{dot2k_templates => templates/dot2k}/trace.h (100%)

diff --git a/tools/verification/rvgen/Makefile b/tools/verification/rvgen/Makefile
index cea9c21c3bce..c1a34fa49619 100644
--- a/tools/verification/rvgen/Makefile
+++ b/tools/verification/rvgen/Makefile
@@ -23,4 +23,4 @@ install:
$(INSTALL) __main__.py -D -m 755 $(DESTDIR)$(bindir)/rvgen

mkdir -p ${miscdir}/
- cp -rp dot2k_templates $(DESTDIR)$(miscdir)/
+ cp -rp templates $(DESTDIR)$(miscdir)/
diff --git a/tools/verification/rvgen/rvgen/dot2k.py b/tools/verification/rvgen/rvgen/dot2k.py
index e29462413194..ed40a2071ddc 100644
--- a/tools/verification/rvgen/rvgen/dot2k.py
+++ b/tools/verification/rvgen/rvgen/dot2k.py
@@ -14,13 +14,16 @@ import os

class dot2k(Dot2c):
monitor_types = { "global" : 1, "per_cpu" : 2, "per_task" : 3 }
- monitor_templates_dir = "rvgen/dot2k_templates/"
rv_dir = "kernel/trace/rv"
monitor_type = "per_cpu"

def __init__(self, file_path, MonitorType, extra_params={}):
self.container = extra_params.get("subcmd") == "container"
self.parent = extra_params.get("parent")
+ if self.container:
+ self.monitor_templates_dir = "rvgen/templates/container"
+ else:
+ self.monitor_templates_dir = "rvgen/templates/dot2k"
self.__fill_rv_templates_dir()

if self.container:
@@ -33,9 +36,7 @@ class dot2k(Dot2c):
self.name = extra_params.get("model_name")
self.events = []
self.states = []
- self.main_c = self.__read_file(self.monitor_templates_dir + "main_container.c")
- self.main_h = self.__read_file(self.monitor_templates_dir + "main_container.h")
- self.kconfig = self.__read_file(self.monitor_templates_dir + "Kconfig_container")
+ self.main_h = self._read_template_file("main.h")
else:
super().__init__(file_path, extra_params.get("model_name"))

@@ -43,9 +44,10 @@ class dot2k(Dot2c):
if self.monitor_type is None:
raise ValueError("Unknown monitor type: %s" % MonitorType)
self.monitor_type = MonitorType
- self.main_c = self.__read_file(self.monitor_templates_dir + "main.c")
- self.trace_h = self.__read_file(self.monitor_templates_dir + "trace.h")
- self.kconfig = self.__read_file(self.monitor_templates_dir + "Kconfig")
+ self.trace_h = self._read_template_file("trace.h")
+
+ self.main_c = self._read_template_file("main.c")
+ self.kconfig = self._read_template_file("Kconfig")
self.enum_suffix = "_%s" % self.name
self.description = extra_params.get("description", self.name) or "auto-generated"
self.auto_patch = extra_params.get("auto_patch")
@@ -60,14 +62,15 @@ class dot2k(Dot2c):
if platform.system() != "Linux":
raise OSError("I can only run on Linux.")

- kernel_path = "/lib/modules/%s/build/tools/verification/rvgen/dot2k_templates/" % (platform.release())
+ kernel_path = "/lib/modules/%s/build/tools/verification/%s/" \
+ % (platform.release(), self.monitor_templates_dir)

if os.path.exists(kernel_path):
self.monitor_templates_dir = kernel_path
return

- if os.path.exists("/usr/share/rvgen/dot2k_templates/"):
- self.monitor_templates_dir = "/usr/share/rvgen/dot2k_templates/"
+ if os.path.exists("/usr/share/%s/" % self.monitor_templates_dir):
+ self.monitor_templates_dir = "/usr/share/%s/" % self.monitor_templates_dir
return

raise FileNotFoundError("Could not find the template directory, do you have the kernel source installed?")
@@ -109,6 +112,16 @@ class dot2k(Dot2c):
fd.close()
return content

+ def _read_template_file(self, file):
+ try:
+ path = os.path.join(self.monitor_templates_dir, file)
+ return self.__read_file(path)
+ except Exception:
+ # Specific template file not found. Try the generic template file in the template/
+ # directory, which is one level up
+ path = os.path.join(self.monitor_templates_dir, "..", file)
+ return self.__read_file(path)
+
def fill_monitor_type(self):
return self.monitor_type.upper()

diff --git a/tools/verification/rvgen/dot2k_templates/Kconfig b/tools/verification/rvgen/templates/Kconfig
similarity index 100%
rename from tools/verification/rvgen/dot2k_templates/Kconfig
rename to tools/verification/rvgen/templates/Kconfig
diff --git a/tools/verification/rvgen/dot2k_templates/Kconfig_container b/tools/verification/rvgen/templates/container/Kconfig
similarity index 100%
rename from tools/verification/rvgen/dot2k_templates/Kconfig_container
rename to tools/verification/rvgen/templates/container/Kconfig
diff --git a/tools/verification/rvgen/dot2k_templates/main_container.c b/tools/verification/rvgen/templates/container/main.c
similarity index 100%
rename from tools/verification/rvgen/dot2k_templates/main_container.c
rename to tools/verification/rvgen/templates/container/main.c
diff --git a/tools/verification/rvgen/dot2k_templates/main_container.h b/tools/verification/rvgen/templates/container/main.h
similarity index 100%
rename from tools/verification/rvgen/dot2k_templates/main_container.h
rename to tools/verification/rvgen/templates/container/main.h
diff --git a/tools/verification/rvgen/dot2k_templates/main.c b/tools/verification/rvgen/templates/dot2k/main.c
similarity index 100%
rename from tools/verification/rvgen/dot2k_templates/main.c
rename to tools/verification/rvgen/templates/dot2k/main.c
diff --git a/tools/verification/rvgen/dot2k_templates/trace.h b/tools/verification/rvgen/templates/dot2k/trace.h
similarity index 100%
rename from tools/verification/rvgen/dot2k_templates/trace.h
rename to tools/verification/rvgen/templates/dot2k/trace.h
--
2.39.5