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.
This commit is contained in:
Florian Weimer 2016-12-31 11:01:40 +01:00
parent 039c5a05cc
commit f47ae51866
6 changed files with 35 additions and 8 deletions

View File

@ -1,3 +1,16 @@
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.
2016-12-31 Florian Weimer <fweimer@redhat.com>
* support/check.h (FAIL_RET, FAIL_EXIT, FAIL_EXIT1): Document that

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)