Commit 242c96ad authored by Michael Biebl's avatar Michael Biebl
Browse files

test: Use installed catalogs when test-catalog is not located at build dir

This makes it possible to run test-catalog as installed test, so we no
longer need to mark it as EXFAIL in our root-unittests autopkgtest.
parent b3d45c99
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ timedate-increment-reference-count-of-sd_bus_message.patch
timedate-defer-the-property-changed-signal-until-job-of-s.patch
user-runtime-dir-fix-selinux-regression.patch
core-fix-gid-when-DynamicUser-yes-with-static-User.patch
test-introduce-test_is_running_from_builddir.patch
test-make-test-catalog-relocatable.patch
debian/Use-Debian-specific-config-files.patch
debian/Bring-tmpfiles.d-tmp.conf-in-line-with-Debian-defaul.patch
debian/Make-run-lock-tmpfs-an-API-fs.patch
+66 −0
Original line number Diff line number Diff line
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 11 Sep 2018 09:17:22 +0900
Subject: test: introduce test_is_running_from_builddir()

(cherry picked from commit 8cb10a4f4dabc508a04f76ea55f23ef517881b61)
---
 src/shared/tests.c | 23 ++++++++++++++++++++---
 src/shared/tests.h |  1 +
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/shared/tests.c b/src/shared/tests.c
index 6b3df0a..c3704c7 100644
--- a/src/shared/tests.c
+++ b/src/shared/tests.c
@@ -19,6 +19,24 @@ char* setup_fake_runtime_dir(void) {
         return p;
 }
 
+bool test_is_running_from_builddir(char **exedir) {
+        _cleanup_free_ char *s = NULL;
+        bool r;
+
+        /* Check if we're running from the builddir. Optionally, this returns
+         * the path to the directory where the binary is located. */
+
+        assert_se(readlink_and_make_absolute("/proc/self/exe", &s) >= 0);
+        r = path_startswith(s, ABS_BUILD_DIR);
+
+        if (exedir) {
+                dirname(s);
+                *exedir = TAKE_PTR(s);
+        }
+
+        return r;
+}
+
 const char* get_testdata_dir(const char *suffix) {
         const char *env;
         /* convenience: caller does not need to free result */
@@ -35,14 +53,13 @@ const char* get_testdata_dir(const char *suffix) {
                 strncpy(testdir, env, sizeof(testdir) - 1);
         } else {
                 _cleanup_free_ char *exedir = NULL;
-                assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0);
 
                 /* Check if we're running from the builddir. If so, use the compiled in path. */
-                if (path_startswith(exedir, ABS_BUILD_DIR))
+                if (test_is_running_from_builddir(&exedir))
                         assert_se(snprintf(testdir, sizeof(testdir), "%s/test", ABS_SRC_DIR) > 0);
                 else
                         /* Try relative path, according to the install-test layout */
-                        assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", dirname(exedir)) > 0);
+                        assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", exedir) > 0);
 
                 /* test this without the suffix, as it may contain a glob */
                 if (access(testdir, F_OK) < 0) {
diff --git a/src/shared/tests.h b/src/shared/tests.h
index b88135e..c9fa11f 100644
--- a/src/shared/tests.h
+++ b/src/shared/tests.h
@@ -2,4 +2,5 @@
 #pragma once
 
 char* setup_fake_runtime_dir(void);
+bool test_is_running_from_builddir(char **exedir);
 const char* get_testdata_dir(const char *suffix);
+100 −0
Original line number Diff line number Diff line
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 11 Sep 2018 09:18:33 +0900
Subject: test: make test-catalog relocatable

Fixes #10045.

(cherry picked from commit d9b6baa69968132d33e4ad8627c7fe0bd527c859)
---
 catalog/meson.build        |  1 -
 src/journal/test-catalog.c | 27 +++++++++++++++++++--------
 src/test/meson.build       |  2 +-
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/catalog/meson.build b/catalog/meson.build
index 1b13150..3db8e39 100644
--- a/catalog/meson.build
+++ b/catalog/meson.build
@@ -17,7 +17,6 @@ in_files = '''
 
 support_url = get_option('support-url')
 support_sed = 's~%SUPPORT_URL%~@0@~'.format(support_url)
-build_catalog_dir = meson.current_build_dir()
 
 foreach file : in_files
         custom_target(
diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c
index 8eae993..0c4da29 100644
--- a/src/journal/test-catalog.c
+++ b/src/journal/test-catalog.c
@@ -14,14 +14,13 @@
 #include "fileio.h"
 #include "log.h"
 #include "macro.h"
+#include "path-util.h"
 #include "string-util.h"
+#include "strv.h"
+#include "tests.h"
 #include "util.h"
 
-static const char *catalog_dirs[] = {
-        CATALOG_DIR,
-        NULL,
-};
-
+static char** catalog_dirs = NULL;
 static const char *no_catalog_dirs[] = {
         "/bin/hopefully/with/no/catalog",
         NULL
@@ -167,8 +166,8 @@ static void test_catalog_update(const char *database) {
         assert_se(r == 0);
 
         /* Make sure that we at least have some files loaded or the
-           catalog_list below will fail. */
-        r = catalog_update(database, NULL, catalog_dirs);
+         * catalog_list below will fail. */
+        r = catalog_update(database, NULL, (const char * const *) catalog_dirs);
         assert_se(r == 0);
 }
 
@@ -202,14 +201,26 @@ static void test_catalog_file_lang(void) {
 
 int main(int argc, char *argv[]) {
         _cleanup_(unlink_tempfilep) char database[] = "/tmp/test-catalog.XXXXXX";
-        _cleanup_free_ char *text = NULL;
+        _cleanup_free_ char *text = NULL, *catalog_dir = NULL;
         int r;
 
         setlocale(LC_ALL, "de_DE.UTF-8");
 
+        log_set_max_level(LOG_DEBUG);
         log_parse_environment();
         log_open();
 
+        /* If test-catalog is located at the build directory, then use catalogs in that.
+         * If it is not, e.g. installed by systemd-tests package, then use installed catalogs. */
+        if (test_is_running_from_builddir(NULL)) {
+                assert_se(catalog_dir = path_join(NULL, ABS_BUILD_DIR, "catalog"));
+                catalog_dirs = STRV_MAKE(catalog_dir);
+        } else
+                catalog_dirs = STRV_MAKE(CATALOG_DIR);
+
+        assert_se(access(catalog_dirs[0], F_OK) >= 0);
+        log_notice("Using catalog directory '%s'", catalog_dirs[0]);
+
         test_catalog_file_lang();
 
         test_catalog_import_invalid();
diff --git a/src/test/meson.build b/src/test/meson.build
index 7da7e3a..1ef7ac6 100644
--- a/src/test/meson.build
+++ b/src/test/meson.build
@@ -757,7 +757,7 @@ tests += [
          [threads,
           libxz,
           liblz4],
-         '', '', '-DCATALOG_DIR="@0@"'.format(build_catalog_dir)],
+         '', '', '-DCATALOG_DIR="@0@"'.format(catalogdir)],
 
         [['src/journal/test-compress.c'],
          [libjournal_core,
+0 −6
Original line number Diff line number Diff line
@@ -3,12 +3,6 @@ set -eu

EXFAIL=""

# No items in catalog.
# Assertion 'r >= 0' failed at ../src/journal/test-catalog.c:252, function main(). Aborting.
EXFAIL="$EXFAIL
test-catalog
"

res=0
for t in /usr/lib/systemd/tests/test-*; do
    tname=$(basename $t)