Exemple #1
0
} END_TEST

/**
 * \brief Verify that it is not possible to insert one image twice
 */
START_TEST(test_insert_image_double) {
	Image*		test_data_1[4] = { pointer_list[0], pointer_list[1], pointer_list[2], pointer_list[3] };
	Image*		test_data_2[4] = { pointer_list[1], pointer_list[4], pointer_list[2], pointer_list[5] };

	ImageGroup* test_group = group_create("test_name", 't');
	ck_assert_int_eq( 0, group_get_size(test_group) );

	// initial insertion of 3 images into list
	ck_assert( OK == group_insert(test_group, 0, test_data_1, 4) );
	ck_assert_int_eq( 4, group_get_size(test_group) );
	ck_assert_str_eq( test_data_1[0]->name, group_get_image(test_group, 0)->name );
	ck_assert_str_eq( test_data_1[1]->name, group_get_image(test_group, 1)->name );
	ck_assert_str_eq( test_data_1[2]->name, group_get_image(test_group, 2)->name );
	ck_assert_str_eq( test_data_1[3]->name, group_get_image(test_group, 3)->name );

	// insert two images at the end of image list
	ck_assert( OK == group_insert(test_group, 4, test_data_2, 4) );
	ck_assert_int_eq( 6, group_get_size(test_group) );
	ck_assert_str_eq( test_data_2[1]->name, group_get_image(test_group, 4)->name );
	ck_assert_str_eq( test_data_2[3]->name, group_get_image(test_group, 5)->name );

	ck_assert( OK == group_destroy(test_group) );
	ck_assert( ! error_is_error() );
} END_TEST
Exemple #2
0
} END_TEST


/**
 * \brief Test function invocation on not created group list.
 *
 * This test must be run without setup funtions which are used for other tests
 *
 * Its aim is to test response of function when GroupList is not allocated.
 */
START_TEST(test_noexistent) {

	ImageGroup *tmp = group_create("test", 'a');

	fail_unless( FAIL == glist_group_insert(tmp), NULL);
	fail_unless( FAIL == glist_group_remove_by_index(0), NULL);

	fail_unless( FAIL == glist_get_by_index(0), NULL);
	fail_unless( NULL == glist_get_by_tag('Y'), NULL);
	fail_unless( NULL == glist_get_by_name("some name"), NULL);

	fail_unless( -1 == glist_get_size(), NULL);

	group_destroy(tmp);
	error_reset();
} END_TEST
Exemple #3
0
void dataset_destroy(dataset_t** dataset_ref)
{
    dataset_t* d = *dataset_ref;

    if(d != NULL)
    {
        if(d->trajectories != NULL)
        {
            int i = 0;
            for(; i < d->n_trajectories; i++)
                trajectory_destroy(&d->trajectories[i]);
            free(d->trajectories);
            d->trajectories = NULL;
        }

        if(d->groups != NULL)
        {
            int i = 0;
            for(; i < d->n_groups; i++)
                group_destroy(&d->groups[i]);
            free(d->groups);
            d->groups = NULL;
        }
        free(d);
        *dataset_ref = NULL;
    }
}
Exemple #4
0
/**
 * Deallocate the group list and destroy the test data created for unit tests.
 */
static void test_teardown(void) {

	COLOR_TEARDOWN_START;
	glist_destroy();

	group_destroy(group_data[0]);
	group_destroy(group_data[1]);
	group_destroy(group_data[2]);
	group_destroy(group_data[3]);
	group_destroy(group_data[4]);

	if ( error_is_error() ) {
		ERROR_LOG();
	}
	COLOR_TEARDOWN_END;
	return ;
}
Exemple #5
0
} END_TEST

/**
 * \brief Verify insertion of images into empty list
 *
 * Insert images into empty list and verify its position in the image group
 * arrays is correct. Verify that the image reference counters are handled
 * correctly.
 *
 * The number of references is 2 at the start of the test (1 reference is held
 * by pointer_list array and another by static image_group).
 */
START_TEST(test_insert_image_simple) {
	Image*		test_data[3] = { pointer_list[0], pointer_list[1], pointer_list[2] };
	ImageGroup *test_group = group_create("test_name", 't');
	int i;

	// check inserting three images into empty image file
	ck_assert( OK == group_insert(test_group, 0, test_data, 3) );
	ck_assert_int_eq( 3, group_get_size(test_group) );

	for (i = 0; i < 3; i++ ) {
		Image* image = group_get_image(test_group, i);

		ck_assert_int_eq( 3, image->ref );
		ck_assert_str_eq( test_data[i]->name, image->name );
		// the image is also in the 'general' group created in setup function
		ck_assert_int_eq( 2, taglist_get_count(image->group));
		ck_assert_int_eq( TRUE, taglist_contains(image->group, 't') );
	}

	// destroy image list
	ck_assert( OK == group_destroy(test_group) );
	ck_assert( ! error_is_error() );

	// check reference count on the images has droped and they are no longer in
	// group
	for (i = 0; i < 3; i++ ) {
		ck_assert_int_eq( 2, test_data[i]->ref );
		ck_assert_int_eq( 1, taglist_get_count(test_data[i]->group));
		ck_assert_int_eq( FALSE, taglist_contains(test_data[i]->group, 't') );
	}
} END_TEST
Exemple #6
0
/**
 * \brief Tear down test related structures after the test finished.
 *
 * Deallocate test group and all test image structures.
 */
static void group_teardown(void) {
	int i;
	COLOR_TEARDOWN_START;

	// destroy test image group and its content
	group_destroy(image_group);
	group_buffer_destroy();

	if ( error_is_error() ) ERROR_LOG();

	// destroy temporary image structures
	for (i = 0; i < 10; i++) {
		image_unref(pointer_list[i]);
		pointer_list[i] = NULL;
		if ( error_is_error() ) ERROR_LOG();
	}
	COLOR_TEARDOWN_END;
	return ;
}
Exemple #7
0
} END_TEST

/**
 * \brief Verify range pasting works correctly
 *
 * Yank and paste some image pointers from one group and paste it to another
 * group. Verify the image pointer references are handled correctly.
 */
START_TEST(test_yank_paste) {
	Range rng;

	ImageGroup* test_group = group_create("test_name", 't');
	ck_assert_int_eq( 0, group_get_size(test_group) );

	// yank some data from the middle of group and do initial yank buffer
	// allocation
	rng.start = 2;
	rng.end = 4;

	ck_assert( OK == group_yank_range(image_group, rng) );
	ck_assert_str_eq( pointer_list[2]->name, group_yank_buffer[0]->name );
	ck_assert_str_eq( pointer_list[3]->name, group_yank_buffer[1]->name );
	ck_assert_str_eq( pointer_list[4]->name, group_yank_buffer[2]->name );
	ck_assert_int_eq( 3, pointer_list[2]->ref );
	ck_assert_int_eq( 3, pointer_list[3]->ref );
	ck_assert_int_eq( 3, pointer_list[4]->ref );
	ck_assert_int_eq( 3, group_buffer_size() );
	ck_assert_int_eq( 3, group_buffer_max_size() );

	// paste from yank buffer
	ck_assert( OK == group_yank_paste(test_group, 0) );
	ck_assert_str_eq( pointer_list[2]->name, group_get_image(test_group, 0)->name );
	ck_assert_str_eq( pointer_list[3]->name, group_get_image(test_group, 1)->name );
	ck_assert_str_eq( pointer_list[4]->name, group_get_image(test_group, 2)->name );
	ck_assert_int_eq( 4, pointer_list[2]->ref );
	ck_assert_int_eq( 4, pointer_list[3]->ref );
	ck_assert_int_eq( 4, pointer_list[4]->ref );
	ck_assert_int_eq( 3, group_get_size(test_group) );

	ck_assert( OK == group_destroy(test_group) );
	ck_assert( ! error_is_error() );
} END_TEST
Exemple #8
0
/*
 * Class callback when a CPU is leaving the system (deletion)
 *
 * "pgdata" is a reference to the CPU's PG data to be deconstructed.
 *
 * cp->cpu_pg is used by the dispatcher to access the CPU's PG data
 * references a "bootstrap" structure across this function's invocation.
 * pg_cmt_cpu_init() and the routines it calls must be careful to operate only
 * on the "pgdata" argument, and not cp->cpu_pg.
 */
static void
pg_cmt_cpu_fini(cpu_t *cp, cpu_pg_t *pgdata)
{
	group_iter_t	i;
	pg_cmt_t	*pg;
	group_t		*pgs, *cmt_pgs;
	lgrp_handle_t	lgrp_handle;
	cmt_lgrp_t	*lgrp;

	if (cmt_sched_disabled)
		return;

	ASSERT(pg_cpu_is_bootstrapped(cp));

	pgs = &pgdata->pgs;
	cmt_pgs = &pgdata->cmt_pgs;

	/*
	 * Find the lgroup that encapsulates this CPU's CMT hierarchy
	 */
	lgrp_handle = lgrp_plat_cpu_to_hand(cp->cpu_id);

	lgrp = pg_cmt_find_lgrp(lgrp_handle);
	if (ncpus == 1 && lgrp != cpu0_lgrp) {
		/*
		 * One might wonder how we could be deconfiguring the
		 * only CPU in the system.
		 *
		 * On Starcat systems when null_proc_lpa is detected,
		 * the boot CPU (which is already configured into a leaf
		 * lgroup), is moved into the root lgroup. This is done by
		 * deconfiguring it from both lgroups and processor
		 * groups), and then later reconfiguring it back in.  This
		 * call to pg_cmt_cpu_fini() is part of that deconfiguration.
		 *
		 * This special case is detected by noting that the platform
		 * has changed the CPU's lgrp affiliation (since it now
		 * belongs in the root). In this case, use the cmt_lgrp_t
		 * cached for the boot CPU, since this is what needs to be
		 * torn down.
		 */
		lgrp = cpu0_lgrp;
	}

	ASSERT(lgrp != NULL);

	/*
	 * First, clean up anything load balancing specific for each of
	 * the CPU's PGs that participated in CMT load balancing
	 */
	pg = (pg_cmt_t *)pgdata->cmt_lineage;
	while (pg != NULL) {

		/*
		 * Remove the PG from the CPU's load balancing lineage
		 */
		(void) group_remove(cmt_pgs, pg, GRP_RESIZE);

		/*
		 * If it's about to become empty, destroy it's children
		 * group, and remove it's reference from it's siblings.
		 * This is done here (rather than below) to avoid removing
		 * our reference from a PG that we just eliminated.
		 */
		if (GROUP_SIZE(&((pg_t *)pg)->pg_cpus) == 1) {
			if (pg->cmt_children != NULL)
				group_destroy(pg->cmt_children);
			if (pg->cmt_siblings != NULL) {
				if (pg->cmt_siblings == &lgrp->cl_pgs)
					lgrp->cl_npgs--;
				else
					pg->cmt_parent->cmt_nchildren--;
			}
		}
		pg = pg->cmt_parent;
	}
	ASSERT(GROUP_SIZE(cmt_pgs) == 0);

	/*
	 * Now that the load balancing lineage updates have happened,
	 * remove the CPU from all it's PGs (destroying any that become
	 * empty).
	 */
	group_iter_init(&i);
	while ((pg = group_iterate(pgs, &i)) != NULL) {
		if (IS_CMT_PG(pg) == 0)
			continue;

		pg_cpu_delete((pg_t *)pg, cp, pgdata);
		/*
		 * Deleting the CPU from the PG changes the CPU's
		 * PG group over which we are actively iterating
		 * Re-initialize the iteration
		 */
		group_iter_init(&i);

		if (GROUP_SIZE(&((pg_t *)pg)->pg_cpus) == 0) {

			/*
			 * The PG has become zero sized, so destroy it.
			 */
			group_destroy(&pg->cmt_cpus_actv);
			bitset_fini(&pg->cmt_cpus_actv_set);
			pghw_fini((pghw_t *)pg);

			pg_destroy((pg_t *)pg);
		}
	}
}
Exemple #9
0
} END_TEST


/**
 * \brief Verify insertion of images into non-empty list
 *
 * Insert from one to three images into various positions in the image group
 * array and verify the insertion was done to correct place. Verify that the
 * image reference counters are handled correctly.
 */
START_TEST(test_insert_image_complex) {
	Image*		test_data_1[1] = { pointer_list[0] };
	Image*		test_data_2[3] = { pointer_list[1], pointer_list[2], pointer_list[3] };
	Image*		test_data_3[2] = { pointer_list[4], pointer_list[5] };
	Image*		test_data_4[1] = { pointer_list[6] };

	ImageGroup* test_group = group_create("test_name", 't');
	ck_assert( NULL != test_group );
	ck_assert( NULL != test_group->list );
	ck_assert_int_eq( 0, group_get_size(test_group) );

	// initial insertion of 3 images into list
	ck_assert( OK == group_insert(test_group, 0, test_data_2, 3) );
	ck_assert_int_eq( 3, group_get_size(test_group) );
	ck_assert_int_eq( 3, test_data_2[0]->ref );
	ck_assert_int_eq( 3, test_data_2[1]->ref );
	ck_assert_int_eq( 3, test_data_2[2]->ref );
	ck_assert_str_eq( test_data_2[0]->name, group_get_image(test_group, 0)->name );
	ck_assert_str_eq( test_data_2[1]->name, group_get_image(test_group, 1)->name );
	ck_assert_str_eq( test_data_2[2]->name, group_get_image(test_group, 2)->name );

	// insert one image at the beginning of image list
	ck_assert( OK == group_insert(test_group, 0, test_data_1, 1) );
	ck_assert_int_eq( 4, group_get_size(test_group) );
	ck_assert_int_eq( 3, test_data_1[0]->ref );
	ck_assert_str_eq( test_data_1[0]->name, group_get_image(test_group, 0)->name );
	ck_assert_str_eq( test_data_2[0]->name, group_get_image(test_group, 1)->name );

	// insert one image at the end of image list
	ck_assert( OK == group_insert(test_group, 4, test_data_4, 1) );
	ck_assert_int_eq( 5, group_get_size(test_group) );
	ck_assert_int_eq( 3, test_data_4[0]->ref );
	ck_assert_str_eq( test_data_4[0]->name, group_get_image(test_group, 4)->name );
	ck_assert_str_eq( test_data_2[2]->name, group_get_image(test_group, 3)->name );

	// insert two images in the middle of image list
	ck_assert( OK == group_insert(test_group,2, test_data_3, 2) );
	ck_assert_int_eq( 7, group_get_size(test_group) );
	ck_assert_int_eq( 3, test_data_3[0]->ref );
	ck_assert_int_eq( 3, test_data_3[1]->ref );
	ck_assert_str_eq( test_data_2[0]->name, group_get_image(test_group, 1)->name );
	ck_assert_str_eq( test_data_3[0]->name, group_get_image(test_group, 2)->name );
	ck_assert_str_eq( test_data_3[1]->name, group_get_image(test_group, 3)->name );
	ck_assert_str_eq( test_data_2[1]->name, group_get_image(test_group, 4)->name );

	// destroy image list
	ck_assert( OK == group_destroy(test_group) );
	ck_assert( ! error_is_error() );

	// check references of selected image pointers
	ck_assert_int_eq( 2, test_data_1[0]->ref );
	ck_assert_int_eq( 2, test_data_2[0]->ref );
	ck_assert_int_eq( 2, test_data_2[1]->ref );
	ck_assert_int_eq( 2, test_data_2[2]->ref );
	ck_assert_int_eq( 2, test_data_3[0]->ref );
	ck_assert_int_eq( 2, test_data_3[1]->ref );
} END_TEST