xref: /spdk/test/unit/lib/bdev/raid/bdev_raid.c/bdev_raid_ut.c (revision b30d57cdad6d2bc75cc1e4e2ebbcebcb0d98dcfa)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) Intel Corporation.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "spdk/stdinc.h"
35 #include "spdk_cunit.h"
36 #include "spdk/env.h"
37 #include "spdk_internal/mock.h"
38 #include "bdev/raid/bdev_raid.c"
39 #include "bdev/raid/bdev_raid_rpc.c"
40 #include "bdev/raid/raid0.c"
41 #include "common/lib/ut_multithread.c"
42 
43 #define MAX_BASE_DRIVES 32
44 #define MAX_RAIDS 2
45 #define INVALID_IO_SUBMIT 0xFFFF
46 #define MAX_TEST_IO_RANGE (3 * 3 * 3 * (MAX_BASE_DRIVES + 5))
47 #define BLOCK_CNT (1024ul * 1024ul * 1024ul * 1024ul)
48 
49 struct spdk_bdev_channel {
50 	struct spdk_io_channel *channel;
51 };
52 
53 struct spdk_bdev_desc {
54 	struct spdk_bdev *bdev;
55 };
56 
57 /* Data structure to capture the output of IO for verification */
58 struct io_output {
59 	struct spdk_bdev_desc       *desc;
60 	struct spdk_io_channel      *ch;
61 	uint64_t                    offset_blocks;
62 	uint64_t                    num_blocks;
63 	spdk_bdev_io_completion_cb  cb;
64 	void                        *cb_arg;
65 	enum spdk_bdev_io_type      iotype;
66 };
67 
68 struct raid_io_ranges {
69 	uint64_t lba;
70 	uint64_t nblocks;
71 };
72 
73 /* Globals */
74 int g_bdev_io_submit_status;
75 struct io_output *g_io_output = NULL;
76 uint32_t g_io_output_index;
77 uint32_t g_io_comp_status;
78 bool g_child_io_status_flag;
79 void *g_rpc_req;
80 uint32_t g_rpc_req_size;
81 TAILQ_HEAD(bdev, spdk_bdev);
82 struct bdev g_bdev_list;
83 TAILQ_HEAD(waitq, spdk_bdev_io_wait_entry);
84 struct waitq g_io_waitq;
85 uint32_t g_block_len;
86 uint32_t g_strip_size;
87 uint32_t g_max_io_size;
88 uint8_t g_max_base_drives;
89 uint8_t g_max_raids;
90 uint8_t g_ignore_io_output;
91 uint8_t g_rpc_err;
92 char *g_get_raids_output[MAX_RAIDS];
93 uint32_t g_get_raids_count;
94 uint8_t g_json_decode_obj_err;
95 uint8_t g_json_decode_obj_create;
96 uint8_t g_config_level_create = 0;
97 uint8_t g_test_multi_raids;
98 struct raid_io_ranges g_io_ranges[MAX_TEST_IO_RANGE];
99 uint32_t g_io_range_idx;
100 uint64_t g_lba_offset;
101 struct spdk_io_channel g_io_channel;
102 
103 DEFINE_STUB_V(spdk_bdev_module_examine_done, (struct spdk_bdev_module *module));
104 DEFINE_STUB_V(spdk_bdev_module_list_add, (struct spdk_bdev_module *bdev_module));
105 DEFINE_STUB(spdk_bdev_register, int, (struct spdk_bdev *bdev), 0);
106 DEFINE_STUB(spdk_bdev_io_type_supported, bool, (struct spdk_bdev *bdev,
107 		enum spdk_bdev_io_type io_type), true);
108 DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc));
109 DEFINE_STUB(spdk_bdev_flush_blocks, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
110 		uint64_t offset_blocks, uint64_t num_blocks, spdk_bdev_io_completion_cb cb,
111 		void *cb_arg), 0);
112 DEFINE_STUB(spdk_conf_next_section, struct spdk_conf_section *, (struct spdk_conf_section *sp),
113 	    NULL);
114 DEFINE_STUB_V(spdk_rpc_register_method, (const char *method, spdk_rpc_method_handler func,
115 		uint32_t state_mask));
116 DEFINE_STUB_V(spdk_rpc_register_alias_deprecated, (const char *method, const char *alias));
117 DEFINE_STUB_V(spdk_jsonrpc_end_result, (struct spdk_jsonrpc_request *request,
118 					struct spdk_json_write_ctx *w));
119 DEFINE_STUB_V(spdk_jsonrpc_send_bool_response, (struct spdk_jsonrpc_request *request,
120 		bool value));
121 DEFINE_STUB(spdk_json_decode_string, int, (const struct spdk_json_val *val, void *out), 0);
122 DEFINE_STUB(spdk_json_decode_uint32, int, (const struct spdk_json_val *val, void *out), 0);
123 DEFINE_STUB(spdk_json_decode_array, int, (const struct spdk_json_val *values,
124 		spdk_json_decode_fn decode_func,
125 		void *out, size_t max_size, size_t *out_size, size_t stride), 0);
126 DEFINE_STUB(spdk_json_write_name, int, (struct spdk_json_write_ctx *w, const char *name), 0);
127 DEFINE_STUB(spdk_json_write_object_begin, int, (struct spdk_json_write_ctx *w), 0);
128 DEFINE_STUB(spdk_json_write_named_object_begin, int, (struct spdk_json_write_ctx *w,
129 		const char *name), 0);
130 DEFINE_STUB(spdk_json_write_object_end, int, (struct spdk_json_write_ctx *w), 0);
131 DEFINE_STUB(spdk_json_write_array_begin, int, (struct spdk_json_write_ctx *w), 0);
132 DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0);
133 DEFINE_STUB(spdk_json_write_named_array_begin, int, (struct spdk_json_write_ctx *w,
134 		const char *name), 0);
135 DEFINE_STUB(spdk_json_write_bool, int, (struct spdk_json_write_ctx *w, bool val), 0);
136 DEFINE_STUB(spdk_json_write_null, int, (struct spdk_json_write_ctx *w), 0);
137 DEFINE_STUB(spdk_strerror, const char *, (int errnum), NULL);
138 DEFINE_STUB(spdk_bdev_queue_io_wait, int, (struct spdk_bdev *bdev, struct spdk_io_channel *ch,
139 		struct spdk_bdev_io_wait_entry *entry), 0);
140 
141 struct spdk_io_channel *
142 spdk_bdev_get_io_channel(struct spdk_bdev_desc *desc)
143 {
144 	g_io_channel.thread = spdk_get_thread();
145 
146 	return &g_io_channel;
147 }
148 
149 static void
150 set_test_opts(void)
151 {
152 
153 	g_max_base_drives = MAX_BASE_DRIVES;
154 	g_max_raids = MAX_RAIDS;
155 	g_block_len = 4096;
156 	g_strip_size = 64;
157 	g_max_io_size = 1024;
158 
159 	printf("Test Options\n");
160 	printf("blocklen = %u, strip_size = %u, max_io_size = %u, g_max_base_drives = %u, "
161 	       "g_max_raids = %u\n",
162 	       g_block_len, g_strip_size, g_max_io_size, g_max_base_drives, g_max_raids);
163 }
164 
165 /* Set globals before every test run */
166 static void
167 set_globals(void)
168 {
169 	uint32_t max_splits;
170 
171 	g_bdev_io_submit_status = 0;
172 	if (g_max_io_size < g_strip_size) {
173 		max_splits = 2;
174 	} else {
175 		max_splits = (g_max_io_size / g_strip_size) + 1;
176 	}
177 	if (max_splits < g_max_base_drives) {
178 		max_splits = g_max_base_drives;
179 	}
180 
181 	g_io_output = calloc(max_splits, sizeof(struct io_output));
182 	SPDK_CU_ASSERT_FATAL(g_io_output != NULL);
183 	g_io_output_index = 0;
184 	memset(g_get_raids_output, 0, sizeof(g_get_raids_output));
185 	g_get_raids_count = 0;
186 	g_io_comp_status = 0;
187 	g_ignore_io_output = 0;
188 	g_config_level_create = 0;
189 	g_rpc_err = 0;
190 	g_test_multi_raids = 0;
191 	g_child_io_status_flag = true;
192 	TAILQ_INIT(&g_bdev_list);
193 	TAILQ_INIT(&g_io_waitq);
194 	g_rpc_req = NULL;
195 	g_rpc_req_size = 0;
196 	g_json_decode_obj_err = 0;
197 	g_json_decode_obj_create = 0;
198 	g_lba_offset = 0;
199 }
200 
201 static void
202 base_bdevs_cleanup(void)
203 {
204 	struct spdk_bdev *bdev;
205 	struct spdk_bdev *bdev_next;
206 
207 	if (!TAILQ_EMPTY(&g_bdev_list)) {
208 		TAILQ_FOREACH_SAFE(bdev, &g_bdev_list, internal.link, bdev_next) {
209 			free(bdev->name);
210 			TAILQ_REMOVE(&g_bdev_list, bdev, internal.link);
211 			free(bdev);
212 		}
213 	}
214 }
215 
216 static void
217 check_and_remove_raid_bdev(struct raid_bdev_config *raid_cfg)
218 {
219 	struct raid_bdev *raid_bdev;
220 	struct raid_base_bdev_info *base_info;
221 
222 	/* Get the raid structured allocated if exists */
223 	raid_bdev = raid_cfg->raid_bdev;
224 	if (raid_bdev == NULL) {
225 		return;
226 	}
227 
228 	assert(raid_bdev->base_bdev_info != NULL);
229 
230 	RAID_FOR_EACH_BASE_BDEV(raid_bdev, base_info) {
231 		if (base_info->bdev) {
232 			raid_bdev_free_base_bdev_resource(raid_bdev, base_info);
233 		}
234 	}
235 	assert(raid_bdev->num_base_bdevs_discovered == 0);
236 	raid_bdev_cleanup(raid_bdev);
237 }
238 
239 /* Reset globals */
240 static void
241 reset_globals(void)
242 {
243 	if (g_io_output) {
244 		free(g_io_output);
245 		g_io_output = NULL;
246 	}
247 	g_rpc_req = NULL;
248 	g_rpc_req_size = 0;
249 }
250 
251 void
252 spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb,
253 		     uint64_t len)
254 {
255 	cb(bdev_io->internal.ch->channel, bdev_io, true);
256 }
257 
258 /* Store the IO completion status in global variable to verify by various tests */
259 void
260 spdk_bdev_io_complete(struct spdk_bdev_io *bdev_io, enum spdk_bdev_io_status status)
261 {
262 	g_io_comp_status = ((status == SPDK_BDEV_IO_STATUS_SUCCESS) ? true : false);
263 }
264 
265 static void
266 set_io_output(struct io_output *output,
267 	      struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
268 	      uint64_t offset_blocks, uint64_t num_blocks,
269 	      spdk_bdev_io_completion_cb cb, void *cb_arg,
270 	      enum spdk_bdev_io_type iotype)
271 {
272 	output->desc = desc;
273 	output->ch = ch;
274 	output->offset_blocks = offset_blocks;
275 	output->num_blocks = num_blocks;
276 	output->cb = cb;
277 	output->cb_arg = cb_arg;
278 	output->iotype = iotype;
279 }
280 
281 /* It will cache the split IOs for verification */
282 int
283 spdk_bdev_writev_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
284 			struct iovec *iov, int iovcnt,
285 			uint64_t offset_blocks, uint64_t num_blocks,
286 			spdk_bdev_io_completion_cb cb, void *cb_arg)
287 {
288 	struct io_output *output = &g_io_output[g_io_output_index];
289 	struct spdk_bdev_io *child_io;
290 
291 	if (g_ignore_io_output) {
292 		return 0;
293 	}
294 
295 	if (g_max_io_size < g_strip_size) {
296 		SPDK_CU_ASSERT_FATAL(g_io_output_index < 2);
297 	} else {
298 		SPDK_CU_ASSERT_FATAL(g_io_output_index < (g_max_io_size / g_strip_size) + 1);
299 	}
300 	if (g_bdev_io_submit_status == 0) {
301 		set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
302 			      SPDK_BDEV_IO_TYPE_WRITE);
303 		g_io_output_index++;
304 
305 		child_io = calloc(1, sizeof(struct spdk_bdev_io));
306 		SPDK_CU_ASSERT_FATAL(child_io != NULL);
307 		cb(child_io, g_child_io_status_flag, cb_arg);
308 	}
309 
310 	return g_bdev_io_submit_status;
311 }
312 
313 int
314 spdk_bdev_reset(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
315 		spdk_bdev_io_completion_cb cb, void *cb_arg)
316 {
317 	struct io_output *output = &g_io_output[g_io_output_index];
318 	struct spdk_bdev_io *child_io;
319 
320 	if (g_ignore_io_output) {
321 		return 0;
322 	}
323 
324 	if (g_bdev_io_submit_status == 0) {
325 		set_io_output(output, desc, ch, 0, 0, cb, cb_arg, SPDK_BDEV_IO_TYPE_RESET);
326 		g_io_output_index++;
327 
328 		child_io = calloc(1, sizeof(struct spdk_bdev_io));
329 		SPDK_CU_ASSERT_FATAL(child_io != NULL);
330 		cb(child_io, g_child_io_status_flag, cb_arg);
331 	}
332 
333 	return g_bdev_io_submit_status;
334 }
335 
336 int
337 spdk_bdev_unmap_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
338 		       uint64_t offset_blocks, uint64_t num_blocks,
339 		       spdk_bdev_io_completion_cb cb, void *cb_arg)
340 {
341 	struct io_output *output = &g_io_output[g_io_output_index];
342 	struct spdk_bdev_io *child_io;
343 
344 	if (g_ignore_io_output) {
345 		return 0;
346 	}
347 
348 	if (g_bdev_io_submit_status == 0) {
349 		set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
350 			      SPDK_BDEV_IO_TYPE_UNMAP);
351 		g_io_output_index++;
352 
353 		child_io = calloc(1, sizeof(struct spdk_bdev_io));
354 		SPDK_CU_ASSERT_FATAL(child_io != NULL);
355 		cb(child_io, g_child_io_status_flag, cb_arg);
356 	}
357 
358 	return g_bdev_io_submit_status;
359 }
360 
361 void
362 spdk_bdev_unregister(struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn, void *cb_arg)
363 {
364 	bdev->fn_table->destruct(bdev->ctxt);
365 
366 	if (cb_fn) {
367 		cb_fn(cb_arg, 0);
368 	}
369 }
370 
371 int
372 spdk_bdev_open_ext(const char *bdev_name, bool write, spdk_bdev_event_cb_t event_cb,
373 		   void *event_ctx, struct spdk_bdev_desc **_desc)
374 {
375 	struct spdk_bdev *bdev;
376 
377 	bdev = spdk_bdev_get_by_name(bdev_name);
378 	if (bdev == NULL) {
379 		return -ENODEV;
380 	}
381 
382 	*_desc = (void *)bdev;
383 	return 0;
384 }
385 
386 struct spdk_bdev *
387 spdk_bdev_desc_get_bdev(struct spdk_bdev_desc *desc)
388 {
389 	return (void *)desc;
390 }
391 
392 char *
393 spdk_sprintf_alloc(const char *format, ...)
394 {
395 	return strdup(format);
396 }
397 
398 int spdk_json_write_named_uint32(struct spdk_json_write_ctx *w, const char *name, uint32_t val)
399 {
400 	struct rpc_bdev_raid_create *req = g_rpc_req;
401 	if (strcmp(name, "strip_size_kb") == 0) {
402 		CU_ASSERT(req->strip_size_kb == val);
403 	} else if (strcmp(name, "blocklen_shift") == 0) {
404 		CU_ASSERT(spdk_u32log2(g_block_len) == val);
405 	} else if (strcmp(name, "num_base_bdevs") == 0) {
406 		CU_ASSERT(req->base_bdevs.num_base_bdevs == val);
407 	} else if (strcmp(name, "state") == 0) {
408 		CU_ASSERT(val == RAID_BDEV_STATE_ONLINE);
409 	} else if (strcmp(name, "destruct_called") == 0) {
410 		CU_ASSERT(val == 0);
411 	} else if (strcmp(name, "num_base_bdevs_discovered") == 0) {
412 		CU_ASSERT(req->base_bdevs.num_base_bdevs == val);
413 	}
414 	return 0;
415 }
416 
417 int spdk_json_write_named_string(struct spdk_json_write_ctx *w, const char *name, const char *val)
418 {
419 	struct rpc_bdev_raid_create *req = g_rpc_req;
420 	if (strcmp(name, "raid_level") == 0) {
421 		CU_ASSERT(strcmp(val, raid_bdev_level_to_str(req->level)) == 0);
422 	}
423 	return 0;
424 }
425 
426 void
427 spdk_bdev_free_io(struct spdk_bdev_io *bdev_io)
428 {
429 	if (bdev_io) {
430 		free(bdev_io);
431 	}
432 }
433 
434 /* It will cache split IOs for verification */
435 int
436 spdk_bdev_readv_blocks(struct spdk_bdev_desc *desc, struct spdk_io_channel *ch,
437 		       struct iovec *iov, int iovcnt,
438 		       uint64_t offset_blocks, uint64_t num_blocks,
439 		       spdk_bdev_io_completion_cb cb, void *cb_arg)
440 {
441 	struct io_output *output = &g_io_output[g_io_output_index];
442 	struct spdk_bdev_io *child_io;
443 
444 	if (g_ignore_io_output) {
445 		return 0;
446 	}
447 
448 	SPDK_CU_ASSERT_FATAL(g_io_output_index <= (g_max_io_size / g_strip_size) + 1);
449 	if (g_bdev_io_submit_status == 0) {
450 		set_io_output(output, desc, ch, offset_blocks, num_blocks, cb, cb_arg,
451 			      SPDK_BDEV_IO_TYPE_READ);
452 		g_io_output_index++;
453 
454 		child_io = calloc(1, sizeof(struct spdk_bdev_io));
455 		SPDK_CU_ASSERT_FATAL(child_io != NULL);
456 		cb(child_io, g_child_io_status_flag, cb_arg);
457 	}
458 
459 	return g_bdev_io_submit_status;
460 }
461 
462 void
463 spdk_bdev_module_release_bdev(struct spdk_bdev *bdev)
464 {
465 	CU_ASSERT(bdev->internal.claim_module != NULL);
466 	bdev->internal.claim_module = NULL;
467 }
468 
469 int
470 spdk_bdev_module_claim_bdev(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
471 			    struct spdk_bdev_module *module)
472 {
473 	if (bdev->internal.claim_module != NULL) {
474 		return -1;
475 	}
476 	bdev->internal.claim_module = module;
477 	return 0;
478 }
479 
480 int
481 spdk_json_decode_object(const struct spdk_json_val *values,
482 			const struct spdk_json_object_decoder *decoders, size_t num_decoders,
483 			void *out)
484 {
485 	struct rpc_bdev_raid_create *req, *_out;
486 	size_t i;
487 
488 	if (g_json_decode_obj_err) {
489 		return -1;
490 	} else if (g_json_decode_obj_create) {
491 		req = g_rpc_req;
492 		_out = out;
493 
494 		_out->name = strdup(req->name);
495 		SPDK_CU_ASSERT_FATAL(_out->name != NULL);
496 		_out->strip_size_kb = req->strip_size_kb;
497 		_out->level = req->level;
498 		_out->base_bdevs.num_base_bdevs = req->base_bdevs.num_base_bdevs;
499 		for (i = 0; i < req->base_bdevs.num_base_bdevs; i++) {
500 			_out->base_bdevs.base_bdevs[i] = strdup(req->base_bdevs.base_bdevs[i]);
501 			SPDK_CU_ASSERT_FATAL(_out->base_bdevs.base_bdevs[i]);
502 		}
503 	} else {
504 		memcpy(out, g_rpc_req, g_rpc_req_size);
505 	}
506 
507 	return 0;
508 }
509 
510 struct spdk_json_write_ctx *
511 spdk_jsonrpc_begin_result(struct spdk_jsonrpc_request *request)
512 {
513 	return (void *)1;
514 }
515 
516 int
517 spdk_json_write_string(struct spdk_json_write_ctx *w, const char *val)
518 {
519 	if (g_test_multi_raids) {
520 		g_get_raids_output[g_get_raids_count] = strdup(val);
521 		SPDK_CU_ASSERT_FATAL(g_get_raids_output[g_get_raids_count] != NULL);
522 		g_get_raids_count++;
523 	}
524 
525 	return 0;
526 }
527 
528 void
529 spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_request *request,
530 				 int error_code, const char *msg)
531 {
532 	g_rpc_err = 1;
533 }
534 
535 void
536 spdk_jsonrpc_send_error_response_fmt(struct spdk_jsonrpc_request *request,
537 				     int error_code, const char *fmt, ...)
538 {
539 	g_rpc_err = 1;
540 }
541 
542 struct spdk_bdev *
543 spdk_bdev_get_by_name(const char *bdev_name)
544 {
545 	struct spdk_bdev *bdev;
546 
547 	if (!TAILQ_EMPTY(&g_bdev_list)) {
548 		TAILQ_FOREACH(bdev, &g_bdev_list, internal.link) {
549 			if (strcmp(bdev_name, bdev->name) == 0) {
550 				return bdev;
551 			}
552 		}
553 	}
554 
555 	return NULL;
556 }
557 
558 static void
559 bdev_io_cleanup(struct spdk_bdev_io *bdev_io)
560 {
561 	if (bdev_io->u.bdev.iovs) {
562 		if (bdev_io->u.bdev.iovs->iov_base) {
563 			free(bdev_io->u.bdev.iovs->iov_base);
564 		}
565 		free(bdev_io->u.bdev.iovs);
566 	}
567 	free(bdev_io);
568 }
569 
570 static void
571 bdev_io_initialize(struct spdk_bdev_io *bdev_io, struct spdk_io_channel *ch, struct spdk_bdev *bdev,
572 		   uint64_t lba, uint64_t blocks, int16_t iotype)
573 {
574 	struct spdk_bdev_channel *channel = spdk_io_channel_get_ctx(ch);
575 
576 	bdev_io->bdev = bdev;
577 	bdev_io->u.bdev.offset_blocks = lba;
578 	bdev_io->u.bdev.num_blocks = blocks;
579 	bdev_io->type = iotype;
580 
581 	if (bdev_io->type == SPDK_BDEV_IO_TYPE_UNMAP || bdev_io->type == SPDK_BDEV_IO_TYPE_FLUSH) {
582 		return;
583 	}
584 
585 	bdev_io->u.bdev.iovcnt = 1;
586 	bdev_io->u.bdev.iovs = calloc(1, sizeof(struct iovec));
587 	SPDK_CU_ASSERT_FATAL(bdev_io->u.bdev.iovs != NULL);
588 	bdev_io->u.bdev.iovs->iov_base = calloc(1, bdev_io->u.bdev.num_blocks * g_block_len);
589 	SPDK_CU_ASSERT_FATAL(bdev_io->u.bdev.iovs->iov_base != NULL);
590 	bdev_io->u.bdev.iovs->iov_len = bdev_io->u.bdev.num_blocks * g_block_len;
591 	bdev_io->internal.ch = channel;
592 }
593 
594 static void
595 verify_reset_io(struct spdk_bdev_io *bdev_io, uint8_t num_base_drives,
596 		struct raid_bdev_io_channel *ch_ctx, struct raid_bdev *raid_bdev, uint32_t io_status)
597 {
598 	uint8_t index = 0;
599 	struct io_output *output;
600 
601 	SPDK_CU_ASSERT_FATAL(raid_bdev != NULL);
602 	SPDK_CU_ASSERT_FATAL(num_base_drives != 0);
603 	SPDK_CU_ASSERT_FATAL(io_status != INVALID_IO_SUBMIT);
604 	SPDK_CU_ASSERT_FATAL(ch_ctx->base_channel != NULL);
605 
606 	CU_ASSERT(g_io_output_index == num_base_drives);
607 	for (index = 0; index < g_io_output_index; index++) {
608 		output = &g_io_output[index];
609 		CU_ASSERT(ch_ctx->base_channel[index] == output->ch);
610 		CU_ASSERT(raid_bdev->base_bdev_info[index].desc == output->desc);
611 		CU_ASSERT(bdev_io->type == output->iotype);
612 	}
613 	CU_ASSERT(g_io_comp_status == io_status);
614 }
615 
616 static void
617 verify_io(struct spdk_bdev_io *bdev_io, uint8_t num_base_drives,
618 	  struct raid_bdev_io_channel *ch_ctx, struct raid_bdev *raid_bdev, uint32_t io_status)
619 {
620 	uint32_t strip_shift = spdk_u32log2(g_strip_size);
621 	uint64_t start_strip = bdev_io->u.bdev.offset_blocks >> strip_shift;
622 	uint64_t end_strip = (bdev_io->u.bdev.offset_blocks + bdev_io->u.bdev.num_blocks - 1) >>
623 			     strip_shift;
624 	uint32_t splits_reqd = (end_strip - start_strip + 1);
625 	uint32_t strip;
626 	uint64_t pd_strip;
627 	uint8_t pd_idx;
628 	uint32_t offset_in_strip;
629 	uint64_t pd_lba;
630 	uint64_t pd_blocks;
631 	uint32_t index = 0;
632 	uint8_t *buf = bdev_io->u.bdev.iovs->iov_base;
633 	struct io_output *output;
634 
635 	if (io_status == INVALID_IO_SUBMIT) {
636 		CU_ASSERT(g_io_comp_status == false);
637 		return;
638 	}
639 	SPDK_CU_ASSERT_FATAL(raid_bdev != NULL);
640 	SPDK_CU_ASSERT_FATAL(num_base_drives != 0);
641 
642 	CU_ASSERT(splits_reqd == g_io_output_index);
643 	for (strip = start_strip; strip <= end_strip; strip++, index++) {
644 		pd_strip = strip / num_base_drives;
645 		pd_idx = strip % num_base_drives;
646 		if (strip == start_strip) {
647 			offset_in_strip = bdev_io->u.bdev.offset_blocks & (g_strip_size - 1);
648 			pd_lba = (pd_strip << strip_shift) + offset_in_strip;
649 			if (strip == end_strip) {
650 				pd_blocks = bdev_io->u.bdev.num_blocks;
651 			} else {
652 				pd_blocks = g_strip_size - offset_in_strip;
653 			}
654 		} else if (strip == end_strip) {
655 			pd_lba = pd_strip << strip_shift;
656 			pd_blocks = ((bdev_io->u.bdev.offset_blocks + bdev_io->u.bdev.num_blocks - 1) &
657 				     (g_strip_size - 1)) + 1;
658 		} else {
659 			pd_lba = pd_strip << raid_bdev->strip_size_shift;
660 			pd_blocks = raid_bdev->strip_size;
661 		}
662 		output = &g_io_output[index];
663 		CU_ASSERT(pd_lba == output->offset_blocks);
664 		CU_ASSERT(pd_blocks == output->num_blocks);
665 		CU_ASSERT(ch_ctx->base_channel[pd_idx] == output->ch);
666 		CU_ASSERT(raid_bdev->base_bdev_info[pd_idx].desc == output->desc);
667 		CU_ASSERT(bdev_io->type == output->iotype);
668 		buf += (pd_blocks << spdk_u32log2(g_block_len));
669 	}
670 	CU_ASSERT(g_io_comp_status == io_status);
671 }
672 
673 static void
674 verify_io_without_payload(struct spdk_bdev_io *bdev_io, uint8_t num_base_drives,
675 			  struct raid_bdev_io_channel *ch_ctx, struct raid_bdev *raid_bdev,
676 			  uint32_t io_status)
677 {
678 	uint32_t strip_shift = spdk_u32log2(g_strip_size);
679 	uint64_t start_offset_in_strip = bdev_io->u.bdev.offset_blocks % g_strip_size;
680 	uint64_t end_offset_in_strip = (bdev_io->u.bdev.offset_blocks + bdev_io->u.bdev.num_blocks - 1) %
681 				       g_strip_size;
682 	uint64_t start_strip = bdev_io->u.bdev.offset_blocks >> strip_shift;
683 	uint64_t end_strip = (bdev_io->u.bdev.offset_blocks + bdev_io->u.bdev.num_blocks - 1) >>
684 			     strip_shift;
685 	uint8_t n_disks_involved;
686 	uint64_t start_strip_disk_idx;
687 	uint64_t end_strip_disk_idx;
688 	uint64_t nblocks_in_start_disk;
689 	uint64_t offset_in_start_disk;
690 	uint8_t disk_idx;
691 	uint64_t base_io_idx;
692 	uint64_t sum_nblocks = 0;
693 	struct io_output *output;
694 
695 	if (io_status == INVALID_IO_SUBMIT) {
696 		CU_ASSERT(g_io_comp_status == false);
697 		return;
698 	}
699 	SPDK_CU_ASSERT_FATAL(raid_bdev != NULL);
700 	SPDK_CU_ASSERT_FATAL(num_base_drives != 0);
701 	SPDK_CU_ASSERT_FATAL(bdev_io->type != SPDK_BDEV_IO_TYPE_READ);
702 	SPDK_CU_ASSERT_FATAL(bdev_io->type != SPDK_BDEV_IO_TYPE_WRITE);
703 
704 	n_disks_involved = spdk_min(end_strip - start_strip + 1, num_base_drives);
705 	CU_ASSERT(n_disks_involved == g_io_output_index);
706 
707 	start_strip_disk_idx = start_strip % num_base_drives;
708 	end_strip_disk_idx = end_strip % num_base_drives;
709 
710 	offset_in_start_disk = g_io_output[0].offset_blocks;
711 	nblocks_in_start_disk = g_io_output[0].num_blocks;
712 
713 	for (base_io_idx = 0, disk_idx = start_strip_disk_idx; base_io_idx < n_disks_involved;
714 	     base_io_idx++, disk_idx++) {
715 		uint64_t start_offset_in_disk;
716 		uint64_t end_offset_in_disk;
717 
718 		output = &g_io_output[base_io_idx];
719 
720 		/* round disk_idx */
721 		if (disk_idx >= num_base_drives) {
722 			disk_idx %= num_base_drives;
723 		}
724 
725 		/* start_offset_in_disk aligned in strip check:
726 		 * The first base io has a same start_offset_in_strip with the whole raid io.
727 		 * Other base io should have aligned start_offset_in_strip which is 0.
728 		 */
729 		start_offset_in_disk = output->offset_blocks;
730 		if (base_io_idx == 0) {
731 			CU_ASSERT(start_offset_in_disk % g_strip_size == start_offset_in_strip);
732 		} else {
733 			CU_ASSERT(start_offset_in_disk % g_strip_size == 0);
734 		}
735 
736 		/* end_offset_in_disk aligned in strip check:
737 		 * Base io on disk at which end_strip is located, has a same end_offset_in_strip
738 		 * with the whole raid io.
739 		 * Other base io should have aligned end_offset_in_strip.
740 		 */
741 		end_offset_in_disk = output->offset_blocks + output->num_blocks - 1;
742 		if (disk_idx == end_strip_disk_idx) {
743 			CU_ASSERT(end_offset_in_disk % g_strip_size == end_offset_in_strip);
744 		} else {
745 			CU_ASSERT(end_offset_in_disk % g_strip_size == g_strip_size - 1);
746 		}
747 
748 		/* start_offset_in_disk compared with start_disk.
749 		 * 1. For disk_idx which is larger than start_strip_disk_idx: Its start_offset_in_disk
750 		 *    mustn't be larger than the start offset of start_offset_in_disk; And the gap
751 		 *    must be less than strip size.
752 		 * 2. For disk_idx which is less than start_strip_disk_idx, Its start_offset_in_disk
753 		 *    must be larger than the start offset of start_offset_in_disk; And the gap mustn't
754 		 *    be less than strip size.
755 		 */
756 		if (disk_idx > start_strip_disk_idx) {
757 			CU_ASSERT(start_offset_in_disk <= offset_in_start_disk);
758 			CU_ASSERT(offset_in_start_disk - start_offset_in_disk < g_strip_size);
759 		} else if (disk_idx < start_strip_disk_idx) {
760 			CU_ASSERT(start_offset_in_disk > offset_in_start_disk);
761 			CU_ASSERT(output->offset_blocks - offset_in_start_disk <= g_strip_size);
762 		}
763 
764 		/* nblocks compared with start_disk:
765 		 * The gap between them must be within a strip size.
766 		 */
767 		if (output->num_blocks <= nblocks_in_start_disk) {
768 			CU_ASSERT(nblocks_in_start_disk - output->num_blocks <= g_strip_size);
769 		} else {
770 			CU_ASSERT(output->num_blocks - nblocks_in_start_disk < g_strip_size);
771 		}
772 
773 		sum_nblocks += output->num_blocks;
774 
775 		CU_ASSERT(ch_ctx->base_channel[disk_idx] == output->ch);
776 		CU_ASSERT(raid_bdev->base_bdev_info[disk_idx].desc == output->desc);
777 		CU_ASSERT(bdev_io->type == output->iotype);
778 	}
779 
780 	/* Sum of each nblocks should be same with raid bdev_io */
781 	CU_ASSERT(bdev_io->u.bdev.num_blocks == sum_nblocks);
782 
783 	CU_ASSERT(g_io_comp_status == io_status);
784 }
785 
786 static void
787 verify_raid_config_present(const char *name, bool presence)
788 {
789 	struct raid_bdev_config *raid_cfg;
790 	bool cfg_found;
791 
792 	cfg_found = false;
793 
794 	TAILQ_FOREACH(raid_cfg, &g_raid_config.raid_bdev_config_head, link) {
795 		if (raid_cfg->name != NULL) {
796 			if (strcmp(name, raid_cfg->name) == 0) {
797 				cfg_found = true;
798 				break;
799 			}
800 		}
801 	}
802 
803 	if (presence == true) {
804 		CU_ASSERT(cfg_found == true);
805 	} else {
806 		CU_ASSERT(cfg_found == false);
807 	}
808 }
809 
810 static void
811 verify_raid_bdev_present(const char *name, bool presence)
812 {
813 	struct raid_bdev *pbdev;
814 	bool   pbdev_found;
815 
816 	pbdev_found = false;
817 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
818 		if (strcmp(pbdev->bdev.name, name) == 0) {
819 			pbdev_found = true;
820 			break;
821 		}
822 	}
823 	if (presence == true) {
824 		CU_ASSERT(pbdev_found == true);
825 	} else {
826 		CU_ASSERT(pbdev_found == false);
827 	}
828 }
829 static void
830 verify_raid_config(struct rpc_bdev_raid_create *r, bool presence)
831 {
832 	struct raid_bdev_config *raid_cfg = NULL;
833 	uint8_t i;
834 	int val;
835 
836 	TAILQ_FOREACH(raid_cfg, &g_raid_config.raid_bdev_config_head, link) {
837 		if (strcmp(r->name, raid_cfg->name) == 0) {
838 			if (presence == false) {
839 				break;
840 			}
841 			CU_ASSERT(raid_cfg->raid_bdev != NULL);
842 			CU_ASSERT(raid_cfg->strip_size == r->strip_size_kb);
843 			CU_ASSERT(raid_cfg->num_base_bdevs == r->base_bdevs.num_base_bdevs);
844 			CU_ASSERT(raid_cfg->level == r->level);
845 			if (raid_cfg->base_bdev != NULL) {
846 				for (i = 0; i < raid_cfg->num_base_bdevs; i++) {
847 					val = strcmp(raid_cfg->base_bdev[i].name,
848 						     r->base_bdevs.base_bdevs[i]);
849 					CU_ASSERT(val == 0);
850 				}
851 			}
852 			break;
853 		}
854 	}
855 
856 	if (presence == true) {
857 		CU_ASSERT(raid_cfg != NULL);
858 	} else {
859 		CU_ASSERT(raid_cfg == NULL);
860 	}
861 }
862 
863 static void
864 verify_raid_bdev(struct rpc_bdev_raid_create *r, bool presence, uint32_t raid_state)
865 {
866 	struct raid_bdev *pbdev;
867 	struct raid_base_bdev_info *base_info;
868 	struct spdk_bdev *bdev = NULL;
869 	bool   pbdev_found;
870 	uint64_t min_blockcnt = 0xFFFFFFFFFFFFFFFF;
871 
872 	pbdev_found = false;
873 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
874 		if (strcmp(pbdev->bdev.name, r->name) == 0) {
875 			pbdev_found = true;
876 			if (presence == false) {
877 				break;
878 			}
879 			CU_ASSERT(pbdev->config->raid_bdev == pbdev);
880 			CU_ASSERT(pbdev->base_bdev_info != NULL);
881 			CU_ASSERT(pbdev->strip_size == ((r->strip_size_kb * 1024) / g_block_len));
882 			CU_ASSERT(pbdev->strip_size_shift == spdk_u32log2(((r->strip_size_kb * 1024) /
883 					g_block_len)));
884 			CU_ASSERT(pbdev->blocklen_shift == spdk_u32log2(g_block_len));
885 			CU_ASSERT((uint32_t)pbdev->state == raid_state);
886 			CU_ASSERT(pbdev->num_base_bdevs == r->base_bdevs.num_base_bdevs);
887 			CU_ASSERT(pbdev->num_base_bdevs_discovered == r->base_bdevs.num_base_bdevs);
888 			CU_ASSERT(pbdev->level == r->level);
889 			CU_ASSERT(pbdev->destruct_called == false);
890 			CU_ASSERT(pbdev->base_bdev_info != NULL);
891 			RAID_FOR_EACH_BASE_BDEV(pbdev, base_info) {
892 				CU_ASSERT(base_info->bdev != NULL);
893 				bdev = spdk_bdev_get_by_name(base_info->bdev->name);
894 				CU_ASSERT(bdev != NULL);
895 				CU_ASSERT(base_info->remove_scheduled == false);
896 
897 				if (bdev && bdev->blockcnt < min_blockcnt) {
898 					min_blockcnt = bdev->blockcnt;
899 				}
900 			}
901 			CU_ASSERT((((min_blockcnt / (r->strip_size_kb * 1024 / g_block_len)) *
902 				    (r->strip_size_kb * 1024 / g_block_len)) *
903 				   r->base_bdevs.num_base_bdevs) == pbdev->bdev.blockcnt);
904 			CU_ASSERT(strcmp(pbdev->bdev.product_name, "Raid Volume") == 0);
905 			CU_ASSERT(pbdev->bdev.write_cache == 0);
906 			CU_ASSERT(pbdev->bdev.blocklen == g_block_len);
907 			if (pbdev->num_base_bdevs > 1) {
908 				CU_ASSERT(pbdev->bdev.optimal_io_boundary == pbdev->strip_size);
909 				CU_ASSERT(pbdev->bdev.split_on_optimal_io_boundary == true);
910 			} else {
911 				CU_ASSERT(pbdev->bdev.optimal_io_boundary == 0);
912 				CU_ASSERT(pbdev->bdev.split_on_optimal_io_boundary == false);
913 			}
914 			CU_ASSERT(pbdev->bdev.ctxt == pbdev);
915 			CU_ASSERT(pbdev->bdev.fn_table == &g_raid_bdev_fn_table);
916 			CU_ASSERT(pbdev->bdev.module == &g_raid_if);
917 			break;
918 		}
919 	}
920 	if (presence == true) {
921 		CU_ASSERT(pbdev_found == true);
922 	} else {
923 		CU_ASSERT(pbdev_found == false);
924 	}
925 	pbdev_found = false;
926 	if (raid_state == RAID_BDEV_STATE_ONLINE) {
927 		TAILQ_FOREACH(pbdev, &g_raid_bdev_configured_list, state_link) {
928 			if (strcmp(pbdev->bdev.name, r->name) == 0) {
929 				pbdev_found = true;
930 				break;
931 			}
932 		}
933 	} else if (raid_state == RAID_BDEV_STATE_CONFIGURING) {
934 		TAILQ_FOREACH(pbdev, &g_raid_bdev_configuring_list, state_link) {
935 			if (strcmp(pbdev->bdev.name, r->name) == 0) {
936 				pbdev_found = true;
937 				break;
938 			}
939 		}
940 	} else if (raid_state == RAID_BDEV_STATE_OFFLINE) {
941 		TAILQ_FOREACH(pbdev, &g_raid_bdev_offline_list, state_link) {
942 			if (strcmp(pbdev->bdev.name, r->name) == 0) {
943 				pbdev_found = true;
944 				break;
945 			}
946 		}
947 	}
948 	if (presence == true) {
949 		CU_ASSERT(pbdev_found == true);
950 	} else {
951 		CU_ASSERT(pbdev_found == false);
952 	}
953 }
954 
955 static void
956 verify_get_raids(struct rpc_bdev_raid_create *construct_req,
957 		 uint8_t g_max_raids,
958 		 char **g_get_raids_output, uint32_t g_get_raids_count)
959 {
960 	uint8_t i, j;
961 	bool found;
962 
963 	CU_ASSERT(g_max_raids == g_get_raids_count);
964 	if (g_max_raids == g_get_raids_count) {
965 		for (i = 0; i < g_max_raids; i++) {
966 			found = false;
967 			for (j = 0; j < g_max_raids; j++) {
968 				if (construct_req[i].name &&
969 				    strcmp(construct_req[i].name, g_get_raids_output[i]) == 0) {
970 					found = true;
971 					break;
972 				}
973 			}
974 			CU_ASSERT(found == true);
975 		}
976 	}
977 }
978 
979 static void
980 create_base_bdevs(uint32_t bbdev_start_idx)
981 {
982 	uint8_t i;
983 	struct spdk_bdev *base_bdev;
984 	char name[16];
985 
986 	for (i = 0; i < g_max_base_drives; i++, bbdev_start_idx++) {
987 		snprintf(name, 16, "%s%u%s", "Nvme", bbdev_start_idx, "n1");
988 		base_bdev = calloc(1, sizeof(struct spdk_bdev));
989 		SPDK_CU_ASSERT_FATAL(base_bdev != NULL);
990 		base_bdev->name = strdup(name);
991 		SPDK_CU_ASSERT_FATAL(base_bdev->name != NULL);
992 		base_bdev->blocklen = g_block_len;
993 		base_bdev->blockcnt = BLOCK_CNT;
994 		TAILQ_INSERT_TAIL(&g_bdev_list, base_bdev, internal.link);
995 	}
996 }
997 
998 static void
999 create_test_req(struct rpc_bdev_raid_create *r, const char *raid_name,
1000 		uint8_t bbdev_start_idx, bool create_base_bdev)
1001 {
1002 	uint8_t i;
1003 	char name[16];
1004 	uint8_t bbdev_idx = bbdev_start_idx;
1005 
1006 	r->name = strdup(raid_name);
1007 	SPDK_CU_ASSERT_FATAL(r->name != NULL);
1008 	r->strip_size_kb = (g_strip_size * g_block_len) / 1024;
1009 	r->level = RAID0;
1010 	r->base_bdevs.num_base_bdevs = g_max_base_drives;
1011 	for (i = 0; i < g_max_base_drives; i++, bbdev_idx++) {
1012 		snprintf(name, 16, "%s%u%s", "Nvme", bbdev_idx, "n1");
1013 		r->base_bdevs.base_bdevs[i] = strdup(name);
1014 		SPDK_CU_ASSERT_FATAL(r->base_bdevs.base_bdevs[i] != NULL);
1015 	}
1016 	if (create_base_bdev == true) {
1017 		create_base_bdevs(bbdev_start_idx);
1018 	}
1019 	g_rpc_req = r;
1020 	g_rpc_req_size = sizeof(*r);
1021 }
1022 
1023 static void
1024 create_raid_bdev_create_req(struct rpc_bdev_raid_create *r, const char *raid_name,
1025 			    uint8_t bbdev_start_idx, bool create_base_bdev,
1026 			    uint8_t json_decode_obj_err)
1027 {
1028 	create_test_req(r, raid_name, bbdev_start_idx, create_base_bdev);
1029 
1030 	g_rpc_err = 0;
1031 	g_json_decode_obj_create = 1;
1032 	g_json_decode_obj_err = json_decode_obj_err;
1033 	g_config_level_create = 0;
1034 	g_test_multi_raids = 0;
1035 }
1036 
1037 static void
1038 free_test_req(struct rpc_bdev_raid_create *r)
1039 {
1040 	uint8_t i;
1041 
1042 	free(r->name);
1043 	for (i = 0; i < r->base_bdevs.num_base_bdevs; i++) {
1044 		free(r->base_bdevs.base_bdevs[i]);
1045 	}
1046 }
1047 
1048 static void
1049 create_raid_bdev_delete_req(struct rpc_bdev_raid_delete *r, const char *raid_name,
1050 			    uint8_t json_decode_obj_err)
1051 {
1052 	r->name = strdup(raid_name);
1053 	SPDK_CU_ASSERT_FATAL(r->name != NULL);
1054 
1055 	g_rpc_req = r;
1056 	g_rpc_req_size = sizeof(*r);
1057 	g_rpc_err = 0;
1058 	g_json_decode_obj_create = 0;
1059 	g_json_decode_obj_err = json_decode_obj_err;
1060 	g_config_level_create = 0;
1061 	g_test_multi_raids = 0;
1062 }
1063 
1064 static void
1065 create_get_raids_req(struct rpc_bdev_raid_get_bdevs *r, const char *category,
1066 		     uint8_t json_decode_obj_err)
1067 {
1068 	r->category = strdup(category);
1069 	SPDK_CU_ASSERT_FATAL(r->category != NULL);
1070 
1071 	g_rpc_req = r;
1072 	g_rpc_req_size = sizeof(*r);
1073 	g_rpc_err = 0;
1074 	g_json_decode_obj_create = 0;
1075 	g_json_decode_obj_err = json_decode_obj_err;
1076 	g_config_level_create = 0;
1077 	g_test_multi_raids = 1;
1078 	g_get_raids_count = 0;
1079 }
1080 
1081 static void
1082 test_create_raid(void)
1083 {
1084 	struct rpc_bdev_raid_create req;
1085 	struct rpc_bdev_raid_delete delete_req;
1086 
1087 	set_globals();
1088 	CU_ASSERT(raid_bdev_init() == 0);
1089 
1090 	verify_raid_config_present("raid1", false);
1091 	verify_raid_bdev_present("raid1", false);
1092 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1093 	rpc_bdev_raid_create(NULL, NULL);
1094 	CU_ASSERT(g_rpc_err == 0);
1095 	verify_raid_config(&req, true);
1096 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1097 	free_test_req(&req);
1098 
1099 	create_raid_bdev_delete_req(&delete_req, "raid1", 0);
1100 	rpc_bdev_raid_delete(NULL, NULL);
1101 	CU_ASSERT(g_rpc_err == 0);
1102 	raid_bdev_exit();
1103 	base_bdevs_cleanup();
1104 	reset_globals();
1105 }
1106 
1107 static void
1108 test_delete_raid(void)
1109 {
1110 	struct rpc_bdev_raid_create construct_req;
1111 	struct rpc_bdev_raid_delete delete_req;
1112 
1113 	set_globals();
1114 	CU_ASSERT(raid_bdev_init() == 0);
1115 
1116 	verify_raid_config_present("raid1", false);
1117 	verify_raid_bdev_present("raid1", false);
1118 	create_raid_bdev_create_req(&construct_req, "raid1", 0, true, 0);
1119 	rpc_bdev_raid_create(NULL, NULL);
1120 	CU_ASSERT(g_rpc_err == 0);
1121 	verify_raid_config(&construct_req, true);
1122 	verify_raid_bdev(&construct_req, true, RAID_BDEV_STATE_ONLINE);
1123 	free_test_req(&construct_req);
1124 
1125 	create_raid_bdev_delete_req(&delete_req, "raid1", 0);
1126 	rpc_bdev_raid_delete(NULL, NULL);
1127 	CU_ASSERT(g_rpc_err == 0);
1128 	verify_raid_config_present("raid1", false);
1129 	verify_raid_bdev_present("raid1", false);
1130 
1131 	raid_bdev_exit();
1132 	base_bdevs_cleanup();
1133 	reset_globals();
1134 }
1135 
1136 static void
1137 test_create_raid_invalid_args(void)
1138 {
1139 	struct rpc_bdev_raid_create req;
1140 	struct rpc_bdev_raid_delete destroy_req;
1141 	struct raid_bdev_config *raid_cfg;
1142 
1143 	set_globals();
1144 	CU_ASSERT(raid_bdev_init() == 0);
1145 
1146 	verify_raid_config_present("raid1", false);
1147 	verify_raid_bdev_present("raid1", false);
1148 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1149 	req.level = INVALID_RAID_LEVEL;
1150 	rpc_bdev_raid_create(NULL, NULL);
1151 	CU_ASSERT(g_rpc_err == 1);
1152 	free_test_req(&req);
1153 	verify_raid_config_present("raid1", false);
1154 	verify_raid_bdev_present("raid1", false);
1155 
1156 	create_raid_bdev_create_req(&req, "raid1", 0, false, 1);
1157 	rpc_bdev_raid_create(NULL, NULL);
1158 	CU_ASSERT(g_rpc_err == 1);
1159 	free_test_req(&req);
1160 	verify_raid_config_present("raid1", false);
1161 	verify_raid_bdev_present("raid1", false);
1162 
1163 	create_raid_bdev_create_req(&req, "raid1", 0, false, 0);
1164 	req.strip_size_kb = 1231;
1165 	rpc_bdev_raid_create(NULL, NULL);
1166 	CU_ASSERT(g_rpc_err == 1);
1167 	free_test_req(&req);
1168 	verify_raid_config_present("raid1", false);
1169 	verify_raid_bdev_present("raid1", false);
1170 
1171 	create_raid_bdev_create_req(&req, "raid1", 0, false, 0);
1172 	rpc_bdev_raid_create(NULL, NULL);
1173 	CU_ASSERT(g_rpc_err == 0);
1174 	verify_raid_config(&req, true);
1175 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1176 	free_test_req(&req);
1177 
1178 	create_raid_bdev_create_req(&req, "raid1", 0, false, 0);
1179 	rpc_bdev_raid_create(NULL, NULL);
1180 	CU_ASSERT(g_rpc_err == 1);
1181 	free_test_req(&req);
1182 
1183 	create_raid_bdev_create_req(&req, "raid2", 0, false, 0);
1184 	rpc_bdev_raid_create(NULL, NULL);
1185 	CU_ASSERT(g_rpc_err == 1);
1186 	free_test_req(&req);
1187 	verify_raid_config_present("raid2", false);
1188 	verify_raid_bdev_present("raid2", false);
1189 
1190 	create_raid_bdev_create_req(&req, "raid2", g_max_base_drives, true, 0);
1191 	free(req.base_bdevs.base_bdevs[g_max_base_drives - 1]);
1192 	req.base_bdevs.base_bdevs[g_max_base_drives - 1] = strdup("Nvme0n1");
1193 	SPDK_CU_ASSERT_FATAL(req.base_bdevs.base_bdevs[g_max_base_drives - 1] != NULL);
1194 	rpc_bdev_raid_create(NULL, NULL);
1195 	CU_ASSERT(g_rpc_err == 1);
1196 	free_test_req(&req);
1197 	verify_raid_config_present("raid2", false);
1198 	verify_raid_bdev_present("raid2", false);
1199 
1200 	create_raid_bdev_create_req(&req, "raid2", g_max_base_drives, true, 0);
1201 	free(req.base_bdevs.base_bdevs[g_max_base_drives - 1]);
1202 	req.base_bdevs.base_bdevs[g_max_base_drives - 1] = strdup("Nvme100000n1");
1203 	SPDK_CU_ASSERT_FATAL(req.base_bdevs.base_bdevs[g_max_base_drives - 1] != NULL);
1204 	rpc_bdev_raid_create(NULL, NULL);
1205 	CU_ASSERT(g_rpc_err == 0);
1206 	free_test_req(&req);
1207 	verify_raid_config_present("raid2", true);
1208 	verify_raid_bdev_present("raid2", true);
1209 	raid_cfg = raid_bdev_config_find_by_name("raid2");
1210 	SPDK_CU_ASSERT_FATAL(raid_cfg != NULL);
1211 	check_and_remove_raid_bdev(raid_cfg);
1212 	raid_bdev_config_cleanup(raid_cfg);
1213 
1214 	create_raid_bdev_create_req(&req, "raid2", g_max_base_drives, false, 0);
1215 	rpc_bdev_raid_create(NULL, NULL);
1216 	CU_ASSERT(g_rpc_err == 0);
1217 	free_test_req(&req);
1218 	verify_raid_config_present("raid2", true);
1219 	verify_raid_bdev_present("raid2", true);
1220 	verify_raid_config_present("raid1", true);
1221 	verify_raid_bdev_present("raid1", true);
1222 
1223 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1224 	rpc_bdev_raid_delete(NULL, NULL);
1225 	create_raid_bdev_delete_req(&destroy_req, "raid2", 0);
1226 	rpc_bdev_raid_delete(NULL, NULL);
1227 	raid_bdev_exit();
1228 	base_bdevs_cleanup();
1229 	reset_globals();
1230 }
1231 
1232 static void
1233 test_delete_raid_invalid_args(void)
1234 {
1235 	struct rpc_bdev_raid_create construct_req;
1236 	struct rpc_bdev_raid_delete destroy_req;
1237 
1238 	set_globals();
1239 	CU_ASSERT(raid_bdev_init() == 0);
1240 
1241 	verify_raid_config_present("raid1", false);
1242 	verify_raid_bdev_present("raid1", false);
1243 	create_raid_bdev_create_req(&construct_req, "raid1", 0, true, 0);
1244 	rpc_bdev_raid_create(NULL, NULL);
1245 	CU_ASSERT(g_rpc_err == 0);
1246 	verify_raid_config(&construct_req, true);
1247 	verify_raid_bdev(&construct_req, true, RAID_BDEV_STATE_ONLINE);
1248 	free_test_req(&construct_req);
1249 
1250 	create_raid_bdev_delete_req(&destroy_req, "raid2", 0);
1251 	rpc_bdev_raid_delete(NULL, NULL);
1252 	CU_ASSERT(g_rpc_err == 1);
1253 
1254 	create_raid_bdev_delete_req(&destroy_req, "raid1", 1);
1255 	rpc_bdev_raid_delete(NULL, NULL);
1256 	CU_ASSERT(g_rpc_err == 1);
1257 	free(destroy_req.name);
1258 	verify_raid_config_present("raid1", true);
1259 	verify_raid_bdev_present("raid1", true);
1260 
1261 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1262 	rpc_bdev_raid_delete(NULL, NULL);
1263 	CU_ASSERT(g_rpc_err == 0);
1264 	verify_raid_config_present("raid1", false);
1265 	verify_raid_bdev_present("raid1", false);
1266 
1267 	raid_bdev_exit();
1268 	base_bdevs_cleanup();
1269 	reset_globals();
1270 }
1271 
1272 static void
1273 test_io_channel(void)
1274 {
1275 	struct rpc_bdev_raid_create req;
1276 	struct rpc_bdev_raid_delete destroy_req;
1277 	struct raid_bdev *pbdev;
1278 	struct raid_bdev_io_channel *ch_ctx;
1279 	uint8_t i;
1280 
1281 	set_globals();
1282 	CU_ASSERT(raid_bdev_init() == 0);
1283 
1284 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1285 	verify_raid_config_present("raid1", false);
1286 	verify_raid_bdev_present("raid1", false);
1287 	rpc_bdev_raid_create(NULL, NULL);
1288 	CU_ASSERT(g_rpc_err == 0);
1289 	verify_raid_config(&req, true);
1290 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1291 
1292 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1293 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1294 			break;
1295 		}
1296 	}
1297 	CU_ASSERT(pbdev != NULL);
1298 	ch_ctx = calloc(1, sizeof(struct raid_bdev_io_channel));
1299 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1300 
1301 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1302 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1303 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1304 	}
1305 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1306 	CU_ASSERT(ch_ctx->base_channel == NULL);
1307 	free_test_req(&req);
1308 
1309 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1310 	rpc_bdev_raid_delete(NULL, NULL);
1311 	CU_ASSERT(g_rpc_err == 0);
1312 	verify_raid_config_present("raid1", false);
1313 	verify_raid_bdev_present("raid1", false);
1314 
1315 	free(ch_ctx);
1316 	raid_bdev_exit();
1317 	base_bdevs_cleanup();
1318 	reset_globals();
1319 }
1320 
1321 static void
1322 test_write_io(void)
1323 {
1324 	struct rpc_bdev_raid_create req;
1325 	struct rpc_bdev_raid_delete destroy_req;
1326 	struct raid_bdev *pbdev;
1327 	struct spdk_io_channel *ch;
1328 	struct raid_bdev_io_channel *ch_ctx;
1329 	uint8_t i;
1330 	struct spdk_bdev_io *bdev_io;
1331 	uint64_t io_len;
1332 	uint64_t lba = 0;
1333 	struct spdk_io_channel *ch_b;
1334 	struct spdk_bdev_channel *ch_b_ctx;
1335 
1336 	set_globals();
1337 	CU_ASSERT(raid_bdev_init() == 0);
1338 
1339 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1340 	verify_raid_config_present("raid1", false);
1341 	verify_raid_bdev_present("raid1", false);
1342 	rpc_bdev_raid_create(NULL, NULL);
1343 	CU_ASSERT(g_rpc_err == 0);
1344 	verify_raid_config(&req, true);
1345 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1346 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1347 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1348 			break;
1349 		}
1350 	}
1351 	CU_ASSERT(pbdev != NULL);
1352 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1353 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1354 
1355 	ch_b = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct spdk_bdev_channel));
1356 	SPDK_CU_ASSERT_FATAL(ch_b != NULL);
1357 	ch_b_ctx = spdk_io_channel_get_ctx(ch_b);
1358 	ch_b_ctx->channel = ch;
1359 
1360 	ch_ctx = spdk_io_channel_get_ctx(ch);
1361 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1362 
1363 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1364 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1365 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1366 	}
1367 
1368 	/* test 2 IO sizes based on global strip size set earlier */
1369 	for (i = 0; i < 2; i++) {
1370 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1371 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1372 		io_len = (g_strip_size / 2) << i;
1373 		bdev_io_initialize(bdev_io, ch_b, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_WRITE);
1374 		lba += g_strip_size;
1375 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1376 		g_io_output_index = 0;
1377 		raid_bdev_submit_request(ch, bdev_io);
1378 		verify_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1379 			  g_child_io_status_flag);
1380 		bdev_io_cleanup(bdev_io);
1381 	}
1382 
1383 	free_test_req(&req);
1384 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1385 	CU_ASSERT(ch_ctx->base_channel == NULL);
1386 	free(ch);
1387 	free(ch_b);
1388 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1389 	rpc_bdev_raid_delete(NULL, NULL);
1390 	CU_ASSERT(g_rpc_err == 0);
1391 	verify_raid_config_present("raid1", false);
1392 	verify_raid_bdev_present("raid1", false);
1393 
1394 	raid_bdev_exit();
1395 	base_bdevs_cleanup();
1396 	reset_globals();
1397 }
1398 
1399 static void
1400 test_read_io(void)
1401 {
1402 	struct rpc_bdev_raid_create req;
1403 	struct rpc_bdev_raid_delete destroy_req;
1404 	struct raid_bdev *pbdev;
1405 	struct spdk_io_channel *ch;
1406 	struct raid_bdev_io_channel *ch_ctx;
1407 	uint8_t i;
1408 	struct spdk_bdev_io *bdev_io;
1409 	uint64_t io_len;
1410 	uint64_t lba;
1411 	struct spdk_io_channel *ch_b;
1412 	struct spdk_bdev_channel *ch_b_ctx;
1413 
1414 	set_globals();
1415 	CU_ASSERT(raid_bdev_init() == 0);
1416 
1417 	verify_raid_config_present("raid1", false);
1418 	verify_raid_bdev_present("raid1", false);
1419 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1420 	rpc_bdev_raid_create(NULL, NULL);
1421 	CU_ASSERT(g_rpc_err == 0);
1422 	verify_raid_config(&req, true);
1423 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1424 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1425 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1426 			break;
1427 		}
1428 	}
1429 	CU_ASSERT(pbdev != NULL);
1430 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1431 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1432 
1433 	ch_b = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct spdk_bdev_channel));
1434 	SPDK_CU_ASSERT_FATAL(ch_b != NULL);
1435 	ch_b_ctx = spdk_io_channel_get_ctx(ch_b);
1436 	ch_b_ctx->channel = ch;
1437 
1438 	ch_ctx = spdk_io_channel_get_ctx(ch);
1439 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1440 
1441 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1442 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1443 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1444 	}
1445 	free_test_req(&req);
1446 
1447 	/* test 2 IO sizes based on global strip size set earlier */
1448 	lba = 0;
1449 	for (i = 0; i < 2; i++) {
1450 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1451 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1452 		io_len = (g_strip_size / 2) << i;
1453 		bdev_io_initialize(bdev_io, ch_b, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_READ);
1454 		lba += g_strip_size;
1455 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1456 		g_io_output_index = 0;
1457 		raid_bdev_submit_request(ch, bdev_io);
1458 		verify_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1459 			  g_child_io_status_flag);
1460 		bdev_io_cleanup(bdev_io);
1461 	}
1462 
1463 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1464 	CU_ASSERT(ch_ctx->base_channel == NULL);
1465 	free(ch);
1466 	free(ch_b);
1467 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1468 	rpc_bdev_raid_delete(NULL, NULL);
1469 	CU_ASSERT(g_rpc_err == 0);
1470 	verify_raid_config_present("raid1", false);
1471 	verify_raid_bdev_present("raid1", false);
1472 
1473 	raid_bdev_exit();
1474 	base_bdevs_cleanup();
1475 	reset_globals();
1476 }
1477 
1478 static void
1479 raid_bdev_io_generate_by_strips(uint64_t n_strips)
1480 {
1481 	uint64_t lba;
1482 	uint64_t nblocks;
1483 	uint64_t start_offset;
1484 	uint64_t end_offset;
1485 	uint64_t offsets_in_strip[3];
1486 	uint64_t start_bdev_idx;
1487 	uint64_t start_bdev_offset;
1488 	uint64_t start_bdev_idxs[3];
1489 	int i, j, l;
1490 
1491 	/* 3 different situations of offset in strip */
1492 	offsets_in_strip[0] = 0;
1493 	offsets_in_strip[1] = g_strip_size >> 1;
1494 	offsets_in_strip[2] = g_strip_size - 1;
1495 
1496 	/* 3 different situations of start_bdev_idx */
1497 	start_bdev_idxs[0] = 0;
1498 	start_bdev_idxs[1] = g_max_base_drives >> 1;
1499 	start_bdev_idxs[2] = g_max_base_drives - 1;
1500 
1501 	/* consider different offset in strip */
1502 	for (i = 0; i < 3; i++) {
1503 		start_offset = offsets_in_strip[i];
1504 		for (j = 0; j < 3; j++) {
1505 			end_offset = offsets_in_strip[j];
1506 			if (n_strips == 1 && start_offset > end_offset) {
1507 				continue;
1508 			}
1509 
1510 			/* consider at which base_bdev lba is started. */
1511 			for (l = 0; l < 3; l++) {
1512 				start_bdev_idx = start_bdev_idxs[l];
1513 				start_bdev_offset = start_bdev_idx * g_strip_size;
1514 				lba = g_lba_offset + start_bdev_offset + start_offset;
1515 				nblocks = (n_strips - 1) * g_strip_size + end_offset - start_offset + 1;
1516 
1517 				g_io_ranges[g_io_range_idx].lba = lba;
1518 				g_io_ranges[g_io_range_idx].nblocks = nblocks;
1519 
1520 				SPDK_CU_ASSERT_FATAL(g_io_range_idx < MAX_TEST_IO_RANGE);
1521 				g_io_range_idx++;
1522 			}
1523 		}
1524 	}
1525 }
1526 
1527 static void
1528 raid_bdev_io_generate(void)
1529 {
1530 	uint64_t n_strips;
1531 	uint64_t n_strips_span = g_max_base_drives;
1532 	uint64_t n_strips_times[5] = {g_max_base_drives + 1, g_max_base_drives * 2 - 1,
1533 				      g_max_base_drives * 2, g_max_base_drives * 3,
1534 				      g_max_base_drives * 4
1535 				     };
1536 	uint32_t i;
1537 
1538 	g_io_range_idx = 0;
1539 
1540 	/* consider different number of strips from 1 to strips spanned base bdevs,
1541 	 * and even to times of strips spanned base bdevs
1542 	 */
1543 	for (n_strips = 1; n_strips < n_strips_span; n_strips++) {
1544 		raid_bdev_io_generate_by_strips(n_strips);
1545 	}
1546 
1547 	for (i = 0; i < SPDK_COUNTOF(n_strips_times); i++) {
1548 		n_strips = n_strips_times[i];
1549 		raid_bdev_io_generate_by_strips(n_strips);
1550 	}
1551 }
1552 
1553 static void
1554 test_unmap_io(void)
1555 {
1556 	struct rpc_bdev_raid_create req;
1557 	struct rpc_bdev_raid_delete destroy_req;
1558 	struct raid_bdev *pbdev;
1559 	struct spdk_io_channel *ch;
1560 	struct raid_bdev_io_channel *ch_ctx;
1561 	uint8_t i;
1562 	struct spdk_bdev_io *bdev_io;
1563 	uint32_t count;
1564 	uint64_t io_len;
1565 	uint64_t lba;
1566 
1567 	set_globals();
1568 	CU_ASSERT(raid_bdev_init() == 0);
1569 
1570 	verify_raid_config_present("raid1", false);
1571 	verify_raid_bdev_present("raid1", false);
1572 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1573 	rpc_bdev_raid_create(NULL, NULL);
1574 	CU_ASSERT(g_rpc_err == 0);
1575 	verify_raid_config(&req, true);
1576 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1577 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1578 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1579 			break;
1580 		}
1581 	}
1582 	CU_ASSERT(pbdev != NULL);
1583 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1584 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1585 	ch_ctx = spdk_io_channel_get_ctx(ch);
1586 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1587 
1588 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1589 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1590 		SPDK_CU_ASSERT_FATAL(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1591 	}
1592 
1593 	CU_ASSERT(raid_bdev_io_type_supported(pbdev, SPDK_BDEV_IO_TYPE_UNMAP) == true);
1594 	CU_ASSERT(raid_bdev_io_type_supported(pbdev, SPDK_BDEV_IO_TYPE_FLUSH) == true);
1595 
1596 	raid_bdev_io_generate();
1597 	for (count = 0; count < g_io_range_idx; count++) {
1598 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1599 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1600 		io_len = g_io_ranges[count].nblocks;
1601 		lba = g_io_ranges[count].lba;
1602 		bdev_io_initialize(bdev_io, ch, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_UNMAP);
1603 		memset(g_io_output, 0, g_max_base_drives * sizeof(struct io_output));
1604 		g_io_output_index = 0;
1605 		raid_bdev_submit_request(ch, bdev_io);
1606 		verify_io_without_payload(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1607 					  g_child_io_status_flag);
1608 		bdev_io_cleanup(bdev_io);
1609 	}
1610 	free_test_req(&req);
1611 
1612 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1613 	CU_ASSERT(ch_ctx->base_channel == NULL);
1614 	free(ch);
1615 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1616 	rpc_bdev_raid_delete(NULL, NULL);
1617 	CU_ASSERT(g_rpc_err == 0);
1618 	verify_raid_config_present("raid1", false);
1619 	verify_raid_bdev_present("raid1", false);
1620 
1621 	raid_bdev_exit();
1622 	base_bdevs_cleanup();
1623 	reset_globals();
1624 }
1625 
1626 /* Test IO failures */
1627 static void
1628 test_io_failure(void)
1629 {
1630 	struct rpc_bdev_raid_create req;
1631 	struct rpc_bdev_raid_delete destroy_req;
1632 	struct raid_bdev *pbdev;
1633 	struct spdk_io_channel *ch;
1634 	struct raid_bdev_io_channel *ch_ctx;
1635 	uint8_t i;
1636 	struct spdk_bdev_io *bdev_io;
1637 	uint32_t count;
1638 	uint64_t io_len;
1639 	uint64_t lba;
1640 
1641 	set_globals();
1642 	CU_ASSERT(raid_bdev_init() == 0);
1643 
1644 	verify_raid_config_present("raid1", false);
1645 	verify_raid_bdev_present("raid1", false);
1646 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1647 	rpc_bdev_raid_create(NULL, NULL);
1648 	CU_ASSERT(g_rpc_err == 0);
1649 	verify_raid_config(&req, true);
1650 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1651 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1652 		if (strcmp(pbdev->bdev.name, req.name) == 0) {
1653 			break;
1654 		}
1655 	}
1656 	CU_ASSERT(pbdev != NULL);
1657 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1658 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1659 	ch_ctx = spdk_io_channel_get_ctx(ch);
1660 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1661 
1662 	CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1663 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1664 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1665 	}
1666 	free_test_req(&req);
1667 
1668 	lba = 0;
1669 	for (count = 0; count < 1; count++) {
1670 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1671 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1672 		io_len = (g_strip_size / 2) << count;
1673 		bdev_io_initialize(bdev_io, ch, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_INVALID);
1674 		lba += g_strip_size;
1675 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1676 		g_io_output_index = 0;
1677 		raid_bdev_submit_request(ch, bdev_io);
1678 		verify_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1679 			  INVALID_IO_SUBMIT);
1680 		bdev_io_cleanup(bdev_io);
1681 	}
1682 
1683 
1684 	lba = 0;
1685 	g_child_io_status_flag = false;
1686 	for (count = 0; count < 1; count++) {
1687 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1688 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1689 		io_len = (g_strip_size / 2) << count;
1690 		bdev_io_initialize(bdev_io, ch, &pbdev->bdev, lba, io_len, SPDK_BDEV_IO_TYPE_WRITE);
1691 		lba += g_strip_size;
1692 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1693 		g_io_output_index = 0;
1694 		raid_bdev_submit_request(ch, bdev_io);
1695 		verify_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1696 			  g_child_io_status_flag);
1697 		bdev_io_cleanup(bdev_io);
1698 	}
1699 
1700 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1701 	CU_ASSERT(ch_ctx->base_channel == NULL);
1702 	free(ch);
1703 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1704 	rpc_bdev_raid_delete(NULL, NULL);
1705 	CU_ASSERT(g_rpc_err == 0);
1706 	verify_raid_config_present("raid1", false);
1707 	verify_raid_bdev_present("raid1", false);
1708 
1709 	raid_bdev_exit();
1710 	base_bdevs_cleanup();
1711 	reset_globals();
1712 }
1713 
1714 /* Test reset IO */
1715 static void
1716 test_reset_io(void)
1717 {
1718 	struct rpc_bdev_raid_create req;
1719 	struct rpc_bdev_raid_delete destroy_req;
1720 	struct raid_bdev *pbdev;
1721 	struct spdk_io_channel *ch;
1722 	struct raid_bdev_io_channel *ch_ctx;
1723 	uint8_t i;
1724 	struct spdk_bdev_io *bdev_io;
1725 
1726 	set_globals();
1727 	CU_ASSERT(raid_bdev_init() == 0);
1728 
1729 	verify_raid_config_present("raid1", false);
1730 	verify_raid_bdev_present("raid1", false);
1731 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
1732 	rpc_bdev_raid_create(NULL, NULL);
1733 	CU_ASSERT(g_rpc_err == 0);
1734 	verify_raid_config(&req, true);
1735 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
1736 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1737 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
1738 			break;
1739 		}
1740 	}
1741 	CU_ASSERT(pbdev != NULL);
1742 	ch = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1743 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1744 	ch_ctx = spdk_io_channel_get_ctx(ch);
1745 	SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1746 
1747 	SPDK_CU_ASSERT_FATAL(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1748 	for (i = 0; i < req.base_bdevs.num_base_bdevs; i++) {
1749 		CU_ASSERT(ch_ctx->base_channel && ch_ctx->base_channel[i] == &g_io_channel);
1750 	}
1751 	free_test_req(&req);
1752 
1753 	g_bdev_io_submit_status = 0;
1754 	g_child_io_status_flag = true;
1755 
1756 	CU_ASSERT(raid_bdev_io_type_supported(pbdev, SPDK_BDEV_IO_TYPE_RESET) == true);
1757 
1758 	bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1759 	SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1760 	bdev_io_initialize(bdev_io, ch, &pbdev->bdev, 0, 1, SPDK_BDEV_IO_TYPE_RESET);
1761 	memset(g_io_output, 0, g_max_base_drives * sizeof(struct io_output));
1762 	g_io_output_index = 0;
1763 	raid_bdev_submit_request(ch, bdev_io);
1764 	verify_reset_io(bdev_io, req.base_bdevs.num_base_bdevs, ch_ctx, pbdev,
1765 			true);
1766 	bdev_io_cleanup(bdev_io);
1767 
1768 	raid_bdev_destroy_cb(pbdev, ch_ctx);
1769 	CU_ASSERT(ch_ctx->base_channel == NULL);
1770 	free(ch);
1771 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
1772 	rpc_bdev_raid_delete(NULL, NULL);
1773 	CU_ASSERT(g_rpc_err == 0);
1774 	verify_raid_config_present("raid1", false);
1775 	verify_raid_bdev_present("raid1", false);
1776 
1777 	raid_bdev_exit();
1778 	base_bdevs_cleanup();
1779 	reset_globals();
1780 }
1781 
1782 /* Create multiple raids, destroy raids without IO, get_raids related tests */
1783 static void
1784 test_multi_raid_no_io(void)
1785 {
1786 	struct rpc_bdev_raid_create *construct_req;
1787 	struct rpc_bdev_raid_delete destroy_req;
1788 	struct rpc_bdev_raid_get_bdevs get_raids_req;
1789 	uint8_t i;
1790 	char name[16];
1791 	uint8_t bbdev_idx = 0;
1792 
1793 	set_globals();
1794 	construct_req = calloc(MAX_RAIDS, sizeof(struct rpc_bdev_raid_create));
1795 	SPDK_CU_ASSERT_FATAL(construct_req != NULL);
1796 	CU_ASSERT(raid_bdev_init() == 0);
1797 	for (i = 0; i < g_max_raids; i++) {
1798 		snprintf(name, 16, "%s%u", "raid", i);
1799 		verify_raid_config_present(name, false);
1800 		verify_raid_bdev_present(name, false);
1801 		create_raid_bdev_create_req(&construct_req[i], name, bbdev_idx, true, 0);
1802 		bbdev_idx += g_max_base_drives;
1803 		rpc_bdev_raid_create(NULL, NULL);
1804 		CU_ASSERT(g_rpc_err == 0);
1805 		verify_raid_config(&construct_req[i], true);
1806 		verify_raid_bdev(&construct_req[i], true, RAID_BDEV_STATE_ONLINE);
1807 	}
1808 
1809 	create_get_raids_req(&get_raids_req, "all", 0);
1810 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1811 	CU_ASSERT(g_rpc_err == 0);
1812 	verify_get_raids(construct_req, g_max_raids, g_get_raids_output, g_get_raids_count);
1813 	for (i = 0; i < g_get_raids_count; i++) {
1814 		free(g_get_raids_output[i]);
1815 	}
1816 
1817 	create_get_raids_req(&get_raids_req, "online", 0);
1818 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1819 	CU_ASSERT(g_rpc_err == 0);
1820 	verify_get_raids(construct_req, g_max_raids, g_get_raids_output, g_get_raids_count);
1821 	for (i = 0; i < g_get_raids_count; i++) {
1822 		free(g_get_raids_output[i]);
1823 	}
1824 
1825 	create_get_raids_req(&get_raids_req, "configuring", 0);
1826 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1827 	CU_ASSERT(g_rpc_err == 0);
1828 	CU_ASSERT(g_get_raids_count == 0);
1829 
1830 	create_get_raids_req(&get_raids_req, "offline", 0);
1831 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1832 	CU_ASSERT(g_rpc_err == 0);
1833 	CU_ASSERT(g_get_raids_count == 0);
1834 
1835 	create_get_raids_req(&get_raids_req, "invalid_category", 0);
1836 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1837 	CU_ASSERT(g_rpc_err == 1);
1838 	CU_ASSERT(g_get_raids_count == 0);
1839 
1840 	create_get_raids_req(&get_raids_req, "all", 1);
1841 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1842 	CU_ASSERT(g_rpc_err == 1);
1843 	free(get_raids_req.category);
1844 	CU_ASSERT(g_get_raids_count == 0);
1845 
1846 	create_get_raids_req(&get_raids_req, "all", 0);
1847 	rpc_bdev_raid_get_bdevs(NULL, NULL);
1848 	CU_ASSERT(g_rpc_err == 0);
1849 	CU_ASSERT(g_get_raids_count == g_max_raids);
1850 	for (i = 0; i < g_get_raids_count; i++) {
1851 		free(g_get_raids_output[i]);
1852 	}
1853 
1854 	for (i = 0; i < g_max_raids; i++) {
1855 		SPDK_CU_ASSERT_FATAL(construct_req[i].name != NULL);
1856 		snprintf(name, 16, "%s", construct_req[i].name);
1857 		create_raid_bdev_delete_req(&destroy_req, name, 0);
1858 		rpc_bdev_raid_delete(NULL, NULL);
1859 		CU_ASSERT(g_rpc_err == 0);
1860 		verify_raid_config_present(name, false);
1861 		verify_raid_bdev_present(name, false);
1862 	}
1863 	raid_bdev_exit();
1864 	for (i = 0; i < g_max_raids; i++) {
1865 		free_test_req(&construct_req[i]);
1866 	}
1867 	free(construct_req);
1868 	base_bdevs_cleanup();
1869 	reset_globals();
1870 }
1871 
1872 /* Create multiple raids, fire IOs on raids */
1873 static void
1874 test_multi_raid_with_io(void)
1875 {
1876 	struct rpc_bdev_raid_create *construct_req;
1877 	struct rpc_bdev_raid_delete destroy_req;
1878 	uint8_t i, j;
1879 	char name[16];
1880 	uint8_t bbdev_idx = 0;
1881 	struct raid_bdev *pbdev;
1882 	struct spdk_io_channel *ch;
1883 	struct raid_bdev_io_channel *ch_ctx = NULL;
1884 	struct spdk_bdev_io *bdev_io;
1885 	uint64_t io_len;
1886 	uint64_t lba = 0;
1887 	int16_t iotype;
1888 	struct spdk_io_channel *ch_b;
1889 	struct spdk_bdev_channel *ch_b_ctx;
1890 
1891 	set_globals();
1892 	construct_req = calloc(g_max_raids, sizeof(struct rpc_bdev_raid_create));
1893 	SPDK_CU_ASSERT_FATAL(construct_req != NULL);
1894 	CU_ASSERT(raid_bdev_init() == 0);
1895 	ch = calloc(g_max_raids, sizeof(struct spdk_io_channel) + sizeof(struct raid_bdev_io_channel));
1896 	SPDK_CU_ASSERT_FATAL(ch != NULL);
1897 
1898 	ch_b = calloc(1, sizeof(struct spdk_io_channel) + sizeof(struct spdk_bdev_channel));
1899 	SPDK_CU_ASSERT_FATAL(ch_b != NULL);
1900 	ch_b_ctx = spdk_io_channel_get_ctx(ch_b);
1901 	ch_b_ctx->channel = ch;
1902 
1903 	for (i = 0; i < g_max_raids; i++) {
1904 		snprintf(name, 16, "%s%u", "raid", i);
1905 		verify_raid_config_present(name, false);
1906 		verify_raid_bdev_present(name, false);
1907 		create_raid_bdev_create_req(&construct_req[i], name, bbdev_idx, true, 0);
1908 		bbdev_idx += g_max_base_drives;
1909 		rpc_bdev_raid_create(NULL, NULL);
1910 		CU_ASSERT(g_rpc_err == 0);
1911 		verify_raid_config(&construct_req[i], true);
1912 		verify_raid_bdev(&construct_req[i], true, RAID_BDEV_STATE_ONLINE);
1913 		TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1914 			if (strcmp(pbdev->bdev.name, construct_req[i].name) == 0) {
1915 				break;
1916 			}
1917 		}
1918 		CU_ASSERT(pbdev != NULL);
1919 		ch_ctx = spdk_io_channel_get_ctx(&ch[i]);
1920 		SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1921 		CU_ASSERT(raid_bdev_create_cb(pbdev, ch_ctx) == 0);
1922 		SPDK_CU_ASSERT_FATAL(ch_ctx->base_channel != NULL);
1923 		for (j = 0; j < construct_req[i].base_bdevs.num_base_bdevs; j++) {
1924 			CU_ASSERT(ch_ctx->base_channel[j] == &g_io_channel);
1925 		}
1926 	}
1927 
1928 	/* This will perform a write on the first raid and a read on the second. It can be
1929 	 * expanded in the future to perform r/w on each raid device in the event that
1930 	 * multiple raid levels are supported.
1931 	 */
1932 	for (i = 0; i < g_max_raids; i++) {
1933 		bdev_io = calloc(1, sizeof(struct spdk_bdev_io) + sizeof(struct raid_bdev_io));
1934 		SPDK_CU_ASSERT_FATAL(bdev_io != NULL);
1935 		io_len = g_strip_size;
1936 		iotype = (i) ? SPDK_BDEV_IO_TYPE_WRITE : SPDK_BDEV_IO_TYPE_READ;
1937 		memset(g_io_output, 0, ((g_max_io_size / g_strip_size) + 1) * sizeof(struct io_output));
1938 		g_io_output_index = 0;
1939 		TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1940 			if (strcmp(pbdev->bdev.name, construct_req[i].name) == 0) {
1941 				break;
1942 			}
1943 		}
1944 		bdev_io_initialize(bdev_io, ch_b, &pbdev->bdev, lba, io_len, iotype);
1945 		CU_ASSERT(pbdev != NULL);
1946 		raid_bdev_submit_request(ch, bdev_io);
1947 		verify_io(bdev_io, g_max_base_drives, ch_ctx, pbdev,
1948 			  g_child_io_status_flag);
1949 		bdev_io_cleanup(bdev_io);
1950 	}
1951 
1952 	for (i = 0; i < g_max_raids; i++) {
1953 		TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
1954 			if (strcmp(pbdev->bdev.name, construct_req[i].name) == 0) {
1955 				break;
1956 			}
1957 		}
1958 		CU_ASSERT(pbdev != NULL);
1959 		ch_ctx = spdk_io_channel_get_ctx(&ch[i]);
1960 		SPDK_CU_ASSERT_FATAL(ch_ctx != NULL);
1961 		raid_bdev_destroy_cb(pbdev, ch_ctx);
1962 		CU_ASSERT(ch_ctx->base_channel == NULL);
1963 		snprintf(name, 16, "%s", construct_req[i].name);
1964 		create_raid_bdev_delete_req(&destroy_req, name, 0);
1965 		rpc_bdev_raid_delete(NULL, NULL);
1966 		CU_ASSERT(g_rpc_err == 0);
1967 		verify_raid_config_present(name, false);
1968 		verify_raid_bdev_present(name, false);
1969 	}
1970 	raid_bdev_exit();
1971 	for (i = 0; i < g_max_raids; i++) {
1972 		free_test_req(&construct_req[i]);
1973 	}
1974 	free(construct_req);
1975 	free(ch);
1976 	free(ch_b);
1977 	base_bdevs_cleanup();
1978 	reset_globals();
1979 }
1980 
1981 static void
1982 test_io_type_supported(void)
1983 {
1984 	CU_ASSERT(raid_bdev_io_type_supported(NULL, SPDK_BDEV_IO_TYPE_READ) == true);
1985 	CU_ASSERT(raid_bdev_io_type_supported(NULL, SPDK_BDEV_IO_TYPE_WRITE) == true);
1986 	CU_ASSERT(raid_bdev_io_type_supported(NULL, SPDK_BDEV_IO_TYPE_INVALID) == false);
1987 }
1988 
1989 static void
1990 test_raid_json_dump_info(void)
1991 {
1992 	struct rpc_bdev_raid_create req;
1993 	struct rpc_bdev_raid_delete destroy_req;
1994 	struct raid_bdev *pbdev;
1995 
1996 	set_globals();
1997 	CU_ASSERT(raid_bdev_init() == 0);
1998 
1999 	verify_raid_config_present("raid1", false);
2000 	verify_raid_bdev_present("raid1", false);
2001 	create_raid_bdev_create_req(&req, "raid1", 0, true, 0);
2002 	rpc_bdev_raid_create(NULL, NULL);
2003 	CU_ASSERT(g_rpc_err == 0);
2004 	verify_raid_bdev(&req, true, RAID_BDEV_STATE_ONLINE);
2005 
2006 	TAILQ_FOREACH(pbdev, &g_raid_bdev_list, global_link) {
2007 		if (strcmp(pbdev->bdev.name, "raid1") == 0) {
2008 			break;
2009 		}
2010 	}
2011 	CU_ASSERT(pbdev != NULL);
2012 
2013 	CU_ASSERT(raid_bdev_dump_info_json(pbdev, NULL) == 0);
2014 
2015 	free_test_req(&req);
2016 
2017 	create_raid_bdev_delete_req(&destroy_req, "raid1", 0);
2018 	rpc_bdev_raid_delete(NULL, NULL);
2019 	CU_ASSERT(g_rpc_err == 0);
2020 	verify_raid_config_present("raid1", false);
2021 	verify_raid_bdev_present("raid1", false);
2022 
2023 	raid_bdev_exit();
2024 	base_bdevs_cleanup();
2025 	reset_globals();
2026 }
2027 
2028 static void
2029 test_context_size(void)
2030 {
2031 	CU_ASSERT(raid_bdev_get_ctx_size() == sizeof(struct raid_bdev_io));
2032 }
2033 
2034 static void
2035 test_raid_level_conversions(void)
2036 {
2037 	const char *raid_str;
2038 
2039 	CU_ASSERT(raid_bdev_parse_raid_level("abcd123") == INVALID_RAID_LEVEL);
2040 	CU_ASSERT(raid_bdev_parse_raid_level("0") == RAID0);
2041 	CU_ASSERT(raid_bdev_parse_raid_level("raid0") == RAID0);
2042 	CU_ASSERT(raid_bdev_parse_raid_level("RAID0") == RAID0);
2043 
2044 	raid_str = raid_bdev_level_to_str(INVALID_RAID_LEVEL);
2045 	CU_ASSERT(raid_str != NULL && strlen(raid_str) == 0);
2046 	raid_str = raid_bdev_level_to_str(1234);
2047 	CU_ASSERT(raid_str != NULL && strlen(raid_str) == 0);
2048 	raid_str = raid_bdev_level_to_str(RAID0);
2049 	CU_ASSERT(raid_str != NULL && strcmp(raid_str, "raid0") == 0);
2050 }
2051 
2052 int main(int argc, char **argv)
2053 {
2054 	CU_pSuite       suite = NULL;
2055 	unsigned int    num_failures;
2056 
2057 	CU_set_error_action(CUEA_ABORT);
2058 	CU_initialize_registry();
2059 
2060 	suite = CU_add_suite("raid", NULL, NULL);
2061 
2062 	CU_ADD_TEST(suite, test_create_raid);
2063 	CU_ADD_TEST(suite, test_delete_raid);
2064 	CU_ADD_TEST(suite, test_create_raid_invalid_args);
2065 	CU_ADD_TEST(suite, test_delete_raid_invalid_args);
2066 	CU_ADD_TEST(suite, test_io_channel);
2067 	CU_ADD_TEST(suite, test_reset_io);
2068 	CU_ADD_TEST(suite, test_write_io);
2069 	CU_ADD_TEST(suite, test_read_io);
2070 	CU_ADD_TEST(suite, test_unmap_io);
2071 	CU_ADD_TEST(suite, test_io_failure);
2072 	CU_ADD_TEST(suite, test_multi_raid_no_io);
2073 	CU_ADD_TEST(suite, test_multi_raid_with_io);
2074 	CU_ADD_TEST(suite, test_io_type_supported);
2075 	CU_ADD_TEST(suite, test_raid_json_dump_info);
2076 	CU_ADD_TEST(suite, test_context_size);
2077 	CU_ADD_TEST(suite, test_raid_level_conversions);
2078 
2079 	allocate_threads(1);
2080 	set_thread(0);
2081 
2082 	CU_basic_set_mode(CU_BRM_VERBOSE);
2083 	set_test_opts();
2084 	CU_basic_run_tests();
2085 	num_failures = CU_get_number_of_failures();
2086 	CU_cleanup_registry();
2087 
2088 	free_threads();
2089 
2090 	return num_failures;
2091 }
2092