From dda14cb57afbfa0c6d7c38d517ff8cc886ffd190 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 1 Mar 2022 16:09:32 -0700 Subject: [PATCH] Less verbose output unless the -v option is used. Also display a test summary at the end. --- .../python/regress/check_python_examples.c | 25 ++++++++++++++++--- plugins/python/regress/testhelpers.h | 5 +++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/python/regress/check_python_examples.c b/plugins/python/regress/check_python_examples.c index ad3559247..10eefac6c 100644 --- a/plugins/python/regress/check_python_examples.c +++ b/plugins/python/regress/check_python_examples.c @@ -44,6 +44,7 @@ DECL_PLUGIN(audit_plugin, python_audit); DECL_PLUGIN(sudoers_group_plugin, group_plugin); static struct passwd example_pwd; +static bool verbose; static int _init_symbols(void); static int _unlink_symbols(void); @@ -1511,13 +1512,26 @@ _unlink_symbols(void) int main(int argc, char *argv[]) { - int errors = 0; + int ch, errors = 0, ntests = 0; - if (argc != 2) { + while ((ch = getopt(argc, argv, "v")) != -1) { + switch (ch) { + case 'v': + verbose = true; + break; + default: + fprintf(stderr, "usage: %s [-v]\n", getprogname()); + return EXIT_FAILURE; + } + } + argc -= optind; + argv += optind; + + if (argc != 1) { printf("Please specify the python_plugin.so as argument!\n"); return EXIT_FAILURE; } - python_plugin_so_path = argv[1]; + python_plugin_so_path = argv[0]; RUN_TEST(check_example_io_plugin_version_display(true)); RUN_TEST(check_example_io_plugin_version_display(false)); @@ -1595,5 +1609,10 @@ main(int argc, char *argv[]) RUN_TEST(check_example_debugging("plugin@err")); RUN_TEST(check_plugin_unload()); + if (ntests != 0) { + printf("%s: %d tests run, %d errors, %d%% success rate\n", + getprogname(), ntests, errors, (ntests - errors) * 100 / ntests); + } + return errors; } diff --git a/plugins/python/regress/testhelpers.h b/plugins/python/regress/testhelpers.h index b5abb9921..0e19d9db0 100644 --- a/plugins/python/regress/testhelpers.h +++ b/plugins/python/regress/testhelpers.h @@ -62,7 +62,10 @@ char ** create_str_array(size_t count, ...); #define RUN_TEST(testcase) \ do { \ int success = 1; \ - printf("Running test " #testcase " ... \n"); \ + ntests++; \ + if (verbose) { \ + printf("Running test " #testcase " ... \n"); \ + } \ if (!init()) { \ printf("FAILED: initialization of testcase %s at %s:%d\n", #testcase, __FILE__, __LINE__); \ success = 0; \