summaryrefslogtreecommitdiff
path: root/tools/verification
diff options
context:
space:
mode:
authorGabriele Monaco <gmonaco@redhat.com>2026-07-23 09:45:20 +0200
committerGabriele Monaco <gmonaco@redhat.com>2026-07-31 13:53:52 +0200
commitc737b725b1ac601816dab5c5072f80ddd413aa6e (patch)
treec4498639012b1dfd3ce817474f862634b5fe7c37 /tools/verification
parentbc4eca3f24e2806c0117215c671013f5297141b6 (diff)
downloadlinux-next-c737b725b1ac601816dab5c5072f80ddd413aa6e.tar.gz
linux-next-c737b725b1ac601816dab5c5072f80ddd413aa6e.zip
verification/rvgen: Improve rv_dir discovery in RVGenerator
The RVGenerator class can find the RV directory (kernel/trace/rv) in the kernel tree to do some auto patching. This works by assuming PWD is either the kernel tree or tools/verification, which isn't always the case (e.g. when running from selftests). Make discovery more robust by relying on the absolute path of the current script and traversing backwards the right number of times. This should work from any location if rvgen is in the kernel tree. Reviewed-by: Nam Cao <namcao@linutronix.de> Link: https://lore.kernel.org/r/20260723074534.43521-4-gmonaco@redhat.com Signed-off-by: Gabriele Monaco <gmonaco@redhat.com>
Diffstat (limited to 'tools/verification')
-rw-r--r--tools/verification/rvgen/rvgen/generator.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/tools/verification/rvgen/rvgen/generator.py b/tools/verification/rvgen/rvgen/generator.py
index 56f3bd8db850..1c20f7d1905c 100644
--- a/tools/verification/rvgen/rvgen/generator.py
+++ b/tools/verification/rvgen/rvgen/generator.py
@@ -7,6 +7,7 @@
import platform
import os
+from pathlib import Path
class RVGenerator:
@@ -25,27 +26,29 @@ class RVGenerator:
self.__fill_rv_kernel_dir()
def __fill_rv_kernel_dir(self):
-
- # first try if we are running in the kernel tree root
- if os.path.exists(self.rv_dir):
- return
-
- # offset if we are running inside the kernel tree from verification/dot2
- kernel_path = os.path.join("../..", self.rv_dir)
-
- if os.path.exists(kernel_path):
- self.rv_dir = kernel_path
+ # find the kernel tree root relative to this file's location
+ resolved_path = Path(__file__).resolve()
+ if len(resolved_path.parents) > 4:
+ kernel_root = resolved_path.parents[4]
+ kernel_path = kernel_root / self.rv_dir
+
+ if kernel_path.exists():
+ self.rv_dir = str(kernel_path)
+ return
+
+ # best effort if rvgen is installed and we are at the root of a kernel tree
+ if Path(self.rv_dir).exists():
return
if platform.system() != "Linux":
raise OSError("I can only run on Linux.")
- kernel_path = os.path.join(f"/lib/modules/{platform.release()}/build", self.rv_dir)
+ kernel_path = Path(f"/lib/modules/{platform.release()}/build") / self.rv_dir
# if the current kernel is from a distro this may not be a full kernel tree
# verify that one of the files we are going to modify is available
- if os.path.exists(os.path.join(kernel_path, "rv_trace.h")):
- self.rv_dir = kernel_path
+ if (kernel_path / "rv_trace.h").exists():
+ self.rv_dir = str(kernel_path)
return
raise FileNotFoundError("Could not find the rv directory, do you have the kernel source installed?")