1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2022 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "spdk/stdinc.h" 7 #include "spdk_internal/cunit.h" 8 #include "spdk/env.h" 9 #include "spdk_internal/mock.h" 10 11 #include "bdev/raid/raid1.c" 12 #include "../common.c" 13 14 DEFINE_STUB_V(raid_bdev_module_list_add, (struct raid_bdev_module *raid_module)); 15 DEFINE_STUB_V(raid_bdev_io_complete, (struct raid_bdev_io *raid_io, 16 enum spdk_bdev_io_status status)); 17 DEFINE_STUB(raid_bdev_io_complete_part, bool, (struct raid_bdev_io *raid_io, uint64_t completed, 18 enum spdk_bdev_io_status status), true); 19 DEFINE_STUB_V(spdk_bdev_free_io, (struct spdk_bdev_io *bdev_io)); 20 DEFINE_STUB_V(raid_bdev_queue_io_wait, (struct raid_bdev_io *raid_io, struct spdk_bdev *bdev, 21 struct spdk_io_channel *ch, spdk_bdev_io_wait_cb cb_fn)); 22 DEFINE_STUB(spdk_bdev_readv_blocks_with_md, int, (struct spdk_bdev_desc *desc, 23 struct spdk_io_channel *ch, 24 struct iovec *iov, int iovcnt, void *md, 25 uint64_t offset_blocks, uint64_t num_blocks, 26 spdk_bdev_io_completion_cb cb, void *cb_arg), 0); 27 DEFINE_STUB(spdk_bdev_writev_blocks_with_md, int, (struct spdk_bdev_desc *desc, 28 struct spdk_io_channel *ch, 29 struct iovec *iov, int iovcnt, void *md, 30 uint64_t offset_blocks, uint64_t num_blocks, 31 spdk_bdev_io_completion_cb cb, void *cb_arg), 0); 32 DEFINE_STUB(spdk_bdev_readv_blocks_ext, int, (struct spdk_bdev_desc *desc, 33 struct spdk_io_channel *ch, 34 struct iovec *iov, int iovcnt, uint64_t offset_blocks, uint64_t num_blocks, 35 spdk_bdev_io_completion_cb cb, void *cb_arg, struct spdk_bdev_ext_io_opts *opts), 0); 36 DEFINE_STUB(spdk_bdev_writev_blocks_ext, int, (struct spdk_bdev_desc *desc, 37 struct spdk_io_channel *ch, 38 struct iovec *iov, int iovcnt, uint64_t offset_blocks, uint64_t num_blocks, 39 spdk_bdev_io_completion_cb cb, void *cb_arg, struct spdk_bdev_ext_io_opts *opts), 0); 40 41 static int 42 test_setup(void) 43 { 44 uint8_t num_base_bdevs_values[] = { 2, 3 }; 45 uint64_t base_bdev_blockcnt_values[] = { 1, 1024, 1024 * 1024 }; 46 uint32_t base_bdev_blocklen_values[] = { 512, 4096 }; 47 uint8_t *num_base_bdevs; 48 uint64_t *base_bdev_blockcnt; 49 uint32_t *base_bdev_blocklen; 50 struct raid_params params; 51 uint64_t params_count; 52 int rc; 53 54 params_count = SPDK_COUNTOF(num_base_bdevs_values) * 55 SPDK_COUNTOF(base_bdev_blockcnt_values) * 56 SPDK_COUNTOF(base_bdev_blocklen_values); 57 rc = raid_test_params_alloc(params_count); 58 if (rc) { 59 return rc; 60 } 61 62 ARRAY_FOR_EACH(num_base_bdevs_values, num_base_bdevs) { 63 ARRAY_FOR_EACH(base_bdev_blockcnt_values, base_bdev_blockcnt) { 64 ARRAY_FOR_EACH(base_bdev_blocklen_values, base_bdev_blocklen) { 65 params.num_base_bdevs = *num_base_bdevs; 66 params.base_bdev_blockcnt = *base_bdev_blockcnt; 67 params.base_bdev_blocklen = *base_bdev_blocklen; 68 params.strip_size = 0; 69 params.md_len = 0; 70 raid_test_params_add(¶ms); 71 } 72 } 73 } 74 75 return 0; 76 } 77 78 static int 79 test_cleanup(void) 80 { 81 raid_test_params_free(); 82 return 0; 83 } 84 85 static struct raid1_info * 86 create_raid1(struct raid_params *params) 87 { 88 struct raid_bdev *raid_bdev = raid_test_create_raid_bdev(params, &g_raid1_module); 89 90 SPDK_CU_ASSERT_FATAL(raid1_start(raid_bdev) == 0); 91 92 return raid_bdev->module_private; 93 } 94 95 static void 96 delete_raid1(struct raid1_info *r1_info) 97 { 98 struct raid_bdev *raid_bdev = r1_info->raid_bdev; 99 100 raid1_stop(raid_bdev); 101 102 raid_test_delete_raid_bdev(raid_bdev); 103 } 104 105 static void 106 test_raid1_start(void) 107 { 108 struct raid_params *params; 109 110 RAID_PARAMS_FOR_EACH(params) { 111 struct raid1_info *r1_info; 112 113 r1_info = create_raid1(params); 114 115 SPDK_CU_ASSERT_FATAL(r1_info != NULL); 116 117 CU_ASSERT_EQUAL(r1_info->raid_bdev->level, RAID1); 118 CU_ASSERT_EQUAL(r1_info->raid_bdev->bdev.blockcnt, params->base_bdev_blockcnt); 119 CU_ASSERT_PTR_EQUAL(r1_info->raid_bdev->module, &g_raid1_module); 120 121 delete_raid1(r1_info); 122 } 123 } 124 125 int 126 main(int argc, char **argv) 127 { 128 CU_pSuite suite = NULL; 129 unsigned int num_failures; 130 131 CU_initialize_registry(); 132 133 suite = CU_add_suite("raid1", test_setup, test_cleanup); 134 CU_ADD_TEST(suite, test_raid1_start); 135 136 num_failures = spdk_ut_run_tests(argc, argv, NULL); 137 CU_cleanup_registry(); 138 return num_failures; 139 } 140