summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2016-04-27 21:23:42 +0200
committerAlexander Larsson <alexl@redhat.com>2016-04-27 21:23:42 +0200
commit327f432219e767ac4f651dfa6b08ba030ec6e3e1 (patch)
treeec7ed45510e1a522553a5447e69b4de55f7d571e /tests
parent3d3ebf814dc714a06793696bb21190fa2815ebca (diff)
downloadxdg-app-327f432219e767ac4f651dfa6b08ba030ec6e3e1.tar.gz
tests: Add a basic test that just runs an app
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am.inc11
-rw-r--r--tests/libtest.sh141
-rwxr-xr-xtests/make-test-app.sh2
-rwxr-xr-xtests/make-test-runtime.sh9
-rwxr-xr-xtests/test-basic.sh38
-rw-r--r--tests/xdg-app-valgrind.supp199
6 files changed, 398 insertions, 2 deletions
diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc
index c05eee6..bf707d9 100644
--- a/tests/Makefile.am.inc
+++ b/tests/Makefile.am.inc
@@ -36,6 +36,17 @@ test_doc_portal_DEPENDENCIES = tests/services/org.freedesktop.portal.Documents.s
check_PROGRAMS += $(TEST_PROGS)
+installed_test_data = \
+ tests/libtest.sh \
+ tests/make-test-app.sh \
+ tests/make-test-runtime.sh \
+ tests/make-test-bundles.sh \
+ $(NULL)
+
+test_scripts = \
+ tests/test-basic.sh \
+ $(NULL)
+
test_programs = testdb test-doc-portal
@VALGRIND_CHECK_RULES@
diff --git a/tests/libtest.sh b/tests/libtest.sh
new file mode 100644
index 0000000..cd05180
--- /dev/null
+++ b/tests/libtest.sh
@@ -0,0 +1,141 @@
+# Source library for shell script tests
+#
+# Copyright (C) 2016 Alexander Larsson <alexl@redhat.com>
+# Copyright (C) 2011 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+if [ -n "${G_TEST_SRCDIR:-}" ]; then
+ test_srcdir="${G_TEST_SRCDIR}/tests"
+else
+ test_srcdir=$(dirname $0)
+fi
+
+if [ -n "${G_TEST_BUILDDIR:-}" ]; then
+ test_builddir="${G_TEST_BUILDDIR}/tests"
+else
+ test_builddir=$(dirname $0)
+fi
+
+assert_not_reached () {
+ echo $@ 1>&2; exit 1
+}
+
+test_tmpdir=$(pwd)
+
+# Sanity check that we're in a tmpdir that has
+# just .testtmp (created by tap-driver for `make check`,
+# or nothing at all (as ginstest-runner does)
+if ! test -f .testtmp; then
+ files=$(ls)
+ if test -n "${files}"; then
+ ls -l
+ assert_not_reached "test tmpdir=${test_tmpdir} is not empty; run this test via \`make check TESTS=\`, not directly"
+ fi
+ # Remember that this is an acceptable test $(pwd), for the benefit of
+ # C and JS tests which may source this file again
+ touch .testtmp
+fi
+
+export G_DEBUG=fatal-warnings
+
+# Also, unbreak `tar` inside `make check`...Automake will inject
+# TAR_OPTIONS: --owner=0 --group=0 --numeric-owner presumably so that
+# tarballs are predictable, except we don't want this in our tests.
+unset TAR_OPTIONS
+
+if test -n "${OT_TESTS_DEBUG:-}"; then
+ set -x
+fi
+
+if test -n "${OT_TESTS_VALGRIND:-}"; then
+ CMD_PREFIX="env G_SLICE=always-malloc valgrind -q --leak-check=full --num-callers=30 --suppressions=${test_srcdir}/xdg-app-valgrind.supp"
+else
+ CMD_PREFIX=""
+fi
+
+export XDG_DATA_HOME=${test_tmpdir}/share
+
+export XDG_APP="${CMD_PREFIX} xdg-app"
+
+assert_streq () {
+ test "$1" = "$2" || (echo 1>&2 "$1 != $2"; exit 1)
+}
+
+assert_not_streq () {
+ (! test "$1" = "$2") || (echo 1>&2 "$1 == $2"; exit 1)
+}
+
+assert_has_file () {
+ test -f "$1" || (echo 1>&2 "Couldn't find '$1'"; exit 1)
+}
+
+assert_has_dir () {
+ test -d "$1" || (echo 1>&2 "Couldn't find '$1'"; exit 1)
+}
+
+assert_not_has_file () {
+ if test -f "$1"; then
+ sed -e 's/^/# /' < "$1" >&2
+ echo 1>&2 "File '$1' exists"
+ exit 1
+ fi
+}
+
+assert_not_file_has_content () {
+ if grep -q -e "$2" "$1"; then
+ sed -e 's/^/# /' < "$1" >&2
+ echo 1>&2 "File '$1' incorrectly matches regexp '$2'"
+ exit 1
+ fi
+}
+
+assert_not_has_dir () {
+ if test -d "$1"; then
+ echo 1>&2 "Directory '$1' exists"; exit 1
+ fi
+}
+
+assert_file_has_content () {
+ if ! grep -q -e "$2" "$1"; then
+ sed -e 's/^/# /' < "$1" >&2
+ echo 1>&2 "File '$1' doesn't match regexp '$2'"
+ exit 1
+ fi
+}
+
+assert_file_empty() {
+ if test -s "$1"; then
+ sed -e 's/^/# /' < "$1" >&2
+ echo 1>&2 "File '$1' is not empty"
+ exit 1
+ fi
+}
+
+setup_repo () {
+ . $(dirname $0)/make-test-runtime.sh
+ . $(dirname $0)/make-test-app.sh
+ xdg-app remote-add --user --no-gpg-verify repo repo
+}
+
+install_repo () {
+ ${XDG_APP} --user install repo org.test.Platform master
+ ${XDG_APP} --user install repo org.test.Hello master
+}
+
+run () {
+ ${CMD_PREFIX} xdg-app run "$@"
+}
diff --git a/tests/make-test-app.sh b/tests/make-test-app.sh
index 594902d..b5bce5a 100755
--- a/tests/make-test-app.sh
+++ b/tests/make-test-app.sh
@@ -31,7 +31,7 @@ gzip -c > ${DIR}/files/share/app-info/xmls/org.test.Hello.xml.gz <<EOF
</component>
</components>
EOF
-cp org.test.Hello.png ${DIR}/files/share/app-info/icons/xdg-app/64x64/
+cp $(dirname $0)/org.test.Hello.png ${DIR}/files/share/app-info/icons/xdg-app/64x64/
xdg-app build-finish --command=hello.sh ${DIR}
xdg-app build-export repo ${DIR}
diff --git a/tests/make-test-runtime.sh b/tests/make-test-runtime.sh
index b9c23b2..500649f 100755
--- a/tests/make-test-runtime.sh
+++ b/tests/make-test-runtime.sh
@@ -11,10 +11,17 @@ sed -i s/Application/Runtime/ ${DIR}/metadata
mkdir -p ${DIR}/usr/bin
mkdir -p ${DIR}/usr/lib
ln -s ../lib ${DIR}/usr/lib64
+ln -s ../lib ${DIR}/usr/lib32
BASH=`which bash`
+LS=`which ls`
+CAT=`which cat`
+ECHO=`which echo`
cp ${BASH} ${DIR}/usr/bin
+cp ${LS} ${DIR}/usr/bin
+cp ${CAT} ${DIR}/usr/bin
+cp ${ECHO} ${DIR}/usr/bin
ln -s bash ${DIR}/usr/bin/sh
-for i in `ldd ${BASH} | sed "s/.* => //" | awk '{ print $1}' | grep ^/`; do
+for i in `ldd ${BASH} ${LS} ${CAT} ${ECHO} | sed "s/.* => //" | awk '{ print $1}' | grep -v :$ | grep ^/ | sort -u`; do
cp "$i" ${DIR}/usr/lib/
done
diff --git a/tests/test-basic.sh b/tests/test-basic.sh
new file mode 100755
index 0000000..f2add78
--- /dev/null
+++ b/tests/test-basic.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Copyright (C) 2011 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+set -euo pipefail
+
+. $(dirname $0)/libtest.sh
+
+echo "1..2"
+
+${XDG_APP} --version > version_out
+
+assert_file_has_content version_out '^xdg-app '
+
+echo "ok version"
+
+setup_repo
+install_repo
+
+run org.test.Hello > hello_out
+assert_file_has_content hello_out '^Hello world, from a sandbox$'
+
+echo "ok hello"
diff --git a/tests/xdg-app-valgrind.supp b/tests/xdg-app-valgrind.supp
new file mode 100644
index 0000000..00efd87
--- /dev/null
+++ b/tests/xdg-app-valgrind.supp
@@ -0,0 +1,199 @@
+{
+ g_type_init_with_debug_flags calloc
+ Memcheck:Leak
+ fun:calloc
+ ...
+ fun:g_type_init_with_debug_flags
+ ...
+}
+
+{
+ g_type_add_interface_static malloc
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_type_add_interface_static
+ ...
+}
+
+{
+ g_type_add_interface_dynamic malloc
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_type_add_interface_dynamic
+ ...
+}
+
+{
+ g_type_class_ref malloc
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_type_class_ref
+ ...
+}
+
+{
+ g_type_register_dynamic malloc
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_type_register_dynamic
+ ...
+}
+
+{
+ g_type_init_with_debug_flags malloc
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_type_init_with_debug_flags
+ ...
+}
+
+{
+ g_type_init_with_debug_flags realloc
+ Memcheck:Leak
+ fun:realloc
+ ...
+ fun:g_type_init_with_debug_flags
+ ...
+}
+
+{
+ g_test_add_vtable malloc
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_test_add_vtable
+ ...
+}
+
+{
+ g_test_init
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_test_init
+ ...
+}
+
+{
+ g_type_register_static malloc
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_type_register_static
+ ...
+}
+
+{
+ g_type_register_static realloc
+ Memcheck:Leak
+ fun:realloc
+ ...
+ fun:g_type_register_static
+ ...
+}
+
+{
+ g_type_register_fundamental never freed
+ Memcheck:Leak
+ fun:malloc
+ ...
+ fun:g_type_register_fundamental
+ ...
+}
+
+{
+ g_type_class_ref never finalized
+ Memcheck:Leak
+ fun:calloc
+ ...
+ fun:g_type_class_ref
+ ...
+}
+
+{
+ DBusGValue qdata
+ Memcheck:Leak
+ fun:realloc
+ fun:g_realloc
+ fun:g_type_set_qdata
+ fun:_dbus_g_value_types_init
+ ...
+}
+
+{
+ gettext conditional jump
+ Memcheck:Cond
+ fun:__GI___strcasecmp_l
+ fun:__gconv_open
+ fun:_nl_find_msg
+ fun:__dcigettext
+ ...
+}
+
+{
+ gettext uninitialized value
+ Memcheck:Value8
+ fun:__GI___strcasecmp_l
+ fun:__gconv_open
+ fun:_nl_find_msg
+ fun:__dcigettext
+ ...
+}
+
+{
+ font config invalid reads
+ Memcheck:Addr4
+ ...
+ fun:FcConfigParseAndLoad
+ ...
+}
+
+{
+ dynamic loader conditional jump
+ Memcheck:Cond
+ fun:index
+ fun:expand_dynamic_string_token
+ fun:_dl_map_object
+ fun:map_doit
+ fun:_dl_catch_error
+ fun:do_preload
+ fun:dl_main
+ ...
+}
+
+{
+ g_vfs_get_local
+ Memcheck:Leak
+ ...
+ fun:g_vfs_get_local
+ ...
+}
+
+{
+ _g_io_modules_ensure_loaded
+ Memcheck:Leak
+ ...
+ fun:_g_io_modules_ensure_loaded
+ ...
+}
+
+{
+ _g_io_module_get_default
+ Memcheck:Leak
+ ...
+ fun:_g_io_module_get_default
+ ...
+}
+
+{
+ _dl_allocate_tls
+ Memcheck:Leak
+ ...
+ fun:_dl_allocate_tls
+ ...
+}