diff mbox series

iotests: fix source directory location

Message ID 20220526002512.1585246-1-jsnow@redhat.com (mailing list archive)
State New, archived
Headers show
Series iotests: fix source directory location | expand

Commit Message

John Snow May 26, 2022, 12:25 a.m. UTC
If you invoke the check script from outside of the tests/qemu-iotests
directory, the directories initialized as source_iotests and
build_iotests will be incorrect.

We can use the location of the source file itself to be more accurate.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
 tests/qemu-iotests/testenv.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Daniel P. Berrangé May 26, 2022, 7:54 a.m. UTC | #1
On Wed, May 25, 2022 at 08:25:12PM -0400, John Snow wrote:
> If you invoke the check script from outside of the tests/qemu-iotests
> directory, the directories initialized as source_iotests and
> build_iotests will be incorrect.
> 
> We can use the location of the source file itself to be more accurate.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tests/qemu-iotests/testenv.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
> index a864c74b123..9b0f01e84db 100644
> --- a/tests/qemu-iotests/testenv.py
> +++ b/tests/qemu-iotests/testenv.py
> @@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
>              self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
>          else:
>              # called from the source tree
> -            self.source_iotests = os.getcwd()
> +            self.source_iotests = str(Path(__file__, '..').resolve())

Path(__file__).parent

>              self.build_iotests = self.source_iotests
>  
> -        self.build_root = os.path.join(self.build_iotests, '..', '..')
> +        self.build_root = str(Path(self.build_iotests, '../..').resolve())

Path(self.build_iotests).parent.parent

to be portable

>  
>          self.init_directories()
>          self.init_binaries()
> -- 
> 2.34.1
> 
> 

With regards,
Daniel
John Snow May 26, 2022, 2:21 p.m. UTC | #2
On Thu, May 26, 2022, 3:54 AM Daniel P. Berrangé <berrange@redhat.com>
wrote:

> On Wed, May 25, 2022 at 08:25:12PM -0400, John Snow wrote:
> > If you invoke the check script from outside of the tests/qemu-iotests
> > directory, the directories initialized as source_iotests and
> > build_iotests will be incorrect.
> >
> > We can use the location of the source file itself to be more accurate.
> >
> > Signed-off-by: John Snow <jsnow@redhat.com>
> > Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> > ---
> >  tests/qemu-iotests/testenv.py | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/tests/qemu-iotests/testenv.py
> b/tests/qemu-iotests/testenv.py
> > index a864c74b123..9b0f01e84db 100644
> > --- a/tests/qemu-iotests/testenv.py
> > +++ b/tests/qemu-iotests/testenv.py
> > @@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str,
> aiomode: str,
> >              self.build_iotests =
> os.path.dirname(os.path.abspath(sys.argv[0]))
> >          else:
> >              # called from the source tree
> > -            self.source_iotests = os.getcwd()
> > +            self.source_iotests = str(Path(__file__, '..').resolve())
>
> Path(__file__).parent
>
> >              self.build_iotests = self.source_iotests
> >
> > -        self.build_root = os.path.join(self.build_iotests, '..', '..')
> > +        self.build_root = str(Path(self.build_iotests,
> '../..').resolve())
>
> Path(self.build_iotests).parent.parent
>
> to be portable
>

With windows? I think Path() is meant to be a fully portable class as-is,
but I'll double-check my assumption. I use ".." elsewhere in code already
checked in, so if it's a problem I ought to fix it everywhere.
John Snow May 26, 2022, 3:20 p.m. UTC | #3
On Thu, May 26, 2022 at 10:21 AM John Snow <jsnow@redhat.com> wrote:
>
>
>
> On Thu, May 26, 2022, 3:54 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
>>
>> On Wed, May 25, 2022 at 08:25:12PM -0400, John Snow wrote:
>> > If you invoke the check script from outside of the tests/qemu-iotests
>> > directory, the directories initialized as source_iotests and
>> > build_iotests will be incorrect.
>> >
>> > We can use the location of the source file itself to be more accurate.
>> >
>> > Signed-off-by: John Snow <jsnow@redhat.com>
>> > Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
>> > ---
>> >  tests/qemu-iotests/testenv.py | 4 ++--
>> >  1 file changed, 2 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
>> > index a864c74b123..9b0f01e84db 100644
>> > --- a/tests/qemu-iotests/testenv.py
>> > +++ b/tests/qemu-iotests/testenv.py
>> > @@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
>> >              self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
>> >          else:
>> >              # called from the source tree
>> > -            self.source_iotests = os.getcwd()
>> > +            self.source_iotests = str(Path(__file__, '..').resolve())
>>
>> Path(__file__).parent
>>
>> >              self.build_iotests = self.source_iotests
>> >
>> > -        self.build_root = os.path.join(self.build_iotests, '..', '..')
>> > +        self.build_root = str(Path(self.build_iotests, '../..').resolve())
>>
>> Path(self.build_iotests).parent.parent
>>
>> to be portable
>
>
> With windows? I think Path() is meant to be a fully portable class as-is, but I'll double-check my assumption. I use ".." elsewhere in code already checked in, so if it's a problem I ought to fix it everywhere.

Found a Windows box, it works there too. Good enough?

--js
Daniel P. Berrangé May 26, 2022, 3:23 p.m. UTC | #4
On Thu, May 26, 2022 at 11:20:18AM -0400, John Snow wrote:
> On Thu, May 26, 2022 at 10:21 AM John Snow <jsnow@redhat.com> wrote:
> >
> >
> >
> > On Thu, May 26, 2022, 3:54 AM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >>
> >> On Wed, May 25, 2022 at 08:25:12PM -0400, John Snow wrote:
> >> > If you invoke the check script from outside of the tests/qemu-iotests
> >> > directory, the directories initialized as source_iotests and
> >> > build_iotests will be incorrect.
> >> >
> >> > We can use the location of the source file itself to be more accurate.
> >> >
> >> > Signed-off-by: John Snow <jsnow@redhat.com>
> >> > Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> >> > ---
> >> >  tests/qemu-iotests/testenv.py | 4 ++--
> >> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >> >
> >> > diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
> >> > index a864c74b123..9b0f01e84db 100644
> >> > --- a/tests/qemu-iotests/testenv.py
> >> > +++ b/tests/qemu-iotests/testenv.py
> >> > @@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
> >> >              self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
> >> >          else:
> >> >              # called from the source tree
> >> > -            self.source_iotests = os.getcwd()
> >> > +            self.source_iotests = str(Path(__file__, '..').resolve())
> >>
> >> Path(__file__).parent
> >>
> >> >              self.build_iotests = self.source_iotests
> >> >
> >> > -        self.build_root = os.path.join(self.build_iotests, '..', '..')
> >> > +        self.build_root = str(Path(self.build_iotests, '../..').resolve())
> >>
> >> Path(self.build_iotests).parent.parent
> >>
> >> to be portable
> >
> >
> > With windows? I think Path() is meant to be a fully portable class as-is, but I'll double-check my assumption. I use ".." elsewhere in code already checked in, so if it's a problem I ought to fix it everywhere.
> 
> Found a Windows box, it works there too. Good enough?

I don't mind

With regards,
Daniel
Kevin Wolf May 27, 2022, 4:29 p.m. UTC | #5
Am 26.05.2022 um 16:21 hat John Snow geschrieben:
> On Thu, May 26, 2022, 3:54 AM Daniel P. Berrangé <berrange@redhat.com>
> wrote:
> 
> > On Wed, May 25, 2022 at 08:25:12PM -0400, John Snow wrote:
> > > If you invoke the check script from outside of the tests/qemu-iotests
> > > directory, the directories initialized as source_iotests and
> > > build_iotests will be incorrect.
> > >
> > > We can use the location of the source file itself to be more accurate.
> > >
> > > Signed-off-by: John Snow <jsnow@redhat.com>
> > > Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> > > ---
> > >  tests/qemu-iotests/testenv.py | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/tests/qemu-iotests/testenv.py
> > b/tests/qemu-iotests/testenv.py
> > > index a864c74b123..9b0f01e84db 100644
> > > --- a/tests/qemu-iotests/testenv.py
> > > +++ b/tests/qemu-iotests/testenv.py
> > > @@ -217,10 +217,10 @@ def __init__(self, imgfmt: str, imgproto: str,
> > aiomode: str,
> > >              self.build_iotests =
> > os.path.dirname(os.path.abspath(sys.argv[0]))
> > >          else:
> > >              # called from the source tree
> > > -            self.source_iotests = os.getcwd()
> > > +            self.source_iotests = str(Path(__file__, '..').resolve())
> >
> > Path(__file__).parent
> >
> > >              self.build_iotests = self.source_iotests
> > >
> > > -        self.build_root = os.path.join(self.build_iotests, '..', '..')
> > > +        self.build_root = str(Path(self.build_iotests,
> > '../..').resolve())
> >
> > Path(self.build_iotests).parent.parent
> >
> > to be portable
> >
> 
> With windows? I think Path() is meant to be a fully portable class as-is,
> but I'll double-check my assumption. I use ".." elsewhere in code already
> checked in, so if it's a problem I ought to fix it everywhere.

I don't see any potential problem with the second hunk because we're
dealing with the path of a directory there, but "regular_file.py/.."
looks a bit fishy to me and doesn't work if you ask the kernel. Is this
guaranteed to work in Python or is it an implementation detail of Path
that may change?

Kevin
diff mbox series

Patch

diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index a864c74b123..9b0f01e84db 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -217,10 +217,10 @@  def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
             self.build_iotests = os.path.dirname(os.path.abspath(sys.argv[0]))
         else:
             # called from the source tree
-            self.source_iotests = os.getcwd()
+            self.source_iotests = str(Path(__file__, '..').resolve())
             self.build_iotests = self.source_iotests
 
-        self.build_root = os.path.join(self.build_iotests, '..', '..')
+        self.build_root = str(Path(self.build_iotests, '../..').resolve())
 
         self.init_directories()
         self.init_binaries()