* James McCoy <james...@debian.org>, 2014-10-11, 22:35:
I think it would be more user-friendly if sadt did this:

* If sadt have to make copy of the source tree anyway (i.e., one of the tests declares the rw-build-tree restriction), then fix permissions in the copy.

Now I noticed that support for rw-build-tree has been broken all the time. Ooops.

* Otherwise, try chmod+x'ing the test file in the source tree, and if that fails, skip the test.

* Restore the original permissions afterwards.

Does it sound sane?

Sounds good to me.

I've attached patches fixing rw-build-tree and #749729 itself.

--
Jakub Wilk
diff --git a/scripts/sadt b/scripts/sadt
--- a/scripts/sadt
+++ b/scripts/sadt
@@ -225,7 +225,7 @@
             allow_stderr = False
         for r in restrictions:
             if r == 'rw-build-tree':
-                options.needs_rw_build_tree = True
+                options.rw_build_tree_needed = True
             elif r == 'needs-root':
                 if os.getuid() != 0:
                     raise Skip('this test needs root privileges')
diff --git a/scripts/sadt b/scripts/sadt
--- a/scripts/sadt
+++ b/scripts/sadt
@@ -42,6 +42,7 @@
     new_mode = old_mode | ((old_mode & 0o444) >> 2)
     if old_mode != new_mode:
         os.chmod(path, new_mode)
+    return old_mode
 
 def annotate_output(child):
     queue = queuemod.Queue()
@@ -256,20 +257,30 @@
         except Skip as exc:
             progress.skip(str(exc))
             raise
+        path = os.path.join(self.tests_directory, test)
+        original_mode = None
         if rw_build_tree:
             cwd = os.getcwd()
             os.chdir(rw_build_tree)
+            chmod_x(path)
         else:
             cwd = None
+            if not os.access(path, os.X_OK):
+                try:
+                    original_mode = chmod_x(path)
+                except OSError as exc:
+                    progress.skip('{path} could not be made executable: {exc}'.format(path=path, exc=exc))
+                    raise Skip
         try:
             self._run(test, progress, allow_stderr=options.allow_stderr)
         finally:
+            if original_mode is not None:
+                os.chmod(path, original_mode)
             if cwd is not None:
                 os.chdir(cwd)
 
     def _run(self, test, progress, allow_stderr=False):
         path = os.path.join(self.tests_directory, test)
-        chmod_x(path)
         tmpdir1 = tempfile.mkdtemp(prefix='sadt.')
         tmpdir2 = tempfile.mkdtemp(prefix='sadt.')
         environ = dict(os.environ)

Reply via email to