integration-test: Always run on a fake system bus

Drop the two modes depending on whether or not the test gets run as root or
not. Set up a fake system bus and always use that. This also eliminates the
need for upowerd's --test option.

Drop usage of dbus-launch, as this leaves dbus-daemon running after the tests.
Use GioTestDBus instead, which cleans up properly.
This commit is contained in:
Martin Pitt 2013-02-20 14:59:56 +01:00
parent 7105ed8a04
commit da066045e4
2 changed files with 15 additions and 22 deletions

View file

@ -131,10 +131,8 @@ systemsleep_SCRIPTS = notify-upower.sh
endif
if UP_BUILD_TESTS
DBUS_LAUNCH=$(shell which dbus-launch)
check-local: upowerd
env top_builddir=$(top_builddir) $(DBUS_LAUNCH) $(srcdir)/linux/integration-test -v
env top_builddir=$(top_builddir) $(srcdir)/linux/integration-test -v
endif
endif

View file

@ -52,39 +52,34 @@ class Tests(unittest.TestCase):
# run from local build tree if we are in one, otherwise use system instance
builddir = os.getenv('top_builddir', '.')
if os.access (os.path.join(builddir, 'src', 'upowerd'), os.X_OK):
daemon_path = os.path.join(builddir, 'src', 'upowerd')
cls.daemon_path = os.path.join(builddir, 'src', 'upowerd')
print('Testing binaries from local build tree')
else:
print('Testing installed system binaries')
daemon_path = None
cls.daemon_path = None
with open('/usr/share/dbus-1/system-services/org.freedesktop.UPower.service') as f:
for line in f:
if line.startswith('Exec='):
daemon_path = line.split('=', 1)[1].strip()
cls.daemon_path = line.split('=', 1)[1].strip()
break
assert daemon_path, 'could not determine daemon path from D-BUS .service file'
assert cls.daemon_path, 'could not determine daemon path from D-BUS .service file'
# fail on CRITICALs on client side
GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_WARNING|
GLib.LogLevelFlags.LEVEL_ERROR|
GLib.LogLevelFlags.LEVEL_CRITICAL)
# if we are root, test the real thing on the system bus, otherwise
# start on the session bus
if os.geteuid() == 0:
# kill running daemons
subprocess.call(['killall', 'upowerd'])
# set up a fake system D-BUS
cls.test_bus = Gio.TestDBus.new(Gio.TestDBusFlags.NONE)
cls.test_bus.up()
del os.environ['DBUS_SESSION_BUS_ADDRESS']
os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = cls.test_bus.get_bus_address()
cls.dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
cls.daemon_argv = ['umockdev-wrapper', daemon_path]
print('Testing as root on the system bus')
else:
cls.dbus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
cls.daemon_argv = ['umockdev-wrapper', daemon_path, '--test']
# use dbus-lauch if possible
print('Testing as user on the session bus')
cls.dbus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
@classmethod
def tearDownClass(cls):
cls.test_bus.down()
def setUp(self):
'''Set up a local umockdev testbed.
@ -127,7 +122,7 @@ class Tests(unittest.TestCase):
# have to do that ourselves
env['UMOCKDEV_DIR'] = self.testbed.get_root_dir()
self.log = tempfile.NamedTemporaryFile()
self.daemon = subprocess.Popen(self.daemon_argv,
self.daemon = subprocess.Popen(['umockdev-wrapper', self.daemon_path, '-v'],
env=env, stdout=self.log, stderr=subprocess.STDOUT)
# wait until the daemon gets online