daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
c2dfb7
From ac476ab0ce970e4a269fee34a15e24f6b20962b7 Mon Sep 17 00:00:00 2001
c2dfb7
From: Yu Watanabe <watanabe.yu+github@gmail.com>
c2dfb7
Date: Tue, 11 Sep 2018 09:18:33 +0900
c2dfb7
Subject: [PATCH] test: make test-catalog relocatable
c2dfb7
c2dfb7
Fixes #10045.
c2dfb7
c2dfb7
(cherry picked from commit d9b6baa69968132d33e4ad8627c7fe0bd527c859)
c2dfb7
c2dfb7
Resolves: #1823767
c2dfb7
---
c2dfb7
 catalog/meson.build        |  1 -
c2dfb7
 src/journal/test-catalog.c | 27 +++++++++++++++++++--------
c2dfb7
 src/test/meson.build       |  2 +-
c2dfb7
 3 files changed, 20 insertions(+), 10 deletions(-)
c2dfb7
c2dfb7
diff --git a/catalog/meson.build b/catalog/meson.build
c2dfb7
index 1b13150894..3db8e390f2 100644
c2dfb7
--- a/catalog/meson.build
c2dfb7
+++ b/catalog/meson.build
c2dfb7
@@ -17,7 +17,6 @@ in_files = '''
c2dfb7
 
c2dfb7
 support_url = get_option('support-url')
c2dfb7
 support_sed = 's~%SUPPORT_URL%~@0@~'.format(support_url)
c2dfb7
-build_catalog_dir = meson.current_build_dir()
c2dfb7
 
c2dfb7
 foreach file : in_files
c2dfb7
         custom_target(
c2dfb7
diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c
c2dfb7
index 8eae993780..0c4da29f31 100644
c2dfb7
--- a/src/journal/test-catalog.c
c2dfb7
+++ b/src/journal/test-catalog.c
c2dfb7
@@ -14,14 +14,13 @@
c2dfb7
 #include "fileio.h"
c2dfb7
 #include "log.h"
c2dfb7
 #include "macro.h"
c2dfb7
+#include "path-util.h"
c2dfb7
 #include "string-util.h"
c2dfb7
+#include "strv.h"
c2dfb7
+#include "tests.h"
c2dfb7
 #include "util.h"
c2dfb7
 
c2dfb7
-static const char *catalog_dirs[] = {
c2dfb7
-        CATALOG_DIR,
c2dfb7
-        NULL,
c2dfb7
-};
c2dfb7
-
c2dfb7
+static char** catalog_dirs = NULL;
c2dfb7
 static const char *no_catalog_dirs[] = {
c2dfb7
         "/bin/hopefully/with/no/catalog",
c2dfb7
         NULL
c2dfb7
@@ -167,8 +166,8 @@ static void test_catalog_update(const char *database) {
c2dfb7
         assert_se(r == 0);
c2dfb7
 
c2dfb7
         /* Make sure that we at least have some files loaded or the
c2dfb7
-           catalog_list below will fail. */
c2dfb7
-        r = catalog_update(database, NULL, catalog_dirs);
c2dfb7
+         * catalog_list below will fail. */
c2dfb7
+        r = catalog_update(database, NULL, (const char * const *) catalog_dirs);
c2dfb7
         assert_se(r == 0);
c2dfb7
 }
c2dfb7
 
c2dfb7
@@ -202,14 +201,26 @@ static void test_catalog_file_lang(void) {
c2dfb7
 
c2dfb7
 int main(int argc, char *argv[]) {
c2dfb7
         _cleanup_(unlink_tempfilep) char database[] = "/tmp/test-catalog.XXXXXX";
c2dfb7
-        _cleanup_free_ char *text = NULL;
c2dfb7
+        _cleanup_free_ char *text = NULL, *catalog_dir = NULL;
c2dfb7
         int r;
c2dfb7
 
c2dfb7
         setlocale(LC_ALL, "de_DE.UTF-8");
c2dfb7
 
c2dfb7
+        log_set_max_level(LOG_DEBUG);
c2dfb7
         log_parse_environment();
c2dfb7
         log_open();
c2dfb7
 
c2dfb7
+        /* If test-catalog is located at the build directory, then use catalogs in that.
c2dfb7
+         * If it is not, e.g. installed by systemd-tests package, then use installed catalogs. */
c2dfb7
+        if (test_is_running_from_builddir(NULL)) {
c2dfb7
+                assert_se(catalog_dir = path_join(NULL, ABS_BUILD_DIR, "catalog"));
c2dfb7
+                catalog_dirs = STRV_MAKE(catalog_dir);
c2dfb7
+        } else
c2dfb7
+                catalog_dirs = STRV_MAKE(CATALOG_DIR);
c2dfb7
+
c2dfb7
+        assert_se(access(catalog_dirs[0], F_OK) >= 0);
c2dfb7
+        log_notice("Using catalog directory '%s'", catalog_dirs[0]);
c2dfb7
+
c2dfb7
         test_catalog_file_lang();
c2dfb7
 
c2dfb7
         test_catalog_import_invalid();
c2dfb7
diff --git a/src/test/meson.build b/src/test/meson.build
c2dfb7
index 4259421f98..ead000e30c 100644
c2dfb7
--- a/src/test/meson.build
c2dfb7
+++ b/src/test/meson.build
c2dfb7
@@ -766,7 +766,7 @@ tests += [
c2dfb7
          [threads,
c2dfb7
           libxz,
c2dfb7
           liblz4],
c2dfb7
-         '', '', '-DCATALOG_DIR="@0@"'.format(build_catalog_dir)],
c2dfb7
+         '', '', '-DCATALOG_DIR="@0@"'.format(catalogdir)],
c2dfb7
 
c2dfb7
         [['src/journal/test-compress.c'],
c2dfb7
          [libjournal_core,