c2dfb7
From 9beae637a919326ddc072c4dd53cb66e80273c8f Mon Sep 17 00:00:00 2001
c2dfb7
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
c2dfb7
Date: Fri, 15 Mar 2019 13:42:55 +0100
c2dfb7
Subject: [PATCH] test-execute: allow filtering test cases by pattern
c2dfb7
c2dfb7
When debugging failure in one of the cases, it's annoying to have to wade
c2dfb7
through the output from all the other cases. Let's allow picking select
c2dfb7
cases.
c2dfb7
c2dfb7
(cherry picked from commit 9efb96315ae502dabeb94ab35816ea8955563b7a)
c2dfb7
c2dfb7
Related: #1737283
c2dfb7
---
c2dfb7
 src/test/test-execute.c | 104 ++++++++++++++++++++++------------------
c2dfb7
 1 file changed, 58 insertions(+), 46 deletions(-)
c2dfb7
c2dfb7
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
c2dfb7
index d88de52d2a..d077674efc 100644
c2dfb7
--- a/src/test/test-execute.c
c2dfb7
+++ b/src/test/test-execute.c
c2dfb7
@@ -659,8 +659,15 @@ static void test_exec_standardoutput_append(Manager *m) {
c2dfb7
         test(m, "exec-standardoutput-append.service", 0, CLD_EXITED);
c2dfb7
 }
c2dfb7
 
c2dfb7
-static int run_tests(UnitFileScope scope, const test_function_t *tests) {
c2dfb7
-        const test_function_t *test = NULL;
c2dfb7
+typedef struct test_entry {
c2dfb7
+        test_function_t f;
c2dfb7
+        const char *name;
c2dfb7
+} test_entry;
c2dfb7
+
c2dfb7
+#define entry(x) {x, #x}
c2dfb7
+
c2dfb7
+static int run_tests(UnitFileScope scope, const test_entry tests[], char **patterns) {
c2dfb7
+        const test_entry *test = NULL;
c2dfb7
         _cleanup_(manager_freep) Manager *m = NULL;
c2dfb7
         int r;
c2dfb7
 
c2dfb7
@@ -674,55 +681,60 @@ static int run_tests(UnitFileScope scope, const test_function_t *tests) {
c2dfb7
         assert_se(r >= 0);
c2dfb7
         assert_se(manager_startup(m, NULL, NULL) >= 0);
c2dfb7
 
c2dfb7
-        for (test = tests; test && *test; test++)
c2dfb7
-                (*test)(m);
c2dfb7
+        for (test = tests; test && test->f; test++)
c2dfb7
+                if (strv_fnmatch_or_empty(patterns, test->name, FNM_NOESCAPE))
c2dfb7
+                        test->f(m);
c2dfb7
+                else
c2dfb7
+                        log_info("Skipping %s because it does not match any pattern.", test->name);
c2dfb7
 
c2dfb7
         return 0;
c2dfb7
 }
c2dfb7
 
c2dfb7
+
c2dfb7
 int main(int argc, char *argv[]) {
c2dfb7
         _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
c2dfb7
-        static const test_function_t user_tests[] = {
c2dfb7
-                test_exec_basic,
c2dfb7
-                test_exec_ambientcapabilities,
c2dfb7
-                test_exec_bindpaths,
c2dfb7
-                test_exec_capabilityboundingset,
c2dfb7
-                test_exec_cpuaffinity,
c2dfb7
-                test_exec_environment,
c2dfb7
-                test_exec_environmentfile,
c2dfb7
-                test_exec_group,
c2dfb7
-                test_exec_ignoresigpipe,
c2dfb7
-                test_exec_inaccessiblepaths,
c2dfb7
-                test_exec_ioschedulingclass,
c2dfb7
-                test_exec_oomscoreadjust,
c2dfb7
-                test_exec_passenvironment,
c2dfb7
-                test_exec_personality,
c2dfb7
-                test_exec_privatedevices,
c2dfb7
-                test_exec_privatenetwork,
c2dfb7
-                test_exec_privatetmp,
c2dfb7
-                test_exec_protectkernelmodules,
c2dfb7
-                test_exec_readonlypaths,
c2dfb7
-                test_exec_readwritepaths,
c2dfb7
-                test_exec_restrictnamespaces,
c2dfb7
-                test_exec_runtimedirectory,
c2dfb7
-                test_exec_standardinput,
c2dfb7
-                test_exec_standardoutput,
c2dfb7
-                test_exec_standardoutput_append,
c2dfb7
-                test_exec_supplementarygroups,
c2dfb7
-                test_exec_systemcallerrornumber,
c2dfb7
-                test_exec_systemcallfilter,
c2dfb7
-                test_exec_temporaryfilesystem,
c2dfb7
-                test_exec_umask,
c2dfb7
-                test_exec_unsetenvironment,
c2dfb7
-                test_exec_user,
c2dfb7
-                test_exec_workingdirectory,
c2dfb7
-                NULL,
c2dfb7
+        _cleanup_free_ char *test_execute_path = NULL;
c2dfb7
+        static const test_entry user_tests[] = {
c2dfb7
+                entry(test_exec_basic),
c2dfb7
+                entry(test_exec_ambientcapabilities),
c2dfb7
+                entry(test_exec_bindpaths),
c2dfb7
+                entry(test_exec_capabilityboundingset),
c2dfb7
+                entry(test_exec_cpuaffinity),
c2dfb7
+                entry(test_exec_environment),
c2dfb7
+                entry(test_exec_environmentfile),
c2dfb7
+                entry(test_exec_group),
c2dfb7
+                entry(test_exec_ignoresigpipe),
c2dfb7
+                entry(test_exec_inaccessiblepaths),
c2dfb7
+                entry(test_exec_ioschedulingclass),
c2dfb7
+                entry(test_exec_oomscoreadjust),
c2dfb7
+                entry(test_exec_passenvironment),
c2dfb7
+                entry(test_exec_personality),
c2dfb7
+                entry(test_exec_privatedevices),
c2dfb7
+                entry(test_exec_privatenetwork),
c2dfb7
+                entry(test_exec_privatetmp),
c2dfb7
+                entry(test_exec_protectkernelmodules),
c2dfb7
+                entry(test_exec_readonlypaths),
c2dfb7
+                entry(test_exec_readwritepaths),
c2dfb7
+                entry(test_exec_restrictnamespaces),
c2dfb7
+                entry(test_exec_runtimedirectory),
c2dfb7
+                entry(test_exec_standardinput),
c2dfb7
+                entry(test_exec_standardoutput),
c2dfb7
+                entry(test_exec_standardoutput_append),
c2dfb7
+                entry(test_exec_supplementarygroups),
c2dfb7
+                entry(test_exec_systemcallerrornumber),
c2dfb7
+                entry(test_exec_systemcallfilter),
c2dfb7
+                entry(test_exec_temporaryfilesystem),
c2dfb7
+                entry(test_exec_umask),
c2dfb7
+                entry(test_exec_unsetenvironment),
c2dfb7
+                entry(test_exec_user),
c2dfb7
+                entry(test_exec_workingdirectory),
c2dfb7
+                {},
c2dfb7
         };
c2dfb7
-        static const test_function_t system_tests[] = {
c2dfb7
-                test_exec_dynamicuser,
c2dfb7
-                test_exec_specifier,
c2dfb7
-                test_exec_systemcallfilter_system,
c2dfb7
-                NULL,
c2dfb7
+        static const test_entry system_tests[] = {
c2dfb7
+                entry(test_exec_dynamicuser),
c2dfb7
+                entry(test_exec_specifier),
c2dfb7
+                entry(test_exec_systemcallfilter_system),
c2dfb7
+                {},
c2dfb7
         };
c2dfb7
         int r;
c2dfb7
 
c2dfb7
@@ -759,9 +771,9 @@ int main(int argc, char *argv[]) {
c2dfb7
         assert_se(unsetenv("VAR2") == 0);
c2dfb7
         assert_se(unsetenv("VAR3") == 0);
c2dfb7
 
c2dfb7
-        r = run_tests(UNIT_FILE_USER, user_tests);
c2dfb7
+        r = run_tests(UNIT_FILE_USER, user_tests, argv + 1);
c2dfb7
         if (r != 0)
c2dfb7
                 return r;
c2dfb7
 
c2dfb7
-        return run_tests(UNIT_FILE_SYSTEM, system_tests);
c2dfb7
+        return run_tests(UNIT_FILE_SYSTEM, system_tests, argv + 1);
c2dfb7
 }