Beispiel #1
0
END_TEST

START_TEST(test_atree_max_value)
{
    ATree *at;
    gint   result;
    gint   key_a;
    gint   data_a;
    gint   key_b;
    gint   data_b;
    gint  *max;
    GRand *random;
    
    at = a_tree_new();
    
    if (at == NULL)
    {
        ck_abort_msg ("Failed to create ATree\n");
    }
    else
    {
        random = g_rand_new_with_seed( (guint32) at );
        key_a  = g_rand_int( random );
        data_a = g_rand_int( random );
        key_b  = g_rand_int( random );
        data_b = g_rand_int( random );
        
        result = atree_insert( at, GINT_TO_POINTER(&key_a), GINT_TO_POINTER(&data_a) );
        ck_assert_int_eq( result, 0 );
        
        result = atree_insert( at, GINT_TO_POINTER(&key_b), GINT_TO_POINTER(&data_b) );
        ck_assert_int_eq( result, 0 );
        
        max    = atree_max_value( at );
        
        if (max == NULL)
        {
            ck_abort_msg ("maximum values is NULL\n");
        }
        else
        {   
            if (key_a > key_b)
            {
                ck_assert_int_eq( *max, data_a );
            }
            else
            {
                ck_assert_int_eq( *max, data_b );
            }
        }
        
        a_tree_destroy( at );
    }
}
Beispiel #2
0
END_TEST

START_TEST(test_atree_insert)
{
    ATree *at;
    gint   result;
    gint   key;
    gint   data;
    
    at = a_tree_new();
    
    if (at == NULL)
    {
        ck_abort_msg ("Failed to create ATree\n");
    }
    else
    {
        key  = 1;
        data = 1;
        
        result = atree_insert( at, GINT_TO_POINTER(&key), GINT_TO_POINTER(&data) );
        ck_assert_int_eq( result, 0 );
        
        a_tree_destroy( at );
    }
}
Beispiel #3
0
io_module_t *__io_moduleCreateWithLibrary(io_library_t *library, bool retainLibrary)
{
	io_module_t *module = halloc(NULL, sizeof(io_module_t));
	if(module)
	{
		module->library = library;
		module->module  = NULL;

		module->name = library->name;
		module->references = 1;
		module->lock = SPINLOCK_INIT;

		module->start = (io_module_start_t)io_libraryFindSymbol(library, "_kern_start");
		module->stop  = (io_module_stop_t)io_libraryFindSymbol(library, "_kern_stop");

		if(!module->start || !module->stop)
		{
			dbg("library %s doesn't provide kernel entry points!\n", library->name);
			hfree(NULL, module);

			return NULL;
		}

		if(retainLibrary)
			io_libraryRetain(library);

		atree_insert(__io_moduleTree, module, module->name);
	}

	return module;
}
Beispiel #4
0
bool io_storeAddLibrary(io_library_t *library)
{
	spinlock_lock(&__io_storeLock);
	if(!atree_find(__io_storeLibraries, (void *)library->name))
	{
		atree_insert(__io_storeLibraries, library, (void *)library->name);
		spinlock_unlock(&__io_storeLock);

		io_libraryResolveDependencies(library);

		bool rel1 = io_libraryRelocateNonPLT(library);
		bool rel2 = io_libraryRelocatePLT(library); 

		if(!rel1 || !rel2)
		{
			io_storeRemoveLibrary(library);
			return false;
		}

		return true;
	}

	spinlock_unlock(&__io_storeLock);
	return true;
}
Beispiel #5
0
END_TEST

START_TEST(test_atree_random_value)
{
    ATree *at;
    gint  result;
    gint  key;
    gint  data;
    gint  *random;
    
    at = a_tree_new();
    
    if (at == NULL)
    {
        ck_abort_msg ("Failed to create ATree\n");
    }
    else
    {
        key  = 1;
        data = 1;
        
        g_rand_set_seed( at->random, 0 );
        
        result = atree_insert( at, GINT_TO_POINTER(&key), GINT_TO_POINTER(&data) );
        ck_assert_int_eq( result, 0 );
		
		random = atree_random_value( at );
        
        if (random == NULL)
        {
            ck_abort_msg ("random values is NULL\n");
        }
        else
        {
            ck_assert_int_eq( *random, data );
        }
        
        a_tree_destroy( at );
    }
}
Beispiel #6
0
END_TEST

START_TEST(test_atree_minmax)
{
    ATree *at;
    gint   result;
    gint   *key;
    gint   *data;
    gint   limit;
    gint   index;
    gint   min;
    gint   max;
    gint   *min_from_tree;
    gint   *max_from_tree;
    GRand  *random;
    
    at = a_tree_new();
    
    if (at == NULL)
    {
        ck_abort_msg ("Failed to create ATree\n");
    }
    else
    {
        limit  = 100;
        random = g_rand_new_with_seed( (guint32) at );
        min    = 0;
        max    = 0;
         
        for (index = 0; index < limit; index++)
        {
            key  = g_new(gint, 1);
            data = g_new(gint, 1);
            
            *key  = g_rand_int( random );
            *data = *key;
            
            if (*key >= max)
            {
                max = *data;
            }
            else
            {
                if (*key <= min)
                {
                    min = *data;
                }
                else
                {
                    /* Do nothing */
                }
            }
            
            result = atree_insert( at, GINT_TO_POINTER(key), GINT_TO_POINTER(data) );
            ck_assert_int_eq( result, 0 );
        }
        
        max_from_tree = atree_max_value( at );
        min_from_tree = atree_min_value( at );
        
        ck_assert_int_eq( *max_from_tree, max );
        ck_assert_int_eq( *min_from_tree, min );
        
        a_tree_destroy( at );
    }
}