diff mbox

support: Implement --verbose option for test programs

Message ID b85c3b17-6f6f-36e3-71e7-3572f0d11a62@redhat.com
State Accepted
Commit f47ae5186624e5bb3a2d2b25be742b90a1eee3cd
Headers show

Commit Message

Florian Weimer Dec. 31, 2016, 10:51 a.m. UTC
This patch depends on the failure recording change posted here:

   <https://sourceware.org/ml/libc-alpha/2016-12/msg01084.html>

Thanks,
Florian
diff mbox

Patch

support: Implement --verbose option for test programs

Some tests can produce rather verbose tracing information,
and the --verbose option provides a standardized way to enable
such logging output.

2016-12-31  Florian Weimer  <fweimer@redhat.com>

	* support/test-driver.h (TEST_DEFAULT_OPTIONS): Add --verbose.
	(test_verbose): Declare.
	* support/test-driver.c (main): Use TEST_DEFAULT_OPTIONS.
	* support/support_test_main.c (default_options): Likewise.
	(usage, support_test_main): Handle 'v'.
	(test_verbose): Define.
	* support/tst-support_record_failure.c (do_test): Use
	test_verbose.
	* support/tst-support_record_failure-2.sh (different_status): Add
	--verbose test.

diff --git a/support/support_test_main.c b/support/support_test_main.c
index 8d31e2f..1c90986 100644
--- a/support/support_test_main.c
+++ b/support/support_test_main.c
@@ -37,8 +37,7 @@ 
 
 static const struct option default_options[] =
 {
-  { "direct", no_argument, NULL, OPT_DIRECT },
-  { "test-dir", required_argument, NULL, OPT_TESTDIR },
+  TEST_DEFAULT_OPTIONS
   { NULL, 0, NULL, 0 }
 };
 
@@ -67,6 +66,9 @@  usage (const struct option *options)
       printf ("%*s", 25 - indent, "");
       switch (options[i].val)
         {
+        case 'v':
+          printf ("Increase the output verbosity");
+          break;
         case OPT_DIRECT:
           printf ("Run the test directly (instead of forking & monitoring)");
           break;
@@ -164,7 +166,7 @@  run_test_function (int argc, char **argv, const struct test_config *config)
 static bool test_main_called;
 
 const char *test_dir = NULL;
-
+unsigned int test_verbose = 0;
 
 /* If test failure reporting has been linked in, it may contribute
    additional test failures.  */
@@ -215,6 +217,9 @@  support_test_main (int argc, char **argv, const struct test_config *config)
       case '?':
         usage (options);
         exit (1);
+      case 'v':
+        ++test_verbose;
+        break;
       case OPT_DIRECT:
         direct = 1;
         break;
diff --git a/support/test-driver.c b/support/test-driver.c
index 3a61b7b..a847c96 100644
--- a/support/test-driver.c
+++ b/support/test-driver.c
@@ -144,9 +144,7 @@  main (int argc, char **argv)
   struct option options[] =
     {
       CMDLINE_OPTIONS
-      { "direct", no_argument, NULL, OPT_DIRECT },
-      { "test-dir", required_argument, NULL, OPT_TESTDIR },
-      { NULL, 0, NULL, 0 }
+      TEST_DEFAULT_OPTIONS
     };
   test_config.options = &options;
 #endif
diff --git a/support/test-driver.h b/support/test-driver.h
index 7787e9c..f3f5c17 100644
--- a/support/test-driver.h
+++ b/support/test-driver.h
@@ -55,12 +55,18 @@  enum
 
 /* Options provided by the test driver.  */
 #define TEST_DEFAULT_OPTIONS                            \
+  { "verbose", no_argument, NULL, 'v' },                \
   { "direct", no_argument, NULL, OPT_DIRECT },          \
   { "test-dir", required_argument, NULL, OPT_TESTDIR }, \
 
 /* The directory the test should use for temporary files.  */
 extern const char *test_dir;
 
+/* The number of --verbose arguments specified during program
+   invocation.  This variable can be used to control the verbosity of
+   tests.  */
+extern unsigned int test_verbose;
+
 int support_test_main (int argc, char **argv, const struct test_config *);
 
 __END_DECLS
diff --git a/support/tst-support_record_failure-2.sh b/support/tst-support_record_failure-2.sh
index a96a60d..6fffd8a 100644
--- a/support/tst-support_record_failure-2.sh
+++ b/support/tst-support_record_failure-2.sh
@@ -54,13 +54,16 @@  different_status () {
     run_test 1 "error: 1 test failures" $direct --status=77
     run_test 2 "error: tst-support_record_failure.c:108: not true: false
 error: 1 test failures" $direct --test-verify
+    run_test 2 "error: tst-support_record_failure.c:108: not true: false
+info: execution passed failed TEST_VERIFY
+error: 1 test failures" $direct --test-verify --verbose
 }
 
 different_status
 different_status --direct
 
-run_test 1 "error: tst-support_record_failure.c:113: not true: false
+run_test 1 "error: tst-support_record_failure.c:115: not true: false
 error: 1 test failures" --test-verify-exit
 # --direct does not print the summary error message if exit is called.
-run_test 1 "error: tst-support_record_failure.c:113: not true: false" \
+run_test 1 "error: tst-support_record_failure.c:115: not true: false" \
 	 --direct --test-verify-exit
diff --git a/support/tst-support_record_failure.c b/support/tst-support_record_failure.c
index a999f70..75dd10f 100644
--- a/support/tst-support_record_failure.c
+++ b/support/tst-support_record_failure.c
@@ -106,6 +106,8 @@  do_test (void)
   if (test_verify)
     {
       TEST_VERIFY (false);
+      if (test_verbose)
+        printf ("info: execution passed failed TEST_VERIFY\n");
       return 2; /* Expected exit status.  */
     }
   if (test_verify_exit)