Commit 7cd209b3 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

test/unit: convert blob_ut to use spdk_ut_run_tests()



Converting this test was a little bit more involved, as it runs all
tests multiple times with different parameter combinations.  Now, a
separate test suite is registered for each such combination, which makes
it compatible with spdk_ut_run_tests() and allows users to run a given
test case (or test suite) with specific parameters.

Also, this patch fixes a bug when some of the test failures weren't
reported in the exit status of the process.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I1a9fcbc370cc2cdfe366255f56da6df950e2aa59
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/19320


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
parent 0e7077ac
Loading
Loading
Loading
Loading
+157 −115
Original line number Diff line number Diff line
@@ -8686,21 +8686,79 @@ suite_blob_cleanup(void)
	CU_ASSERT(g_bs == NULL);
}

static int
ut_setup_config_nocopy_noextent(void)
{
	g_dev_copy_enabled = false;
	g_use_extent_table = false;

	return 0;
}

static int
ut_setup_config_nocopy_extent(void)
{
	g_dev_copy_enabled = false;
	g_use_extent_table = true;

	return 0;
}

static int
ut_setup_config_copy_noextent(void)
{
	g_dev_copy_enabled = true;
	g_use_extent_table = false;

	return 0;
}

static int
ut_setup_config_copy_extent(void)
{
	g_dev_copy_enabled = true;
	g_use_extent_table = true;

	return 0;
}

struct ut_config {
	const char *suffix;
	CU_InitializeFunc setup_cb;
};

int
main(int argc, char **argv)
{
	CU_pSuite		suite, suite_bs, suite_blob, suite_esnap_bs;
	unsigned int	num_failures;
	unsigned int		i, num_failures;
	char			suite_name[4096];
	struct ut_config	*config;
	struct ut_config	configs[] = {
		{"nocopy_noextent", ut_setup_config_nocopy_noextent},
		{"nocopy_extent", ut_setup_config_nocopy_extent},
		{"copy_noextent", ut_setup_config_copy_noextent},
		{"copy_extent", ut_setup_config_copy_extent},
	};

	CU_set_error_action(CUEA_ABORT);
	CU_initialize_registry();

	suite = CU_add_suite("blob", NULL, NULL);
	suite_bs = CU_add_suite_with_setup_and_teardown("blob_bs", NULL, NULL,
	for (i = 0; i < SPDK_COUNTOF(configs); ++i) {
		config = &configs[i];

		snprintf(suite_name, sizeof(suite_name), "blob_%s", config->suffix);
		suite = CU_add_suite(suite_name, config->setup_cb, NULL);

		snprintf(suite_name, sizeof(suite_name), "blob_bs_%s", config->suffix);
		suite_bs = CU_add_suite_with_setup_and_teardown(suite_name, config->setup_cb, NULL,
				suite_bs_setup, suite_bs_cleanup);
	suite_blob = CU_add_suite_with_setup_and_teardown("blob_blob", NULL, NULL,

		snprintf(suite_name, sizeof(suite_name), "blob_blob_%s", config->suffix);
		suite_blob = CU_add_suite_with_setup_and_teardown(suite_name, config->setup_cb, NULL,
				suite_blob_setup, suite_blob_cleanup);
	suite_esnap_bs = CU_add_suite_with_setup_and_teardown("blob_esnap_bs", NULL, NULL,

		snprintf(suite_name, sizeof(suite_name), "blob_esnap_bs_%s", config->suffix);
		suite_esnap_bs = CU_add_suite_with_setup_and_teardown(suite_name, config->setup_cb, NULL,
				 suite_esnap_bs_setup,
				 suite_bs_cleanup);

@@ -8789,30 +8847,14 @@ main(int argc, char **argv)
		CU_ADD_TEST(suite_esnap_bs, blob_esnap_clone_reload);
		CU_ADD_TEST(suite_esnap_bs, blob_esnap_hotplug);
		CU_ADD_TEST(suite_blob, blob_is_degraded);
	}

	allocate_threads(2);
	set_thread(0);

	g_dev_buffer = calloc(1, DEV_BUFFER_SIZE);

	g_dev_copy_enabled = false;
	CU_basic_set_mode(CU_BRM_VERBOSE);
	g_use_extent_table = false;
	CU_basic_run_tests();
	num_failures = CU_get_number_of_failures();
	g_use_extent_table = true;
	CU_basic_run_tests();
	num_failures += CU_get_number_of_failures();

	g_dev_copy_enabled = true;
	CU_basic_set_mode(CU_BRM_VERBOSE);
	g_use_extent_table = false;
	CU_basic_run_tests();
	num_failures = CU_get_number_of_failures();
	g_use_extent_table = true;
	CU_basic_run_tests();
	num_failures += CU_get_number_of_failures();
	CU_cleanup_registry();
	num_failures = spdk_ut_run_tests(argc, argv, NULL);

	free(g_dev_buffer);