コード例 #1
0
ファイル: rbtree.c プロジェクト: BoozzyAmdJin/gtk-
static void
test_reorder (void)
{
  guint n = g_test_perf () ? 1000000 : 100;
  GtkRBTree *tree;
  GtkRBNode *node;
  gint *reorder;
  guint i;
  double elapsed;

  reorder = fisher_yates_shuffle (n);
  tree = create_unsorted_tree (reorder, n);

  g_test_timer_start ();

  _gtk_rbtree_reorder (tree, reorder, n);

  elapsed = g_test_timer_elapsed ();
  if (g_test_perf ())
    g_test_minimized_result (elapsed, "reordering rbtree with %u items: %gsec", n, elapsed);

  _gtk_rbtree_test (tree);

  for (node = _gtk_rbtree_first (tree), i = 0;
       node != NULL;
       node = _gtk_rbtree_next (tree, node), i++)
    {
      g_assert (GTK_RBNODE_GET_HEIGHT (node) == i);
    }
  g_assert (i == n);

  _gtk_rbtree_free (tree);
}
コード例 #2
0
ファイル: test-bufferiszero.c プロジェクト: 8tab/qemu
static void test_2(void)
{
    if (g_test_perf()) {
        test_1();
    } else {
        do {
            test_1();
        } while (test_buffer_is_zero_next_accel());
    }
}
コード例 #3
0
static void
perform (gconstpointer data)
{
  GrindFunc grind_func = (GrindFunc) data;

  if (!g_test_perf ())
    return;

  perform_for (grind_func, str_ascii, "ASCII:");
  perform_for (grind_func, str_latin1, "Latin-1:");
  perform_for (grind_func, str_cyrillic, "Cyrillic:");
  perform_for (grind_func, str_chinese, "Chinese:");
}
コード例 #4
0
ファイル: dbus-daemon.c プロジェクト: OmarBizreh/Sliding_XZ
static void
test_echo (Fixture *f,
    gconstpointer context G_GNUC_UNUSED)
{
  guint count = 2000;
  guint sent;
  guint received = 0;
  double elapsed;

  if (g_test_perf ())
    count = 100000;

  add_echo_filter (f);

  g_test_timer_start ();

  for (sent = 0; sent < count; sent++)
    {
      DBusMessage *m = dbus_message_new_method_call (
          dbus_bus_get_unique_name (f->right_conn), "/",
          "com.example", "Spam");
      DBusPendingCall *pc;

      if (m == NULL)
        g_error ("OOM");

      if (!dbus_connection_send_with_reply (f->left_conn, m, &pc,
                                            DBUS_TIMEOUT_INFINITE) ||
          pc == NULL)
        g_error ("OOM");

      if (dbus_pending_call_get_completed (pc))
        pc_count (pc, &received);
      else if (!dbus_pending_call_set_notify (pc, pc_count, &received,
            NULL))
        g_error ("OOM");

      dbus_pending_call_unref (pc);
      dbus_message_unref (m);
    }

  while (received < count)
    g_main_context_iteration (NULL, TRUE);

  elapsed = g_test_timer_elapsed ();

  g_test_maximized_result (count / elapsed, "%u messages / %f seconds",
      count, elapsed);
}
コード例 #5
0
static void
test_immediate_performance_n_tasks(TestFixture *fixture,
                                   const void  *data,
                                   int          n_tasks)
{
    int i, j;

    if (!g_test_perf())
        return;

    /* this has to be set up front of there's a race in using it to
     * decide to quit mainloop, because task runner starts running
     * tasks right away, doesn't wait for our local mainloop
     */
    fixture->tasks_started_count = n_tasks;

    /* start here, to include task creation. Also, immediates can start
     * running right away, before we block in main loop.
     */
    g_test_timer_start();

    for (i = 0; i < n_tasks; ++i) {
        HrtTask *task;

        task =
            hrt_task_runner_create_task(fixture->runner);

#define NUM_IMMEDIATES 4
        for (j = 0; j < NUM_IMMEDIATES; ++j) {
            hrt_task_add_immediate(task,
                                   on_immediate_for_performance_many_tasks,
                                   fixture,
                                   on_dnotify_bump_count);
        }
    }

    g_main_loop_run(fixture->loop);

    g_test_minimized_result(g_test_timer_elapsed(),
                            "Run %d tasks with %d immediates each",
                            n_tasks, NUM_IMMEDIATES);

    g_assert_cmpint(fixture->tasks_completed_count, ==, n_tasks);
    g_assert_cmpint(fixture->tasks_completed_count, ==,
                    fixture->tasks_started_count);
    g_assert_cmpint(fixture->dnotify_count, ==, NUM_IMMEDIATES * n_tasks);

#undef NUM_IMMEDIATES
}
コード例 #6
0
ファイル: test_suite.c プロジェクト: abiggerhammer/hammer
int main(int argc, char** argv) {
  g_test_init(&argc, &argv, NULL);

  // register various test suites...
  register_bitreader_tests();
  register_bitwriter_tests();
  register_parser_tests();
  register_grammar_tests();
  register_misc_tests();
  register_regression_tests();
  if (g_test_slow() || g_test_perf())
    register_benchmark_tests();

  g_test_run();
}
コード例 #7
0
ファイル: test-coroutine.c プロジェクト: B-Rich/qemu
int main(int argc, char **argv)
{
    g_test_init(&argc, &argv, NULL);
    g_test_add_func("/basic/lifecycle", test_lifecycle);
    g_test_add_func("/basic/yield", test_yield);
    g_test_add_func("/basic/nesting", test_nesting);
    g_test_add_func("/basic/self", test_self);
    g_test_add_func("/basic/in_coroutine", test_in_coroutine);
    if (g_test_perf()) {
        g_test_add_func("/perf/lifecycle", perf_lifecycle);
        g_test_add_func("/perf/nesting", perf_nesting);
        g_test_add_func("/perf/yield", perf_yield);
    }
    return g_test_run();
}
コード例 #8
0
int
main (int argc, char **argv)
{
  g_test_init (&argc, &argv, NULL);

  if (g_test_perf ())
    {
      g_test_add_data_func ("/utf8/perf/get_char", grind_get_char, perform);
      g_test_add_data_func ("/utf8/perf/get_char-backwards", grind_get_char_backwards, perform);
      g_test_add_data_func ("/utf8/perf/get_char_validated", grind_get_char_validated, perform);
      g_test_add_data_func ("/utf8/perf/utf8_to_ucs4", grind_utf8_to_ucs4, perform);
      g_test_add_data_func ("/utf8/perf/utf8_to_ucs4-sized", grind_utf8_to_ucs4_sized, perform);
      g_test_add_data_func ("/utf8/perf/utf8_to_ucs4_fast", grind_utf8_to_ucs4_fast, perform);
      g_test_add_data_func ("/utf8/perf/utf8_to_ucs4_fast-sized", grind_utf8_to_ucs4_fast_sized, perform);
    }

  return g_test_run ();
}
コード例 #9
0
ファイル: test-suite.c プロジェクト: CAARNICL/gnucash
/* Assert macros that you can use in your test functions. "cmp" is a
 * comparison operator, one of ==, !=, <, >, <=, >=.
 *
 *  g_assert( boolean_expression )
 *  g_assert_not_reached()
 *  g_assert_cmpstr( gchar *s1, cmp, gchar *s2 )
 *  g_assert_cmpint( int s1, cmp, int s2 )
 *  g_assert_cmpuint( unsigned int s1, cmp, unsigned int s2 )
 *  g_assert_cmphex( unsigned int s1, cmp, unsigned int s2 )
 *  g_assert_cmpfloat( double s1, cmp, double s2 )
 *  g_assert_no_error( GError *err )
 *  g_assert_error( GError *err, GQuark domain, gint code )
 *
 * You can also emit arbitrary messages into the test report with
 *  g_test_message( const char* format, ... )
 */
void
test_suite_module1 (void)
{
    Datatype data = something();
    GNC_TEST_ADD_FUNC (suitename, "Test Name 1", test_function);
    {
        gchar *testpath = g_strdup_printf ("%s/Test Name 2", suitename);
        g_test_add_data_func( suitename, (gconstpointer)(&data),
                              test_function_with_data );
        g_free (testpath);
    }
    GNC_TEST_ADD (suitename, "Test Name 3", Fixture, data, setup,
                  test_function_with_fixture, teardown);
    /* Other conditionals are g_test_quick(), g_test_slow(), and
     * g_test_thorough() */
    if ( g_test_perf() )
    {
        GNC_TEST_ADD_FUNC (suitename, "Test Name 4", test_performance_func);
    }
}
コード例 #10
0
ファイル: log4g-test.c プロジェクト: msteinert/log4g
int
main(int argc, char *argv[])
{
	GOptionContext *context =
		g_option_context_new("- test Log4g initialization");
	if (!context) {
		return EXIT_FAILURE;
	}
	GOptionEntry entries[] = {
		{ NULL, '\0', 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
	};
	g_test_init(&argc, &argv, NULL);
#if !GLIB_CHECK_VERSION(2, 36, 0)
	g_type_init();
#endif
	g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
	g_option_context_add_group(context, log4g_get_option_group());
	GError *error = NULL;
	if (!g_option_context_parse(context, &argc, &argv, &error)) {
		g_message("option parsing failed: %s\n", error->message);
		g_error_free(error);
		return EXIT_FAILURE;
	}
	g_option_context_free(context);
	g_test_add(CLASS"/001", gpointer, NULL, NULL, test_001, NULL);
	if (g_test_perf()) {
		g_test_add(CLASS"/perf/001", gpointer, NULL, NULL,
				perf_001, NULL);
		g_test_add(CLASS"/perf/002", gpointer, NULL, NULL,
				perf_002, NULL);
		g_test_add(CLASS"/perf/003", gpointer, NULL, NULL,
				perf_003, NULL);
	}
	int status = g_test_run();
	log4g_finalize();
	return status;
}
コード例 #11
0
static void
test_immediate_performance_n_watchers(TestFixture *fixture,
                                      const void  *data,
                                      int          n_watchers)
{
    int i, j;

    if (!g_test_perf())
        return;

    /* this has to be set up front of there's a race in using it to
     * decide to quit mainloop, because task runner starts running
     * tasks right away, doesn't wait for our local mainloop
     */
    fixture->tasks_started_count = NUM_TASKS;

    /* start here, to include task creation. Also, immediates can start
     * running right away, before we block in main loop.
     */
    g_test_timer_start();

    for (i = 0; i < NUM_TASKS; ++i) {
        HrtTask *task;

        task =
            hrt_task_runner_create_task(fixture->runner);

        fixture->tasks[i].task = task;
    }

    /* If we added n_watchers immediates to task 0, then task 1, then 2,
     * etc.  then we'd never use any parallelism because we'd just
     * have one task active at a time using only one thread.  By doing
     * the loop this way we get some use of multiple threads in
     * theory. Also this is more "real world" in that most likely
     * tasks do some work, add an event loop source, do some work,
     * etc. instead of just adding a pile of sources from the
     * same task all at once. This more "real world" scenario is
     * less efficient and slows down the benchmark.
     */
    for (j = 0; j < n_watchers; ++j) {
        for (i = 0; i < NUM_TASKS; ++i) {
            HrtTask *task = fixture->tasks[i].task;
            hrt_task_add_immediate(task,
                                   on_immediate_for_performance_many_watchers,
                                   fixture,
                                   on_dnotify_bump_count);
        }
    }

    g_main_loop_run(fixture->loop);

    g_test_minimized_result(g_test_timer_elapsed(),
                            "Run %d tasks with %d immediates each",
                            NUM_TASKS, n_watchers);

    g_assert_cmpint(fixture->tasks_completed_count, ==, NUM_TASKS);
    g_assert_cmpint(fixture->tasks_completed_count, ==,
                    fixture->tasks_started_count);
    g_assert_cmpint(fixture->dnotify_count, ==, n_watchers * NUM_TASKS);
}