summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2020-03-30 16:25:12 +0200
committerGitHub <noreply@github.com>2020-03-30 16:25:12 +0200
commit15529f5cea0ea60d1202994e5950a31e2b4916e7 (patch)
tree3e3122e3d851337fd3d9903a2547a1b4798864a3 /src/test
parentci: turn off FuzzBuzz (diff)
parenttest: print test of name in output (diff)
downloadsystemd-15529f5cea0ea60d1202994e5950a31e2b4916e7.tar.xz
systemd-15529f5cea0ea60d1202994e5950a31e2b4916e7.zip
Merge pull request #14338 from keszybz/functional-test-rework
Functional test rework
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-bpf-firewall.c4
-rw-r--r--src/test/test-cgroup-mask.c4
-rw-r--r--src/test/test-cgroup-unit-default.c4
-rw-r--r--src/test/test-engine.c5
-rw-r--r--src/test/test-execute.c6
-rw-r--r--src/test/test-fileio.c16
-rw-r--r--src/test/test-journal-importer.c4
-rw-r--r--src/test/test-path.c2
-rw-r--r--src/test/test-sched-prio.c5
-rw-r--r--src/test/test-umount.c12
-rw-r--r--src/test/test-watch-pid.c5
11 files changed, 43 insertions, 24 deletions
diff --git a/src/test/test-bpf-firewall.c b/src/test/test-bpf-firewall.c
index fbaa349b45..71aed12558 100644
--- a/src/test/test-bpf-firewall.c
+++ b/src/test/test-bpf-firewall.c
@@ -48,7 +48,9 @@ int main(int argc, char *argv[]) {
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);
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
index 02c8549b4b..daafba4ef6 100644
--- a/src/test/test-cgroup-mask.c
+++ b/src/test/test-cgroup-mask.c
@@ -38,7 +38,9 @@ static int test_cgroup_mask(void) {
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)) {
diff --git a/src/test/test-cgroup-unit-default.c b/src/test/test-cgroup-unit-default.c
index 1286f11e4e..372667041c 100644
--- a/src/test/test-cgroup-unit-default.c
+++ b/src/test/test-cgroup-unit-default.c
@@ -22,7 +22,9 @@ static int test_default_memory_low(void) {
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)) {
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
index b8351141fe..6465151b27 100644
--- a/src/test/test-engine.c
+++ b/src/test/test-engine.c
@@ -26,8 +26,11 @@ int main(int argc, char *argv[]) {
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");
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
index 4e0fd7d5b4..5a96b46a77 100644
--- a/src/test/test-execute.c
+++ b/src/test/test-execute.c
@@ -806,7 +806,6 @@ static int run_tests(UnitFileScope scope, const test_entry tests[], char **patte
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),
@@ -878,9 +877,10 @@ int main(int argc, char *argv[]) {
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),
diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c
index 23c7d370d4..32a00349ac 100644
--- a/src/test/test-fileio.c
+++ b/src/test/test-fileio.c
@@ -444,20 +444,20 @@ static void test_write_string_file_verify(void) {
_cleanup_free_ char *buf = NULL, *buf2 = NULL;
int r;
- assert_se(read_one_line_file("/proc/cmdline", &buf) >= 0);
+ assert_se(read_one_line_file("/proc/version", &buf) >= 0);
assert_se(buf2 = strjoin(buf, "\n"));
- r = write_string_file("/proc/cmdline", buf, 0);
+ r = write_string_file("/proc/version", buf, 0);
assert_se(IN_SET(r, -EACCES, -EIO));
- r = write_string_file("/proc/cmdline", buf2, 0);
+ r = write_string_file("/proc/version", buf2, 0);
assert_se(IN_SET(r, -EACCES, -EIO));
- assert_se(write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
- assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
+ assert_se(write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
+ assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE) == 0);
- r = write_string_file("/proc/cmdline", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE);
+ r = write_string_file("/proc/version", buf, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE);
assert_se(IN_SET(r, -EACCES, -EIO));
- assert_se(write_string_file("/proc/cmdline", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
+ assert_se(write_string_file("/proc/version", buf2, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_AVOID_NEWLINE) == 0);
}
static void test_load_env_file_pairs(void) {
@@ -757,7 +757,7 @@ static void test_read_line3(void) {
_cleanup_free_ char *line = NULL;
int r;
- f = fopen("/proc/cmdline", "re");
+ f = fopen("/proc/uptime", "re");
if (!f && IN_SET(errno, ENOENT, EPERM))
return;
assert_se(f);
diff --git a/src/test/test-journal-importer.c b/src/test/test-journal-importer.c
index 7e898735c9..4883356956 100644
--- a/src/test/test-journal-importer.c
+++ b/src/test/test-journal-importer.c
@@ -25,7 +25,7 @@ static void test_basic_parsing(void) {
_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);
@@ -56,7 +56,7 @@ static void test_bad_input(void) {
_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);
diff --git a/src/test/test-path.c b/src/test/test-path.c
index 6ad222b5f9..830d5f261b 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -251,7 +251,7 @@ int main(int argc, char *argv[]) {
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());
diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c
index cd45537847..da6d2a21e6 100644
--- a/src/test/test-sched-prio.c
+++ b/src/test/test-sched-prio.c
@@ -25,8 +25,11 @@ int main(int argc, char *argv[]) {
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");
diff --git a/src/test/test-umount.c b/src/test/test-umount.c
index 6ab5758ede..b27b75b352 100644
--- a/src/test/test-umount.c
+++ b/src/test/test-umount.c
@@ -15,8 +15,10 @@ static void test_mount_points_list(const char *fname) {
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);
@@ -37,8 +39,10 @@ static void test_swap_list(const char *fname) {
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);
diff --git a/src/test/test-watch-pid.c b/src/test/test-watch-pid.c
index bad289767d..28ecffb0c0 100644
--- a/src/test/test-watch-pid.c
+++ b/src/test/test-watch-pid.c
@@ -20,7 +20,10 @@ int main(int argc, char *argv[]) {
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);