From 49cdae63d168b2fe0e19f9f090b90d79de3c39bb Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Wed, 12 Sep 2018 00:23:40 -0700 Subject: [PATCH] test: use ${builddir}/systemd-runtest.env for $SYSTEMD_CATALOG_DIR 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 | 4 ++-- src/journal/test-catalog.c | 6 +----- src/shared/tests.c | 22 ++++++++++++++++------ src/shared/tests.h | 2 +- src/test/meson.build | 3 +-- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/meson.build b/meson.build index ed91d1a4dbf..a97c5fcffc3 100644 --- a/meson.build +++ b/meson.build @@ -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) diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c index 0c4da29f312..d9ee557b9c4 100644 --- a/src/journal/test-catalog.c +++ b/src/journal/test-catalog.c @@ -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]); diff --git a/src/shared/tests.c b/src/shared/tests.c index ac11f5191be..94f4629b1b8 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -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; +} diff --git a/src/shared/tests.h b/src/shared/tests.h index da4155ee170..0d5e6a8386a 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -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); diff --git a/src/test/meson.build b/src/test/meson.build index 3f91c250a5e..e82c993ab4d 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -756,8 +756,7 @@ tests += [ libshared], [threads, libxz, - liblz4], - '', '', '-DCATALOG_DIR="@0@"'.format(catalogdir)], + liblz4]], [['src/journal/test-compress.c'], [libjournal_core,