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.

Signed-off-by: Gabriele Monaco <[email protected]>
---
 tools/verification/rvgen/rvgen/generator.py | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/tools/verification/rvgen/rvgen/generator.py 
b/tools/verification/rvgen/rvgen/generator.py
index 56f3bd8db8..b7ab0c70d4 100644
--- a/tools/verification/rvgen/rvgen/generator.py
+++ b/tools/verification/rvgen/rvgen/generator.py
@@ -25,13 +25,10 @@ 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)
+        # find the kernel tree root relative to this file's location
+        current_dir = os.path.dirname(os.path.abspath(__file__))
+        kernel_root = os.path.abspath(os.path.join(current_dir, "../../../.."))
+        kernel_path = os.path.join(kernel_root, self.rv_dir)
 
         if os.path.exists(kernel_path):
             self.rv_dir = kernel_path
-- 
2.54.0


Reply via email to