summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2011-05-04 13:30:22 +0200
committerMartin Pitt <martin.pitt@ubuntu.com>2011-05-04 13:42:49 +0200
commit958bb53105b0a7386ec9df96babfc2d1ac2df52c (patch)
tree51faea5c6eabcd4e806dc5c6834b45a4c268d794
parentbdddb74723b6ffcaaacc5ba203c41791b28b78b2 (diff)
up-self-test: Run subset of tests when system D-BUS is not available
In restricted environments such as package builds we do not have a system D-BUS running. In that case, don't just fail, but use the recently introduced up_daemon_set_bus_type() to run tests on the session D-BUS instead. Run up-self-tests under dbus-launch for this if available. Skip tests which need polkit if there is no system D-BUS, as we can't sensibly run this on the session bus.
-rw-r--r--src/Makefile.am1
-rw-r--r--src/up-self-test.c28
2 files changed, 29 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f8284d7..c8e9854 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -176,6 +176,7 @@ up_self_test_LDADD = \
up_self_test_CFLAGS = $(AM_CFLAGS) $(WARNINGFLAGS_C)
+TESTS_ENVIRONMENT = $(DBUS_LAUNCH)
TESTS = up-self-test
endif
diff --git a/src/up-self-test.c b/src/up-self-test.c
index fd69a51..419935c 100644
--- a/src/up-self-test.c
+++ b/src/up-self-test.c
@@ -38,6 +38,8 @@
gchar *history_dir = NULL;
+#define DBUS_SYSTEM_SOCKET "/var/run/dbus/system_bus_socket"
+
static void
up_test_native_func (void)
{
@@ -64,6 +66,12 @@ up_test_daemon_func (void)
{
UpDaemon *daemon;
+ /* needs polkit, which only listens to the system bus */
+ if (!g_file_test (DBUS_SYSTEM_SOCKET, G_FILE_TEST_EXISTS)) {
+ puts("No system D-BUS running, skipping test");
+ return;
+ }
+
daemon = up_daemon_new ();
g_assert (daemon != NULL);
@@ -242,6 +250,12 @@ up_test_polkit_func (void)
{
UpPolkit *polkit;
+ /* polkit only listens to the system bus */
+ if (!g_file_test (DBUS_SYSTEM_SOCKET, G_FILE_TEST_EXISTS)) {
+ puts("No system D-BUS running, skipping test");
+ return;
+ }
+
polkit = up_polkit_new ();
g_assert (polkit != NULL);
@@ -254,6 +268,12 @@ up_test_qos_func (void)
{
UpQos *qos;
+ /* needs polkit, which only listens to the system bus */
+ if (!g_file_test (DBUS_SYSTEM_SOCKET, G_FILE_TEST_EXISTS)) {
+ puts("No system D-BUS running, skipping test");
+ return;
+ }
+
qos = up_qos_new ();
g_assert (qos != NULL);
@@ -285,6 +305,14 @@ main (int argc, char **argv)
else
g_setenv ("UPOWER_CONF_FILE_NAME", "../../etc/UPower.conf", TRUE);
+ /* Test on system bus if possible, but fall back to session bus; this
+ * allows the test suite to work in restricted environments like
+ * package builds. */
+ if (!g_file_test (DBUS_SYSTEM_SOCKET, G_FILE_TEST_EXISTS)) {
+ puts("No system D-BUS running, running on session D-BUS");
+ up_daemon_set_bus_type (DBUS_BUS_SESSION);
+ }
+
/* tests go here */
g_test_add_func ("/power/backend", up_test_backend_func);
g_test_add_func ("/power/device", up_test_device_func);