[reprotest] 04/04: main: Push use of UNIX return codes to the edges of the program
Ximin Luo
infinity0 at debian.org
Fri Sep 22 16:31:42 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository reprotest.
commit 1f93944c6f344d2e2d7c5757babdd0972c7b281a
Author: Ximin Luo <infinity0 at debian.org>
Date: Fri Sep 22 18:29:11 2017 +0200
main: Push use of UNIX return codes to the edges of the program
---
reprotest/__init__.py | 24 +++++++++++++-----------
tests/test_reprotest.py | 32 +++++++++++++-------------------
2 files changed, 26 insertions(+), 30 deletions(-)
diff --git a/reprotest/__init__.py b/reprotest/__init__.py
index d73171f..6487f87 100644
--- a/reprotest/__init__.py
+++ b/reprotest/__init__.py
@@ -288,14 +288,14 @@ def check(build_command, source_root, artifact_pattern, store_dir=None, no_clean
run_or_tee(['sh', '-ec', 'find %s -type f -exec sha256sum "{}" \;' % artifact_pattern],
'SHA256SUMS', store_dir,
cwd=os.path.join(local_dists[0], VSRC_DIR))
- else:
+ elif retcode == 1:
if 0 in retcodes.values():
print("Reproduction failed but partially successful: in %s" %
", ".join(name for name, r in retcodes.items() if r == 0))
- # a slight hack, to trigger no_clean_on_error
- # TODO: this is out-of-date, see debian/TODO
- raise SystemExit(retcode)
- return retcode
+ else:
+ raise RuntimeError("diffoscope exited non-boolean %s" % retcode)
+
+ return not retcode
def check_auto(build_command, source_root, artifact_pattern, store_dir=None, no_clean_on_error=False,
@@ -324,11 +324,11 @@ def check_auto(build_command, source_root, artifact_pattern, store_dir=None, no_
if not is_reproducible("0", var_x0):
print("Not reproducible, even when fixing as much as reprotest knows how to. :(")
- return 1
+ return False
if is_reproducible("1", var_x1):
print("Reproducible, even when varying as much as reprotest knows how to! :)")
- return 0
+ return True
var_cur = var_x0
unreproducibles = []
@@ -343,9 +343,11 @@ def check_auto(build_command, source_root, artifact_pattern, store_dir=None, no_
else:
# don't vary it for the next test, continue testing other variations
unreproducibles.append(v)
+
print("Observed unreproducibility when varying each of the following:")
print(" ".join(unreproducibles))
print("The build is probably reproducible when varying other things.")
+ return False
def config_to_args(parser, filename):
@@ -535,7 +537,7 @@ def command_line(parser, argv):
return args
-def run(argv, check):
+def run(argv, dry_run=None):
# Argparse exits with status code 2 if something goes wrong, which
# is already the right status exit code for reprotest.
parser = cli_parser()
@@ -633,18 +635,18 @@ def run(argv, check):
"testbed_pre", "testbed_init", "host_distro")
l = locals()
check_args = collections.OrderedDict([(k, l[k]) for k in check_args_keys])
- if parsed_args.dry_run:
+ if parsed_args.dry_run or dry_run:
return check_args
else:
try:
- return check_func(**check_args)
+ return 0 if check_func(**check_args) else 1
except Exception:
traceback.print_exc()
return 125
def main():
- r = run(sys.argv[1:], check)
+ r = run(sys.argv[1:])
if isinstance(r, collections.OrderedDict):
import pprint
pprint.pprint(r)
diff --git a/tests/test_reprotest.py b/tests/test_reprotest.py
index 5c9c884..f1d7f72 100644
--- a/tests/test_reprotest.py
+++ b/tests/test_reprotest.py
@@ -18,24 +18,17 @@ if REPROTEST_TEST_DONTVARY:
TEST_VARIATIONS = frozenset(reprotest.build.VARIATIONS.keys()) - frozenset(REPROTEST_TEST_DONTVARY)
-def check_return_code(command, virtual_server, code):
- try:
- build_variations = reprotest.build.Variations.of(
- reprotest.build.VariationSpec.default(TEST_VARIATIONS))
- retcode = reprotest.check(command, 'tests', 'artifact',
- virtual_server_args=virtual_server, build_variations=build_variations)
- except SystemExit as system_exit:
- retcode = system_exit.args[0]
- finally:
- if isinstance(code, int):
- assert(retcode == code)
- else:
- assert(retcode in code)
+def check_reproducibility(command, virtual_server, reproducible):
+ build_variations = reprotest.build.Variations.of(
+ reprotest.build.VariationSpec.default(TEST_VARIATIONS))
+ result = reprotest.check(command, 'tests', 'artifact',
+ virtual_server_args=virtual_server, build_variations=build_variations)
+ assert result == reproducible
def check_command_line(command_line, code=None):
try:
retcode = 0
- return reprotest.run(command_line, lambda **x: x)
+ return reprotest.run(command_line, True)
except SystemExit as system_exit:
retcode = system_exit.args[0]
finally:
@@ -58,15 +51,16 @@ def virtual_server(request):
raise ValueError(request.param)
def test_simple_builds(virtual_server):
- check_return_code('python3 mock_build.py', virtual_server, 0)
- check_return_code('python3 mock_failure.py', virtual_server, 2)
- check_return_code('python3 mock_build.py irreproducible', virtual_server, 1)
+ check_reproducibility('python3 mock_build.py', virtual_server, True)
+ with pytest.raises(Exception):
+ check_reproducibility('python3 mock_failure.py', virtual_server)
+ check_reproducibility('python3 mock_build.py irreproducible', virtual_server, False)
# TODO: test all variations that we support
@pytest.mark.parametrize('captures', list(reprotest.build.VARIATIONS.keys()))
def test_variations(virtual_server, captures):
- expected = 1 if captures in TEST_VARIATIONS else 0
- check_return_code('python3 mock_build.py ' + captures, virtual_server, expected)
+ expected = captures not in TEST_VARIATIONS
+ check_reproducibility('python3 mock_build.py ' + captures, virtual_server, expected)
def test_self_build(virtual_server):
# at time of writing (2016-09-23) these are not expected to reproduce;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/reprotest.git
More information about the Reproducible-commits
mailing list