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