All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
@ 2016-04-14 11:32 Sascha Silbe
  2016-04-14 22:11 ` Max Reitz
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Sascha Silbe @ 2016-04-14 11:32 UTC (permalink / raw)
  To: qemu-devel, qemu-block; +Cc: Kevin Wolf, Max Reitz

Running an iotests-based Python test directly might appear to work,
but may fail in subtle ways and is insecure:

- It creates files with predictable file names in a world-writable
  location (/var/tmp).

- Tests expect the environment to be set up by check. E.g. 041 and 055
  may take the wrong code paths if QEMU_DEFAULT_MACHINE is not
  set. This can lead to false negatives.

Instead fail hard and tell the user we want to be run via "check".

Signed-off-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
Reviewed-by: Bo Tu <tubo@linux.vnet.ibm.com>
---
It's possible to fix iotests.py to work even outside of check, but
that requires reimplementing parts of what check currently does. I'd
prefer not to do that this late in the cycle.

It would be nice to have this in 2.6, just in case someone even tries
running a Python-based test directly instead of using ./check like for
the shell-based tests. But it's not crucial.
---
 tests/qemu-iotests/iotests.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 0c0b533..8c7138f 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -46,7 +46,7 @@ if os.environ.get('QEMU_OPTIONS'):
 
 imgfmt = os.environ.get('IMGFMT', 'raw')
 imgproto = os.environ.get('IMGPROTO', 'file')
-test_dir = os.environ.get('TEST_DIR', '/var/tmp')
+test_dir = os.environ.get('TEST_DIR')
 output_dir = os.environ.get('OUTPUT_DIR', '.')
 cachemode = os.environ.get('CACHEMODE')
 qemu_default_machine = os.environ.get('QEMU_DEFAULT_MACHINE')
@@ -441,6 +441,10 @@ def verify_quorum():
 def main(supported_fmts=[], supported_oses=['linux']):
     '''Run tests'''
 
+    if test_dir is None or qemu_default_machine is None:
+        sys.stderr.write('Please run this test via ./check\n')
+        sys.exit(os.EX_USAGE)
+
     debug = '-d' in sys.argv
     verbosity = 1
     verify_image_format(supported_fmts)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-14 11:32 [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check" Sascha Silbe
@ 2016-04-14 22:11 ` Max Reitz
  2016-04-19 12:22   ` Sascha Silbe
  2016-04-18  7:19 ` Markus Armbruster
  2016-04-19 19:34 ` [Qemu-devel] [PATCH for-2.6? v2] " Sascha Silbe
  2 siblings, 1 reply; 15+ messages in thread
From: Max Reitz @ 2016-04-14 22:11 UTC (permalink / raw)
  To: Sascha Silbe, qemu-devel, qemu-block; +Cc: Kevin Wolf


[-- Attachment #1.1: Type: text/plain, Size: 2787 bytes --]

On 14.04.2016 13:32, Sascha Silbe wrote:
> Running an iotests-based Python test directly might appear to work,
> but may fail in subtle ways and is insecure:
> 
> - It creates files with predictable file names in a world-writable
>   location (/var/tmp).
> 
> - Tests expect the environment to be set up by check. E.g. 041 and 055
>   may take the wrong code paths if QEMU_DEFAULT_MACHINE is not
>   set. This can lead to false negatives.
> 
> Instead fail hard and tell the user we want to be run via "check".
> 
> Signed-off-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
> Reviewed-by: Bo Tu <tubo@linux.vnet.ibm.com>
> ---
> It's possible to fix iotests.py to work even outside of check, but
> that requires reimplementing parts of what check currently does. I'd
> prefer not to do that this late in the cycle.
> 
> It would be nice to have this in 2.6, just in case someone even tries
> running a Python-based test directly instead of using ./check like for
> the shell-based tests. But it's not crucial.
> ---
>  tests/qemu-iotests/iotests.py | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 0c0b533..8c7138f 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -46,7 +46,7 @@ if os.environ.get('QEMU_OPTIONS'):
>  
>  imgfmt = os.environ.get('IMGFMT', 'raw')
>  imgproto = os.environ.get('IMGPROTO', 'file')
> -test_dir = os.environ.get('TEST_DIR', '/var/tmp')
> +test_dir = os.environ.get('TEST_DIR')
>  output_dir = os.environ.get('OUTPUT_DIR', '.')
>  cachemode = os.environ.get('CACHEMODE')
>  qemu_default_machine = os.environ.get('QEMU_DEFAULT_MACHINE')
> @@ -441,6 +441,10 @@ def verify_quorum():
>  def main(supported_fmts=[], supported_oses=['linux']):
>      '''Run tests'''
>  
> +    if test_dir is None or qemu_default_machine is None:

I think checking test_dir would have been sufficient; this makes it look
like it might want to be a complete list of variables that have to be
set, but then "cachemode" is missing.

> +        sys.stderr.write('Please run this test via ./check\n')

Or not ./, for people who have separate build and source trees, you
don't want to invoke check in the source tree. ;-)

I'm not sure whether I'd want a v2 just because of this. It's
bike-shedding, but now that I think about it I guess I think I do.

So would you be so kind as to replace the "./check" by "the check
script"? :-)

(I don't particularly care about whether you change the condition used
in the if statement, though.)

Max

> +        sys.exit(os.EX_USAGE)
> +
>      debug = '-d' in sys.argv
>      verbosity = 1
>      verify_image_format(supported_fmts)
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-14 11:32 [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check" Sascha Silbe
  2016-04-14 22:11 ` Max Reitz
@ 2016-04-18  7:19 ` Markus Armbruster
  2016-04-19 11:59   ` Sascha Silbe
  2016-04-19 19:34 ` [Qemu-devel] [PATCH for-2.6? v2] " Sascha Silbe
  2 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2016-04-18  7:19 UTC (permalink / raw)
  To: Sascha Silbe; +Cc: qemu-devel, qemu-block, Kevin Wolf, Max Reitz

Sascha Silbe <silbe@linux.vnet.ibm.com> writes:

> Running an iotests-based Python test directly might appear to work,
> but may fail in subtle ways and is insecure:
>
> - It creates files with predictable file names in a world-writable
>   location (/var/tmp).
>
> - Tests expect the environment to be set up by check. E.g. 041 and 055
>   may take the wrong code paths if QEMU_DEFAULT_MACHINE is not
>   set. This can lead to false negatives.
>
> Instead fail hard and tell the user we want to be run via "check".

Are the problems serious enough to warrant rejecting the attempt to run
the tests directly outright?

Judging from your description, I'm inclined to "no".

> Signed-off-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
> Reviewed-by: Bo Tu <tubo@linux.vnet.ibm.com>
> ---
> It's possible to fix iotests.py to work even outside of check, but
> that requires reimplementing parts of what check currently does. I'd
> prefer not to do that this late in the cycle.
>
> It would be nice to have this in 2.6, just in case someone even tries
> running a Python-based test directly instead of using ./check like for
> the shell-based tests. But it's not crucial.
> ---
>  tests/qemu-iotests/iotests.py | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 0c0b533..8c7138f 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -46,7 +46,7 @@ if os.environ.get('QEMU_OPTIONS'):
>  
>  imgfmt = os.environ.get('IMGFMT', 'raw')
>  imgproto = os.environ.get('IMGPROTO', 'file')
> -test_dir = os.environ.get('TEST_DIR', '/var/tmp')
> +test_dir = os.environ.get('TEST_DIR')
>  output_dir = os.environ.get('OUTPUT_DIR', '.')
>  cachemode = os.environ.get('CACHEMODE')
>  qemu_default_machine = os.environ.get('QEMU_DEFAULT_MACHINE')
> @@ -441,6 +441,10 @@ def verify_quorum():
>  def main(supported_fmts=[], supported_oses=['linux']):
>      '''Run tests'''
>  
> +    if test_dir is None or qemu_default_machine is None:
> +        sys.stderr.write('Please run this test via ./check\n')
> +        sys.exit(os.EX_USAGE)
> +
>      debug = '-d' in sys.argv
>      verbosity = 1
>      verify_image_format(supported_fmts)

Aha, you're not actually rejecting the attempt to run the tests
directly, you're merely requiring two environment variables.  That's
okay with me.  However, the commit message should explain it.  I'd also
rephrase the error message to something like

    <program_name>: TEST_DIR and QEMU_DEFAULT_MACHINE must be set in environment
    The easiest way to do that is running the test via the check script.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-18  7:19 ` Markus Armbruster
@ 2016-04-19 11:59   ` Sascha Silbe
  2016-04-19 12:25     ` Markus Armbruster
  0 siblings, 1 reply; 15+ messages in thread
From: Sascha Silbe @ 2016-04-19 11:59 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: Kevin Wolf, qemu-devel, qemu-block, Max Reitz

Dear Markus,

Markus Armbruster <armbru@redhat.com> writes:

>> Running an iotests-based Python test directly might appear to work,
>> but may fail in subtle ways and is insecure:
>>
>> - It creates files with predictable file names in a world-writable
>>   location (/var/tmp).
>>
>> - Tests expect the environment to be set up by check. E.g. 041 and 055
>>   may take the wrong code paths if QEMU_DEFAULT_MACHINE is not
>>   set. This can lead to false negatives.
>>
>> Instead fail hard and tell the user we want to be run via "check".
>
> Are the problems serious enough to warrant rejecting the attempt to run
> the tests directly outright?
>
> Judging from your description, I'm inclined to "no".

Having tests do unexpected things and / or fail silently is "serious" in
my book. After all, what's the value of tests if they don't yell when
something is broken?


[tests/qemu-iotests/iotests.py]
[...]
>> +    if test_dir is None or qemu_default_machine is None:
>> +        sys.stderr.write('Please run this test via ./check\n')
>> +        sys.exit(os.EX_USAGE)
>> +
>
> Aha, you're not actually rejecting the attempt to run the tests
> directly, you're merely requiring two environment variables.  That's
> okay with me. [...]

I should probably add a comment that these two environment variables are
merely used as proxies that indicate we haven't been run via
"check". They are the ones where there isn't any useful default value we
could fall back, but without a full audit we can't tell what else some
of the tests may expect that would normally be set up by "check" (or at
least I can't).

Sascha
-- 
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg
https://se-silbe.de/
USt-IdNr. DE281696641

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-14 22:11 ` Max Reitz
@ 2016-04-19 12:22   ` Sascha Silbe
  2016-04-19 19:06     ` Max Reitz
  0 siblings, 1 reply; 15+ messages in thread
From: Sascha Silbe @ 2016-04-19 12:22 UTC (permalink / raw)
  To: Max Reitz, qemu-devel, qemu-block; +Cc: Kevin Wolf

Dear Max,

Max Reitz <mreitz@redhat.com> writes:

> On 14.04.2016 13:32, Sascha Silbe wrote:
[tests/qemu-iotests/iotests.py]
[...]
>>  def main(supported_fmts=[], supported_oses=['linux']):
>>      '''Run tests'''
>>  
>> +    if test_dir is None or qemu_default_machine is None:
>
> I think checking test_dir would have been sufficient; this makes it look
> like it might want to be a complete list of variables that have to be
> set, but then "cachemode" is missing.

Markus Armbruster basically pointed out the same issue, so how about
this version:

    # We are using TEST_DIR and QEMU_DEFAULT_MACHINE as proxies to
    # indicate that we're not being run via "check". There may be
    # other things set up by "check" that individual test cases rely
    # on.
    if test_dir is None or qemu_default_machine is None:
        sys.stderr.write('Please run this test via the "check" script\n')
        sys.exit(os.EX_USAGE)


>> +        sys.stderr.write('Please run this test via ./check\n')
>
> Or not ./, for people who have separate build and source trees, you
> don't want to invoke check in the source tree. ;-)

Yeah, was thinking about that, but ultimately considered ./check to be
the best indication of a) "check" being the name of a script and b)
residing in the same directory as the test. But I don't care much about
this, so see the above version.

Sascha
-- 
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg
https://se-silbe.de/
USt-IdNr. DE281696641

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-19 11:59   ` Sascha Silbe
@ 2016-04-19 12:25     ` Markus Armbruster
  2016-04-19 16:49       ` Sascha Silbe
  0 siblings, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2016-04-19 12:25 UTC (permalink / raw)
  To: Sascha Silbe; +Cc: Kevin Wolf, qemu-devel, qemu-block, Max Reitz

Sascha Silbe <silbe@linux.vnet.ibm.com> writes:

> Dear Markus,
>
> Markus Armbruster <armbru@redhat.com> writes:
>
>>> Running an iotests-based Python test directly might appear to work,
>>> but may fail in subtle ways and is insecure:
>>>
>>> - It creates files with predictable file names in a world-writable
>>>   location (/var/tmp).
>>>
>>> - Tests expect the environment to be set up by check. E.g. 041 and 055
>>>   may take the wrong code paths if QEMU_DEFAULT_MACHINE is not
>>>   set. This can lead to false negatives.
>>>
>>> Instead fail hard and tell the user we want to be run via "check".
>>
>> Are the problems serious enough to warrant rejecting the attempt to run
>> the tests directly outright?
>>
>> Judging from your description, I'm inclined to "no".
>
> Having tests do unexpected things and / or fail silently is "serious" in
> my book. After all, what's the value of tests if they don't yell when
> something is broken?
>
>
> [tests/qemu-iotests/iotests.py]
> [...]
>>> +    if test_dir is None or qemu_default_machine is None:
>>> +        sys.stderr.write('Please run this test via ./check\n')
>>> +        sys.exit(os.EX_USAGE)
>>> +
>>
>> Aha, you're not actually rejecting the attempt to run the tests
>> directly, you're merely requiring two environment variables.  That's
>> okay with me. [...]
>
> I should probably add a comment that these two environment variables are
> merely used as proxies that indicate we haven't been run via
> "check". They are the ones where there isn't any useful default value we
> could fall back, but without a full audit we can't tell what else some
> of the tests may expect that would normally be set up by "check" (or at
> least I can't).

Say you had an accurate way to find out whether we're running under
"check".  You could then reject any attempt to run the test directly.
I'd oppose that.

It's okay to have test wrapper scripts to configure the tests just so.
It's okay to tell people to use them.  But "you can't do that, Dave" is
not okay.

It's okay to require certain environment variables to be set.  That's
what your patch does (but your commit message doesn't quite say).

It would not be okay to interfere with my ability to run tests the way
*I* want.  If a test breaks when I run it my way, I get to keep the
pieces.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-19 12:25     ` Markus Armbruster
@ 2016-04-19 16:49       ` Sascha Silbe
  2016-04-20  8:38         ` Kevin Wolf
  0 siblings, 1 reply; 15+ messages in thread
From: Sascha Silbe @ 2016-04-19 16:49 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: Kevin Wolf, qemu-devel, qemu-block, Max Reitz

Dear Markus,

Markus Armbruster <armbru@redhat.com> writes:

> Say you had an accurate way to find out whether we're running under
> "check".  You could then reject any attempt to run the test directly.
> I'd oppose that.
>
> It's okay to have test wrapper scripts to configure the tests just so.
> It's okay to tell people to use them.  But "you can't do that, Dave" is
> not okay. [...]

AFAICT the environment in which the individual test cases run isn't
well-defined. Currently it's indirectly defined by whatever "check"
does.

The goal of the patch is to catch unwary developers invoking the tests
directly from the command line, providing them with useful advice. If
somebody wants to write another test runner (in place of "check"), it's
their responsibility to set up the environment appropriately. (They
could even set an environment variable "I_AM_CHECK=yes" if that's part
of the environment the tests expect).

I'd be perfectly fine with defining the environment more clearly and
possibly extending the implementation to allow individual test cases to
be invoked directly (without a test runner like "check"). But that would
be 2.7 material.

Sascha
-- 
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg
https://se-silbe.de/
USt-IdNr. DE281696641

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-19 12:22   ` Sascha Silbe
@ 2016-04-19 19:06     ` Max Reitz
  2016-04-19 19:32       ` Sascha Silbe
  2016-04-20  6:55       ` Markus Armbruster
  0 siblings, 2 replies; 15+ messages in thread
From: Max Reitz @ 2016-04-19 19:06 UTC (permalink / raw)
  To: Sascha Silbe, qemu-devel, qemu-block; +Cc: Kevin Wolf


[-- Attachment #1.1: Type: text/plain, Size: 2936 bytes --]

On 19.04.2016 14:22, Sascha Silbe wrote:
> Dear Max,
> 
> Max Reitz <mreitz@redhat.com> writes:
> 
>> On 14.04.2016 13:32, Sascha Silbe wrote:
> [tests/qemu-iotests/iotests.py]
> [...]
>>>  def main(supported_fmts=[], supported_oses=['linux']):
>>>      '''Run tests'''
>>>  
>>> +    if test_dir is None or qemu_default_machine is None:
>>
>> I think checking test_dir would have been sufficient; this makes it look
>> like it might want to be a complete list of variables that have to be
>> set, but then "cachemode" is missing.
> 
> Markus Armbruster basically pointed out the same issue, so how about
> this version:
> 
>     # We are using TEST_DIR and QEMU_DEFAULT_MACHINE as proxies to
>     # indicate that we're not being run via "check". There may be
>     # other things set up by "check" that individual test cases rely
>     # on.
>     if test_dir is None or qemu_default_machine is None:
>         sys.stderr.write('Please run this test via the "check" script\n')
>         sys.exit(os.EX_USAGE)

I'm OK with that. I can imagine Markus isn't, because it's implying that
you should only run this test through "check", whereas Markus says that
maybe you have your own script and that is fine, too.

I think two things:

1. I'm not sure why you would want your own script. If the check script
isn't good enough, extend it.

2. If you do want your own script, I guess setting up the necessary
environment for each test is complicated enough to require you to know
what you're doing. And if you know what you're doing, you won't really
care about the wording of this warning anyway.

I think this is just a warning for unwary users who just try to execute
a python test directly because they think that maybe they can. And then
this line is just telling them that no, that is not how the test is
supposed to be run; instead, it tells them the most convenient and
common way to run it.

I think it would be confusing if we printed the exact technical details
here which basically nobody cares about anyway.

So I'm completely fine with this version.

>>> +        sys.stderr.write('Please run this test via ./check\n')
>>
>> Or not ./, for people who have separate build and source trees, you
>> don't want to invoke check in the source tree. ;-)
> 
> Yeah, was thinking about that, but ultimately considered ./check to be
> the best indication of a) "check" being the name of a script and b)
> residing in the same directory as the test. But I don't care much about
> this, so see the above version.

Yes, that looks fine to me.

Regarding b): If you separate the build tree from the source tree, you
have to run the check script from the build tree. During the build
process, qemu will in fact automatically create a symlink in the build
tree. Therefore, in that case, you don't want to execute "./check" in
the same directory as the test is in.

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-19 19:06     ` Max Reitz
@ 2016-04-19 19:32       ` Sascha Silbe
  2016-04-20  6:55       ` Markus Armbruster
  1 sibling, 0 replies; 15+ messages in thread
From: Sascha Silbe @ 2016-04-19 19:32 UTC (permalink / raw)
  To: Max Reitz, qemu-devel, qemu-block; +Cc: Kevin Wolf

Dear Max,

Max Reitz <mreitz@redhat.com> writes:

> On 19.04.2016 14:22, Sascha Silbe wrote:
[...]
>>     # We are using TEST_DIR and QEMU_DEFAULT_MACHINE as proxies to
>>     # indicate that we're not being run via "check". There may be
>>     # other things set up by "check" that individual test cases rely
>>     # on.
>>     if test_dir is None or qemu_default_machine is None:
>>         sys.stderr.write('Please run this test via the "check" script\n')
>>         sys.exit(os.EX_USAGE)
>
> I'm OK with that. I can imagine Markus isn't, because it's implying that
> you should only run this test through "check", whereas Markus says that
> maybe you have your own script and that is fine, too.
[...]
> 2. If you do want your own script, I guess setting up the necessary
> environment for each test is complicated enough to require you to know
> what you're doing. And if you know what you're doing, you won't really
> care about the wording of this warning anyway.
>
> I think this is just a warning for unwary users who just try to execute
> a python test directly because they think that maybe they can. [...]

Seems we're on the same page. For those who want to write their own test
runners, the comment in the source indicates why we recommend running
via "check", implying that they'd need to set up the environment just
like "check" does. That's more or less the best we can do in the current
situation, so I'll spin up a v2 with the above code block. If Markus
would like it explicitly spelled out in the comment or the error
message, that'd be fine with me, too. Feel free to amend locally before
merging in that case.


[...]
> Regarding b): If you separate the build tree from the source tree, you
> have to run the check script from the build tree. During the build
> process, qemu will in fact automatically create a symlink in the build
> tree. Therefore, in that case, you don't want to execute "./check" in
> the same directory as the test is in.

Whereas there probably are no symlinks to the individual test
cases. Good point.

Sascha
-- 
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg
https://se-silbe.de/
USt-IdNr. DE281696641

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH for-2.6? v2] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-14 11:32 [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check" Sascha Silbe
  2016-04-14 22:11 ` Max Reitz
  2016-04-18  7:19 ` Markus Armbruster
@ 2016-04-19 19:34 ` Sascha Silbe
  2016-05-11 15:43   ` Max Reitz
  2 siblings, 1 reply; 15+ messages in thread
From: Sascha Silbe @ 2016-04-19 19:34 UTC (permalink / raw)
  To: qemu-devel, qemu-block, Kevin Wolf, Max Reitz; +Cc: Tu Bo

Running an iotests-based Python test directly might appear to work,
but may fail in subtle ways and is insecure:

- It creates files with predictable file names in a world-writable
  location (/var/tmp).

- Tests expect the environment to be set up by check. E.g. 041 and 055
  may take the wrong code paths if QEMU_DEFAULT_MACHINE is not
  set. This can lead to false negatives.

Instead fail hard and tell the user we want to be run via "check".

The actual environment expected by the tests is currently only defined
by the implementation of "check". We use two of the environment
variables set by "check" as indication of whether we're being run via
"check". Anyone writing their own test runner (replacing "check") will
need to replicate the full environment (in a broader sense, not just
environment variables) provided by "check" anyway, including setting
the two environment variables we check. Whereas a regular developer
just trying to invoke the tests usually won't have both of these
defined in their environment so we can catch their mistake and give
out useful advice.

Signed-off-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
Reviewed-by: Bo Tu <tubo@linux.vnet.ibm.com>
---
v1→v2:
  - Add comment indicating that it's not just TEST_DIR and
    QEMU_DEFAULT_MACHINE that need to be set. Amend commit message in
    a similar way.

@Tu Bo: I'm assuming your Reviewed-By: still stands as I only added
more information on the background of the change and the check.
---
 tests/qemu-iotests/iotests.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 0c0b533..054b482 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -46,7 +46,7 @@ if os.environ.get('QEMU_OPTIONS'):
 
 imgfmt = os.environ.get('IMGFMT', 'raw')
 imgproto = os.environ.get('IMGPROTO', 'file')
-test_dir = os.environ.get('TEST_DIR', '/var/tmp')
+test_dir = os.environ.get('TEST_DIR')
 output_dir = os.environ.get('OUTPUT_DIR', '.')
 cachemode = os.environ.get('CACHEMODE')
 qemu_default_machine = os.environ.get('QEMU_DEFAULT_MACHINE')
@@ -441,6 +441,14 @@ def verify_quorum():
 def main(supported_fmts=[], supported_oses=['linux']):
     '''Run tests'''
 
+    # We are using TEST_DIR and QEMU_DEFAULT_MACHINE as proxies to
+    # indicate that we're not being run via "check". There may be
+    # other things set up by "check" that individual test cases rely
+    # on.
+    if test_dir is None or qemu_default_machine is None:
+        sys.stderr.write('Please run this test via the "check" script\n')
+        sys.exit(os.EX_USAGE)
+
     debug = '-d' in sys.argv
     verbosity = 1
     verify_image_format(supported_fmts)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-19 19:06     ` Max Reitz
  2016-04-19 19:32       ` Sascha Silbe
@ 2016-04-20  6:55       ` Markus Armbruster
  2016-04-20  8:37         ` Sascha Silbe
  1 sibling, 1 reply; 15+ messages in thread
From: Markus Armbruster @ 2016-04-20  6:55 UTC (permalink / raw)
  To: Max Reitz; +Cc: Sascha Silbe, qemu-devel, qemu-block, Kevin Wolf

Max Reitz <mreitz@redhat.com> writes:

> On 19.04.2016 14:22, Sascha Silbe wrote:
>> Dear Max,
>> 
>> Max Reitz <mreitz@redhat.com> writes:
>> 
>>> On 14.04.2016 13:32, Sascha Silbe wrote:
>> [tests/qemu-iotests/iotests.py]
>> [...]
>>>>  def main(supported_fmts=[], supported_oses=['linux']):
>>>>      '''Run tests'''
>>>>  
>>>> +    if test_dir is None or qemu_default_machine is None:
>>>
>>> I think checking test_dir would have been sufficient; this makes it look
>>> like it might want to be a complete list of variables that have to be
>>> set, but then "cachemode" is missing.
>> 
>> Markus Armbruster basically pointed out the same issue, so how about
>> this version:
>> 
>>     # We are using TEST_DIR and QEMU_DEFAULT_MACHINE as proxies to
>>     # indicate that we're not being run via "check". There may be
>>     # other things set up by "check" that individual test cases rely
>>     # on.
>>     if test_dir is None or qemu_default_machine is None:
>>         sys.stderr.write('Please run this test via the "check" script\n')
>>         sys.exit(os.EX_USAGE)
>
> I'm OK with that. I can imagine Markus isn't, because it's implying that
> you should only run this test through "check", whereas Markus says that
> maybe you have your own script and that is fine, too.
>
> I think two things:
>
> 1. I'm not sure why you would want your own script. If the check script
> isn't good enough, extend it.
>
> 2. If you do want your own script, I guess setting up the necessary
> environment for each test is complicated enough to require you to know
> what you're doing. And if you know what you're doing, you won't really
> care about the wording of this warning anyway.
>
> I think this is just a warning for unwary users who just try to execute
> a python test directly because they think that maybe they can. And then
> this line is just telling them that no, that is not how the test is
> supposed to be run; instead, it tells them the most convenient and
> common way to run it.
>
> I think it would be confusing if we printed the exact technical details
> here which basically nobody cares about anyway.
>
> So I'm completely fine with this version.

As Max predicted, I'm not :)

'Please run this test via the "check" script' isn't an error message,
it's advice.  Advice is appreciated, but an error message must come
first.  I reiterate my proposal to use something like

    <program_name>: TEST_DIR and QEMU_DEFAULT_MACHINE must be set in environment
    The easiest way to do that is running the test via the check script.

or

    <program_name>: TEST_DIR and QEMU_DEFAULT_MACHINE must be set in environment
    Please run this test via the "check" script

[...]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-20  6:55       ` Markus Armbruster
@ 2016-04-20  8:37         ` Sascha Silbe
  0 siblings, 0 replies; 15+ messages in thread
From: Sascha Silbe @ 2016-04-20  8:37 UTC (permalink / raw)
  To: Markus Armbruster, Max Reitz; +Cc: Kevin Wolf, qemu-devel, qemu-block

Dear Markus,

Markus Armbruster <armbru@redhat.com> writes:

> 'Please run this test via the "check" script' isn't an error message,
> it's advice.  Advice is appreciated, but an error message must come
> first.  I reiterate my proposal to use something like
>
>     <program_name>: TEST_DIR and QEMU_DEFAULT_MACHINE must be set in environment
>     The easiest way to do that is running the test via the check script.

But I don't know how the environment (again, broader sense than just
environment variables) must be set up; that's part of the problem. I
know that at least the TEST_DIR and QEMU_DEFAULT_MACHINE environment
variables must be set, but listing those in the error message gives an
impression that it's all the user needs to do. Bad advice is worse than
no advice.

We could write something like "The TEST_DIR and QEMU_DEFAULT_MACHINE
environment variables must be set and there may be other things that the
tests may expect to have been set up. See what the 'check' script does
if you want to invoke the tests some other way than running 'check'.",
but I don't really see the additional value to the user.

Sascha
-- 
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg
https://se-silbe.de/
USt-IdNr. DE281696641

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-19 16:49       ` Sascha Silbe
@ 2016-04-20  8:38         ` Kevin Wolf
  2016-04-20  8:51           ` Sascha Silbe
  0 siblings, 1 reply; 15+ messages in thread
From: Kevin Wolf @ 2016-04-20  8:38 UTC (permalink / raw)
  To: Sascha Silbe; +Cc: Markus Armbruster, qemu-devel, qemu-block, Max Reitz

Am 19.04.2016 um 18:49 hat Sascha Silbe geschrieben:
> Dear Markus,
> 
> Markus Armbruster <armbru@redhat.com> writes:
> 
> > Say you had an accurate way to find out whether we're running under
> > "check".  You could then reject any attempt to run the test directly.
> > I'd oppose that.
> >
> > It's okay to have test wrapper scripts to configure the tests just so.
> > It's okay to tell people to use them.  But "you can't do that, Dave" is
> > not okay. [...]
> 
> AFAICT the environment in which the individual test cases run isn't
> well-defined. Currently it's indirectly defined by whatever "check"
> does.
> 
> The goal of the patch is to catch unwary developers invoking the tests
> directly from the command line, providing them with useful advice. If
> somebody wants to write another test runner (in place of "check"), it's
> their responsibility to set up the environment appropriately. (They
> could even set an environment variable "I_AM_CHECK=yes" if that's part
> of the environment the tests expect).
> 
> I'd be perfectly fine with defining the environment more clearly and
> possibly extending the implementation to allow individual test cases to
> be invoked directly (without a test runner like "check"). But that would
> be 2.7 material.

At this point in the 2.6 release cycle, this series is 2.7 material
anyway. It's critical fixes only now.

Kevin

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-20  8:38         ` Kevin Wolf
@ 2016-04-20  8:51           ` Sascha Silbe
  0 siblings, 0 replies; 15+ messages in thread
From: Sascha Silbe @ 2016-04-20  8:51 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Max Reitz, Markus Armbruster, qemu-block, qemu-devel

Dear Kevin,

Kevin Wolf <kwolf@redhat.com> writes:

> At this point in the 2.6 release cycle, this series is 2.7 material
> anyway. It's critical fixes only now.

Fair enough.

Sascha
-- 
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg
https://se-silbe.de/
USt-IdNr. DE281696641

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.6? v2] qemu-iotests: iotests: fail hard if not run via "check"
  2016-04-19 19:34 ` [Qemu-devel] [PATCH for-2.6? v2] " Sascha Silbe
@ 2016-05-11 15:43   ` Max Reitz
  0 siblings, 0 replies; 15+ messages in thread
From: Max Reitz @ 2016-05-11 15:43 UTC (permalink / raw)
  To: Sascha Silbe, qemu-devel, qemu-block, Kevin Wolf; +Cc: Tu Bo

[-- Attachment #1: Type: text/plain, Size: 2452 bytes --]

On 19.04.2016 21:34, Sascha Silbe wrote:
> Running an iotests-based Python test directly might appear to work,
> but may fail in subtle ways and is insecure:
> 
> - It creates files with predictable file names in a world-writable
>   location (/var/tmp).
> 
> - Tests expect the environment to be set up by check. E.g. 041 and 055
>   may take the wrong code paths if QEMU_DEFAULT_MACHINE is not
>   set. This can lead to false negatives.
> 
> Instead fail hard and tell the user we want to be run via "check".
> 
> The actual environment expected by the tests is currently only defined
> by the implementation of "check". We use two of the environment
> variables set by "check" as indication of whether we're being run via
> "check". Anyone writing their own test runner (replacing "check") will
> need to replicate the full environment (in a broader sense, not just
> environment variables) provided by "check" anyway, including setting
> the two environment variables we check. Whereas a regular developer
> just trying to invoke the tests usually won't have both of these
> defined in their environment so we can catch their mistake and give
> out useful advice.
> 
> Signed-off-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
> Reviewed-by: Bo Tu <tubo@linux.vnet.ibm.com>
> ---
> v1→v2:
>   - Add comment indicating that it's not just TEST_DIR and
>     QEMU_DEFAULT_MACHINE that need to be set. Amend commit message in
>     a similar way.
> 
> @Tu Bo: I'm assuming your Reviewed-By: still stands as I only added
> more information on the background of the change and the check.
> ---
>  tests/qemu-iotests/iotests.py | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)

Having noted Markus' objections, I have still applied this patch to my
block-next tree (https://github.com/XanClic/qemu/commits/block-next),
for the following reasons:

First, I think it's reasonable to require users to find the source of
this error (which is really trivial, and the environment is
self-explaining) if they wish to write an own iotest platform.

Second, most of the Python tests fail with an exception anyway because
they try to os.path.join() the iotests.test_dir (which is None) with a
string before the main method is even invoked. Therefore, this is
basically only a backup for the few tests that somehow get past this
point, so you generally won't see this error message anyway.

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-05-11 15:43 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-14 11:32 [Qemu-devel] [PATCH for-2.6?] qemu-iotests: iotests: fail hard if not run via "check" Sascha Silbe
2016-04-14 22:11 ` Max Reitz
2016-04-19 12:22   ` Sascha Silbe
2016-04-19 19:06     ` Max Reitz
2016-04-19 19:32       ` Sascha Silbe
2016-04-20  6:55       ` Markus Armbruster
2016-04-20  8:37         ` Sascha Silbe
2016-04-18  7:19 ` Markus Armbruster
2016-04-19 11:59   ` Sascha Silbe
2016-04-19 12:25     ` Markus Armbruster
2016-04-19 16:49       ` Sascha Silbe
2016-04-20  8:38         ` Kevin Wolf
2016-04-20  8:51           ` Sascha Silbe
2016-04-19 19:34 ` [Qemu-devel] [PATCH for-2.6? v2] " Sascha Silbe
2016-05-11 15:43   ` Max Reitz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.