We have a bazillion of those unit files, and keeping them all directly in tests/
has become rather unwieldy.
int main(int argc, char **argv) {
int i, N;
- _cleanup_free_ char *pkts_glob = NULL;
_cleanup_globfree_ glob_t g = {};
char **fnames;
N = argc - 1;
fnames = argv + 1;
} else {
- pkts_glob = path_join(get_testdata_dir(), "test-resolve/*.pkts");
+ _cleanup_free_ char *pkts_glob = NULL;
+ assert_se(get_testdata_dir("test-resolve/*.pkts", &pkts_glob) >= 0);
assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0);
N = g.gl_pathc;
fnames = g.gl_pathv;
setenv(*k, *v, 0);
}
-const char* get_testdata_dir(void) {
- const char *env;
+int get_testdata_dir(const char *suffix, char **ret) {
+ const char *dir;
+ char *p;
load_testdata_env();
/* if the env var is set, use that */
- env = getenv("SYSTEMD_TEST_DATA");
- if (!env)
- env = SYSTEMD_TEST_DATA;
- if (access(env, F_OK) < 0) {
- fprintf(stderr, "ERROR: $SYSTEMD_TEST_DATA directory [%s] does not exist\n", env);
- exit(EXIT_FAILURE);
- }
+ dir = getenv("SYSTEMD_TEST_DATA");
+ if (!dir)
+ dir = SYSTEMD_TEST_DATA;
+ if (access(dir, F_OK) < 0)
+ return log_error_errno(errno, "ERROR: $SYSTEMD_TEST_DATA directory [%s] not accesible: %m", dir);
- return env;
+ p = path_join(dir, suffix);
+ if (!p)
+ return log_oom();
+
+ *ret = p;
+ return 0;
}
const char* get_catalog_dir(void) {
char* setup_fake_runtime_dir(void);
int enter_cgroup_subroot(char **ret_cgroup);
-const char* get_testdata_dir(void);
+int get_testdata_dir(const char *suffix, char **ret);
const char* get_catalog_dir(void);
bool slow_tests_enabled(void);
void test_setup_logging(int level);
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
- assert_se(set_unit_path(get_testdata_dir()) >= 0);
+ _cleanup_free_ char *unit_dir = NULL;
+ assert_se(get_testdata_dir("units", &unit_dir) >= 0);
+ assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, &p);
return log_tests_skipped("cgroupfs not available");
/* Prepare the manager. */
- assert_se(set_unit_path(get_testdata_dir()) >= 0);
+ _cleanup_free_ char *unit_dir = NULL;
+ assert_se(get_testdata_dir("units", &unit_dir) >= 0);
+ assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (IN_SET(r, -EPERM, -EACCES)) {
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
- assert_se(set_unit_path(get_testdata_dir()) >= 0);
+ _cleanup_free_ char *unit_dir = NULL;
+ assert_se(get_testdata_dir("units", &unit_dir) >= 0);
+ assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (IN_SET(r, -EPERM, -EACCES)) {
return log_tests_skipped("cgroupfs not available");
/* prepare the test */
- assert_se(set_unit_path(get_testdata_dir()) >= 0);
+ _cleanup_free_ char *unit_dir = NULL;
+ assert_se(get_testdata_dir("units", &unit_dir) >= 0);
+ assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
+
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (manager_errno_skip_test(r))
return log_tests_skipped_errno(r, "manager_new");
int main(int argc, char *argv[]) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
- _cleanup_free_ char *test_execute_path = NULL;
static const test_entry user_tests[] = {
entry(test_exec_basic),
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
+ _cleanup_free_ char *unit_dir = NULL;
+ assert_se(get_testdata_dir("test-execute/", &unit_dir) >= 0);
+ assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
- test_execute_path = path_join(get_testdata_dir(), "test-execute");
- assert_se(set_unit_path(test_execute_path) >= 0);
/* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
* cases, otherwise (and if they are present in the environment),
_cleanup_free_ char *journal_data_path = NULL;
int r;
- journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-1.txt");
+ assert_se(get_testdata_dir("journal-data/journal-1.txt", &journal_data_path) >= 0);
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);
_cleanup_free_ char *journal_data_path = NULL;
int r;
- journal_data_path = path_join(get_testdata_dir(), "journal-data/journal-2.txt");
+ assert_se(get_testdata_dir("journal-data/journal-1.txt", &journal_data_path) >= 0);
imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
assert_se(imp.fd >= 0);
test_setup_logging(LOG_INFO);
- test_path = path_join(get_testdata_dir(), "test-path");
+ assert_se(get_testdata_dir("test-path", &test_path) >= 0);
assert_se(set_unit_path(test_path) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
return log_tests_skipped("cgroupfs not available");
/* prepare the test */
- assert_se(set_unit_path(get_testdata_dir()) >= 0);
+ _cleanup_free_ char *unit_dir = NULL;
+ assert_se(get_testdata_dir("units", &unit_dir) >= 0);
+ assert_se(set_unit_path(unit_dir) >= 0);
assert_se(runtime_dir = setup_fake_runtime_dir());
+
r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
if (manager_errno_skip_test(r))
return log_tests_skipped_errno(r, "manager_new");
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
- if (fname)
- fname = testdata_fname = path_join(get_testdata_dir(), fname);
+ if (fname) {
+ assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
+ fname = testdata_fname;
+ }
LIST_HEAD_INIT(mp_list_head);
assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
- if (fname)
- fname = testdata_fname = path_join(get_testdata_dir(), fname);
+ if (fname) {
+ assert_se(get_testdata_dir(fname, &testdata_fname) >= 0);
+ fname = testdata_fname;
+ }
LIST_HEAD_INIT(mp_list_head);
assert_se(swap_list_get(fname, &mp_list_head) >= 0);
if (r == -ENOMEDIUM)
return log_tests_skipped("cgroupfs not available");
- assert_se(set_unit_path(get_testdata_dir()) >= 0);
+ _cleanup_free_ char *unit_dir = NULL;
+ assert_se(get_testdata_dir("units/", &unit_dir) >= 0);
+ assert_se(set_unit_path(unit_dir) >= 0);
+
assert_se(runtime_dir = setup_fake_runtime_dir());
assert_se(manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m) >= 0);
+++ /dev/null
-../units/basic.target
\ No newline at end of file
# SPDX-License-Identifier: LGPL-2.1+
test_data_files = '''
- a.service
- a-conj.service
- b.service
- basic.target
- c.service
- d.service
- daughter.service
- dml.slice
- dml-passthrough.slice
- dml-passthrough-empty.service
- dml-passthrough-set-dml.service
- dml-passthrough-set-ml.service
- dml-override.slice
- dml-override-empty.service
- dml-discard.slice
- dml-discard-empty.service
- dml-discard-set-ml.service
- e.service
- end.service
- f.service
- g.service
- grandchild.service
- h.service
- hello-after-sleep.target
- hello.service
- hwdb.d/10-bad.hwdb
- i.service
journal-data/journal-1.txt
journal-data/journal-2.txt
- nomem.slice
- nomemleaf.service
- parent-deep.slice
- parent.slice
- sched_idle_bad.service
- sched_idle_ok.service
- sched_rr_bad.service
- sched_rr_change.service
- sched_rr_ok.service
- shutdown.target
- sleep.service
- sockets.target
- son.service
- sysinit.target
test-execute/exec-basic.service
test-execute/exec-ambientcapabilities-merge-nfsnobody.service
test-execute/exec-ambientcapabilities-merge-nobody.service
test-umount/example.swaps
test-umount/garbled.mountinfo
test-umount/rhbug-1554943.mountinfo
- testsuite.target
- timers.target
- unit-with-.service.d/20-override.conf
- unit-with-multiple-.service.d/20-override.conf
- unit-with-multiple-.service.d/30-override.conf
- unit-with-multiple-dashes.service
- unit-with-multiple-dashes.service.d/10-override.conf
- unstoppable.service
'''.split()
if conf.get('ENABLE_RESOLVE') == 1
endforeach
endif
+install_subdir(
+ 'units',
+ install_dir : testsdir + '/testdata/')
+
############################################################
rule_syntax_check_py = find_program('rule-syntax-check.py')
+++ /dev/null
-../units/shutdown.target
\ No newline at end of file
+++ /dev/null
-../units/sockets.target
\ No newline at end of file
+++ /dev/null
-../units/sysinit.target
\ No newline at end of file
+++ /dev/null
-../units/timers.target
\ No newline at end of file
--- /dev/null
+../../units/basic.target
\ No newline at end of file
--- /dev/null
+../../units/shutdown.target
\ No newline at end of file
--- /dev/null
+../../units/sockets.target
\ No newline at end of file
--- /dev/null
+../../units/sysinit.target
\ No newline at end of file
--- /dev/null
+../../units/timers.target
\ No newline at end of file