From d4bfa601f7af11c2ca7c3866e67d49e379d82aad Mon Sep 17 00:00:00 2001 From: "17:21:05 Tim Janik" Date: Wed, 5 Dec 2007 16:22:44 +0000 Subject: [PATCH] print out random seed for verbose tests, also adapted test result 2007-12-05 17:21:05 Tim Janik * 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 --- ChangeLog | 12 ++++++++++++ glib/gtester.c | 19 +++++++++++++------ glib/gtestutils.c | 18 +++++++++++++++--- glib/gtestutils.h | 1 + 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 88e4c29d2..eb908f66c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-12-05 17:21:05 Tim Janik + + * 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 * glib/gtestutils.[hc]: added g_test_add_data_func() to pass data diff --git a/glib/gtester.c b/glib/gtester.c index 5a035d72f..f3aaee959 100644 --- a/glib/gtester.c +++ b/glib/gtester.c @@ -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%.6Lf\n", sindent (log_indent), duration); - test_log_printfe ("%s\n", - sindent (log_indent), exit_status, n_forks); + test_log_printfe ("%s\n", + sindent (log_indent), exit_status, n_forks, + exit_status ? "failed" : "success"); log_indent -= 2; test_log_printfe ("%s\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\n", sindent (log_indent), msg->strings[0]); - test_log_printfe ("%s%s\n", sindent (log_indent), msg->strings[1]); + subtest_last_seed = g_strdup (msg->strings[1]); + test_log_printfe ("%s%s\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%.6f\n", sindent (log_indent), g_timer_elapsed (btimer, NULL)); log_indent -= 2; test_log_printfe ("%s\n", sindent (log_indent)); + g_free (subtest_last_seed); + subtest_last_seed = NULL; if (need_restart) { /* restart test binary, skipping processed test cases */ diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 393613dd5..1e5dd601a 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -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. diff --git a/glib/gtestutils.h b/glib/gtestutils.h index ccbbcb098..96a241074 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -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)