Beispiel #1
0
static void test_hash_speed(const void *opaque)
{
    size_t chunk_size = (size_t)opaque;
    uint8_t *in = NULL, *out = NULL;
    size_t out_len = 0;
    double total = 0.0;
    struct iovec iov;
    int ret;

    in = g_new0(uint8_t, chunk_size);
    memset(in, g_test_rand_int(), chunk_size);

    iov.iov_base = (char *)in;
    iov.iov_len = chunk_size;

    g_test_timer_start();
    do {
        ret = qcrypto_hash_bytesv(QCRYPTO_HASH_ALG_SHA256,
                                  &iov, 1, &out, &out_len,
                                  NULL);
        g_assert(ret == 0);

        total += chunk_size;
    } while (g_test_timer_elapsed() < 5.0);

    total /= MiB;
    g_print("sha256: ");
    g_print("Testing chunk_size %zu bytes ", chunk_size);
    g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last());
    g_print("%.2f MB/sec\n", total / g_test_timer_last());

    g_free(out);
    g_free(in);
}
Beispiel #2
0
/**
 * test_visitor_register_identity:
 * @fn test_visitor_register_identity
 * Tests whether compilerkit_visitor_register_identity function works as intended.
 * @pre None
 * @param None
 * @return void
 */
void test_visitor_register_identity (void)
{
    GObject *symbol;
    GObject *empty_set;
    CompilerKitVisitor *visitor;

    g_test_message ("Testing visitor register identity");
    g_test_timer_start ();

    symbol    = compilerkit_symbol_new ('a');
    empty_set = compilerkit_empty_set_get_instance ();
    visitor   = compilerkit_visitor_new();

    // Register the identity function (it returns whatever GObject* gets as a parameter during the visit)
    compilerkit_visitor_register_identity (visitor, COMPILERKIT_TYPE_EMPTY_SET);

    // Since we didn't register the symbol, the visitor should return NULL
    g_assert (compilerkit_visitor_visit (visitor, symbol) == NULL);

    // The visitor should produce symbol here, since we registered the identity function for the symbol class.
    g_assert (compilerkit_visitor_visit (visitor, empty_set) == empty_set);

    // Decrease the reference count for objects to free them.
    g_object_unref (symbol);
    g_object_unref (empty_set);
    g_object_unref (visitor);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #3
0
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);
}
Beispiel #4
0
void test_creation(GThreadFunc f, sc_int32 count, sc_int thread_count)
{
    int test_count = count / thread_count;

    g_message("Threads count: %d, Test per thread: %d", thread_count, test_count);

    tGThreadVector threads;
    threads.reserve(thread_count);


    print_storage_statistics();

    g_test_timer_start();
    for (size_t i = 0; i < thread_count; ++i)
    {
        GThread * thread = g_thread_try_new(0, f, GINT_TO_POINTER(test_count), 0);
        if (thread == 0)
            continue;
        threads.push_back(thread);
    }

    for (size_t i = 0; i < thread_count; ++i)
        g_assert(GPOINTER_TO_INT(g_thread_join(threads[i])) == test_count);

    printf("Time: %lf\n", g_test_timer_elapsed());

    print_storage_statistics();
}
Beispiel #5
0
/**
 * test_FSM_state:
 * @fn test_FSM_state
 * Tests `compilerkit_FSM_*_state` in CompilerKitFSM struct.
 * @pre None
 * @param None
 * @return void
 */
void test_FSM_states (void)
{
    CompilerKitFSM *fsm;
    g_test_message ("Testing FSM state");
    g_test_timer_start ();

    fsm = compilerkit_FSM_new ("zero");
    compilerkit_FSM_add_state (fsm, "one");
    compilerkit_FSM_add_state (fsm, "two");
    compilerkit_FSM_add_state (fsm, "three");
    
    g_assert (compilerkit_FSM_has_state (fsm, "zero"));
    g_assert (compilerkit_FSM_has_state (fsm, "one"));
    g_assert (compilerkit_FSM_has_state (fsm, "two"));
    g_assert (compilerkit_FSM_has_state (fsm, "three"));
    g_assert (!compilerkit_FSM_has_state (fsm, "four"));
    g_assert (!compilerkit_FSM_has_state (fsm, NULL));
    
    compilerkit_FSM_add_transition (fsm, "zero", "five", '5');
    compilerkit_FSM_add_accepting_state (fsm, "six");
    g_assert (compilerkit_FSM_has_state (fsm, "five"));
    g_assert (compilerkit_FSM_has_state (fsm, "six"));
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
    g_object_unref (fsm);
}
Beispiel #6
0
/**
 * test_visitor_null_visit:
 * @fn test_visitor_null_visit
 * Tests whether compilerkit_visitor_visit produces appropriate results in the CompilerKitVisitor struct.
 * @pre None
 * @param None
 * @return void
 */
void test_visitor_null_visit(void)
{
    GObject *symbol;
    GObject *empty_set;
    CompilerKitVisitor* visitor;

    g_test_message ("Testing visitor null visits");
    g_test_timer_start ();

    symbol = compilerkit_symbol_new ('a');
    empty_set = compilerkit_empty_set_get_instance ();
    visitor = check_symbol();

    // Assert that visitor produces the correct result
    g_assert(compilerkit_visitor_visit(visitor, symbol) == symbol);

    // NULL objects will produce NULL
    g_assert(compilerkit_visitor_visit(visitor, NULL) == NULL);

    // Nothing registered for empty set, so return NULL
    g_assert(compilerkit_visitor_visit(visitor, empty_set) == NULL);

    // Decrease the reference count for objects to free them.
    g_object_unref (symbol);
    g_object_unref (empty_set);
    g_object_unref (visitor);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #7
0
static void
wmem_time_allocators(void)
{
    double simple_time, block_time;

    g_test_timer_start();
    wmem_time_allocator(WMEM_ALLOCATOR_SIMPLE);
    simple_time = g_test_timer_elapsed();

    g_test_timer_start();
    wmem_time_allocator(WMEM_ALLOCATOR_BLOCK);
    block_time = g_test_timer_elapsed();

    printf("(simple: %lf; block: %lf) ", simple_time, block_time);
    g_assert(simple_time > block_time);
}
Beispiel #8
0
/**
 * test_symbol_flyweight:
 * @fn test_symbol_unicode
 * Tests whether compilerkit_symbol_new in CompilerKitSymbol struct allocates new space only for unique symbols.
 * @pre None
 * @param None
 * @return void
 */
void test_symbol_flyweight (void)
{
    CompilerKitSymbol *symbol1, *symbol2, *symbol3;
    
    g_test_message ("Testing Symbol unicode");
    g_test_timer_start ();
    
    /** @todo Test here  */
    symbol1 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('a'));
    symbol2 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('b'));
    symbol3 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('a'));

    /* Symbol b is distinct from Symbol a */
    g_assert (symbol2 != symbol3);
    g_assert (symbol2 != symbol1);

    /* The pointer to Symbol('a') should equal the pointer to Symbol('a').
       This of course, would make Ayn Rand proud ;-) */
    g_assert (symbol1 == symbol3);

    g_object_unref(symbol1);
    g_object_unref(symbol2);
    g_object_unref(symbol3);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
/**
 * test_alternation_vlist_new:
 * @fn test_alternation_vlist_new
 * Tests method compilerkit_alternation_vlist_new in CompilerKitAlternation struct.
 * @pre None
 * @param None
 * @return void
 */
void test_alternation_vlist_new (void)
{
	GObject* alt;
	GObject* one;
	GObject* two;
	GObject* three;
	
    g_test_message ("Testing Alternation vlist new");
    g_test_timer_start ();
	
	one = compilerkit_symbol_new('a');
	two = compilerkit_symbol_new('b');
	three = compilerkit_symbol_new('c');
	alt = compilerkit_alternation_vlist_new(one, two, three, NULL);
   
    g_assert (COMPILERKIT_IS_ALTERNATION(alt));
	g_assert (one != two);
	g_assert (two != three);
	g_assert (one != three);
	g_assert (one != alt);
	g_assert (two != alt);
	g_assert (three != alt);
	g_assert (three == compilerkit_alternation_get_right(COMPILERKIT_ALTERNATION(alt)));
	g_assert (one == compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(alt)))));
	g_assert (two == compilerkit_alternation_get_right(COMPILERKIT_ALTERNATION(compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(alt)))));

	g_object_unref (alt); // This will unref one, two and three as well
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #10
0
gpointer start_save_threaded(gpointer data)
{
    g_test_timer_start();
    sc_memory_save(s_default_ctx);
    printf("Save time: %lf\n", g_test_timer_elapsed());

	return 0;
}
/**
 * test_complement_constructor:
 * @fn test_complement_constructor
 * Tests method compilerkit_complement_new in CompilerKitComplement struct.
 * @pre None
 * @param None
 * @return void
 */
void test_complement_constructor (void)
{
    g_test_message ("Testing Complement method");
    g_test_timer_start ();
    
    /** @todo Test here  */
    g_assert(FALSE);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
/**
 * test_concatenation_method:
 * @fn test_concatenation_method
 * Tests method compilerkit_concatenation_method in CompilerKitConcatenation struct.
 * @pre None
 * @param None
 * @return void
 */
void test_concatenation_method (void)
{
    g_test_message ("Testing Concatenation method");
    g_test_timer_start ();
    
    /** @todo Test here  */
    g_assert(FALSE);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #13
0
/**
 * test_scanner_method:
 * @fn test_scanner_method
 * Tests method compilerkit_scanner_method in CompilerKitScanner struct.
 * @pre None
 * @param None
 * @return void
 */
void test_scanner_method (void)
{
    g_test_message ("Testing Scanner method");
    g_test_timer_start ();
    
    /** @todo Test here  */
    g_assert(FALSE);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
/**
 * test_pushdown_automata_method:
 * @fn test_pushdown_automata_method
 * Tests method compilerkit_pushdown_automata_method in CompilerKitPushdownAutomata struct.
 * @pre None
 * @param None
 * @return void
 */
void test_pushdown_automata_method (void)
{
    g_test_message ("Testing PushdownAutomata method");
    g_test_timer_start ();
    
    /** @todo Test here  */
    g_assert(FALSE);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
/**
 * test_empty_string_method:
 * @fn test_empty_string_method
 * Tests method compilerkit_empty_string_method in CompilerKitEmptyString struct.
 * @pre None
 * @param None
 * @return void
 */
void test_empty_string_method (void)
{
    g_test_message ("Testing EmptyString method");
    g_test_timer_start ();
    
    /** @todo Test here  */
    g_assert(FALSE);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #16
0
void
perf_002(G_GNUC_UNUSED gpointer *fixture, G_GNUC_UNUSED gconstpointer data)
{
	gint log = 1000000;
	g_test_timer_start();
	for (gint i = 0; i < log; ++i) {
		log4g_error("%d log this message", i);
	}
	gdouble e = g_test_timer_elapsed();
	g_test_minimized_result(e, "logged messages, rate=%d/second",
			(gint)(log / e));
}
Beispiel #17
0
void
perf_003(G_GNUC_UNUSED gpointer *fixture, G_GNUC_UNUSED gconstpointer data)
{
	gint log = 1000000;
	FILE *file = fopen("tests/file.txt", "w");
	g_test_timer_start();
	for (gint i = 0; i < log; ++i) {
		fprintf(file, "%d log this message\n", i);
	}
	gdouble e = g_test_timer_elapsed();
	g_test_minimized_result(e, "logged messages, rate=%d/second",
			(gint)(log / e));
}
Beispiel #18
0
void test_g_test_timer()
    {
    double ret_time1, ret_time2;
    
    g_test_timer_start();
    ret_time1 = g_test_timer_elapsed();
    ret_time2 = g_test_timer_last();
    
    if(!(ret_time1 == ret_time2))
        {
        std_log(LOG_FILENAME_LINE, "g_test_timer* didnt work as expected");
        assert_failed = 1;
        }
    }
Beispiel #19
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
}
Beispiel #20
0
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);
}
/**
 * test_string_builder_visitor:
 * @fn test_string_builder_visitor
 * Tests compilerkit_string_builder_visitor.
 * @pre None
 * @param None
 * @return void
 */
void test_string_builder_case (void)
{
    CompilerKitVisitor *string_builder;
    g_test_message ("Testing StringBuilder visitor");
    g_test_timer_start ();

    /** @todo Test here  */
    string_builder = compilerkit_string_builder_visitor();
    g_assert(FALSE);

    g_object_unref (string_builder);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #22
0
/**
 * test_production_case:
 * @fn test_production_case
 * Tests compilerkit_production_case in CompilerKitProduction struct.
 * @pre None
 * @param None
 * @return void
 */
void test_production_case (void)
{
    //CompilerKitProduction *obj;

    g_test_message ("Testing Production case");
    g_test_timer_start ();
    
    /** @todo Test here  */
    g_assert(FALSE);
    
    //g_object_unref (obj);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
/**
 * test_derivative_visitor:
 * @fn test_derivative_visitor
 * Tests compilerkit_derivative_visitor.
 * @pre None
 * @param None
 * @return void
 */
void test_derivative_case (void)
{
    CompilerKitVisitor *derivative;
    g_test_message ("Testing Derivative visitor");
    g_test_timer_start ();
    
    /** @todo Test here  */
    derivative = compilerkit_derivative_visitor();
    g_assert(FALSE);
    
    g_object_unref (derivative);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #24
0
/**
 * test_FSM_start_state:
 * @fn test_FSM_set_start_state
 * Tests `compilerkit_FSM_*_start_state` in CompilerKitFSM struct.
 * @pre None
 * @param None
 * @return void
 */
void test_FSM_start_state (void)
{
    CompilerKitFSM *fsm;
    g_test_message ("Testing FSM start_state");
    g_test_timer_start ();

    fsm = compilerkit_FSM_new ("constructor");
    g_assert (g_strcmp0 (compilerkit_FSM_get_start_state (fsm), "constructor") == 0);
    compilerkit_FSM_set_start_state (fsm, "start_state");

    g_assert (g_strcmp0 (compilerkit_FSM_get_start_state (fsm), "start_state") == 0);

    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
    g_object_unref (fsm);
}
/**
 * test_to_grammar_visitor:
 * @fn test_to_grammar_visitor
 * Tests compilerkit_to_grammar_visitor.
 * @pre None
 * @param None
 * @return void
 */
void test_to_grammar_visitor (void)
{
    CompilerKitVisitor *to_grammar;
    g_test_message ("Testing ToGrammar visitor");
    g_test_timer_start ();
    
    /** @todo Test here  */
    to_grammar = compilerkit_to_grammar_visitor();
    g_assert(FALSE);
    
    g_object_unref (to_grammar);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #26
0
/**
 * test_symbol_unicode:
 * @fn test_symbol_unicode
 * Tests compilerkit_symbol_new in CompilerKitSymbol struct for the ability to deal with Unicode (specifically, UTF-8).
 * @pre None
 * @param None
 * @return void
 */
void test_symbol_unicode (void)
{
    CompilerKitSymbol *symbol;
    g_test_message ("Testing Symbol unicode");
    g_test_timer_start ();
   
    gunichar ch = g_utf8_get_char("台");

    symbol = COMPILERKIT_SYMBOL (compilerkit_symbol_new(ch));

    g_assert(compilerkit_symbol_get_symbol (symbol) == ch /*'台'*/ );

    g_object_unref(symbol);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Beispiel #27
0
/**
 * test_FSM_state:
 * @fn test_FSM_state
 * Tests `compilerkit_FSM_*_state` in CompilerKitFSM struct.
 * @pre None
 * @param None
 * @return void
 */
void test_FSM_states (void)
{
    CompilerKitFSM *fsm;
    g_test_message ("Testing FSM state");
    g_test_timer_start ();

    fsm = compilerkit_FSM_new ("zero");
    compilerkit_FSM_add_transition(fsm,"zero","one","a");
    compilerkit_FSM_add_transition(fsm,"zero","two","b");

    g_assert(compilerkit_FSM_has_state(fsm,"zero"));
    g_assert(compilerkit_FSM_has_state(fsm,"one"));

    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
    g_object_unref (fsm);
}
Beispiel #28
0
static void perf_lifecycle(void)
{
    Coroutine *coroutine;
    unsigned int i, max;
    double duration;

    max = 1000000;

    g_test_timer_start();
    for (i = 0; i < max; i++) {
        coroutine = qemu_coroutine_create(empty_coroutine);
        qemu_coroutine_enter(coroutine, NULL);
    }
    duration = g_test_timer_elapsed();

    g_test_message("Lifecycle %u iterations: %f s\n", max, duration);
}
Beispiel #29
0
static void
magic_uri_performance (void)
{
    gsize i;

    g_test_timer_start ();

    for (i = 0; i < 1000; i++)
    {
        magic_uri_uri ();
        magic_uri_idn ();
        magic_uri_search ();
        magic_uri_pseudo ();
    }

    g_print ("\nTime needed for URI tests: %f ", g_test_timer_elapsed ());
}
Beispiel #30
0
static void perf_yield(void)
{
    unsigned int i, maxcycles;
    double duration;

    maxcycles = 100000000;
    i = maxcycles;
    Coroutine *coroutine = qemu_coroutine_create(yield_loop);

    g_test_timer_start();
    while (i > 0) {
        qemu_coroutine_enter(coroutine, &i);
    }
    duration = g_test_timer_elapsed();

    g_test_message("Yield %u iterations: %f s\n",
        maxcycles, duration);
}