test/thread: Simplify thread creation

For tests that aren't specifically testing the thread API,
leverage the ut_multithread framework to simplify them.

Change-Id: Ib772ac4ebd3179b71a51697edc50ad9b7b70536b
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/435938
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Ben Walker 2018-12-03 13:59:59 -07:00
parent 0cdb37eb53
commit 0275e63cc5

View File

@ -407,12 +407,12 @@ destroy_cb_2(void *io_device, void *ctx_buf)
static void
channel(void)
{
struct spdk_thread *thread;
struct spdk_io_channel *ch1, *ch2;
void *ctx;
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, "thread0");
SPDK_CU_ASSERT_FATAL(thread != NULL);
allocate_threads(1);
set_thread(0);
spdk_io_device_register(&device1, create_cb_1, destroy_cb_1, sizeof(ctx1), NULL);
spdk_io_device_register(&device2, create_cb_2, destroy_cb_2, sizeof(ctx2), NULL);
@ -429,7 +429,7 @@ channel(void)
g_destroy_cb_calls = 0;
spdk_put_io_channel(ch2);
while (spdk_thread_poll(thread, 0) > 0) {}
poll_threads();
CU_ASSERT(g_destroy_cb_calls == 0);
g_create_cb_calls = 0;
@ -443,23 +443,23 @@ channel(void)
g_destroy_cb_calls = 0;
spdk_put_io_channel(ch1);
while (spdk_thread_poll(thread, 0) > 0) {}
poll_threads();
CU_ASSERT(g_destroy_cb_calls == 1);
g_destroy_cb_calls = 0;
spdk_put_io_channel(ch2);
while (spdk_thread_poll(thread, 0) > 0) {}
poll_threads();
CU_ASSERT(g_destroy_cb_calls == 1);
ch1 = spdk_get_io_channel(&device3);
CU_ASSERT(ch1 == NULL);
spdk_io_device_unregister(&device1, NULL);
while (spdk_thread_poll(thread, 0) > 0) {}
poll_threads();
spdk_io_device_unregister(&device2, NULL);
while (spdk_thread_poll(thread, 0) > 0) {}
poll_threads();
CU_ASSERT(TAILQ_EMPTY(&g_io_devices));
spdk_free_thread();
free_threads();
CU_ASSERT(TAILQ_EMPTY(&g_threads));
}
@ -491,12 +491,12 @@ destroy_cb(void *io_device, void *ctx_buf)
static void
channel_destroy_races(void)
{
struct spdk_thread *thread;
uint64_t device;
struct spdk_io_channel *ch;
thread = spdk_allocate_thread(NULL, NULL, NULL, NULL, "thread0");
SPDK_CU_ASSERT_FATAL(thread != NULL);
allocate_threads(1);
set_thread(0);
spdk_io_device_register(&device, create_cb, destroy_cb, sizeof(uint64_t), NULL);
ch = spdk_get_io_channel(&device);
@ -508,13 +508,13 @@ channel_destroy_races(void)
SPDK_CU_ASSERT_FATAL(ch != NULL);
spdk_put_io_channel(ch);
while (spdk_thread_poll(thread, 0) > 0) {}
poll_threads();
spdk_io_device_unregister(&device, NULL);
while (spdk_thread_poll(thread, 0) > 0) {}
poll_threads();
CU_ASSERT(TAILQ_EMPTY(&g_io_devices));
spdk_free_thread();
free_threads();
CU_ASSERT(TAILQ_EMPTY(&g_threads));
}