ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
4cad4c
From e73aa709bff2eb5c4649ed7c7055f29ca42f52aa Mon Sep 17 00:00:00 2001
4cad4c
From: Filipe Brandenburger <filbranden@google.com>
4cad4c
Date: Tue, 11 Sep 2018 23:15:09 -0700
4cad4c
Subject: [PATCH] test: remove support for suffix in get_testdata_dir()
4cad4c
4cad4c
Instead, use path_join() in callers wherever needed.
4cad4c
4cad4c
(cherry picked from commit 55890a40c3ec0c061c04d1395a38c26313132d12)
4cad4c
4cad4c
Related: #1763435
4cad4c
---
4cad4c
 src/resolve/test-dns-packet.c    |  5 ++++-
4cad4c
 src/shared/tests.c               |  4 +---
4cad4c
 src/shared/tests.h               |  2 +-
4cad4c
 src/test/test-bpf.c              |  2 +-
4cad4c
 src/test/test-cgroup-mask.c      |  2 +-
4cad4c
 src/test/test-engine.c           |  2 +-
4cad4c
 src/test/test-execute.c          |  3 ++-
4cad4c
 src/test/test-journal-importer.c | 10 ++++++++--
4cad4c
 src/test/test-path.c             |  5 ++++-
4cad4c
 src/test/test-sched-prio.c       |  2 +-
4cad4c
 src/test/test-umount.c           | 18 ++++++++++++++----
4cad4c
 src/test/test-watch-pid.c        |  2 +-
4cad4c
 12 files changed, 39 insertions(+), 18 deletions(-)
4cad4c
4cad4c
diff --git a/src/resolve/test-dns-packet.c b/src/resolve/test-dns-packet.c
4cad4c
index 905f000dc2..0dac05e7be 100644
4cad4c
--- a/src/resolve/test-dns-packet.c
4cad4c
+++ b/src/resolve/test-dns-packet.c
4cad4c
@@ -12,6 +12,7 @@
4cad4c
 #include "macro.h"
4cad4c
 #include "resolved-dns-packet.h"
4cad4c
 #include "resolved-dns-rr.h"
4cad4c
+#include "path-util.h"
4cad4c
 #include "string-util.h"
4cad4c
 #include "strv.h"
4cad4c
 #include "tests.h"
4cad4c
@@ -92,6 +93,7 @@ static void test_packet_from_file(const char* filename, bool canonical) {
4cad4c
 
4cad4c
 int main(int argc, char **argv) {
4cad4c
         int i, N;
4cad4c
+        _cleanup_free_ char *pkts_glob = NULL;
4cad4c
         _cleanup_globfree_ glob_t g = {};
4cad4c
         char **fnames;
4cad4c
 
4cad4c
@@ -101,7 +103,8 @@ int main(int argc, char **argv) {
4cad4c
                 N = argc - 1;
4cad4c
                 fnames = argv + 1;
4cad4c
         } else {
4cad4c
-                assert_se(glob(get_testdata_dir("/test-resolve/*.pkts"), GLOB_NOSORT, NULL, &g) == 0);
4cad4c
+                pkts_glob = path_join(NULL, get_testdata_dir(), "test-resolve/*.pkts");
4cad4c
+                assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0);
4cad4c
                 N = g.gl_pathc;
4cad4c
                 fnames = g.gl_pathv;
4cad4c
         }
4cad4c
diff --git a/src/shared/tests.c b/src/shared/tests.c
4cad4c
index c77eb00924..100b62b9b0 100644
4cad4c
--- a/src/shared/tests.c
4cad4c
+++ b/src/shared/tests.c
4cad4c
@@ -37,7 +37,7 @@ bool test_is_running_from_builddir(char **exedir) {
4cad4c
         return r;
4cad4c
 }
4cad4c
 
4cad4c
-const char* get_testdata_dir(const char *suffix) {
4cad4c
+const char* get_testdata_dir(void) {
4cad4c
         const char *env;
4cad4c
         /* convenience: caller does not need to free result */
4cad4c
         static char testdir[PATH_MAX];
4cad4c
@@ -61,14 +61,12 @@ const char* get_testdata_dir(const char *suffix) {
4cad4c
                         /* Try relative path, according to the install-test layout */
4cad4c
                         assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", exedir) > 0);
4cad4c
 
4cad4c
-                /* test this without the suffix, as it may contain a glob */
4cad4c
                 if (access(testdir, F_OK) < 0) {
4cad4c
                         fputs("ERROR: Cannot find testdata directory, set $SYSTEMD_TEST_DATA\n", stderr);
4cad4c
                         exit(EXIT_FAILURE);
4cad4c
                 }
4cad4c
         }
4cad4c
 
4cad4c
-        strncpy(testdir + strlen(testdir), suffix, sizeof(testdir) - strlen(testdir) - 1);
4cad4c
         return testdir;
4cad4c
 }
4cad4c
 
4cad4c
diff --git a/src/shared/tests.h b/src/shared/tests.h
4cad4c
index 7f45c32d32..3d696d02fd 100644
4cad4c
--- a/src/shared/tests.h
4cad4c
+++ b/src/shared/tests.h
4cad4c
@@ -3,5 +3,5 @@
4cad4c
 
4cad4c
 char* setup_fake_runtime_dir(void);
4cad4c
 bool test_is_running_from_builddir(char **exedir);
4cad4c
-const char* get_testdata_dir(const char *suffix);
4cad4c
+const char* get_testdata_dir(void);
4cad4c
 void test_setup_logging(int level);
4cad4c
diff --git a/src/test/test-bpf.c b/src/test/test-bpf.c
4cad4c
index 4d89bd46d3..6f4a22a1cc 100644
4cad4c
--- a/src/test/test-bpf.c
4cad4c
+++ b/src/test/test-bpf.c
4cad4c
@@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
4cad4c
                 return EXIT_TEST_SKIP;
4cad4c
         }
4cad4c
 
4cad4c
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
4cad4c
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
4cad4c
         assert_se(runtime_dir = setup_fake_runtime_dir());
4cad4c
 
4cad4c
         r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, &p);
4cad4c
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
4cad4c
index 93c3f5d856..ed2d810dd6 100644
4cad4c
--- a/src/test/test-cgroup-mask.c
4cad4c
+++ b/src/test/test-cgroup-mask.c
4cad4c
@@ -26,7 +26,7 @@ static int test_cgroup_mask(void) {
4cad4c
         }
4cad4c
 
4cad4c
         /* Prepare the manager. */
4cad4c
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
4cad4c
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
4cad4c
         assert_se(runtime_dir = setup_fake_runtime_dir());
4cad4c
         r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
4cad4c
         if (IN_SET(r, -EPERM, -EACCES)) {
4cad4c
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
4cad4c
index d072a15cb1..0f3e244dc1 100644
4cad4c
--- a/src/test/test-engine.c
4cad4c
+++ b/src/test/test-engine.c
4cad4c
@@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
4cad4c
         }
4cad4c
 
4cad4c
         /* prepare the test */
4cad4c
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
4cad4c
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
4cad4c
         assert_se(runtime_dir = setup_fake_runtime_dir());
4cad4c
         r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
4cad4c
         if (MANAGER_SKIP_TEST(r)) {
4cad4c
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
4cad4c
index 882e866ea9..294f8fe7dd 100644
4cad4c
--- a/src/test/test-execute.c
4cad4c
+++ b/src/test/test-execute.c
4cad4c
@@ -815,7 +815,8 @@ int main(int argc, char *argv[]) {
4cad4c
         }
4cad4c
 
4cad4c
         assert_se(runtime_dir = setup_fake_runtime_dir());
4cad4c
-        assert_se(set_unit_path(get_testdata_dir("/test-execute")) >= 0);
4cad4c
+        test_execute_path = path_join(NULL, get_testdata_dir(), "test-execute");
4cad4c
+        assert_se(set_unit_path(test_execute_path) >= 0);
4cad4c
 
4cad4c
         /* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test
4cad4c
          * cases, otherwise (and if they are present in the environment),
4cad4c
diff --git a/src/test/test-journal-importer.c b/src/test/test-journal-importer.c
4cad4c
index 56bf6a1296..8f09d5ad2f 100644
4cad4c
--- a/src/test/test-journal-importer.c
4cad4c
+++ b/src/test/test-journal-importer.c
4cad4c
@@ -4,8 +4,10 @@
4cad4c
 #include <sys/stat.h>
4cad4c
 #include <fcntl.h>
4cad4c
 
4cad4c
+#include "alloc-util.h"
4cad4c
 #include "log.h"
4cad4c
 #include "journal-importer.h"
4cad4c
+#include "path-util.h"
4cad4c
 #include "string-util.h"
4cad4c
 #include "tests.h"
4cad4c
 
4cad4c
@@ -20,9 +22,11 @@ static void assert_iovec_entry(const struct iovec *iovec, const char* content) {
4cad4c
 
4cad4c
 static void test_basic_parsing(void) {
4cad4c
         _cleanup_(journal_importer_cleanup) JournalImporter imp = {};
4cad4c
+        _cleanup_free_ char *journal_data_path = NULL;
4cad4c
         int r;
4cad4c
 
4cad4c
-        imp.fd = open(get_testdata_dir("/journal-data/journal-1.txt"), O_RDONLY|O_CLOEXEC);
4cad4c
+        journal_data_path = path_join(NULL, get_testdata_dir(), "journal-data/journal-1.txt");
4cad4c
+        imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
4cad4c
         assert_se(imp.fd >= 0);
4cad4c
 
4cad4c
         do
4cad4c
@@ -49,9 +53,11 @@ static void test_basic_parsing(void) {
4cad4c
 
4cad4c
 static void test_bad_input(void) {
4cad4c
         _cleanup_(journal_importer_cleanup) JournalImporter imp = {};
4cad4c
+        _cleanup_free_ char *journal_data_path = NULL;
4cad4c
         int r;
4cad4c
 
4cad4c
-        imp.fd = open(get_testdata_dir("/journal-data/journal-2.txt"), O_RDONLY|O_CLOEXEC);
4cad4c
+        journal_data_path = path_join(NULL, get_testdata_dir(), "journal-data/journal-2.txt");
4cad4c
+        imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
4cad4c
         assert_se(imp.fd >= 0);
4cad4c
 
4cad4c
         do
4cad4c
diff --git a/src/test/test-path.c b/src/test/test-path.c
4cad4c
index 3a1469ae02..faae142696 100644
4cad4c
--- a/src/test/test-path.c
4cad4c
+++ b/src/test/test-path.c
4cad4c
@@ -12,6 +12,7 @@
4cad4c
 #include "macro.h"
4cad4c
 #include "manager.h"
4cad4c
 #include "mkdir.h"
4cad4c
+#include "path-util.h"
4cad4c
 #include "rm-rf.h"
4cad4c
 #include "string-util.h"
4cad4c
 #include "strv.h"
4cad4c
@@ -247,6 +248,7 @@ int main(int argc, char *argv[]) {
4cad4c
         };
4cad4c
 
4cad4c
         _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
4cad4c
+        _cleanup_free_ char *test_path = NULL;
4cad4c
         const test_function_t *test = NULL;
4cad4c
         Manager *m = NULL;
4cad4c
 
4cad4c
@@ -255,7 +257,8 @@ int main(int argc, char *argv[]) {
4cad4c
         log_parse_environment();
4cad4c
         log_open();
4cad4c
 
4cad4c
-        assert_se(set_unit_path(get_testdata_dir("/test-path")) >= 0);
4cad4c
+        test_path = path_join(NULL, get_testdata_dir(), "test-path");
4cad4c
+        assert_se(set_unit_path(test_path) >= 0);
4cad4c
         assert_se(runtime_dir = setup_fake_runtime_dir());
4cad4c
 
4cad4c
         for (test = tests; test && *test; test++) {
4cad4c
diff --git a/src/test/test-sched-prio.c b/src/test/test-sched-prio.c
4cad4c
index c986284155..60012e47d2 100644
4cad4c
--- a/src/test/test-sched-prio.c
4cad4c
+++ b/src/test/test-sched-prio.c
4cad4c
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
4cad4c
         }
4cad4c
 
4cad4c
         /* prepare the test */
4cad4c
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
4cad4c
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
4cad4c
         assert_se(runtime_dir = setup_fake_runtime_dir());
4cad4c
         r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
4cad4c
         if (MANAGER_SKIP_TEST(r)) {
4cad4c
diff --git a/src/test/test-umount.c b/src/test/test-umount.c
4cad4c
index 770d1a73c8..c068f7a0f0 100644
4cad4c
--- a/src/test/test-umount.c
4cad4c
+++ b/src/test/test-umount.c
4cad4c
@@ -1,6 +1,8 @@
4cad4c
 /* SPDX-License-Identifier: LGPL-2.1+ */
4cad4c
 
4cad4c
+#include "alloc-util.h"
4cad4c
 #include "log.h"
4cad4c
+#include "path-util.h"
4cad4c
 #include "string-util.h"
4cad4c
 #include "tests.h"
4cad4c
 #include "umount.h"
4cad4c
@@ -8,10 +10,14 @@
4cad4c
 
4cad4c
 static void test_mount_points_list(const char *fname) {
4cad4c
         _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
4cad4c
+        _cleanup_free_ char *testdata_fname = NULL;
4cad4c
         MountPoint *m;
4cad4c
 
4cad4c
         log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
4cad4c
 
4cad4c
+        if (fname)
4cad4c
+                fname = testdata_fname = path_join(NULL, get_testdata_dir(), fname);
4cad4c
+
4cad4c
         LIST_HEAD_INIT(mp_list_head);
4cad4c
         assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
4cad4c
 
4cad4c
@@ -26,10 +32,14 @@ static void test_mount_points_list(const char *fname) {
4cad4c
 
4cad4c
 static void test_swap_list(const char *fname) {
4cad4c
         _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
4cad4c
+        _cleanup_free_ char *testdata_fname = NULL;
4cad4c
         MountPoint *m;
4cad4c
 
4cad4c
         log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
4cad4c
 
4cad4c
+        if (fname)
4cad4c
+                fname = testdata_fname = path_join(NULL, get_testdata_dir(), fname);
4cad4c
+
4cad4c
         LIST_HEAD_INIT(mp_list_head);
4cad4c
         assert_se(swap_list_get(fname, &mp_list_head) >= 0);
4cad4c
 
4cad4c
@@ -48,10 +58,10 @@ int main(int argc, char **argv) {
4cad4c
         log_open();
4cad4c
 
4cad4c
         test_mount_points_list(NULL);
4cad4c
-        test_mount_points_list(get_testdata_dir("/test-umount/empty.mountinfo"));
4cad4c
-        test_mount_points_list(get_testdata_dir("/test-umount/garbled.mountinfo"));
4cad4c
-        test_mount_points_list(get_testdata_dir("/test-umount/rhbug-1554943.mountinfo"));
4cad4c
+        test_mount_points_list("/test-umount/empty.mountinfo");
4cad4c
+        test_mount_points_list("/test-umount/garbled.mountinfo");
4cad4c
+        test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
4cad4c
 
4cad4c
         test_swap_list(NULL);
4cad4c
-        test_swap_list(get_testdata_dir("/test-umount/example.swaps"));
4cad4c
+        test_swap_list("/test-umount/example.swaps");
4cad4c
 }
4cad4c
diff --git a/src/test/test-watch-pid.c b/src/test/test-watch-pid.c
4cad4c
index 8c70175aed..d6e2886dde 100644
4cad4c
--- a/src/test/test-watch-pid.c
4cad4c
+++ b/src/test/test-watch-pid.c
4cad4c
@@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
4cad4c
                 return EXIT_TEST_SKIP;
4cad4c
         }
4cad4c
 
4cad4c
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
4cad4c
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
4cad4c
         assert_se(runtime_dir = setup_fake_runtime_dir());
4cad4c
 
4cad4c
         assert_se(manager_new(UNIT_FILE_USER, true, &m) >= 0);