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