]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/unit/lib/nvme/nvme_ctrlr_ocssd_cmd.c/nvme_ctrlr_ocssd_cmd_ut.c
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / test / unit / lib / nvme / nvme_ctrlr_ocssd_cmd.c / nvme_ctrlr_ocssd_cmd_ut.c
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_cunit.h"
35
36 #include "nvme/nvme_ctrlr_ocssd_cmd.c"
37
38 #define DECLARE_AND_CONSTRUCT_CTRLR() \
39 struct spdk_nvme_ctrlr ctrlr = {}; \
40 struct spdk_nvme_qpair adminq = {}; \
41 struct nvme_request req; \
42 \
43 STAILQ_INIT(&adminq.free_req); \
44 STAILQ_INSERT_HEAD(&adminq.free_req, &req, stailq); \
45 ctrlr.adminq = &adminq;
46
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;
51
52 static const uint32_t expected_geometry_ns = 1;
53
54 int
55 nvme_ctrlr_submit_admin_request(struct spdk_nvme_ctrlr *ctrlr, struct nvme_request *req)
56 {
57 verify_fn(req);
58 memset(req, 0, sizeof(*req));
59 return 0;
60 }
61
62 struct nvme_request *
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)
65 {
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);
68 }
69
70 static void verify_geometry_cmd(struct nvme_request *req)
71 {
72 CU_ASSERT(req->cmd.opc == SPDK_OCSSD_OPC_GEOMETRY);
73 CU_ASSERT(req->cmd.nsid == expected_geometry_ns);
74 }
75
76 static void
77 test_geometry_cmd(void)
78 {
79 DECLARE_AND_CONSTRUCT_CTRLR();
80
81 struct spdk_ocssd_geometry_data geo;
82
83 verify_fn = verify_geometry_cmd;
84
85 spdk_nvme_ocssd_ctrlr_cmd_geometry(&ctrlr, expected_geometry_ns, &geo,
86 sizeof(geo), NULL, NULL);
87 }
88
89 int main(int argc, char **argv)
90 {
91 CU_pSuite suite = NULL;
92 unsigned int num_failures;
93
94 if (CU_initialize_registry() != CUE_SUCCESS) {
95 return CU_get_error();
96 }
97
98 suite = CU_add_suite("nvme_ctrlr_cmd", NULL, NULL);
99 if (suite == NULL) {
100 CU_cleanup_registry();
101 return CU_get_error();
102 }
103
104 if (
105 CU_add_test(suite, "test ocssd ctrlr geometry cmd ", test_geometry_cmd) == NULL
106 ) {
107 CU_cleanup_registry();
108 return CU_get_error();
109 }
110
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();
115 return num_failures;
116 }