mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-26 08:55:18 +03:00
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.
This commit is contained in:
parent
e2d413707f
commit
49cdae63d1
@ -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)
|
||||
|
||||
|
@ -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]);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -756,8 +756,7 @@ tests += [
|
||||
libshared],
|
||||
[threads,
|
||||
libxz,
|
||||
liblz4],
|
||||
'', '', '-DCATALOG_DIR="@0@"'.format(catalogdir)],
|
||||
liblz4]],
|
||||
|
||||
[['src/journal/test-compress.c'],
|
||||
[libjournal_core,
|
||||
|
Loading…
Reference in New Issue
Block a user