From a5d70667b224ce065b97acf82db1c011e6a30da0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 7 Sep 2016 12:48:35 +0100 Subject: [PATCH 1/7] test_install_launch_uninstall: consistently check for GError first An assertion failure that says res is FALSE is a lot less useful than an assertion failure that says we got a specific GError. Signed-off-by: Simon McVittie --- tests/testlibrary.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/testlibrary.c b/tests/testlibrary.c index abf5fb6c..06a16250 100644 --- a/tests/testlibrary.c +++ b/tests/testlibrary.c @@ -314,8 +314,8 @@ test_install_launch_uninstall (void) &progress_count, NULL, &error); - g_assert (FLATPAK_IS_INSTALLED_REF (ref)); g_assert_no_error (error); + g_assert (FLATPAK_IS_INSTALLED_REF (ref)); g_assert_cmpint (progress_count, >, 0); quit_id = g_timeout_add (500, quit, NULL); @@ -359,8 +359,8 @@ test_install_launch_uninstall (void) &progress_count, NULL, &error); - g_assert (FLATPAK_IS_INSTALLED_REF (ref)); g_assert_no_error (error); + g_assert (FLATPAK_IS_INSTALLED_REF (ref)); g_assert_cmpint (progress_count, >, 0); quit_id = g_timeout_add (500, quit, loop); @@ -384,8 +384,8 @@ test_install_launch_uninstall (void) g_ptr_array_unref (refs); res = flatpak_installation_launch (inst, "org.test.Hello", NULL, NULL, NULL, NULL, &error); - g_assert_true (res); g_assert_no_error (error); + g_assert_true (res); quit_id = g_timeout_add (500, quit, loop); g_main_loop_run (loop); @@ -402,8 +402,8 @@ test_install_launch_uninstall (void) &progress_count, NULL, &error); - g_assert_true (res); g_assert_no_error (error); + g_assert_true (res); //FIXME: no progress for uninstall //g_assert_cmpint (progress_count, >, 0); @@ -428,8 +428,8 @@ test_install_launch_uninstall (void) &progress_count, NULL, &error); - g_assert_true (res); g_assert_no_error (error); + g_assert_true (res); //FIXME: no progress for uninstall //g_assert_cmpint (progress_count, >, 0); From 1769f8e8dcff34320ff7d7c7900645589d59d73a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 7 Sep 2016 13:30:59 +0100 Subject: [PATCH 2/7] Tell build-time tests which bwrap we are going to use In autobuilder environments that deprive the build of capabilities, it is entirely possible that we have a system bwrap(1) but cannot run it, for example because CAP_SYS_ADMIN has been excluded from the capability bounding set. Tell the tests which bwrap we are going to run, so we can run it in a simpler way and see whether it works. Debian's sbuild autobuilder currently suffers from a different issue in which pivot_root(2) returns EINVAL, possibly caused by sbuild being chroot-based and so not having the mount point structure that is required for pivot_root. This avoids the problematic build-time tests there too; they work on ci.debian.net, which uses lxc instead of chroots, and in virtual machines. Because $(BWRAP) might be non-absolute, we need to search PATH for it. Signed-off-by: Simon McVittie --- tests/Makefile.am.inc | 4 +++- tests/testlibrary.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index ec8e9f2c..2f83c116 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -6,7 +6,9 @@ TESTS_ENVIRONMENT += FLATPAK_TESTS_DEBUG=1 \ PATH=$$(cd $(top_builddir) && pwd):$${PATH} \ $(NULL) -if !WITH_SYSTEM_BWRAP +if WITH_SYSTEM_BWRAP +TESTS_ENVIRONMENT += FLATPAK_BWRAP=$(BWRAP) +else TESTS_ENVIRONMENT += FLATPAK_BWRAP=$$(cd $(top_builddir) && pwd)/flatpak-bwrap endif diff --git a/tests/testlibrary.c b/tests/testlibrary.c index 06a16250..e6baf44c 100644 --- a/tests/testlibrary.c +++ b/tests/testlibrary.c @@ -276,7 +276,7 @@ test_install_launch_uninstall (void) { gint exit_code = 0; char *argv[] = { (char *)bwrap, "--ro-bind", "/", "/", "/bin/true", NULL }; - g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, &exit_code, &error); + g_spawn_sync (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &exit_code, &error); g_assert_no_error (error); if (exit_code != 0) { From 9f52d5044808690661e5760d44770fff114cf256 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 6 Sep 2016 11:10:55 +0100 Subject: [PATCH 3/7] make-test-runtime: cope with Debian's Python 2.7 configuration Signed-off-by: Simon McVittie --- tests/make-test-runtime.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/make-test-runtime.sh b/tests/make-test-runtime.sh index 461d36e8..22031552 100755 --- a/tests/make-test-runtime.sh +++ b/tests/make-test-runtime.sh @@ -33,8 +33,16 @@ for i in $@; do _sysconfigdata ; do cp ${PYDIR}/$py.py ${DIR}/usr/lib/python2.7 done + # These might not exist, depending how Python was configured; and the + # part after ${so} might be "module" or ".x86_64-linux-gnu" or + # something else for so in _locale strop ; do - cp ${PYDIR}/lib-dynload/${so}module.so ${DIR}/usr/lib/python2.7/lib-dynload + cp ${PYDIR}/lib-dynload/${so}*.so ${DIR}/usr/lib/python2.7/lib-dynload || : + done + for plat in $( cd ${PYDIR} && echo plat-* ); do + test -e ${PYDIR}/${plat} || continue + mkdir -p ${DIR}/usr/lib/python2.7/${plat} + cp ${PYDIR}/${plat}/*.py ${DIR}/usr/lib/python2.7/${plat}/ done fi done From 1cdc43c8fac545cc96201cdd6d4cd420157b7c3a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 7 Sep 2016 16:42:08 +0100 Subject: [PATCH 4/7] Make empty-configure executable when it is installed Signed-off-by: Simon McVittie --- tests/Makefile.am.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index 2f83c116..7104abb1 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -74,6 +74,7 @@ tests/test-basic.sh: tests/package_version.txt dist_installed_test_extra_scripts += \ buildutil/tap-driver.sh \ + tests/empty-configure \ tests/test-configure \ tests/make-test-app.sh \ tests/make-test-runtime.sh \ @@ -88,7 +89,6 @@ installed_test_data = \ tests/session.conf.in \ tests/0001-Add-test-logo.patch \ tests/org.test.Python.json \ - tests/empty-configure \ tests/testpython.py \ tests/importme.py \ tests/importme2.py \ From c9a6da7fe5640e3c5c25962caa0fdbd6a73b24bb Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 7 Sep 2016 16:43:27 +0100 Subject: [PATCH 5/7] Use dist_installed_test_data instead of installed_test_data This means we don't have to add it to EXTRA_DIST, and also means we can have generated (non-distributed) test data in future if we want to. Signed-off-by: Simon McVittie --- tests/Makefile.am.inc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index 7104abb1..6531c6cf 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -81,7 +81,7 @@ dist_installed_test_extra_scripts += \ tests/make-test-bundles.sh \ $(NULL) -installed_test_data = \ +dist_installed_test_data = \ tests/libtest.sh \ tests/org.test.Hello.png \ tests/package_version.txt \ @@ -106,8 +106,6 @@ dist_installed_test_keyring_DATA = \ dist_installed_test_dbs_DATA = tests/dbs/no_tables endif -EXTRA_DIST += $(installed_test_data) - dist_test_scripts = \ tests/test-basic.sh \ tests/test-run.sh \ From 0160ed937d9074fd398b65a4bb792f17838b8eda Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 6 Sep 2016 11:20:39 +0100 Subject: [PATCH 6/7] document portal: cope with multiple events that would cause failure If the name is lost *and* the session bus is closed, we would crash with an assertion failure when the GError is overwritten. Signed-off-by: Simon McVittie --- document-portal/xdp-main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/document-portal/xdp-main.c b/document-portal/xdp-main.c index a3bacc0a..8c2c5e47 100644 --- a/document-portal/xdp-main.c +++ b/document-portal/xdp-main.c @@ -972,8 +972,13 @@ on_name_lost (GDBusConnection *connection, gpointer user_data) { g_debug ("%s lost", name); - final_exit_status = 20; - g_set_error (&exit_error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "D-Bus name \"%s\" lost", name); + + if (final_exit_status == 0) + final_exit_status = 20; + + if (exit_error == NULL) + g_set_error (&exit_error, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "D-Bus name \"%s\" lost", name); + g_main_loop_quit (loop); } @@ -991,7 +996,9 @@ session_bus_closed (GDBusConnection *connection, gboolean remote_peer_vanished, GError *bus_error) { - g_set_error (&exit_error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE, "Disconnected from session bus"); + if (exit_error == NULL) + g_set_error (&exit_error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE, "Disconnected from session bus"); + g_main_loop_quit (loop); } From 57bfce9a55a2046e7200e700db775352f8972cf0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 7 Sep 2016 22:07:07 +0100 Subject: [PATCH 7/7] Terminate gpg-agent after using it for tests Signed-off-by: Simon McVittie --- tests/libtest.sh | 1 + tests/make-test-bundles.sh | 2 ++ tests/testlibrary.c | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/tests/libtest.sh b/tests/libtest.sh index cf74760d..6b4414a9 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -264,6 +264,7 @@ fi cleanup () { /bin/kill $DBUS_SESSION_BUS_PID + gpg-connect-agent --homedir "${FL_GPG_HOMEDIR}" killagent /bye || true fusermount -u $XDG_RUNTIME_DIR/doc || : rm -rf $TEST_DATA_DIR } diff --git a/tests/make-test-bundles.sh b/tests/make-test-bundles.sh index fda23135..7b7ea64b 100755 --- a/tests/make-test-bundles.sh +++ b/tests/make-test-bundles.sh @@ -25,3 +25,5 @@ flatpak build-bundle repo --repo-url=${URL} --gpg-keys=test-keyring/pubring.gpg REF=`(cd repo/refs/heads; echo runtime/org.test.Platform/*/master)` ostree gpg-sign --repo=repo --gpg-homedir=test-keyring ${REF} 7B0961FD flatpak build-bundle --runtime repo --repo-url=${URL} --gpg-keys=test-keyring/pubring.gpg platform.flatpak org.test.Platform + +gpg-connect-agent --homedir test-keyring killagent /bye || true diff --git a/tests/testlibrary.c b/tests/testlibrary.c index e6baf44c..6a7db875 100644 --- a/tests/testlibrary.c +++ b/tests/testlibrary.c @@ -668,9 +668,33 @@ global_setup (void) static void global_teardown (void) { + int status; + g_autoptr (GError) error = NULL; + char *argv[] = { "gpg-connect-agent", "--homedir", "", "killagent", "/bye", NULL }; + GSpawnFlags flags = G_SPAWN_SEARCH_PATH; + if (g_getenv ("SKIP_TEARDOWN")) return; + argv[2] = gpg_homedir; + + if (g_test_verbose ()) + { + g_autofree char *commandline = g_strjoinv (" ", argv); + g_print ("running %s\n", commandline); + } + else + { + flags |= G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL; + } + + /* mostly ignore failure here */ + if (!g_spawn_sync (NULL, (char **)argv, NULL, flags, NULL, NULL, NULL, NULL, &status, &error) || + !g_spawn_check_exit_status (status, &error)) + { + g_print ("# failed to run gpg-connect-agent to stop gpg-agent: %s\n", error->message); + } + glnx_shutil_rm_rf_at (-1, testdir, NULL, NULL); g_free (testdir); }