1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2025 Oxide Computer Company 14 */ 15 16 #ifndef _LIBNVME_TEST_COMMON_H 17 #define _LIBNVME_TEST_COMMON_H 18 19 #include <stdbool.h> 20 #include <libnvme.h> 21 #include <sys/ccompile.h> 22 23 /* 24 * Common definitions and functions for the libnvme tests. 25 */ 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 #define NVME_TEST_DEV_ENVVAR "NVME_TEST_DEVICE" 32 33 /* 34 * Target default LBA size and namespace size in bytes. We default to a 1 GiB 35 * namespace when using common test code. In the future we may need to look at 36 * the namespace granularity instead. 37 */ 38 #define NVME_TEST_LBA_SIZE 4096 39 #define NVME_TEST_NS_SIZE (1ULL * 1024ULL * 1024ULL * 1024ULL) 40 41 extern void libnvme_test_init(nvme_t **, nvme_ctrl_t **); 42 43 /* 44 * Warnings and fatal errors from the surrounding tests. 45 */ 46 extern void libnvme_test_hdl_warn(nvme_t *, const char *, 47 ...) __PRINTFLIKE(2); 48 extern void libnvme_test_ctrl_warn(nvme_ctrl_t *, const char *, 49 ...) __PRINTFLIKE(2); 50 extern void libnvme_test_ctrl_info_warn(nvme_ctrl_info_t *, const char *, 51 ...) __PRINTFLIKE(2); 52 extern void libnvme_test_ns_info_warn(nvme_ns_info_t *, const char *, 53 ...) __PRINTFLIKE(2); 54 extern void libnvme_test_hdl_fatal(nvme_t *, const char *, 55 ...) __PRINTFLIKE(2) __NORETURN; 56 extern void libnvme_test_ctrl_fatal(nvme_ctrl_t *, const char *, 57 ...) __PRINTFLIKE(2) __NORETURN; 58 extern void libnvme_test_ctrl_info_fatal(nvme_ctrl_info_t *, const char *, 59 ...) __PRINTFLIKE(2) __NORETURN; 60 61 /* 62 * Misc. utilities. 63 */ 64 extern bool libnvme_test_ctrl_err(nvme_ctrl_t *, uint32_t, uint32_t, 65 const char *); 66 extern bool libnvme_test_lbaf(nvme_ctrl_info_t *, uint32_t, uint32_t *); 67 extern bool libnvme_test_setup_ns(nvme_ctrl_t *, nvme_ns_disc_level_t, 68 uint32_t, uint32_t); 69 70 /* 71 * Basic namespace routines. These will normally return true if they complete 72 * successfully. If the error pointer is passed then they will return true as 73 * long as the error pointer is valid and it will be up to the caller to figure 74 * out what to do with it. 75 */ 76 extern bool libnvme_test_ns_delete(nvme_ctrl_t *, uint32_t, nvme_err_t *); 77 extern bool libnvme_test_ns_create(nvme_ctrl_t *, uint64_t, uint32_t, 78 uint32_t *, nvme_err_t *); 79 extern bool libnvme_test_ctrl_attach(nvme_ctrl_t *, uint32_t, uint32_t, 80 nvme_err_t *); 81 extern bool libnvme_test_ns_blkdev(nvme_ctrl_t *, uint32_t, bool, nvme_err_t *); 82 83 #ifdef __cplusplus 84 } 85 #endif 86 87 #endif /* _LIBNVME_TEST_COMMON_H */ 88