aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-13 09:07:55 -0700
committerGravatar Nikolaus Rath <Nikolaus@rath.org>2016-10-13 11:02:04 -0700
commita47dedd47f79685c1b025331d30de7d998e1c4b7 (patch)
treecfcbb9db5b5a6b5eb2027604fa3a4d8c1450ac15
parentfaf109f1d25df6e374582f3ad96e39b4f9354646 (diff)
tests: use freshly-build fusermount (instead of system version)
When running tests as non-root, make fusermount setuid root.
-rw-r--r--Makefile.am15
-rwxr-xr-xtest/test_examples.py3
-rw-r--r--test/util.py23
3 files changed, 36 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index 54aee13..25d88d0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,6 +15,19 @@ pkgconfig_DATA = fuse3.pc
$(pkgconfig_DATA): config.status
+.PHONY: setuid_fusermount
+setuid_fusermount:
+ @echo "Attempting to use sudo to make util/fusermount setuid root"
+ @echo "If this fails, set permissions manually and re-run make test"
+ test $$(ls -n util/fusermount | awk 'NR==1 {print $$3}') -eq 0 || \
+ sudo chown root util/fusermount
+ test -u util/fusermount || \
+ sudo chmod u+s util/fusermount
+
+# If we are not root, util/fusermount needs to be setuid root
+# for tests to work.
+
+test_deps = $(shell [ "$${UID}" -eq 0 ] || echo setuid_fusermount)
.PHONY: test
-test: all
+test: all $(test_deps)
python3 -m pytest test/
diff --git a/test/test_examples.py b/test/test_examples.py
index 9f62054..a8064c3 100755
--- a/test/test_examples.py
+++ b/test/test_examples.py
@@ -17,10 +17,9 @@ import platform
from distutils.version import LooseVersion
from tempfile import NamedTemporaryFile
from util import (wait_for_mount, umount, cleanup, base_cmdline,
- safe_sleep)
+ safe_sleep, basename)
from os.path import join as pjoin
-basename = pjoin(os.path.dirname(__file__), '..')
TEST_FILE = __file__
with open(TEST_FILE, 'rb') as fh:
diff --git a/test/util.py b/test/util.py
index 2160f70..baba20b 100644
--- a/test/util.py
+++ b/test/util.py
@@ -3,6 +3,9 @@ import subprocess
import pytest
import os
import time
+from os.path import join as pjoin
+
+basename = pjoin(os.path.dirname(__file__), '..')
def wait_for_mount(mount_process, mnt_dir,
test_fn=os.path.ismount):
@@ -17,12 +20,24 @@ def wait_for_mount(mount_process, mnt_dir,
pytest.fail("mountpoint failed to come up")
def cleanup(mnt_dir):
- subprocess.call(['fusermount', '-z', '-u', mnt_dir],
+ # Don't bother trying Valgrind if things already went wrong
+
+ subprocess.call([pjoin(basename, 'util', 'fusermount'),
+ '-z', '-u', mnt_dir],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
def umount(mount_process, mnt_dir):
- subprocess.check_call(['fusermount', '-z', '-u', mnt_dir])
+ # fusermount will be setuid root, so we can only trace it with
+ # valgrind if we're root
+ if os.getuid() == 0:
+ cmdline = base_cmdline
+ else:
+ cmdline = []
+
+ cmdline = cmdline + [ pjoin(basename, 'util', 'fusermount'),
+ '-z', '-u', mnt_dir ]
+ subprocess.check_call(cmdline)
assert not os.path.ismount(mnt_dir)
# Give mount process a little while to terminate. Popen.wait(timeout)
@@ -68,3 +83,7 @@ if has_program('valgrind') and has_program('libtool'):
'valgrind', '-q', '--' ]
else:
base_cmdline = []
+
+
+# Try to use local fusermount
+os.environ['PATH'] = '%s:%s' % (pjoin(basename, 'util'), os.environ['PATH'])