Commit 28d51593 authored by Frédéric Dalleau's avatar Frédéric Dalleau

Add sadt tests to canterbury-tests package

Initially, the sadt tests are retrieved with the source code
using apt source. For that, they reside in debian/tests subdirectory.
In order to run sadt tests on OSTree image, the tests have to be
distributed. Thus, they are added to canterbury-tests package which
already distributes scripts used by installed-tests.
The original file are replaced by relative symlinks to maintain
compatibility with existing tests.
Signed-off-by: 's avatarFrédéric Dalleau <frederic.dalleau@collabora.com>
parent b208de2c
......@@ -852,6 +852,16 @@ uninstalled_test_extra_programs = \
dist_installed_test_extra_scripts = \
tests/cby-inspect.py \
tests/systemd-mock-run.py \
tests/scripts/agent-after-reboot \
tests/scripts/agent-after-reboot-full \
tests/scripts/agents-slow \
tests/scripts/build \
tests/scripts/control \
tests/scripts/core \
tests/scripts/core-as-root \
tests/scripts/full \
tests/scripts/full-as-root \
tests/scripts/store-app-bundle-apparmor \
$(NULL)
dist_installed_test_data = \
......
usr/lib/installed-tests/canterbury-0/agent-after-reboot exists
usr/lib/installed-tests/canterbury-0/agent-after-reboot-full
usr/lib/installed-tests/canterbury-0/agents-slow
usr/lib/installed-tests/canterbury-0/build
usr/lib/installed-tests/canterbury-0/core exists
usr/lib/installed-tests/canterbury-0/core-as-root
usr/lib/installed-tests/canterbury-0/full
usr/lib/installed-tests/canterbury-0/full-as-root
usr/lib/installed-tests/canterbury-0/store-app-bundle-apparmor
usr/lib/installed-tests/canterbury-0/agent-after-reboot
usr/lib/installed-tests/canterbury-0/agent-after-reboot-full
usr/lib/installed-tests/canterbury-0/agents-slow
usr/lib/installed-tests/canterbury-0/build
usr/lib/installed-tests/canterbury-0/control
usr/lib/installed-tests/canterbury-0/core
usr/lib/installed-tests/canterbury-0/core-as-root
usr/lib/installed-tests/canterbury-0/full
usr/lib/installed-tests/canterbury-0/full-as-root
usr/lib/installed-tests/canterbury-0/store-app-bundle-apparmor
......@@ -175,6 +175,20 @@ Description: Canterbury application manager - tests (with full GUI support)
.
This package contains automated tests.
Package: canterbury-tests-additions
Section: libdevel
Architecture: any
Depends:
apparmor (>= 2.11.0-2ubuntu5~),
canterbury-tests (= ${binary:Version}),
canterbury (= ${binary:Version}),
${misc:Depends},
${shlibs:Depends},
Description: Canterbury application manager - additional tests
Canterbury is the Apertis application management service.
.
This package contains additional automated tests.
Package: canterbury-update-component-index
Architecture: any
Depends:
......
#!/bin/bash
# Copyright © 2016-2017 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 -eu -o pipefail
exit_status=0
test_number=0
skip_all () {
echo "1..0 # SKIP - $*"
# We exit 0 because autopkgtest has no concept of a skipped test, only
# pass or fail, and we don't want tests that are not applicable to
# root to be a hard failure when run as non-root.
exit 0
}
not_ok () {
test_number=$(($test_number + 1))
echo "not ok $test_number - $*"
exit_status=1
}
ok () {
test_number=$(($test_number + 1))
echo "ok $test_number - $*"
}
done_testing () {
echo "1..$test_number"
exit "$exit_status"
}
case "$(id -n -u)" in
(root)
ribchesterctl="ribchesterctl"
as_root=
if ! user_uid="$(id -u user)"; then
skip_all "user 'user' not found; is this really Apertis?"
elif ! [ -d "/run/user/$user_uid" ]; then
skip_all "no XDG_RUNTIME_DIR for uid $user_uid 'user';" \
"is this really Apertis?"
fi
as_user="sudo -H -u user env XDG_RUNTIME_DIR=/run/user/$user_uid"
;;
(user)
as_root="sudo -H --non-interactive"
as_user=
if [ -e /etc/polkit-1/rules.d/60-apertis-minimal-user.rules ]; then
# assume we don't need sudo here
ribchesterctl="ribchesterctl"
elif ! sudo --non-interactive --validate; then
skip_all "cannot use sudo without password here"
else
ribchesterctl="$as_root ribchesterctl"
fi
;;
(*)
skip_all "neither root nor user; is this really Apertis?"
;;
esac
bundle_id="org.apertis.CanterburyTests.Agent"
agent_entry_point="${bundle_id}"
not_agent_entry_point="${bundle_id}.NotAgent"
version="1.0"
stage="${AUTOPKGTEST_REBOOT_MARK:-"${1:-before-reboot}"}"
systemctl_user="$as_user systemctl --user --no-pager --full"
if [ -x /usr/bin/canterbury ]; then
canterbury_service=canterbury.service
else
canterbury_service=canterbury-core.service
fi
echo "# Test stage: $stage"
case "$stage" in
(before-reboot)
# We have not rebooted yet. Install the app-bundle
${ribchesterctl} remove ${bundle_id} || true
${ribchesterctl} install \
/usr/lib/installed-tests/canterbury-0/tests/${bundle_id}-${version}.bundle
next=installed
;;
(installed)
if [ -x /etc/init.d/nodm ]; then
# SDK images are special: Canterbury isn't started automatically
$systemctl_user start "${canterbury_service}"
fi
echo "# Waiting for canterbury-agents.target..."
while true; do
if $systemctl_user is-failed canterbury-agents.target; then
$systemctl_user status canterbury-agents.target >&2 || true
not_ok "canterbury-agents.target failed"
break
elif $systemctl_user is-active canterbury-agents.target; then
ok "canterbury-agents.target started"
break
fi
sleep 1
done
echo "# Waiting for ${canterbury_service}..."
while true; do
if $systemctl_user is-failed "${canterbury_service}"; then
$systemctl_user status "${canterbury_service}" >&2 || true
not_ok "${canterbury_service} failed"
break
elif $systemctl_user is-active "${canterbury_service}"; then
ok "${canterbury_service} started"
break
fi
sleep 1
done
if $systemctl_user is-active "${agent_entry_point}.service"; then
$systemctl_user status "${agent_entry_point}.service" >&2 || true
ok "${agent_entry_point}.service is active"
else
$systemctl_user status "${agent_entry_point}.service" >&2 || true
not_ok "${agent_entry_point}.service not active"
fi
if status="$($systemctl_user is-active \
"${not_agent_entry_point}.service")"; then
$systemctl_user status "${not_agent_entry_point}.service" >&2 || true
not_ok "${not_agent_entry_point}.service should not have" \
"even been attempted, so it should not have succeeded"
elif [ "$status" = "inactive" ]; then
ok "${not_agent_entry_point}.service never even attempted," \
"as expected"
else
$systemctl_user status "${not_agent_entry_point}.service" >&2 || true
not_ok "${not_agent_entry_point}.service should not have" \
"even been attempted, so it should still be inactive," \
"not \"$status\""
fi
done_testing
;;
(*)
echo "Bail out! Internal error: stage should not be $stage" >&2
exit 1
;;
esac
if [ -x /tmp/autopkgtest-reboot ]; then
echo "# Requesting reboot for next stage: $stage"
/tmp/autopkgtest-reboot "$next"
else
echo "Please reboot, then run: cd $(pwd) && $0 $next"
exit 75 # EX_TEMPFAIL
fi
# vim:set sw=4 sts=4 et:
../../tests/scripts/agent-after-reboot
\ No newline at end of file
agent-after-reboot
\ No newline at end of file
../../tests/scripts/agent-after-reboot-full
\ No newline at end of file
#!/bin/sh
set -e
exec 2>&1
if [ -x /usr/bin/canterbury ]; then
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user stop canterbury-core.service
# Ideally we'd *re*start Canterbury, but on non-SDK images,
# canterbury-full triggers a reboot when killed.
if [ -x /etc/init.d/nodm ]; then
verb=restart
else
verb=start
fi
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user $verb canterbury.service
else
# It's safe to restart canterbury-core.
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user restart canterbury-core.service
fi
exec /usr/lib/apertis-tests/common/run-test-in-systemd \
--name=canterbury-0-agents-slow \
--no-lava \
/usr/lib/installed-tests/canterbury-0/agents.t --tap -m slow
../../tests/scripts/agents-slow
\ No newline at end of file
#!/bin/sh
# Copyright © 2016 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
exec 2>&1
set -x
cd "$ADTTMP"
cat > lib.c <<'EOF'
#include <stdio.h>
#include <glib.h>
#include <canterbury/canterbury.h>
int main (void)
{
CbyProcessInfo *them = cby_process_info_new_for_apparmor_context (
"/usr/Applications/org.apertis.Eye (enforce)");
g_assert_cmpstr (cby_process_info_get_bundle_id (them), ==,
"org.apertis.Eye");
printf ("ok 1 - lib\n");
return 0;
}
EOF
cc -o lib lib.c $(pkg-config --cflags --libs canterbury-0)
test -x lib
./lib
cat > gdbus.c <<'EOF'
#include <stdio.h>
#include <glib.h>
#include <canterbury/gdbus/canterbury.h>
int main (void)
{
g_assert_cmpstr (g_type_name (CANTERBURY_TYPE_APP_DB_HANDLER), ==,
"CanterburyAppDbHandler");
g_assert_cmpstr (g_type_name (CANTERBURY_TYPE_EXECUTABLE_TYPE), ==,
"CanterburyExecutableType");
printf ("ok 2 - gdbus\n");
return 0;
}
EOF
cc -o gdbus gdbus.c $(pkg-config --cflags --libs canterbury-gdbus-0)
test -x gdbus
./gdbus
cat > compat.c <<'EOF'
#include <stdio.h>
#include <glib.h>
#include <canterbury.h>
#include <canterbury/canterbury.h>
int main (void)
{
CbyProcessInfo *them = cby_process_info_new_for_apparmor_context (
"/usr/Applications/org.apertis.Eye (enforce)");
g_assert_cmpstr (cby_process_info_get_bundle_id (them), ==,
"org.apertis.Eye");
g_assert_cmpstr (g_type_name (CANTERBURY_TYPE_APP_DB_HANDLER), ==,
"CanterburyAppDbHandler");
g_assert_cmpstr (g_type_name (CANTERBURY_TYPE_EXECUTABLE_TYPE), ==,
"CanterburyExecutableType");
printf ("ok 3 - compat\n");
return 0;
}
EOF
cc -o compat compat.c $(pkg-config --cflags --libs canterbury)
test -x compat
./compat
../../tests/scripts/build
\ No newline at end of file
Tests: build
Depends: build-essential, canterbury-dev
Tests: core agents-slow
Depends: apertis-tests, canterbury-core-tests, gnome-desktop-testing, ribchester-core (>= 0.1709.0~)
Tests: core-as-root
Depends: canterbury-core-tests, gnome-desktop-testing, ribchester-core (>= 0.1709.0~)
Tests: full
Depends: apertis-tests, canterbury-tests, gnome-desktop-testing, libglib2.0-bin
Tests: full-as-root
Depends: canterbury-tests, gnome-desktop-testing, ribchester-full (>= 0.1709.0~)
Tests: store-app-bundle-apparmor agent-after-reboot
Depends: canterbury-common, canterbury-core-tests, ribchester-core (>= 0.1709.0~)
Restrictions: allow-stderr, isolation-machine, needs-root
Tests: agent-after-reboot-full
Depends: canterbury-core-tests, canterbury-full, ribchester-full (>= 0.1709.0~)
Restrictions: allow-stderr, isolation-machine, needs-root
../../tests/scripts/control
\ No newline at end of file
#!/bin/sh
set -e
exec 2>&1
if [ -x /usr/bin/canterbury ]; then
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user stop canterbury-core.service
# Ideally we'd *re*start Canterbury, but on non-SDK images,
# canterbury-full triggers a reboot when killed.
if [ -x /etc/init.d/nodm ]; then
verb=restart
else
verb=start
fi
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user $verb canterbury.service
else
# It's safe to restart canterbury-core.
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user restart canterbury-core.service
fi
exec /usr/lib/apertis-tests/common/run-test-in-systemd \
--name=canterbury-0-core \
--no-lava \
gnome-desktop-testing-runner \
canterbury-0
../../tests/scripts/core
\ No newline at end of file
#!/bin/sh
# Copyright © 2016 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
exec 2>&1
skip_all () {
echo "SKIP: $*"
# We exit 0 because autopkgtest has no concept of a skipped test, only
# pass or fail, and we don't want tests that are not applicable to
# root to be a hard failure when run as non-root.
exit 0
}
case "$(id -n -u)" in
(root)
as_root=
;;
(user)
if ! sudo --non-interactive --validate; then
skip_all "cannot use sudo without password here"
fi
as_root="sudo -H --non-interactive"
;;
(*)
skip_all "neither root nor user; is this really Apertis?"
;;
esac
# It's inappropriate to use gvfs in privileged processes
export GIO_USE_VFS=local
# The SDK "simulator" sometimes shuts down Ribchester; make sure it's back up
if [ -e /usr/bin/ribchester ]; then
$as_root systemctl start ribchester.service
else
$as_root systemctl start ribchester-core.service
fi
NULL=
EXIT_STATUS=0
$as_root \
dbus-run-session -- \
gnome-desktop-testing-runner \
canterbury-0/postinst-prerm-core.t \
canterbury-0/process-info.t \
${NULL} || EXIT_STATUS=$?
exit $EXIT_STATUS
../../tests/scripts/core-as-root
\ No newline at end of file
#!/bin/sh
set -e
exec 2>&1
if [ -x /usr/bin/canterbury ]; then
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user stop canterbury-core.service
# Ideally we'd *re*start Canterbury, but on non-SDK images,
# canterbury-full triggers a reboot when killed.
if [ -x /etc/init.d/nodm ]; then
verb=restart
else
verb=start
fi
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user $verb canterbury.service
else
# It's safe to restart canterbury-core.
/usr/lib/apertis-tests/common/run-test-in-systemd --no-lava \
systemctl --user restart canterbury-core.service
fi
exec /usr/lib/apertis-tests/common/run-test-in-systemd \
--name=canterbury-0 \
--no-lava \
gnome-desktop-testing-runner \
canterbury-0
../../tests/scripts/full
\ No newline at end of file
#!/bin/sh
# Copyright © 2016 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
exec 2>&1
skip_all () {
echo "SKIP: $*"
# We exit 0 because autopkgtest has no concept of a skipped test, only
# pass or fail, and we don't want tests that are not applicable to
# root to be a hard failure when run as non-root.
exit 0
}
case "$(id -n -u)" in
(root)
as_root=
;;
(user)
if ! sudo --non-interactive --validate; then
skip_all "cannot use sudo without password here"
fi
as_root="sudo -H --non-interactive"
;;
(*)
skip_all "neither root nor user; is this really Apertis?"
;;
esac
# It's inappropriate to use gvfs in privileged processes
export GIO_USE_VFS=local
# The SDK "simulator" sometimes shuts down Ribchester; make sure it's back up
$as_root systemctl start ribchester.service
NULL=
EXIT_STATUS=0
$as_root \
dbus-run-session -- \
gnome-desktop-testing-runner \
canterbury-0/postinst-prerm-core.t \
canterbury-0/postinst-prerm.t \
canterbury-0/process-info.t \
${NULL} || EXIT_STATUS=$?
$as_root \
dbus-run-session -- \
python3 /usr/lib/installed-tests/canterbury-0/systemd-mock-run.py -- \
gnome-desktop-testing-runner \
canterbury-0/service-manager.t \
${NULL} || EXIT_STATUS=$?
exit $EXIT_STATUS
../../tests/scripts/full-as-root
\ No newline at end of file
#!/bin/bash
# Copyright © 2016 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 -eu -o pipefail
set -x
skip_all () {
echo "SKIP: $*"
# We exit 0 because autopkgtest has no concept of a skipped test, only
# pass or fail, and we don't want tests that are not applicable to
# root to be a hard failure when run as non-root.
exit 0
}
case "$(id -n -u)" in
(root)
as_root=
;;
(user)
if ! sudo --non-interactive --validate; then
skip_all "cannot use sudo without password here"
fi
as_root="sudo -H --non-interactive"
;;
(*)
skip_all "neither root nor user; is this really Apertis?"
;;
esac
bundle_id="org.apertis.CanterburyTests.StoreAppBundleAppArmor"
stage="${AUTOPKGTEST_REBOOT_MARK:-"${1:-before-reboot}"}"
if [ "$stage" = before-reboot ]; then
# We have not rebooted yet. Build and install the app-bundle
${as_root} ribchesterctl remove ${bundle_id} || :
${as_root} ribchesterctl install \
/usr/lib/installed-tests/canterbury-0/tests/${bundle_id}-0.bundle
fi
if ! ${as_root} grep "^/Applications/${bundle_id}/\\*\\* " \
/sys/kernel/security/apparmor/profiles; then
echo "E: AppArmor profile not found (stage: $stage)" >&2
exit 1
fi
if ! aa-exec -p "/Applications/${bundle_id}/**" /bin/true; then
echo "E: unable to run under our AppArmor profile (stage: $stage)" >&2
exit 1
fi
case "$stage" in
(before-reboot)
next=installed
;;
(installed)
next=corrupted
# Assume this script is not valid content for an AppArmor ubercache!
$as_root cp "$0" /var/lib/apertis_extensions/apparmor.d/cache/.ubercache
;;
(corrupted)
next=deleted
$as_root rm /var/lib/apertis_extensions/apparmor.d/cache/.ubercache
;;
(deleted)
next=emptied
: | $as_root tee /var/lib/apertis_extensions/apparmor.d/cache/.ubercache
;;
(emptied)
# We have tested everything we want to
echo "OK: tested everything, seems successful"
exit 0
;;
(*)
echo "E: internal error: stage should not be $stage" >&2
exit 1
;;
esac
if [ -x /tmp/autopkgtest-reboot ]; then
/tmp/autopkgtest-reboot "$next"
else
echo "Please reboot, then run: cd $(pwd) && $0 $next"
exit 75 # EX_TEMPFAIL
fi
# vim:set sw=4 sts=4 et:
../../tests/scripts/store-app-bundle-apparmor
\ No newline at end of file
#!/bin/bash
# Copyright © 2016-2017 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 -eu -o pipefail
exit_status=0
test_number=0
skip_all () {
echo "1..0 # SKIP - $*"
# We exit 0 because autopkgtest has no concept of a skipped test, only
# pass or fail, and we don't want tests that are not applicable to
# root to be a hard failure when run as non-root.
exit 0
}
not_ok () {
test_number=$(($test_number + 1))
echo "not ok $test_number - $*"
exit_status=1
}
ok () {
test_number=$(($test_number + 1))
echo "ok $test_number - $*"
}
done_testing () {
echo "1..$test_number"
exit "$exit_status"
}
case "$(id -n -u)" in
(root)
ribchesterctl="ribchesterctl"
as_root=
if ! user_uid="$(id -u user)"; then
skip_all "user 'user' not found; is this really Apertis?"
elif ! [ -d "/run/user/$user_uid" ]; then
skip_all "no XDG_RUNTIME_DIR for uid $user_uid 'user';" \
"is this really Apertis?"
fi
as_user="sudo -H -u user env XDG_RUNTIME_DIR=/run/user/$user_uid"
;;
(user)
as_root="sudo -H --non-interactive"
as_user=
if [ -e /etc/polkit-1/rules.d/60-apertis-minimal-user.rules ]; then
# assume we don't need sudo here
ribchesterctl="ribchesterctl"
elif ! sudo --non-interactive --validate; then
skip_all "cannot use sudo without password here"