print out random seed for verbose tests, also adapted test result
author17:21:05 Tim Janik <timj@imendio.com>
Wed, 5 Dec 2007 16:22:44 +0000 (16:22 +0000)
committerTim Janik <timj@src.gnome.org>
Wed, 5 Dec 2007 16:22:44 +0000 (16:22 +0000)
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

ChangeLog
glib/gtester.c
glib/gtestutils.c
glib/gtestutils.h

index 88e4c29d2e71b3785c04957d68023332222d245e..eb908f66c07812e5ff25bad19ba1976f360cef7a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 5a035d72f05775e5efd3f120f6a731bf199d93d2..f3aaee959d47473d0bdc5d983a914e2d6c68441b 100644 (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 */
index 393613dd5b8662f7f85530888b130a1222ec5230..1e5dd601a909d7ef597a6c5ee72d2bfecd933914 100644 (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.
index ccbbcb0982be792b3dab81806f3346bfdd912924..96a2410742aa695b9c7be20943d181b4863fbb4a 100644 (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)