Tizen 2.1 base
[platform/upstream/glib2.0.git] / glib / gtester.c
index ca023f7..279f6f2 100644 (file)
@@ -50,9 +50,11 @@ static gboolean     subtest_verbose = FALSE;
 static gboolean     subtest_mode_fatal = TRUE;
 static gboolean     subtest_mode_perf = FALSE;
 static gboolean     subtest_mode_quick = TRUE;
+static gboolean     subtest_mode_undefined = TRUE;
 static const gchar *subtest_seedstr = NULL;
 static gchar       *subtest_last_seed = NULL;
 static GSList      *subtest_paths = NULL;
+static GSList      *skipped_paths = NULL;
 static GSList      *subtest_args = NULL;
 static gboolean     testcase_open = FALSE;
 static guint        testcase_count = 0;
@@ -113,7 +115,7 @@ testcase_close (long double duration,
     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)
+  if (subtest_mode_fatal && exit_status)
     terminate();
 }
 
@@ -306,6 +308,8 @@ launch_test_binary (const char *binary,
     argc++;
   if (subtest_mode_perf)
     argc++;
+  if (!subtest_mode_undefined)
+    argc++;
   if (gtester_list_tests)
     argc++;
   if (subtest_seedstr)
@@ -315,6 +319,8 @@ launch_test_binary (const char *binary,
     argc++;
   for (slist = subtest_paths; slist; slist = slist->next)
     argc++;
+  for (slist = skipped_paths; slist; slist = slist->next)
+    argc++;
 
   /* setup argv */
   argv = g_malloc ((argc + 2) * sizeof(gchar *));
@@ -334,6 +340,8 @@ launch_test_binary (const char *binary,
     argv[i++] = "-m=slow";
   if (subtest_mode_perf)
     argv[i++] = "-m=perf";
+  if (!subtest_mode_undefined)
+    argv[i++] = "-m=no-undefined";
   if (gtester_list_tests)
     argv[i++] = "-l";
   if (subtest_seedstr)
@@ -343,6 +351,8 @@ launch_test_binary (const char *binary,
     argv[i++] = queue_gfree (&free_list, g_strdup_printf ("--GTestSkipCount=%u", skip_tests));
   for (slist = subtest_paths; slist; slist = slist->next)
     argv[i++] = queue_gfree (&free_list, g_strdup_printf ("-p=%s", (gchar*) slist->data));
+  for (slist = skipped_paths; slist; slist = slist->next)
+    argv[i++] = queue_gfree (&free_list, g_strdup_printf ("-s=%s", (gchar*) slist->data));
   argv[i++] = NULL;
 
   g_spawn_async_with_pipes (NULL, /* g_get_current_dir() */
@@ -418,8 +428,8 @@ launch_test (const char *binary)
   gboolean success = TRUE;
   GTimer *btimer = g_timer_new();
   gboolean need_restart;
+
   testcase_count = 0;
-  testcase_fail_count = 0;
   if (!gtester_quiet)
     g_print ("TEST: %s... ", binary);
 
@@ -445,8 +455,12 @@ launch_test (const char *binary)
       goto retry;
     }
 
+  /* count the inability to run a test as a failure */
+  if (!success && testcase_count == 0)
+    testcase_fail_count++;
+
   if (!gtester_quiet)
-    g_print ("%s: %s\n", testcase_fail_count || !success ? "FAIL" : "PASS", binary);
+    g_print ("%s: %s\n", !success ? "FAIL" : "PASS", binary);
   g_timer_destroy (btimer);
   if (subtest_mode_fatal && !success)
     terminate();
@@ -470,7 +484,9 @@ usage (gboolean just_version)
   g_print ("  -l                          list paths of available test cases\n");
   g_print ("  -m=perf, -m=slow, -m=quick -m=thorough\n");
   g_print ("                              run test cases in mode perf, slow/thorough or quick (default)\n");
+  g_print ("  -m=no-undefined             don't run test cases that provoke assertions\n");
   g_print ("  -p=TESTPATH                 only start test cases matching TESTPATH\n");
+  g_print ("  -s=TESTPATH                 skip test cases matching TESTPATH\n");
   g_print ("  --seed=SEEDSTRING           start all tests with random number seed SEEDSTRING\n");
   g_print ("  -o=LOGFILE                  write the test log to LOGFILE\n");
   g_print ("  -q, --quiet                 suppress per test binary output\n");
@@ -530,6 +546,18 @@ parse_args (gint    *argc_p,
             }
           argv[i] = NULL;
         }
+      else if (strcmp ("-s", argv[i]) == 0 || strncmp ("-s=", argv[i], 3) == 0)
+        {
+          gchar *equal = argv[i] + 2;
+          if (*equal == '=')
+            skipped_paths = g_slist_prepend (skipped_paths, equal + 1);
+          else if (i + 1 < argc)
+            {
+              argv[i++] = NULL;
+              skipped_paths = g_slist_prepend (skipped_paths, argv[i]);
+            }
+          argv[i] = NULL;
+        }
       else if (strcmp ("--test-arg", argv[i]) == 0 || strncmp ("--test-arg=", argv[i], 11) == 0)
         {
           gchar *equal = argv[i] + 10;
@@ -574,6 +602,10 @@ parse_args (gint    *argc_p,
               subtest_mode_quick = TRUE;
               subtest_mode_perf = FALSE;
             }
+          else if (strcmp (mode, "undefined") == 0)
+            subtest_mode_undefined = TRUE;
+          else if (strcmp (mode, "no-undefined") == 0)
+            subtest_mode_undefined = FALSE;
           else
             g_error ("unknown test mode: -m %s", mode);
           argv[i] = NULL;
@@ -626,20 +658,6 @@ main (int    argc,
 {
   guint ui;
 
-  /* some unices need SA_RESTART for SIGCHLD to return -EAGAIN for io.
-   * we must fiddle with sigaction() *before* glib is used, otherwise
-   * we could revoke signal hanmdler setups from glib initialization code.
-   */
-  if (TRUE)
-    {
-      struct sigaction sa;
-      struct sigaction osa;
-      sa.sa_handler = SIG_DFL;
-      sigfillset (&sa.sa_mask);
-      sa.sa_flags = SA_RESTART;
-      sigaction (SIGCHLD, &sa, &osa);
-    }
-
   g_set_prgname (argv[0]);
   parse_args (&argc, &argv);
   if (gtester_selftest)
@@ -672,7 +690,7 @@ main (int    argc,
 
   close (log_fd);
 
-  return testcase_fail_count == 0 ? 0 : 1;
+  return testcase_fail_count == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
 static void
@@ -704,7 +722,7 @@ static int
 main_selftest (int    argc,
                char **argv)
 {
-  /* gtester main() for --gtester-selftest invokations */
+  /* gtester main() for --gtester-selftest invocations */
   g_test_init (&argc, &argv, NULL);
   g_test_add ("/gtester/fixture-test", guint, NULL, fixture_setup, fixture_test, fixture_teardown);
   return g_test_run();