Skip to content
Snippets Groups Projects
Commit 59e71588 authored by Simon McVittie's avatar Simon McVittie Committed by Sjoerd Simons
Browse files

Add new test dbus/check-dbus-services (T342)

- verify that every D-Bus system service is a systemd system service
  (test for T283)
- verify that every D-Bus session service is a systemd user service
  (test for T284; failures are currently marked as expected)
- verify that every D-Bus service can be activated successfully
  (certain failures are currently marked as expected, with bugs opened)
- verify that a non-systemd-activated D-Bus service cannot be activated
  (marked as an expected failure until T282 is completed)

Differential Revision: https://phabricator.apertis.org/D361
Reviewed-by: pwith
parent fe85481b
Branches
Tags
No related merge requests found
<?xml version="1.0"?>
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="org.apertis.ApertisTests.FailToActivate"/>
<allow send_destination="org.apertis.ApertisTests.FailToActivate"/>
</policy>
</busconfig>
[D-BUS Service]
Name=org.apertis.ApertisTests.FailToActivate
Exec=/usr/bin/dbus-test-tool echo --name=org.apertis.ApertisTests.FailToActivate
[D-BUS Service]
Name=org.apertis.ApertisTests.FailToActivate
Exec=/usr/bin/dbus-test-tool echo --system --name=org.apertis.ApertisTests.FailToActivate
User=root
......@@ -2,7 +2,15 @@ all:
:
install:
:
install -d $(DESTDIR)/usr/share/dbus-1/services
install -d $(DESTDIR)/usr/share/dbus-1/system.d
install -d $(DESTDIR)/usr/share/dbus-1/system-services
install -m644 FailToActivate.system-service \
$(DESTDIR)/usr/share/dbus-1/system-services/org.apertis.ApertisTests.FailToActivate.service
install -m644 FailToActivate.service \
$(DESTDIR)/usr/share/dbus-1/services/org.apertis.ApertisTests.FailToActivate.service
install -m644 FailToActivate.conf \
$(DESTDIR)/usr/share/dbus-1/system.d/org.apertis.ApertisTests.FailToActivate.conf
clean:
:
#!/bin/sh
# Check that all activatable D-Bus services use systemd, and that they
# can be started
#
# Copyright © 2015 Collabora Ltd.
#
# SPDX-License-Identifier: MPL-2.0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
set -e
any_failed=0
failed=0
xfailed=0
# pass NAME [MESSAGE...]
# Record a test as passed
pass () {
name="$1"
shift
# highlight in green, for easier manual testing
printf "\033[32mvvvvvvvvvvvvvvvvvvvv\n"
# keep the result on its own logical line so LAVA can parse it
echo "RESULT:pass:$name: $*"
# reset after this line
printf "^^^^^^^^^^^^^^^^^^^^\033[0m\n"
}
# fail NAME [MESSAGE...]
# Record a test as failed
fail () {
name="$1"
shift
# like pass(), but red
printf "\033[31mvvvvvvvvvvvvvvvvvvvv\n"
echo "RESULT:fail:$name: $*"
printf "^^^^^^^^^^^^^^^^^^^^\033[0m\n"
any_failed=1
failed=1
}
# xfail NAME [MESSAGE...]
# Record a test as an expected failure
xfail () {
name="$1"
shift
# like pass(), but purple
printf "\033[35mvvvvvvvvvvvvvvvvvvvv\n"
echo "RESULT:xfail:$name: $*"
printf "^^^^^^^^^^^^^^^^^^^^\033[0m\n"
xfailed=1
}
# run_verbose COMMAND [ARGS...]
# Run COMMAND ARGS and exit with the same status, diagnosing the command
# and its exit status.
run_verbose () {
echo "+ $*"
e=0
"$@" || e=$?
echo "-> $e"
return $e
}
if [ "$(id -u)" = 0 ]; then
bus=system
systemd=system
dir=system-services
systemd_dir="/lib/systemd/$systemd"
else
bus=session
systemd=user
dir=services
systemd_dir="/usr/lib/systemd/$systemd"
fi
cd "/usr/share/dbus-1/$dir"
# Make sure systemd and dbus-daemon are up to date with any recently-installed
# services or configuration
run_verbose systemctl --$systemd daemon-reload
run_verbose gdbus call --$bus -d org.freedesktop.DBus -o /org/freedesktop/dbus \
-m org.freedesktop.DBus.ReloadConfig
# Positive tests: services that we actually want have got it right
for service in *.service; do
failed=0
xfailed=0
name="${bus}_${service}"
if [ "${service}" = "org.freedesktop.systemd1.service" ]; then
# silently skip: this is not really activatable
continue
fi
if [ "${service}" = "org.apertis.ApertisTests.FailToActivate.service" ]; then
# silently skip: this is tested a bit later
continue
fi
echo "---------------------------------------------------------------"
if ! bus_name="$(grep "^Name=" "$service")"; then
fail "$name" "name not configured"
continue
fi
if ! systemd_service="$(grep "^SystemdService=" "$service")"; then
if [ "$bus" = session ]; then
# TODO: port the session services, too (T284)
xfail "$name" "systemd service not configured"
else
fail "$name" "systemd service not configured"
fi
fi
systemd_service="${systemd_service#SystemdService=}"
bus_name="${bus_name#Name=}"
if [ "$service" != "${bus_name}.service" ]; then
if [ "$bus" = system ]; then
# on the system bus this is fatally bad
# https://lintian.debian.org/tags/dbus-system-service-wrong-name.html
fail "$name" "filename does not match Name=${bus_name}"
else
# on the session bus this is undesirable but OK
# https://lintian.debian.org/tags/dbus-session-service-wrong-name.html
echo "WARNING:$name: filename does not match Name=${bus_name}"
fi
fi
if [ -n "$systemd_service" ] &&
! { [ -e "$systemd_dir/$systemd_service" ] ||
[ -e "/etc/systemd/${systemd}/$systemd_service" ]; }; then
fail "$name" "matching systemd service $systemd_service not found"
fi
if ! run_verbose gdbus call --$bus -d "$bus_name" -o / \
-m org.freedesktop.DBus.Peer.Ping; then
case "${bus}:$bus_name" in
(system:com.chaiwala.Updater)
# chaiwala-btrfs-updater currently only responds to user, not root
xfail "$name" "could not ping $bus_name as root, trying as user"
if ! sudo -u user gdbus call --$bus -d "$bus_name" -o / \
-m org.freedesktop.DBus.Peer.Ping; then
fail "$name" "could not ping $bus_name"
fi
;;
(system:org.freedesktop.locale1)
# https://bugs.apertis.org/show_bug.cgi?id=428
xfail "$name" "could not ping $bus_name (bug: Apertis #428)"
;;
(session:ca.desrt.dconf-editor)
# https://bugs.apertis.org/show_bug.cgi?id=431
xfail "$name" "could not ping $bus_name (bug: Apertis #431)"
;;
(session:org.freedesktop.Tracker1.Writeback)
# https://bugs.apertis.org/show_bug.cgi?id=432
xfail "$name" "could not ping $bus_name (bug: Apertis #432)"
;;
(session:org.gnome.evolution.dataserver.UserPrompter0)
# https://bugs.apertis.org/show_bug.cgi?id=433
xfail "$name" "could not ping $bus_name (bug: Apertis #433)"
;;
(system:org.pacrunner)
# https://bugs.apertis.org/show_bug.cgi?id=434
xfail "$name" "could not ping $bus_name (bug: Apertis #434)"
;;
(system:fi.w1.wpa_supplicant1|system:fi.epitest.hostap.WPASupplicant)
# https://bugs.apertis.org/show_bug.cgi?id=435
xfail "$name" "could not ping $bus_name (bug: Apertis #435)"
;;
(*)
fail "$name" "could not ping $bus_name"
;;
esac
fi
# The exit code from this does not necessarily tell us anything about it;
# it will be nonzero if an on-demand service has exited.
if [ -n "$systemd_service" ]; then
run_verbose systemctl -l --$systemd status "$systemd_service" || true
fi
if [ "$failed" = 0 ] && [ "$xfailed" = 0 ]; then
pass "$name"
fi
done
echo "---------------------------------------------------------------"
# Negative tests: services that have got it wrong do not activate
failed=0
xfailed=0
bus_name="org.apertis.ApertisTests.FailToActivate"
service="${bus_name}.service"
name="${bus}_FailToActivate"
# check that it would have succeeded if legacy activation worked
if ! [ -x "/usr/bin/dbus-test-tool" ]; then
fail "$name" "dbus-test-tool not found"
elif ! [ -e "$service" ]; then
fail "$name" "$(pwd)/$service not found"
elif run_verbose gdbus call --$bus -d "$bus_name" -o / -m org.freedesktop.DBus.Peer.Ping; then
# TODO: treat this as a failure after we enforce that
# traditional activation is not allowed (T282)
xfail "$name" "$bus_name should not have been activatable"
else
pass "$name"
fi
echo "---------------------------------------------------------------"
systemd-cgls --no-pager
exit "$any_failed"
# vim:set sw=4 sts=4 et:
metadata:
name: check-dbus-services
format: "Lava-Test-Shell Test Definition 1.0"
description: "Sanity-check all installed D-Bus services"
maintainer: "simon.mcvittie@collabora.co.uk"
scope:
- functional
devices:
- i386
environment:
- lava-test-shell
install:
deps:
- apertis-tests
- dbus-tests
run:
steps:
- common/run-test-in-systemd --user=user dbus/check-dbus-services
- common/run-test-in-systemd dbus/check-dbus-services
parse:
pattern: 'RESULT:(?P<result>\w+):(?P<test_case_id>[^:]+):'
# LAVA doesn't seem to have the concept of an expected failure,
# so calling it skipped is the next best thing
fixupdict:
xfail: skip
# vim:set sw=2 sts=2 et:
......@@ -12,3 +12,6 @@ usr/lib/apertis-tests/predeployed-misc
usr/lib/apertis-tests/resources
usr/lib/apertis-tests/sdk
usr/lib/apertis-tests/templates
usr/share/dbus-1/services/org.apertis.ApertisTests.FailToActivate.service
usr/share/dbus-1/system-services/org.apertis.ApertisTests.FailToActivate.service
usr/share/dbus-1/system.d/org.apertis.ApertisTests.FailToActivate.conf
......@@ -5,6 +5,15 @@ apertis-tests (1:0.20150814.2) UNRELEASED; urgency=medium
* Move dbus-dos-* tests from root directory to dbus/
- add compatibility symlinks for dbus-dos-* tests in chaiwala-tests,
so that old manual test instructions continue to work
* Add new test dbus/check-dbus-services (T342)
- verify that every D-Bus system service is a systemd system service
(test for T283)
- verify that every D-Bus session service is a systemd user service
(test for T284; failures are currently marked as expected)
- verify that every D-Bus service can be activated successfully
(certain failures are currently marked as expected, with bugs opened)
- verify that a non-systemd-activated D-Bus service cannot be activated
(marked as an expected failure until T282 is completed)
-- Simon McVittie <simon.mcvittie@collabora.co.uk> Tue, 25 Aug 2015 11:35:18 +0100
......
......
......@@ -139,6 +139,11 @@
"git-repo": "https://lavagit:uT0ahxeiaiD5nie7@git.apertis.org/git/apertis-tests.git",
"revision": "master",
"testdef": "dbus/installed-tests.yaml"
},
{
"git-repo": "https://lavagit:uT0ahxeiaiD5nie7@git.apertis.org/git/apertis-tests.git",
"revision": "master",
"testdef": "dbus/check-dbus-services.yaml"
}
]
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment