Re: [PATCH v3 03/17] verification/rvgen: Improve rv_dir discovery in RVGenerator

From: Gabriele Monaco

Date: Thu Jul 02 2026 - 10:04:18 EST




On Thu, 2026-07-02 at 15:53 +0200, Nam Cao wrote:
> Gabriele Monaco <gmonaco@xxxxxxxxxx> writes:
> > 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.
>
> Agree.
>
> > +        # 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,
> > "../../../.."))
>
>
> The  "../../../.." makes me sad.
>
> We can find the git project root instead. For example:
>
> def getGitRoot():
>     return subprocess.Popen(['git', 'rev-parse', '--show-toplevel'],
> stdout=subprocess.PIPE).communicate()[0].rstrip().decode('utf-8')
>
> (stolen from
> https://stackoverflow.com/questions/22081209/find-the-root-of-the-git-repository-where-the-file-lives
> )
>
> But that's not important, up to you.

Mmh good point, but what if we're running from a tarball?

I could still fall back to something that uses directory parents (maybe
something arguably nicer like

os.path.join(current_dir, *([".."] * 4))

But that may not be more readable..

Thanks,
Gabriele