diff --git a/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c b/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c index 6cdb92028..8c5ae9363 100644 --- a/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c +++ b/test/unit/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c @@ -35,11 +35,12 @@ #include "CUnit/Basic.h" -#include "common/lib/test_env.c" +#include "common/lib/ut_multithread.c" #include "spdk_cunit.h" #include "blobfs/blobfs.c" #include "blobfs/tree.c" +#include "blob/blobstore.h" #include "spdk_internal/thread.h" @@ -63,12 +64,6 @@ spdk_conf_section_get_intval(struct spdk_conf_section *sp, const char *key) return -1; } -static void -_fs_send_msg(spdk_msg_fn fn, void *ctx, void *thread_ctx) -{ - fn(ctx); -} - static void fs_op_complete(void *ctx, int fserrno) { @@ -91,12 +86,15 @@ fs_init(void) dev = init_dev(); spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); + poll_threads(); SPDK_CU_ASSERT_FATAL(g_fs != NULL); CU_ASSERT(g_fserrno == 0); fs = g_fs; + SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); g_fserrno = 1; spdk_fs_unload(fs, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); } @@ -132,22 +130,27 @@ fs_open(void) memset(name, 'a', sizeof(name) - 1); spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); + poll_threads(); SPDK_CU_ASSERT_FATAL(g_fs != NULL); CU_ASSERT(g_fserrno == 0); fs = g_fs; + SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); g_fserrno = 0; /* Open should fail, because the file name is too long. */ spdk_fs_open_file_async(fs, name, SPDK_BLOBFS_OPEN_CREATE, open_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == -ENAMETOOLONG); g_fserrno = 0; spdk_fs_open_file_async(fs, "file1", 0, open_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == -ENOENT); g_file = NULL; g_fserrno = 1; spdk_fs_open_file_async(fs, "file1", SPDK_BLOBFS_OPEN_CREATE, open_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); SPDK_CU_ASSERT_FATAL(g_file != NULL); CU_ASSERT(!strcmp("file1", g_file->name)); @@ -164,16 +167,19 @@ fs_open(void) g_fserrno = 0; /* Delete should successful, we will mark the file as deleted. */ spdk_fs_delete_file_async(fs, "file1", delete_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(!TAILQ_EMPTY(&fs->files)); g_fserrno = 1; spdk_file_close_async(g_file, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(TAILQ_EMPTY(&fs->files)); g_fserrno = 1; spdk_fs_unload(fs, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); } @@ -188,30 +194,37 @@ fs_create(void) memset(name, 'a', sizeof(name) - 1); spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); + poll_threads(); SPDK_CU_ASSERT_FATAL(g_fs != NULL); CU_ASSERT(g_fserrno == 0); fs = g_fs; + SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); g_fserrno = 0; /* Create should fail, because the file name is too long. */ spdk_fs_create_file_async(fs, name, create_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == -ENAMETOOLONG); g_fserrno = 1; spdk_fs_create_file_async(fs, "file1", create_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); g_fserrno = 1; spdk_fs_create_file_async(fs, "file1", create_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == -EEXIST); g_fserrno = 1; spdk_fs_delete_file_async(fs, "file1", delete_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(TAILQ_EMPTY(&fs->files)); g_fserrno = 1; spdk_fs_unload(fs, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); } @@ -224,43 +237,52 @@ fs_truncate(void) dev = init_dev(); spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); + poll_threads(); SPDK_CU_ASSERT_FATAL(g_fs != NULL); CU_ASSERT(g_fserrno == 0); fs = g_fs; + SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); g_file = NULL; g_fserrno = 1; spdk_fs_open_file_async(fs, "file1", SPDK_BLOBFS_OPEN_CREATE, open_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); SPDK_CU_ASSERT_FATAL(g_file != NULL); g_fserrno = 1; spdk_file_truncate_async(g_file, 18 * 1024 * 1024 + 1, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(g_file->length == 18 * 1024 * 1024 + 1); g_fserrno = 1; spdk_file_truncate_async(g_file, 1, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(g_file->length == 1); g_fserrno = 1; spdk_file_truncate_async(g_file, 18 * 1024 * 1024 + 1, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(g_file->length == 18 * 1024 * 1024 + 1); g_fserrno = 1; spdk_file_close_async(g_file, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(g_file->ref_count == 0); g_fserrno = 1; spdk_fs_delete_file_async(fs, "file1", delete_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(TAILQ_EMPTY(&fs->files)); g_fserrno = 1; spdk_fs_unload(fs, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); } @@ -274,17 +296,21 @@ fs_rename(void) dev = init_dev(); spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); + poll_threads(); SPDK_CU_ASSERT_FATAL(g_fs != NULL); CU_ASSERT(g_fserrno == 0); fs = g_fs; + SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); g_fserrno = 1; spdk_fs_create_file_async(fs, "file1", create_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); g_file = NULL; g_fserrno = 1; spdk_fs_open_file_async(fs, "file1", 0, open_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); SPDK_CU_ASSERT_FATAL(g_file != NULL); CU_ASSERT(g_file->ref_count == 1); @@ -293,12 +319,14 @@ fs_rename(void) g_file = NULL; g_fserrno = 1; spdk_file_close_async(file, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); SPDK_CU_ASSERT_FATAL(file->ref_count == 0); g_file = NULL; g_fserrno = 1; spdk_fs_open_file_async(fs, "file2", SPDK_BLOBFS_OPEN_CREATE, open_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); SPDK_CU_ASSERT_FATAL(g_file != NULL); CU_ASSERT(g_file->ref_count == 1); @@ -307,6 +335,7 @@ fs_rename(void) g_file = NULL; g_fserrno = 1; spdk_file_close_async(file2, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); SPDK_CU_ASSERT_FATAL(file2->ref_count == 0); @@ -316,6 +345,7 @@ fs_rename(void) */ g_fserrno = 1; spdk_fs_rename_file_async(fs, "file1", "file2", fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(file->ref_count == 0); CU_ASSERT(!strcmp(file->name, "file2")); @@ -324,6 +354,7 @@ fs_rename(void) g_fserrno = 0; spdk_fs_delete_file_async(fs, "file1", delete_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == -ENOENT); CU_ASSERT(!TAILQ_EMPTY(&fs->files)); TAILQ_FOREACH(file_iter, &fs->files, tailq) { @@ -334,11 +365,13 @@ fs_rename(void) g_fserrno = 1; spdk_fs_delete_file_async(fs, "file2", delete_cb, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); CU_ASSERT(TAILQ_EMPTY(&fs->files)); g_fserrno = 1; spdk_fs_unload(fs, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); } @@ -429,9 +462,11 @@ channel_ops(void) dev = init_dev(); spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); + poll_threads(); SPDK_CU_ASSERT_FATAL(g_fs != NULL); CU_ASSERT(g_fserrno == 0); fs = g_fs; + SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); channel = spdk_fs_alloc_io_channel(fs); CU_ASSERT(channel != NULL); @@ -440,6 +475,7 @@ channel_ops(void) g_fserrno = 1; spdk_fs_unload(fs, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); g_fs = NULL; } @@ -454,9 +490,11 @@ channel_ops_sync(void) dev = init_dev(); spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); + poll_threads(); SPDK_CU_ASSERT_FATAL(g_fs != NULL); CU_ASSERT(g_fserrno == 0); fs = g_fs; + SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); channel = spdk_fs_alloc_io_channel_sync(fs); CU_ASSERT(channel != NULL); @@ -465,13 +503,13 @@ channel_ops_sync(void) g_fserrno = 1; spdk_fs_unload(fs, fs_op_complete, NULL); + poll_threads(); CU_ASSERT(g_fserrno == 0); g_fs = NULL; } int main(int argc, char **argv) { - struct spdk_thread *thread; CU_pSuite suite = NULL; unsigned int num_failures; @@ -499,8 +537,8 @@ int main(int argc, char **argv) return CU_get_error(); } - thread = spdk_allocate_thread(_fs_send_msg, NULL, NULL, NULL, "thread0"); - spdk_set_thread(thread); + allocate_threads(1); + set_thread(0); g_dev_buffer = calloc(1, DEV_BUFFER_SIZE); CU_basic_set_mode(CU_BRM_VERBOSE); @@ -508,6 +546,8 @@ int main(int argc, char **argv) num_failures = CU_get_number_of_failures(); CU_cleanup_registry(); free(g_dev_buffer); - spdk_free_thread(); + + free_threads(); + return num_failures; }