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.
34 #include "spdk_cunit.h"
36 #include "nvme/nvme_ctrlr_ocssd_cmd.c"
38 #define DECLARE_AND_CONSTRUCT_CTRLR() \
39 struct spdk_nvme_ctrlr ctrlr = {}; \
40 struct spdk_nvme_qpair adminq = {}; \
41 struct nvme_request req; \
43 STAILQ_INIT(&adminq.free_req); \
44 STAILQ_INSERT_HEAD(&adminq.free_req, &req, stailq); \
45 ctrlr.adminq = &adminq;
47 pid_t g_spdk_nvme_pid
;
48 struct nvme_request g_req
;
49 typedef void (*verify_request_fn_t
)(struct nvme_request
*req
);
50 verify_request_fn_t verify_fn
;
52 static const uint32_t expected_geometry_ns
= 1;
55 nvme_ctrlr_submit_admin_request(struct spdk_nvme_ctrlr
*ctrlr
, struct nvme_request
*req
)
58 memset(req
, 0, sizeof(*req
));
63 nvme_allocate_request_user_copy(struct spdk_nvme_qpair
*qpair
, void *buffer
, uint32_t payload_size
,
64 spdk_nvme_cmd_cb cb_fn
, void *cb_arg
, bool host_to_controller
)
66 /* For the unit test, we don't actually need to copy the buffer */
67 return nvme_allocate_request_contig(qpair
, buffer
, payload_size
, cb_fn
, cb_arg
);
70 static void verify_geometry_cmd(struct nvme_request
*req
)
72 CU_ASSERT(req
->cmd
.opc
== SPDK_OCSSD_OPC_GEOMETRY
);
73 CU_ASSERT(req
->cmd
.nsid
== expected_geometry_ns
);
77 test_geometry_cmd(void)
79 DECLARE_AND_CONSTRUCT_CTRLR();
81 struct spdk_ocssd_geometry_data geo
;
83 verify_fn
= verify_geometry_cmd
;
85 spdk_nvme_ocssd_ctrlr_cmd_geometry(&ctrlr
, expected_geometry_ns
, &geo
,
86 sizeof(geo
), NULL
, NULL
);
89 int main(int argc
, char **argv
)
91 CU_pSuite suite
= NULL
;
92 unsigned int num_failures
;
94 if (CU_initialize_registry() != CUE_SUCCESS
) {
95 return CU_get_error();
98 suite
= CU_add_suite("nvme_ctrlr_cmd", NULL
, NULL
);
100 CU_cleanup_registry();
101 return CU_get_error();
105 CU_add_test(suite
, "test ocssd ctrlr geometry cmd ", test_geometry_cmd
) == NULL
107 CU_cleanup_registry();
108 return CU_get_error();
111 CU_basic_set_mode(CU_BRM_VERBOSE
);
112 CU_basic_run_tests();
113 num_failures
= CU_get_number_of_failures();
114 CU_cleanup_registry();