[Reproducible-commits] [reprotest] 02/03: Add umask variation

Ceridwen ceridwen-guest at moszumanska.debian.org
Thu Jun 9 14:18:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

ceridwen-guest pushed a commit to branch master
in repository reprotest.

commit f657ed3d081d68f7bc1d28536bffe8ca1d580feb
Author: Ceridwen <ceridwenv at gmail.com>
Date:   Wed Jun 8 18:41:33 2016 -0400

    Add umask variation
---
 reprotest/__init__.py | 29 +++++++++++++++++------------
 tests/build.py        | 12 ++++++++++++
 tests/test.py         |  1 +
 3 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/reprotest/__init__.py b/reprotest/__init__.py
index f7cf4a5..e96d3d1 100644
--- a/reprotest/__init__.py
+++ b/reprotest/__init__.py
@@ -2,6 +2,7 @@
 # For details: reprotest/debian/copyright
 
 import argparse
+import collections
 import configparser
 import contextlib
 import logging
@@ -113,6 +114,7 @@ def timezone(command1, command2, env1, env2, tree1, tree2):
 
 @contextlib.contextmanager
 def umask(command1, command2, env1, env2, tree1, tree2):
+    command2 = ['umask', '0002;'] + command2
     yield command1, command2, env1, env2, tree1, tree2
 
 # TODO: This definitely requires superuser privileges.
@@ -120,14 +122,15 @@ def umask(command1, command2, env1, env2, tree1, tree2):
 def user_group(command1, command2, env1, env2, tree1, tree2):
     yield command1, command2, env1, env2, tree1, tree2
 
-VARIATIONS = {'captures_environment': captures_environment,
-              # 'cpu': cpu, 
-              'domain_host': domain_host, 'filesystem': filesystem,
-              'home': home, 'kernel': kernel, 'locales': locales,
-              # 'namespace': namespace,
-              'path': path, 'shell': shell, 'time': time,
-              'timezone': timezone, 'umask': umask, 'user_group': user_group
-}
+VARIATIONS = collections.OrderedDict([
+    ('captures_environment', captures_environment),
+    # 'cpu': cpu,
+    ('domain_host', domain_host), ('filesystem', filesystem),
+    ('home', home), ('kernel', kernel), ('locales', locales),
+    # 'namespace': namespace,
+    ('path', path), ('shell', shell),
+    ('timezone', timezone), ('umask', umask), ('user_group', user_group)
+])
 
 def build(command, source_root, built_artifact, artifact_store, **kws):
     subprocess.check_call(command, cwd=source_root, **kws)
@@ -147,10 +150,10 @@ def check(build_command, artifact_name, source_root, variations=VARIATIONS):
             with contextlib.ExitStack() as stack:
                 for variation in variations:
                     command1, command2, env1, env2, tree1, tree2 = stack.enter_context(VARIATIONS[variation](command1, command2, env1, env2, tree1, tree2))
-                build(command1, str(tree1), temp + '/tree1/' + artifact_name,
-                      open(temp + '/artifact1', 'wb'), env=env1)
-                build(command2, str(tree2), temp + '/tree2/' + artifact_name,
-                      open(temp + '/artifact2', 'wb'), env=env2)
+                build(' '.join(command1), str(tree1), temp + '/tree1/' + artifact_name,
+                      open(temp + '/artifact1', 'wb'), env=env1, shell=True)
+                build(' '.join(command2), str(tree2), temp + '/tree2/' + artifact_name,
+                      open(temp + '/artifact2', 'wb'), env=env2, shell=True)
         except Exception:
             sys.exit(2)
         sys.exit(subprocess.call(['diffoscope', temp + '/artifact1', temp + '/artifact2']))
@@ -218,6 +221,8 @@ def main():
         variations = variations - args.dont_vary
     elif args.variations:
         variations = args.variations
+    # Restore the order
+    variations = [v for v in VARIATIONS if v in variations]
 
     if not build_command:
         print("No build command provided.")
diff --git a/tests/build.py b/tests/build.py
index 3e4f738..59e8d6a 100755
--- a/tests/build.py
+++ b/tests/build.py
@@ -4,7 +4,9 @@
 import argparse
 import locale
 import os
+import pathlib
 import subprocess
+import tarfile
 import tempfile
 import time
 
@@ -17,6 +19,8 @@ if __name__ == '__main__':
     args = set(arg_parser.parse_args().commands)
     output = [b'']
     if 'irreproducible' in args:
+        # This test can theoretically fail by producing the same
+        # random bits in both runs, but it is extremely unlikely.
         output.append(os.urandom(1024))
     if 'home' in args:
         output.append(os.path.expanduser('~').encode('ascii'))
@@ -30,5 +34,13 @@ if __name__ == '__main__':
         output.extend(p.encode('ascii') for p in os.get_exec_path())
     if 'timezone' in args:
         output.append(str(time.timezone).encode('ascii'))
+    if 'umask' in args:
+        test_permissions = pathlib.Path.cwd() / 'test_permissions'
+        test_permissions.touch()
+        with tempfile.TemporaryFile() as temp:
+            archive = tarfile.open(name='temp', mode='w', fileobj=temp)
+            archive.add(str(test_permissions))
+            temp.seek(0)
+            output.append(temp.read())
     with open('artifact', 'wb') as artifact:
         artifact.write(b''.join(output))
diff --git a/tests/test.py b/tests/test.py
index 1d775a1..4f1f936 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -20,3 +20,4 @@ if __name__ == '__main__':
     test_return_code(['python', 'build.py', 'locales'], 1)
     test_return_code(['python', 'build.py', 'path'], 1)
     test_return_code(['python', 'build.py', 'timezone'], 1)
+    test_return_code(['python', 'build.py', 'umask'], 1)

-- 
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