]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: remove support for suffix in get_testdata_dir()
authorFilipe Brandenburger <filbranden@google.com>
Wed, 12 Sep 2018 06:15:09 +0000 (23:15 -0700)
committerFilipe Brandenburger <filbranden@google.com>
Wed, 12 Sep 2018 16:49:03 +0000 (09:49 -0700)
Instead, use path_join() in callers wherever needed.

12 files changed:
src/resolve/test-dns-packet.c
src/shared/tests.c
src/shared/tests.h
src/test/test-bpf.c
src/test/test-cgroup-mask.c
src/test/test-engine.c
src/test/test-execute.c
src/test/test-journal-importer.c
src/test/test-path.c
src/test/test-sched-prio.c
src/test/test-umount.c
src/test/test-watch-pid.c

index 905f000dc2bb29a7dedcab9abff667b2d7697620..0dac05e7bed6cb327899f4be7b611ba8f7b17274 100644 (file)
@@ -12,6 +12,7 @@
 #include "macro.h"
 #include "resolved-dns-packet.h"
 #include "resolved-dns-rr.h"
+#include "path-util.h"
 #include "string-util.h"
 #include "strv.h"
 #include "tests.h"
@@ -92,6 +93,7 @@ static void test_packet_from_file(const char* filename, bool canonical) {
 
 int main(int argc, char **argv) {
         int i, N;
+        _cleanup_free_ char *pkts_glob = NULL;
         _cleanup_globfree_ glob_t g = {};
         char **fnames;
 
@@ -101,7 +103,8 @@ int main(int argc, char **argv) {
                 N = argc - 1;
                 fnames = argv + 1;
         } else {
-                assert_se(glob(get_testdata_dir("/test-resolve/*.pkts"), GLOB_NOSORT, NULL, &g) == 0);
+                pkts_glob = path_join(NULL, get_testdata_dir(), "test-resolve/*.pkts");
+                assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0);
                 N = g.gl_pathc;
                 fnames = g.gl_pathv;
         }
index c3704c743fd5b46784147c026f98cddb3deaafd5..a002260439030197de8dd3846562646377f9dc49 100644 (file)
@@ -37,7 +37,7 @@ bool test_is_running_from_builddir(char **exedir) {
         return r;
 }
 
-const char* get_testdata_dir(const char *suffix) {
+const char* get_testdata_dir(void) {
         const char *env;
         /* convenience: caller does not need to free result */
         static char testdir[PATH_MAX];
@@ -61,13 +61,11 @@ const char* get_testdata_dir(const char *suffix) {
                         /* Try relative path, according to the install-test layout */
                         assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", exedir) > 0);
 
-                /* test this without the suffix, as it may contain a glob */
                 if (access(testdir, F_OK) < 0) {
                         fputs("ERROR: Cannot find testdata directory, set $SYSTEMD_TEST_DATA\n", stderr);
                         exit(EXIT_FAILURE);
                 }
         }
 
-        strncpy(testdir + strlen(testdir), suffix, sizeof(testdir) - strlen(testdir) - 1);
         return testdir;
 }
index c9fa11fb6a42bb42076b43f2b9a3800e7c57ff4e..da4155ee1702fe16f4f9712bcc5c57d6b279198b 100644 (file)
@@ -3,4 +3,4 @@
 
 char* setup_fake_runtime_dir(void);
 bool test_is_running_from_builddir(char **exedir);
-const char* get_testdata_dir(const char *suffix);
+const char* get_testdata_dir(void);
index 4d89bd46d33abbde5781c9bc3ee27149a97b2e55..6f4a22a1ccc9616af91968287927233618d40717 100644 (file)
@@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
                 return EXIT_TEST_SKIP;
         }
 
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
         assert_se(runtime_dir = setup_fake_runtime_dir());
 
         r = bpf_program_new(BPF_PROG_TYPE_CGROUP_SKB, &p);
index d8ee8280de7bb7a31d2b383455f06e1ccf725247..8dc1639720c26468470b51c3d4e7699699bfdd08 100644 (file)
@@ -23,7 +23,7 @@ static int test_cgroup_mask(void) {
         }
 
         /* Prepare the manager. */
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
+        assert_se(set_unit_path(get_testdata_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)) {
index d072a15cb19a500ed1fc51d14958394559bf3875..0f3e244dc1c7bdbd58b612676b83184c504298de 100644 (file)
@@ -29,7 +29,7 @@ int main(int argc, char *argv[]) {
         }
 
         /* prepare the test */
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
         assert_se(runtime_dir = setup_fake_runtime_dir());
         r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
         if (MANAGER_SKIP_TEST(r)) {
index 9ef18bb2114a04c6f9f9278c4f332167a9c7d6e4..b37e6017538e3d46c01de546c1fcc43a7812d160 100644 (file)
@@ -679,6 +679,7 @@ static int run_tests(UnitFileScope scope, const test_function_t *tests) {
 
 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_function_t user_tests[] = {
                 test_exec_basic,
                 test_exec_ambientcapabilities,
@@ -744,7 +745,8 @@ int main(int argc, char *argv[]) {
         }
 
         assert_se(runtime_dir = setup_fake_runtime_dir());
-        assert_se(set_unit_path(get_testdata_dir("/test-execute")) >= 0);
+        test_execute_path = path_join(NULL, 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),
index 56bf6a12969b5f215f46d6c91054b24e9ac2c73f..8f09d5ad2f3d8c7ffab7c756aca00cd807f8018d 100644 (file)
@@ -4,8 +4,10 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#include "alloc-util.h"
 #include "log.h"
 #include "journal-importer.h"
+#include "path-util.h"
 #include "string-util.h"
 #include "tests.h"
 
@@ -20,9 +22,11 @@ static void assert_iovec_entry(const struct iovec *iovec, const char* content) {
 
 static void test_basic_parsing(void) {
         _cleanup_(journal_importer_cleanup) JournalImporter imp = {};
+        _cleanup_free_ char *journal_data_path = NULL;
         int r;
 
-        imp.fd = open(get_testdata_dir("/journal-data/journal-1.txt"), O_RDONLY|O_CLOEXEC);
+        journal_data_path = path_join(NULL, get_testdata_dir(), "journal-data/journal-1.txt");
+        imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
         assert_se(imp.fd >= 0);
 
         do
@@ -49,9 +53,11 @@ static void test_basic_parsing(void) {
 
 static void test_bad_input(void) {
         _cleanup_(journal_importer_cleanup) JournalImporter imp = {};
+        _cleanup_free_ char *journal_data_path = NULL;
         int r;
 
-        imp.fd = open(get_testdata_dir("/journal-data/journal-2.txt"), O_RDONLY|O_CLOEXEC);
+        journal_data_path = path_join(NULL, get_testdata_dir(), "journal-data/journal-2.txt");
+        imp.fd = open(journal_data_path, O_RDONLY|O_CLOEXEC);
         assert_se(imp.fd >= 0);
 
         do
index 209eb2e3662cf748d1f2018ba8a3e7b69b51a71f..5e78a560ffe8135ee6e6d3ddab4e21746ad5be89 100644 (file)
@@ -12,6 +12,7 @@
 #include "macro.h"
 #include "manager.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "rm-rf.h"
 #include "string-util.h"
 #include "strv.h"
@@ -247,6 +248,7 @@ int main(int argc, char *argv[]) {
         };
 
         _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
+        _cleanup_free_ char *test_path = NULL;
         const test_function_t *test = NULL;
         Manager *m = NULL;
 
@@ -255,7 +257,8 @@ int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
 
-        assert_se(set_unit_path(get_testdata_dir("/test-path")) >= 0);
+        test_path = path_join(NULL, get_testdata_dir(), "test-path");
+        assert_se(set_unit_path(test_path) >= 0);
         assert_se(runtime_dir = setup_fake_runtime_dir());
 
         for (test = tests; test && *test; test++) {
index c986284155b3e5257654886efc9eec697adfea7c..60012e47d28818e38d3689891a09b4016c14b5b3 100644 (file)
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
         }
 
         /* prepare the test */
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
         assert_se(runtime_dir = setup_fake_runtime_dir());
         r = manager_new(UNIT_FILE_USER, MANAGER_TEST_RUN_BASIC, &m);
         if (MANAGER_SKIP_TEST(r)) {
index 770d1a73c8677af8bb127ff391e8759dca3f79be..c068f7a0f0db7fac84b58eb1d08bb5d78f6bd730 100644 (file)
@@ -1,6 +1,8 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
+#include "alloc-util.h"
 #include "log.h"
+#include "path-util.h"
 #include "string-util.h"
 #include "tests.h"
 #include "umount.h"
 
 static void test_mount_points_list(const char *fname) {
         _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
+        _cleanup_free_ char *testdata_fname = NULL;
         MountPoint *m;
 
         log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo");
 
+        if (fname)
+                fname = testdata_fname = path_join(NULL, get_testdata_dir(), fname);
+
         LIST_HEAD_INIT(mp_list_head);
         assert_se(mount_points_list_get(fname, &mp_list_head) >= 0);
 
@@ -26,10 +32,14 @@ static void test_mount_points_list(const char *fname) {
 
 static void test_swap_list(const char *fname) {
         _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head);
+        _cleanup_free_ char *testdata_fname = NULL;
         MountPoint *m;
 
         log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps");
 
+        if (fname)
+                fname = testdata_fname = path_join(NULL, get_testdata_dir(), fname);
+
         LIST_HEAD_INIT(mp_list_head);
         assert_se(swap_list_get(fname, &mp_list_head) >= 0);
 
@@ -48,10 +58,10 @@ int main(int argc, char **argv) {
         log_open();
 
         test_mount_points_list(NULL);
-        test_mount_points_list(get_testdata_dir("/test-umount/empty.mountinfo"));
-        test_mount_points_list(get_testdata_dir("/test-umount/garbled.mountinfo"));
-        test_mount_points_list(get_testdata_dir("/test-umount/rhbug-1554943.mountinfo"));
+        test_mount_points_list("/test-umount/empty.mountinfo");
+        test_mount_points_list("/test-umount/garbled.mountinfo");
+        test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
 
         test_swap_list(NULL);
-        test_swap_list(get_testdata_dir("/test-umount/example.swaps"));
+        test_swap_list("/test-umount/example.swaps");
 }
index cb43b35bc5d986e254824232079b4c3ee8e319d4..4e349ab927b5302853b130f7138b22e546f0e65e 100644 (file)
@@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
                 return EXIT_TEST_SKIP;
         }
 
-        assert_se(set_unit_path(get_testdata_dir("")) >= 0);
+        assert_se(set_unit_path(get_testdata_dir()) >= 0);
         assert_se(runtime_dir = setup_fake_runtime_dir());
 
         assert_se(manager_new(UNIT_FILE_USER, true, &m) >= 0);