]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: use ${builddir}/systemd-runtest.env for $SYSTEMD_CATALOG_DIR
authorFilipe Brandenburger <filbranden@google.com>
Wed, 12 Sep 2018 07:23:40 +0000 (00:23 -0700)
committerFilipe Brandenburger <filbranden@google.com>
Wed, 12 Sep 2018 16:49:03 +0000 (09:49 -0700)
This makes it so that tests no longer need to know the absolute paths to the
source and build dirs, instead using the systemd-runtest.env file to get these
paths when running from the build tree.

Confirmed that test-catalog works on `ninja test`, when called standalone and
also when the environment file is not present, in which case it will use the
installed location under /usr/lib/systemd/catalog.

The location can now also be overridden for this test by setting the
$SYSTEMD_CATALOG_DIR environment variable.

meson.build
src/journal/test-catalog.c
src/shared/tests.c
src/shared/tests.h
src/test/meson.build

index ed91d1a4dbf895b028c76209358e9ae82c1e8d91..a97c5fcffc3f696dd779366607c1c400fa0bf041 100644 (file)
@@ -207,6 +207,7 @@ conf.set_quoted('SYSTEM_SLEEP_PATH',                          systemsleepdir)
 conf.set_quoted('SYSTEMD_KBD_MODEL_MAP',                      join_paths(pkgdatadir, 'kbd-model-map'))
 conf.set_quoted('SYSTEMD_LANGUAGE_FALLBACK_MAP',              join_paths(pkgdatadir, 'language-fallback-map'))
 conf.set_quoted('SYSTEMD_TEST_DATA',                          join_paths(testsdir, 'testdata'))
+conf.set_quoted('SYSTEMD_CATALOG_DIR',                        catalogdir)
 conf.set_quoted('UDEVLIBEXECDIR',                             udevlibexecdir)
 conf.set_quoted('POLKIT_AGENT_BINARY_PATH',                   join_paths(bindir, 'pkttyagent'))
 conf.set_quoted('LIBDIR',                                     libdir)
@@ -222,8 +223,6 @@ conf.set_quoted('DOCUMENT_ROOT',                              join_paths(pkgdata
 conf.set('MEMORY_ACCOUNTING_DEFAULT',                         memory_accounting_default ? 'true' : 'false')
 conf.set_quoted('MEMORY_ACCOUNTING_DEFAULT_YES_NO',           memory_accounting_default ? 'yes' : 'no')
 
-conf.set_quoted('ABS_BUILD_DIR',                              meson.build_root())
-
 substs.set('prefix',                                          prefixdir)
 substs.set('exec_prefix',                                     prefixdir)
 substs.set('libdir',                                          libdir)
@@ -2612,6 +2611,7 @@ custom_target(
         output : 'systemd-runtest.env',
         command : ['sh', '-c', '{ ' +
                    'echo SYSTEMD_TEST_DATA=@0@; '.format(join_paths(meson.current_source_dir(), 'test')) +
+                   'echo SYSTEMD_CATALOG_DIR=@0@; '.format(join_paths(meson.current_build_dir(), 'catalog')) +
                    '} >@OUTPUT@'],
         build_by_default : true)
 
index 0c4da29f3129fed22dba92cf263d6ca8c32476bf..d9ee557b9c4a036b8f13190605d4cd06871d5e1d 100644 (file)
@@ -212,11 +212,7 @@ int main(int argc, char *argv[]) {
 
         /* 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);
+        catalog_dirs = STRV_MAKE(get_catalog_dir());
 
         assert_se(access(catalog_dirs[0], F_OK) >= 0);
         log_notice("Using catalog directory '%s'", catalog_dirs[0]);
index ac11f5191be3c3a3304e3e9dcf5e07a80786f6fb..94f4629b1b8b69cbcf97e6b478af49e223be5dc6 100644 (file)
@@ -44,12 +44,6 @@ static void load_testdata_env(void) {
                 setenv(*k, *v, 0);
 }
 
-bool test_is_running_from_builddir(char **exedir) {
-        load_testdata_env();
-
-        return !!getenv("SYSTEMD_TEST_DATA");
-}
-
 const char* get_testdata_dir(void) {
         const char *env;
 
@@ -66,3 +60,19 @@ const char* get_testdata_dir(void) {
 
         return env;
 }
+
+const char* get_catalog_dir(void) {
+        const char *env;
+
+        load_testdata_env();
+
+        /* if the env var is set, use that */
+        env = getenv("SYSTEMD_CATALOG_DIR");
+        if (!env)
+                env = SYSTEMD_CATALOG_DIR;
+        if (access(env, F_OK) < 0) {
+                fprintf(stderr, "ERROR: $SYSTEMD_CATALOG_DIR directory [%s] does not exist\n", env);
+                exit(EXIT_FAILURE);
+        }
+        return env;
+}
index da4155ee1702fe16f4f9712bcc5c57d6b279198b..0d5e6a8386ab4438a1121c5d32eaefc53c562ef5 100644 (file)
@@ -2,5 +2,5 @@
 #pragma once
 
 char* setup_fake_runtime_dir(void);
-bool test_is_running_from_builddir(char **exedir);
 const char* get_testdata_dir(void);
+const char* get_catalog_dir(void);
index 3f91c250a5e1ab40c50df569daf0cd02dc0c7d08..e82c993ab4d6b471c06bf60ed266886b3d17870a 100644 (file)
@@ -756,8 +756,7 @@ tests += [
           libshared],
          [threads,
           libxz,
-          liblz4],
-         '', '', '-DCATALOG_DIR="@0@"'.format(catalogdir)],
+          liblz4]],
 
         [['src/journal/test-compress.c'],
          [libjournal_core,