Source: gcab Version: 1.2-3 Severity: wishlist Tags: patch upstream I've developed a patch to install gcab's regression tests for as-installed testing, which can be used from the autopkgtest framework as an easy way to get test coverage.
This requires some upstream changes, which were accepted at <https://gitlab.gnome.org/GNOME/gcab/merge_requests/2>, followed by some corresponding Debian packaging changes. The cleanest implementation is to produce a new package named libgcab-tests or similar, which would need to go through binary-NEW - that's the approach taken in packages like clutter-1.0, dbus, glib2.0 and systemd, and in the attached patch. If you would prefer not to do that, another possibility would be to bundle the tests into some suitable other package, for example libgcab-dev. To avoid breaking multiarch co-installability, if you choose to put the tests in the -dev package they would have to be installed into /usr/lib/${DEB_HOST_MULTIARCH}, similar to these WIP commits in cogl: https://salsa.debian.org/gnome-team/cogl/commit/0ee41cb7e37c177e4accc148a351d18824ba2a11 https://salsa.debian.org/gnome-team/cogl/commit/33ad10fe0b2a62b153d2fa7977bd6a188959e5c8 The patch attached depends on the other autopkgtest (for the -dev package) that I proposed on #939222, but should be easy to disentangle if you don't want the -dev test. smcv
>From cda5f38ee6cc709bddae9e5d45ec378f078ff377 Mon Sep 17 00:00:00 2001 From: Simon McVittie <[email protected]> Date: Mon, 2 Sep 2019 09:19:54 +0100 Subject: [PATCH] Install and run gcab-self-test as an "as-installed" test This is particularly useful as a way to check for regressions triggered by changes to gcab's dependencies, which might either be bugs in gcab itself or in those dependencies. - d/p/self-test-Use-g_test_message-instead-of-printing-to-stdou.patch: Avoid corrupting structured output on stdout - d/p/self-test-Optionally-install-for-as-installed-testing.patch: Alter the upstream build system to be able to install the test - d/p/do-not-use-path-max.patch: Drop patch, superseded by installed-test changes --- debian/control | 14 ++ debian/libgcab-tests.install | 2 + debian/patches/do-not-use-path-max.patch | 22 --- ...lly-install-for-as-installed-testing.patch | 136 ++++++++++++++++++ ...message-instead-of-printing-to-stdou.patch | 47 ++++++ debian/patches/series | 3 +- debian/rules | 7 + debian/tests/control | 5 + debian/tests/installed-tests | 9 ++ 9 files changed, 222 insertions(+), 23 deletions(-) create mode 100644 debian/libgcab-tests.install delete mode 100644 debian/patches/do-not-use-path-max.patch create mode 100644 debian/patches/self-test-Optionally-install-for-as-installed-testing.patch create mode 100644 debian/patches/self-test-Use-g_test_message-instead-of-printing-to-stdou.patch create mode 100755 debian/tests/installed-tests diff --git a/debian/control b/debian/control index eb012c9..c7dcb01 100644 --- a/debian/control +++ b/debian/control @@ -68,6 +68,20 @@ Description: Microsoft Cabinet file manipulation library - documentation . This package contains the documentation. +Package: libgcab-tests +Architecture: any +Section: misc +Depends: ${misc:Depends}, + ${shlibs:Depends} +Recommends: gnome-desktop-testing +Description: Microsoft Cabinet file manipulation library - as-installed tests + libgcab provides functions to manipulate cabinet (.cab) files, + both for reading and writing their contents. + . + This package contains automated tests, mostly for use via autopkgtest. + They can most easily be invoked via the gnome-desktop-testing-runner + tool in the gnome-desktop-testing package. + Package: gir1.2-gcab-1.0 Architecture: any Multi-Arch: same diff --git a/debian/libgcab-tests.install b/debian/libgcab-tests.install new file mode 100644 index 0000000..e2a2951 --- /dev/null +++ b/debian/libgcab-tests.install @@ -0,0 +1,2 @@ +usr/libexec/installed-tests +usr/share/installed-tests diff --git a/debian/patches/do-not-use-path-max.patch b/debian/patches/do-not-use-path-max.patch deleted file mode 100644 index 9331c25..0000000 --- a/debian/patches/do-not-use-path-max.patch +++ /dev/null @@ -1,22 +0,0 @@ -Description: Avoid PATH_MAX -Author: Paul Sonnenschein <[email protected]> -Bug-Debian: 888640 - ---- a/tests/gcab-self-test.c -+++ b/tests/gcab-self-test.c -@@ -30,13 +30,10 @@ - gcab_test_get_filename (const gchar *filename) - { - gchar *tmp; -- char full_tmp[PATH_MAX]; - g_autofree gchar *path = NULL; - path = g_build_filename (TESTDATADIR, filename, NULL); -- tmp = realpath (path, full_tmp); -- if (tmp != NULL) -- return g_strdup (full_tmp); -- return NULL; -+ tmp = realpath (path, NULL); -+ return tmp; - } - - static void diff --git a/debian/patches/self-test-Optionally-install-for-as-installed-testing.patch b/debian/patches/self-test-Optionally-install-for-as-installed-testing.patch new file mode 100644 index 0000000..0210656 --- /dev/null +++ b/debian/patches/self-test-Optionally-install-for-as-installed-testing.patch @@ -0,0 +1,136 @@ +From: Simon McVittie <[email protected]> +Date: Mon, 2 Sep 2019 10:01:43 +0100 +Subject: self-test: Optionally install for as-installed testing + +This follows the interface proposed in +https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests and can +be used for "as-installed" testing, which is a useful way to check for +regressions (for example if a GLib upgrade might cause a regression in +the already-compiled version of gcab), especially in frameworks like +Debian's autopkgtest and Fedora's Standard Test Interface. + +To locate the test data in a way that is compatible with as-installed +tests, use g_test_build_filename() instead of hard-coding the source +directory into the test executable. This incidentally also avoids relying +on PATH_MAX, which is not completely portable. + +Signed-off-by: Simon McVittie <[email protected]> +Forwarded: https://gitlab.gnome.org/GNOME/gcab/merge_requests/2 +Applied-upstream: 1.3, commit:48e80eacb9eef0654ad9694603bf5ba58f567c68 +--- + meson.build | 1 - + meson_options.txt | 1 + + tests/gcab-self-test.c | 9 +-------- + tests/meson.build | 44 +++++++++++++++++++++++++++++++++++++++++++- + tests/template-tap.test.in | 4 ++++ + 5 files changed, 49 insertions(+), 10 deletions(-) + create mode 100644 tests/template-tap.test.in + +diff --git a/meson.build b/meson.build +index f98e09a..b24b121 100644 +--- a/meson.build ++++ b/meson.build +@@ -107,7 +107,6 @@ conf.set_quoted('PACKAGE_NAME', meson.project_name()) + conf.set_quoted('PACKAGE_STRING', package_string) + conf.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir'))) + conf.set_quoted('PACKAGE_BUGREPORT', 'https://bugzilla.gnome.org/enter_bug.cgi?product=msitools&component=gcab') +-conf.set_quoted('TESTDATADIR', join_paths(meson.source_root(), 'tests')) + configure_file( + output : 'config.h', + configuration : conf +diff --git a/meson_options.txt b/meson_options.txt +index bbcbbea..77b3c4c 100644 +--- a/meson_options.txt ++++ b/meson_options.txt +@@ -1,3 +1,4 @@ + option('docs', type : 'boolean', value : true, description : 'enable developer documentation') + option('introspection', type : 'boolean', value : true, description : 'generate GObject Introspection data') + option('tests', type : 'boolean', value : true, description : 'enable tests') ++option('installed_tests', type : 'boolean', value : false, description : 'install tests for "as-installed" testing') +diff --git a/tests/gcab-self-test.c b/tests/gcab-self-test.c +index 66a4778..746d069 100644 +--- a/tests/gcab-self-test.c ++++ b/tests/gcab-self-test.c +@@ -29,14 +29,7 @@ + static gchar * + gcab_test_get_filename (const gchar *filename) + { +- gchar *tmp; +- char full_tmp[PATH_MAX]; +- g_autofree gchar *path = NULL; +- path = g_build_filename (TESTDATADIR, filename, NULL); +- tmp = realpath (path, full_tmp); +- if (tmp != NULL) +- return g_strdup (full_tmp); +- return NULL; ++ return g_test_build_filename (G_TEST_DIST, filename, NULL); + } + + static void +diff --git a/tests/meson.build b/tests/meson.build +index d9be63c..1e46e2a 100644 +--- a/tests/meson.build ++++ b/tests/meson.build +@@ -1,3 +1,40 @@ ++installed_tests_metadir = join_paths(get_option('datadir'), 'installed-tests', 'libgcab-1.0') ++installed_tests_execdir = join_paths(get_option('libexecdir'), 'installed-tests', 'libgcab-1.0') ++installed_tests_enabled = get_option('installed_tests') ++installed_tests_template_tap = files('template-tap.test.in') ++abs_installed_tests_execdir = join_paths(get_option('prefix'), installed_tests_execdir) ++ ++if installed_tests_enabled ++ install_data( ++ 'CVE-2014-9556.cab', ++ 'CVE-2014-9732.cab', ++ 'CVE-2015-4470.cab', ++ 'CVE-2015-4471.cab', ++ 'privkey.pem', ++ 'test-mszip.cab', ++ 'test-ncbytes-overflow.cab', ++ 'test-none.cab', ++ 'test-signed.cab', ++ install_dir : installed_tests_execdir, ++ ) ++ install_data( ++ 'src/test.sh', ++ 'src/test.txt', ++ install_dir : join_paths(installed_tests_execdir, 'src'), ++ ) ++ ++ test_conf = configuration_data() ++ test_conf.set('installed_tests_dir', abs_installed_tests_execdir) ++ test_conf.set('program', 'gcab-self-test') ++ test_conf.set('env', '') ++ configure_file( ++ input : installed_tests_template_tap, ++ output : 'gcab-self-test.test', ++ install_dir : installed_tests_metadir, ++ configuration : test_conf, ++ ) ++endif ++ + e = executable( + 'gcab-self-test', + sources : [ +@@ -16,5 +53,10 @@ e = executable( + link_with : [ + libgcab, + ], ++ install : installed_tests_enabled, ++ install_dir : installed_tests_execdir, + ) +-test('gcab-self-test', e) ++env = environment() ++env.set('G_TEST_SRCDIR', meson.current_source_dir()) ++env.set('G_TEST_BUILDDIR', meson.current_build_dir()) ++test('gcab-self-test', e, env : env) +diff --git a/tests/template-tap.test.in b/tests/template-tap.test.in +new file mode 100644 +index 0000000..30cd166 +--- /dev/null ++++ b/tests/template-tap.test.in +@@ -0,0 +1,4 @@ ++[Test] ++Type=session ++Exec=@env@@installed_tests_dir@/@program@ --tap ++Output=TAP diff --git a/debian/patches/self-test-Use-g_test_message-instead-of-printing-to-stdou.patch b/debian/patches/self-test-Use-g_test_message-instead-of-printing-to-stdou.patch new file mode 100644 index 0000000..fce1a94 --- /dev/null +++ b/debian/patches/self-test-Use-g_test_message-instead-of-printing-to-stdou.patch @@ -0,0 +1,47 @@ +From: Simon McVittie <[email protected]> +Date: Mon, 2 Sep 2019 10:46:52 +0100 +Subject: self-test: Use g_test_message instead of printing to stdout + +GLib now defaults to structured TAP output on stdout, and printing +unstructured messages to stdout corrupts this. In a TAP test, arbitrary +diagnostics can either use g_test_message() or a GLib logging function +like g_debug(), or be printed to stderr with g_printerr(). + +Signed-off-by: Simon McVittie <[email protected]> +Forwarded: https://gitlab.gnome.org/GNOME/gcab/merge_requests/2 +Applied-upstream: 1.3, commit:a57e5d66e9f2625b627f49779c03d4018015378a +--- + tests/gcab-self-test.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/tests/gcab-self-test.c b/tests/gcab-self-test.c +index aee690b..66a4778 100644 +--- a/tests/gcab-self-test.c ++++ b/tests/gcab-self-test.c +@@ -365,7 +365,7 @@ gcab_test_cabinet_load_func (void) + }; + + /* read file */ +- g_print ("%s... ", tests[i].fn); ++ g_test_message ("%s... ", tests[i].fn); + fn = gcab_test_get_filename (tests[i].fn); + g_assert (fn != NULL); + file = g_file_new_for_path (fn); +@@ -446,7 +446,7 @@ gcab_test_cabinet_error_cves_func (void) + g_autoptr(GInputStream) in = NULL; + + /* read file */ +- g_print ("%s... ", tests[i]); ++ g_test_message ("%s... ", tests[i]); + fn = gcab_test_get_filename (tests[i]); + g_assert (fn != NULL); + file = g_file_new_for_path (fn); +@@ -557,7 +557,7 @@ gcab_test_cabinet_write_func (void) + } + + /* write the file */ +- g_print ("%s... ", tests[i].fn); ++ g_test_message ("%s... ", tests[i].fn); + fn_out = g_build_filename ("/tmp", tests[i].fn, NULL); + file_out = g_file_new_for_path (fn_out); + op = G_OUTPUT_STREAM (g_file_replace (file_out, NULL, FALSE, 0, NULL, &error)); diff --git a/debian/patches/series b/debian/patches/series index 8ecd949..b38734f 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,5 +1,6 @@ manpage-hyphens.patch zalloc_integer_overflow.patch no-git-version.patch -do-not-use-path-max.patch overflow.patch +self-test-Use-g_test_message-instead-of-printing-to-stdou.patch +self-test-Optionally-install-for-as-installed-testing.patch diff --git a/debian/rules b/debian/rules index d1afa0f..478a9b9 100755 --- a/debian/rules +++ b/debian/rules @@ -5,6 +5,13 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all %: dh $@ --with gir +override_dh_auto_configure: + dh_auto_configure \ + -- \ + -Dinstalled_tests=true \ + --libexecdir=libexec \ + ${NULL} + override_dh_install: dh_install -X.la -X.pyc -X.pyo diff --git a/debian/tests/control b/debian/tests/control index 93d2696..fa2967f 100644 --- a/debian/tests/control +++ b/debian/tests/control @@ -1,3 +1,8 @@ +Tests: installed-tests +Depends: gnome-desktop-testing, + libgcab-tests +Restrictions: allow-stderr + Tests: libgcab-dev Depends: build-essential, libgcab-dev, diff --git a/debian/tests/installed-tests b/debian/tests/installed-tests new file mode 100755 index 0000000..68309ff --- /dev/null +++ b/debian/tests/installed-tests @@ -0,0 +1,9 @@ +#!/bin/sh + +set -eu + +if [ -z "${HOME-}" ] || ! [ -w "${HOME}" ]; then + export HOME="${AUTOPKGTEST_TMP}" +fi + +exec gnome-desktop-testing-runner libgcab-1.0 -- 2.23.0

