From: Lennart Poettering Date: Wed, 21 Jun 2023 13:02:59 +0000 (+0200) Subject: tests: teach tests boilerplate to run selected tests only X-Git-Tag: v254-rc1~141 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1a83e41ae985bd17056b3a9fe285cc196358183;p=thirdparty%2Fsystemd.git tests: teach tests boilerplate to run selected tests only sometimes its useful to only run a specific test (or multiple) instead of all implemented in a test. Allow the test name(s) to be specified on the in a $TESTFUNCS env var, separated by colons. --- diff --git a/src/shared/tests.h b/src/shared/tests.h index cabd659fbdf..6b870266617 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -8,6 +8,7 @@ #include "argv-util.h" #include "macro.h" #include "static-destruct.h" +#include "strv.h" static inline bool manager_errno_skip_test(int r) { return IN_SET(abs(r), @@ -83,13 +84,27 @@ extern const TestFunc _weak_ __stop_SYSTEMD_TEST_TABLE[]; static int test_##name(void) static inline int run_test_table(void) { + _cleanup_strv_free_ char **tests = NULL; int r = EXIT_SUCCESS; + bool ran = false; + const char *e; if (!__start_SYSTEMD_TEST_TABLE) return r; - const TestFunc *t = ALIGN_PTR(__start_SYSTEMD_TEST_TABLE); - while (t < __stop_SYSTEMD_TEST_TABLE) { + e = getenv("TESTFUNCS"); + if (e) { + r = strv_split_full(&tests, e, ":", EXTRACT_DONT_COALESCE_SEPARATORS); + if (r < 0) + return log_error_errno(r, "Failed to parse $TESTFUNCS: %m"); + } + + for (const TestFunc *t = ALIGN_PTR(__start_SYSTEMD_TEST_TABLE); + t + 1 <= __stop_SYSTEMD_TEST_TABLE; + t = ALIGN_PTR(t + 1)) { + + if (tests && !strv_contains(tests, t->name)) + continue; if (t->sd_booted && sd_booted() <= 0) { log_info("/* systemd not booted, skipping %s */", t->name); @@ -106,9 +121,12 @@ static inline int run_test_table(void) { t->f.void_func(); } - t = ALIGN_PTR(t + 1); + ran = true; } + if (!ran) + return log_error_errno(SYNTHETIC_ERRNO(ENXIO), "No matching tests found."); + return r; }