anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0405-test-remove-support-for-suffix-in-get_testdata_dir.patch

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