print out random seed for verbose tests, also adapted test result

2007-12-05 17:21:05  Tim Janik  <timj@imendio.com>

        * glib/glib/gtestutils.c: print out random seed for verbose tests,
        also adapted test result reporting slightly in verbose mode to allow
        custom debugging output. support "thorough" as test mode alis for "slow".

        * glib/glib/gtestutils.h: added g_test_thorough().

        * glib/glib/gtester.c: print out the last random seed when tests fail.
        added result attribute to test case status logging to easily spot
        failing tests in log files. disabled debugging output when skipping tests.



svn path=/trunk/; revision=6052
This commit is contained in:
17:21:05 Tim Janik 2007-12-05 16:22:44 +00:00 committed by Tim Janik
parent 3869c33a73
commit d4bfa601f7
4 changed files with 41 additions and 9 deletions

View File

@ -1,3 +1,15 @@
2007-12-05 17:21:05 Tim Janik <timj@imendio.com>
* glib/glib/gtestutils.c: print out random seed for verbose tests,
also adapted test result reporting slightly in verbose mode to allow
custom debugging output. support "thorough" as test mode alis for "slow".
* glib/glib/gtestutils.h: added g_test_thorough().
* glib/glib/gtester.c: print out the last random seed when tests fail.
added result attribute to test case status logging to easily spot
failing tests in log files. disabled debugging output when skipping tests.
2007-12-05 11:43:22 Tim Janik <timj@imendio.com>
* glib/gtestutils.[hc]: added g_test_add_data_func() to pass data

View File

@ -51,6 +51,7 @@ static gboolean subtest_mode_fatal = TRUE;
static gboolean subtest_mode_perf = FALSE;
static gboolean subtest_mode_quick = TRUE;
static const gchar *subtest_seedstr = NULL;
static gchar *subtest_last_seed = NULL;
static GSList *subtest_paths = NULL;
static GSList *subtest_args = NULL;
static gboolean testcase_open = FALSE;
@ -95,18 +96,21 @@ terminate (void)
static void
testcase_close (long double duration,
guint exit_status,
gint exit_status,
guint n_forks)
{
g_return_if_fail (testcase_open > 0);
test_log_printfe ("%s<duration>%.6Lf</duration>\n", sindent (log_indent), duration);
test_log_printfe ("%s<status exit-status=\"%d\" n-forks=\"%d\"/>\n",
sindent (log_indent), exit_status, n_forks);
test_log_printfe ("%s<status exit-status=\"%d\" n-forks=\"%d\" result=\"%s\"/>\n",
sindent (log_indent), exit_status, n_forks,
exit_status ? "failed" : "success");
log_indent -= 2;
test_log_printfe ("%s</testcase>\n", sindent (log_indent));
testcase_open--;
if (gtester_verbose)
g_print ("%s\n", exit_status ? "FAIL" : "OK");
if (exit_status && subtest_last_seed)
g_print ("GTester: last random seed: %s\n", subtest_last_seed);
if (exit_status)
testcase_fail_count += 1;
if (subtest_mode_fatal && testcase_fail_count)
@ -125,7 +129,8 @@ test_log_msg (GTestLogMsg *msg)
break;
case G_TEST_LOG_START_BINARY:
test_log_printfe ("%s<binary file=\"%s\"/>\n", sindent (log_indent), msg->strings[0]);
test_log_printfe ("%s<random-seed>%s</random-seed>\n", sindent (log_indent), msg->strings[1]);
subtest_last_seed = g_strdup (msg->strings[1]);
test_log_printfe ("%s<random-seed>%s</random-seed>\n", sindent (log_indent), subtest_last_seed);
break;
case G_TEST_LOG_LIST_CASE:
g_print ("%s\n", msg->strings[0]);
@ -146,7 +151,7 @@ test_log_msg (GTestLogMsg *msg)
log_indent += 2;
break;
case G_TEST_LOG_SKIP_CASE:
if (TRUE && gtester_verbose) // enable to debug test case skipping logic
if (FALSE && gtester_verbose) // enable to debug test case skipping logic
{
gchar *sc = g_strconcat (msg->strings[0], ":", NULL);
gchar *sleft = g_strdup_printf ("%-68s", sc);
@ -369,11 +374,13 @@ launch_test (const char *binary)
success &= subtest_exitstatus == 0;
need_restart = testcase_open != 0;
if (testcase_open)
testcase_close (0, -999, 0);
testcase_close (0, -256, 0);
g_timer_stop (btimer);
test_log_printfe ("%s<duration>%.6f</duration>\n", sindent (log_indent), g_timer_elapsed (btimer, NULL));
log_indent -= 2;
test_log_printfe ("%s</testbinary>\n", sindent (log_indent));
g_free (subtest_last_seed);
subtest_last_seed = NULL;
if (need_restart)
{
/* restart test binary, skipping processed test cases */

View File

@ -172,8 +172,14 @@ g_test_log (GTestLogType lbit,
switch (lbit)
{
case G_TEST_LOG_START_BINARY:
if (g_test_verbose())
g_print ("GTest: random seed: %s\n", string2);
break;
case G_TEST_LOG_STOP_CASE:
if (!g_test_quiet())
if (g_test_verbose())
g_print ("GTest: result: %s\n", fail ? "FAIL" : "OK");
else if (!g_test_quiet())
g_print ("%s\n", fail ? "FAIL" : "OK");
if (fail && test_mode_fatal)
abort();
@ -207,7 +213,9 @@ g_test_log (GTestLogType lbit,
switch (lbit)
{
case G_TEST_LOG_START_CASE:
if (!g_test_quiet())
if (g_test_verbose())
g_print ("GTest: run: %s\n", string1);
else if (!g_test_quiet())
g_print ("%s: ", string1);
break;
default: ;
@ -293,6 +301,8 @@ parse_args (gint *argc_p,
mutable_test_config_vars.test_perf = TRUE;
else if (strcmp (mode, "slow") == 0)
mutable_test_config_vars.test_quick = FALSE;
else if (strcmp (mode, "thorough") == 0)
mutable_test_config_vars.test_quick = FALSE;
else if (strcmp (mode, "quick") == 0)
{
mutable_test_config_vars.test_quick = TRUE;
@ -361,9 +371,11 @@ parse_args (gint *argc_p,
* --verbose run tests verbosely.
* -q, --quiet run tests quietly.
* -p TESTPATH execute all tests matching TESTPATH.
* -m {perf|slow|quick} execute tests according to this test modes:
* -m {perf|slow|thorough|quick}
* execute tests according to these test modes:
* perf - performance tests, may take long and report results.
* slow - slow and thorough tests, may take quite long and maximize coverage.
* thorough - currently an alias for "slow".
* quick - quick tests, should run really quickly and give good coverage.
* --debug-log debug test logging output.
* -k, --keep-going gtester specific argument.

View File

@ -68,6 +68,7 @@ void g_test_init (int *argc,
/* query testing framework config */
#define g_test_quick() (g_test_config_vars->test_quick)
#define g_test_slow() (!g_test_config_vars->test_quick)
#define g_test_thorough() (!g_test_config_vars->test_quick)
#define g_test_perf() (g_test_config_vars->test_perf)
#define g_test_verbose() (g_test_config_vars->test_verbose)
#define g_test_quiet() (g_test_config_vars->test_quiet)