]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: Slightly rework DEFINE_TEST_MAIN macros
authorJan Janssen <medhefgo@web.de>
Tue, 23 Nov 2021 12:40:27 +0000 (13:40 +0100)
committerJan Janssen <medhefgo@web.de>
Thu, 25 Nov 2021 13:56:33 +0000 (14:56 +0100)
- A lot of tests want a different log level
- Provides saved_argc/saved_argv to tests
- Separate intro/outro is more flexible

src/shared/tests.h
src/test/test-macro.c

index f333ebd842089fc55e7b358a4808f733c4610d80..872b9b2d6c776bdae72d2e356da0667724c68742 100644 (file)
@@ -6,6 +6,7 @@
 #include "sd-daemon.h"
 
 #include "macro.h"
+#include "util.h"
 
 static inline bool manager_errno_skip_test(int r) {
         return IN_SET(abs(r),
@@ -77,16 +78,14 @@ static inline void run_test_table(void) {
         }
 }
 
-#define DEFINE_TEST_MAIN                      \
-        int main(int argc, char *argv[]) {    \
-                test_setup_logging(LOG_INFO); \
-                run_test_table();             \
-                return EXIT_SUCCESS;          \
+#define DEFINE_CUSTOM_TEST_MAIN(log_level, intro, outro) \
+        int main(int argc, char *argv[]) {               \
+                test_setup_logging(log_level);           \
+                save_argc_argv(argc, argv);              \
+                intro;                                   \
+                run_test_table();                        \
+                outro;                                   \
+                return EXIT_SUCCESS;                     \
         }
 
-#define DEFINE_CUSTOM_TEST_MAIN(impl)         \
-        int main(int argc, char *argv[]) {    \
-                test_setup_logging(LOG_INFO); \
-                run_test_table();             \
-                return impl();                \
-        }
+#define DEFINE_TEST_MAIN(log_level) DEFINE_CUSTOM_TEST_MAIN(log_level, , )
index 09cb4bf7bc62a38875ef7762bc5aba9544ebb197..d33d22c18cb427099255f9717727c965c4d3e8a9 100644 (file)
@@ -387,4 +387,4 @@ TEST(flags) {
         assert_se(f == F2);
 }
 
-DEFINE_TEST_MAIN;
+DEFINE_TEST_MAIN(LOG_INFO);