qemu-iotests: iotests: fail hard if not run via "check"
PATCH 1/1 qemu-iotests: iotests: fail hard if not run via "check"
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".
---
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(-)
tests/qemu-iotests/iotests.py +5 -1
@@ -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)
Signature · 1 line
1.9.1
Quoted 40 lines · Sascha Silbe
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_MACHINEis 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 <[email protected]>Reviewed-by Bo Tu <[email protected]>---
It's possible to fixiotests.pyto 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(-)tests/qemu-iotests/iotests.py +1
-1@@ -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')
tests/qemu-iotests/iotests.py def verify_quorum(): · line 444
Quoted 4 lines
tests/qemu-iotests/iotests.py +1
-0@@ -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.
tests/qemu-iotests/iotests.py def verify_quorum(): · line 445
Quoted 1 line
tests/qemu-iotests/iotests.py +1
-0+ 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
Quoted 6 lines
tests/qemu-iotests/iotests.py +2
-0+ sys.exit(os.EX_USAGE) + debug = '-d' in sys.argv verbosity = 1 verify_image_format(supported_fmts)
Quoted 11 lines · Sascha Silbe
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_MACHINEis 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".
Quoted 28 lines
Signed-off-by Sascha Silbe <[email protected]>Reviewed-by Bo Tu <[email protected]>---
It's possible to fixiotests.pyto 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(-)tests/qemu-iotests/iotests.py +1
-1@@ -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')
tests/qemu-iotests/iotests.py def verify_quorum(): · line 450
Quoted 10 lines
tests/qemu-iotests/iotests.py +4
-0@@ -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.
Dear Markus,
Quoted 10 lines · Markus Armbruster
Quoted 10 lines
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_MACHINEis not set. This can lead to false negatives.
Quoted 6 lines
Quoted 1 line
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]
[...]
Quoted 8 lines
tests/qemu-iotests/iotests.py def verify_quorum(): · line 447
Quoted 4 lines
tests/qemu-iotests/iotests.py +4
-0+ 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
Signature · 3 lines
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641
Dear Max,
Quoted 1 line · Max Reitz
On 14.04.2016 13:32, Sascha Silbe wrote:
[tests/qemu-iotests/iotests.py]
[...]
Quoted 8 lines
Quoted 4 lines
def
main(supported_fmts=[], supported_oses=['linux']):'''Run tests'''+ if
test_diris None orqemu_default_machineis None:I think checking
test_dirwould 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)
Quoted 4 lines
Quoted 1 line
+
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
Signature · 3 lines
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641
Quoted 37 lines · Sascha Silbe
Dear Markus,
Quoted 10 lines · Markus Armbruster
Quoted 10 lines
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_MACHINEis not set. This can lead to false negatives.Quoted 6 lines
Quoted 1 line
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]
[...]Quoted 8 lines
tests/qemu-iotests/iotests.py def verify_quorum(): · line 447
Quoted 4 lines
tests/qemu-iotests/iotests.py +4
-0+ 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. [...]
Quoted 6 lines
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.
Dear Markus,
Quoted 7 lines · Markus Armbruster
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
Signature · 3 lines
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641
Quoted 19 lines · Sascha Silbe
Dear Max,
Quoted 1 line · Max Reitz
On 14.04.2016 13:32, Sascha Silbe wrote:
[
tests/qemu-iotests/iotests.py]
[...]Quoted 8 lines
Quoted 4 lines
def
main(supported_fmts=[], supported_oses=['linux']):'''Run tests'''+ if
test_diris None orqemu_default_machineis None:I think checking
test_dirwould 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:
Quoted 7 lines
# We are using
TEST_DIRandQEMU_DEFAULT_MACHINEas 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.
iftest_diris None orqemu_default_machineis 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.
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
+
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
Dear Max,
Quoted 1 line · Max Reitz
On 19.04.2016 14:22, Sascha Silbe wrote:
[...]
Quoted 11 lines
Quoted 7 lines
# We are using
TEST_DIRandQEMU_DEFAULT_MACHINEas 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.
iftest_diris None orqemu_default_machineis 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.
[...]
Quoted 7 lines
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.
[...]
Quoted 5 lines
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
Signature · 3 lines
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641
PATCH v2 1/1 qemu-iotests: iotests: fail hard if not run via "check"
In reply to Sascha SilbeRunning 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.
---
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(-)
tests/qemu-iotests/iotests.py +9 -1
@@ -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)
Signature · 1 line
1.9.1
Quoted 48 lines · Max Reitz
Quoted 19 lines · Sascha Silbe
Dear Max,
Quoted 1 line · Max Reitz
On 14.04.2016 13:32, Sascha Silbe wrote:
[
tests/qemu-iotests/iotests.py]
[...]Quoted 8 lines
Quoted 4 lines
def
main(supported_fmts=[], supported_oses=['linux']):'''Run tests'''+ if
test_diris None orqemu_default_machineis None:I think checking
test_dirwould 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:
Quoted 7 lines
# We are using
TEST_DIRandQEMU_DEFAULT_MACHINEas 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.
iftest_diris None orqemu_default_machineis 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.
Quoted 4 lines
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
[...]
Dear Markus,
Quoted 6 lines · Markus Armbruster
'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_DIRandQEMU_DEFAULT_MACHINEmust 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
Signature · 3 lines
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641
Am 19.04.2016 um 18:49 hat Sascha Silbe geschrieben:
Quoted 23 lines
Dear Markus,
Quoted 7 lines · Markus Armbruster
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).
Quoted 4 lines
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
Dear Kevin,
Quoted 2 lines · Kevin Wolf
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
Signature · 3 lines
Softwareentwicklung Sascha Silbe, Niederhofenstraße 5/1, 71229 Leonberg https://se-silbe.de/ USt-IdNr. DE281696641
Quoted 31 lines · Sascha Silbe
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_MACHINEis 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 <[email protected]>Reviewed-by Bo Tu <[email protected]>---
v1→v2:
- Add comment indicating that it's not justTEST_DIRandQEMU_DEFAULT_MACHINEthat need to be set. Amend commit message in a similar way.
Quoted 5 lines
@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