static void finalize (GObject* object) { if (PRIV (object)->error) { g_error_free (PRIV (object)->error); } if (PRIV (object)->io_watch) { g_source_remove (PRIV (object)->io_watch); } if (PRIV (object)->child_watch) { g_source_remove (PRIV (object)->child_watch); g_child_watch_add (PRIV (object)->pid, cleanup_func, NULL); } g_object_unref (PRIV (object)->hierarchy); g_object_unref (PRIV (object)->file_monitor); g_object_unref (PRIV (object)->file); g_test_log_buffer_free (PRIV (object)->buffer); G_OBJECT_CLASS (gutachter_suite_parent_class)->finalize (object); }
void test_g_log_buffer() { GTestLogBuffer* log_buffer; GTestLogMsg* log_msg; GTestLogMsg msg_ip; gchar *astrings[1] = {NULL}; guint8 *dbuffer; guint dbufferlen; int i; msg_ip.log_type = G_TEST_LOG_MESSAGE; msg_ip.n_strings = 1; msg_ip.strings = astrings; astrings[0] = (gchar*) "test-log-some-dummy-log"; msg_ip.n_nums = 0; msg_ip.nums = 0; dbuffer = (guint8*)g_test_log_dump(&msg_ip, &dbufferlen); log_buffer = g_test_log_buffer_new(); if(log_buffer) { g_test_log_buffer_push(log_buffer, dbufferlen, (const guint8*)dbuffer); log_msg = g_test_log_buffer_pop(log_buffer); if(log_msg) { g_test_log_msg_free(log_msg); } else { std_log(LOG_FILENAME_LINE, "g_test_log_buffer_pop returned NULL"); assert_failed = 1; } g_test_log_buffer_free(log_buffer); } else { std_log(LOG_FILENAME_LINE, "g_test_log_buffer_new returned NULL"); assert_failed = 1; } g_free (dbuffer); }
static gboolean launch_test_binary (const char *binary, guint skip_tests) { GTestLogBuffer *tlb; GSList *slist, *free_list = NULL; GError *error = NULL; int argc = 0; const gchar **argv; GPid pid = 0; gint report_pipe[2] = { -1, -1 }; guint child_report_cb_id = 0; gboolean loop_pending; gint i = 0; if (!g_unix_open_pipe (report_pipe, FD_CLOEXEC, &error)) { if (subtest_mode_fatal) g_error ("Failed to open pipe for test binary: %s: %s", binary, error->message); else g_warning ("Failed to open pipe for test binary: %s: %s", binary, error->message); g_clear_error (&error); return FALSE; } /* setup argc */ for (slist = subtest_args; slist; slist = slist->next) argc++; /* argc++; */ if (subtest_quiet) argc++; if (subtest_verbose) argc++; if (!subtest_mode_fatal) argc++; /* Either -m=quick or -m=slow is always appended. */ argc++; if (subtest_mode_perf) argc++; if (!subtest_mode_undefined) argc++; if (gtester_list_tests) argc++; if (subtest_seedstr) argc++; argc++; if (skip_tests) 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 *)); argv[i++] = binary; for (slist = subtest_args; slist; slist = slist->next) argv[i++] = (gchar*) slist->data; /* argv[i++] = "--debug-log"; */ if (subtest_quiet) argv[i++] = "--quiet"; if (subtest_verbose) argv[i++] = "--verbose"; if (!subtest_mode_fatal) argv[i++] = "--keep-going"; if (subtest_mode_quick) argv[i++] = "-m=quick"; else 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) argv[i++] = queue_gfree (&free_list, g_strdup_printf ("--seed=%s", subtest_seedstr)); argv[i++] = queue_gfree (&free_list, g_strdup_printf ("--GTestLogFD=%u", report_pipe[1])); if (skip_tests) 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() */ (gchar**) argv, NULL, /* envp */ G_SPAWN_DO_NOT_REAP_CHILD, /* G_SPAWN_SEARCH_PATH */ unset_cloexec_fdp, &report_pipe[1], /* pre-exec callback */ &pid, NULL, /* standard_input */ NULL, /* standard_output */ NULL, /* standard_error */ &error); g_slist_foreach (free_list, (void(*)(void*,void*)) g_free, NULL); g_slist_free (free_list); free_list = NULL; close (report_pipe[1]); if (!gtester_quiet) g_print ("(pid=%lu)\n", (unsigned long) pid); if (error) { close (report_pipe[0]); if (subtest_mode_fatal) g_error ("Failed to execute test binary: %s: %s", argv[0], error->message); else g_warning ("Failed to execute test binary: %s: %s", argv[0], error->message); g_clear_error (&error); g_free (argv); return FALSE; } g_free (argv); subtest_running = TRUE; subtest_io_pending = TRUE; tlb = g_test_log_buffer_new(); if (report_pipe[0] >= 0) { ioc_report = g_io_channel_unix_new (report_pipe[0]); g_io_channel_set_flags (ioc_report, G_IO_FLAG_NONBLOCK, NULL); g_io_channel_set_encoding (ioc_report, NULL, NULL); g_io_channel_set_buffered (ioc_report, FALSE); child_report_cb_id = g_io_add_watch_full (ioc_report, G_PRIORITY_DEFAULT - 1, G_IO_IN | G_IO_ERR | G_IO_HUP, child_report_cb, tlb, NULL); g_io_channel_unref (ioc_report); } g_child_watch_add_full (G_PRIORITY_DEFAULT + 1, pid, child_watch_cb, NULL, NULL); loop_pending = g_main_context_pending (NULL); while (subtest_running || /* FALSE once child exits */ subtest_io_pending || /* FALSE once ioc_report closes */ loop_pending) /* TRUE while idler, etc are running */ { /* g_print ("LOOPSTATE: subtest_running=%d subtest_io_pending=%d\n", subtest_running, subtest_io_pending); */ /* check for unexpected hangs that are not signalled on report_pipe */ if (!subtest_running && /* child exited */ subtest_io_pending && /* no EOF detected on report_pipe */ !loop_pending) /* no IO events pending however */ break; g_main_context_iteration (NULL, TRUE); loop_pending = g_main_context_pending (NULL); } if (subtest_io_pending) g_source_remove (child_report_cb_id); close (report_pipe[0]); g_test_log_buffer_free (tlb); return TRUE; }