4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
39 #include "spdk_cunit.h"
40 #include "subsystem.h"
42 const struct spdk_nvmf_ctrlr_ops spdk_nvmf_direct_ctrlr_ops
;
43 const struct spdk_nvmf_ctrlr_ops spdk_nvmf_virtual_ctrlr_ops
;
44 const struct spdk_nvmf_ctrlr_ops spdk_nvmf_discovery_ctrlr_ops
;
46 #include "subsystem.c"
48 SPDK_LOG_REGISTER_TRACE_FLAG("nvmf", SPDK_TRACE_NVMF
)
50 struct spdk_nvmf_tgt g_nvmf_tgt
;
52 struct spdk_nvmf_listen_addr
*
53 spdk_nvmf_listen_addr_create(const char *trname
, const char *traddr
, const char *trsvcid
)
55 struct spdk_nvmf_listen_addr
*listen_addr
;
57 listen_addr
= calloc(1, sizeof(*listen_addr
));
62 listen_addr
->traddr
= strdup(traddr
);
63 if (!listen_addr
->traddr
) {
68 listen_addr
->trsvcid
= strdup(trsvcid
);
69 if (!listen_addr
->trsvcid
) {
70 free(listen_addr
->traddr
);
75 listen_addr
->trname
= strdup(trname
);
76 if (!listen_addr
->trname
) {
77 free(listen_addr
->traddr
);
78 free(listen_addr
->trsvcid
);
87 spdk_nvmf_listen_addr_destroy(struct spdk_nvmf_listen_addr
*addr
)
96 spdk_nvmf_listen_addr_cleanup(struct spdk_nvmf_listen_addr
*addr
)
102 test_transport1_listen_addr_add(struct spdk_nvmf_listen_addr
*listen_addr
)
108 test_transport1_listen_addr_discover(struct spdk_nvmf_listen_addr
*listen_addr
,
109 struct spdk_nvmf_discovery_log_page_entry
*entry
)
114 static const struct spdk_nvmf_transport test_transport1
= {
115 .listen_addr_add
= test_transport1_listen_addr_add
,
116 .listen_addr_discover
= test_transport1_listen_addr_discover
,
119 const struct spdk_nvmf_transport
*
120 spdk_nvmf_transport_get(const char *trname
)
122 if (!strcasecmp(trname
, "test_transport1")) {
123 return &test_transport1
;
130 spdk_nvme_ctrlr_process_admin_completions(struct spdk_nvme_ctrlr
*ctrlr
)
136 spdk_nvme_qpair_process_completions(struct spdk_nvme_qpair
*qpair
, uint32_t max_completions
)
142 spdk_nvme_detach(struct spdk_nvme_ctrlr
*ctrlr
)
148 spdk_nvmf_session_destruct(struct spdk_nvmf_session
*session
)
153 spdk_nvmf_session_poll(struct spdk_nvmf_session
*session
)
159 spdk_bdev_claim(struct spdk_bdev
*bdev
, spdk_bdev_remove_cb_t remove_cb
,
166 nvmf_test_create_subsystem(void)
169 struct spdk_nvmf_subsystem
*subsystem
;
170 TAILQ_INIT(&g_nvmf_tgt
.subsystems
);
172 strncpy(nqn
, "nqn.2016-06.io.spdk:subsystem1", sizeof(nqn
));
173 subsystem
= spdk_nvmf_create_subsystem(nqn
, SPDK_NVMF_SUBTYPE_NVME
,
174 NVMF_SUBSYSTEM_MODE_DIRECT
, NULL
, NULL
, NULL
);
175 SPDK_CU_ASSERT_FATAL(subsystem
!= NULL
);
176 CU_ASSERT_STRING_EQUAL(subsystem
->subnqn
, nqn
);
177 spdk_nvmf_delete_subsystem(subsystem
);
179 /* Longest valid name */
180 strncpy(nqn
, "nqn.2016-06.io.spdk:", sizeof(nqn
));
181 memset(nqn
+ strlen(nqn
), 'a', 222 - strlen(nqn
));
183 CU_ASSERT(strlen(nqn
) == 222);
184 subsystem
= spdk_nvmf_create_subsystem(nqn
, SPDK_NVMF_SUBTYPE_NVME
,
185 NVMF_SUBSYSTEM_MODE_DIRECT
, NULL
, NULL
, NULL
);
186 SPDK_CU_ASSERT_FATAL(subsystem
!= NULL
);
187 CU_ASSERT_STRING_EQUAL(subsystem
->subnqn
, nqn
);
188 spdk_nvmf_delete_subsystem(subsystem
);
190 /* Name that is one byte longer than allowed */
191 strncpy(nqn
, "nqn.2016-06.io.spdk:", sizeof(nqn
));
192 memset(nqn
+ strlen(nqn
), 'a', 223 - strlen(nqn
));
194 CU_ASSERT(strlen(nqn
) == 223);
195 subsystem
= spdk_nvmf_create_subsystem(nqn
, SPDK_NVMF_SUBTYPE_NVME
,
196 NVMF_SUBSYSTEM_MODE_DIRECT
, NULL
, NULL
, NULL
);
197 CU_ASSERT(subsystem
== NULL
);
201 nvmf_test_find_subsystem(void)
203 CU_ASSERT_PTR_NULL(nvmf_find_subsystem(NULL
));
204 CU_ASSERT_PTR_NULL(nvmf_find_subsystem("fake"));
207 int main(int argc
, char **argv
)
209 CU_pSuite suite
= NULL
;
210 unsigned int num_failures
;
212 if (CU_initialize_registry() != CUE_SUCCESS
) {
213 return CU_get_error();
216 suite
= CU_add_suite("nvmf", NULL
, NULL
);
218 CU_cleanup_registry();
219 return CU_get_error();
223 CU_add_test(suite
, "create_subsystem", nvmf_test_create_subsystem
) == NULL
||
224 CU_add_test(suite
, "find_subsystem", nvmf_test_find_subsystem
) == NULL
) {
225 CU_cleanup_registry();
226 return CU_get_error();
229 CU_basic_set_mode(CU_BRM_VERBOSE
);
230 CU_basic_run_tests();
231 num_failures
= CU_get_number_of_failures();
232 CU_cleanup_registry();