]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/test/unit/lib/nvme/nvme_ns.c/nvme_ns_ut.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / unit / lib / nvme / nvme_ns.c / nvme_ns_ut.c
CommitLineData
7c673cae
FG
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 "spdk/env.h"
37
38#include "nvme/nvme_ns.c"
39
11fdf7f2
TL
40#include "common/lib/test_env.c"
41
42SPDK_LOG_REGISTER_COMPONENT("nvme", SPDK_LOG_NVME)
43
f67539c2 44DEFINE_STUB(nvme_wait_for_completion_robust_lock, int,
11fdf7f2
TL
45 (struct spdk_nvme_qpair *qpair,
46 struct nvme_completion_poll_status *status,
47 pthread_mutex_t *robust_mutex), 0);
7c673cae
FG
48
49int
11fdf7f2
TL
50nvme_ctrlr_cmd_identify(struct spdk_nvme_ctrlr *ctrlr, uint8_t cns, uint16_t cntid, uint32_t nsid,
51 void *payload, size_t payload_size,
52 spdk_nvme_cmd_cb cb_fn, void *cb_arg)
7c673cae
FG
53{
54 return -1;
55}
56
57void
58nvme_completion_poll_cb(void *arg, const struct spdk_nvme_cpl *cpl)
59{
60}
61
62int32_t
63spdk_nvme_qpair_process_completions(struct spdk_nvme_qpair *qpair, uint32_t max_completions)
64{
65 return -1;
66}
67
68static void
69test_nvme_ns_construct(void)
70{
71 struct spdk_nvme_ns ns = {};
11fdf7f2 72 uint32_t id = 1;
7c673cae
FG
73 struct spdk_nvme_ctrlr ctrlr = {};
74
75 nvme_ns_construct(&ns, id, &ctrlr);
76 CU_ASSERT(ns.id == 1);
11fdf7f2
TL
77}
78
79static void
80test_nvme_ns_uuid(void)
81{
82 struct spdk_nvme_ns ns = {};
83 const struct spdk_uuid *uuid;
84 struct spdk_uuid expected_uuid;
85
86 memset(&expected_uuid, 0xA5, sizeof(expected_uuid));
87
88 /* Empty list - no UUID should be found */
89 memset(ns.id_desc_list, 0, sizeof(ns.id_desc_list));
90 uuid = spdk_nvme_ns_get_uuid(&ns);
91 CU_ASSERT(uuid == NULL);
92
93 /* NGUID only (no UUID in list) */
94 memset(ns.id_desc_list, 0, sizeof(ns.id_desc_list));
95 ns.id_desc_list[0] = 0x02; /* NIDT == NGUID */
96 ns.id_desc_list[1] = 0x10; /* NIDL */
97 memset(&ns.id_desc_list[4], 0xCC, 0x10);
98 uuid = spdk_nvme_ns_get_uuid(&ns);
99 CU_ASSERT(uuid == NULL);
100
101 /* Just UUID in the list */
102 memset(ns.id_desc_list, 0, sizeof(ns.id_desc_list));
103 ns.id_desc_list[0] = 0x03; /* NIDT == UUID */
104 ns.id_desc_list[1] = 0x10; /* NIDL */
105 memcpy(&ns.id_desc_list[4], &expected_uuid, sizeof(expected_uuid));
106 uuid = spdk_nvme_ns_get_uuid(&ns);
107 SPDK_CU_ASSERT_FATAL(uuid != NULL);
108 CU_ASSERT(memcmp(uuid, &expected_uuid, sizeof(*uuid)) == 0);
109
110 /* UUID followed by NGUID */
111 memset(ns.id_desc_list, 0, sizeof(ns.id_desc_list));
112 ns.id_desc_list[0] = 0x03; /* NIDT == UUID */
113 ns.id_desc_list[1] = 0x10; /* NIDL */
114 memcpy(&ns.id_desc_list[4], &expected_uuid, sizeof(expected_uuid));
115 ns.id_desc_list[20] = 0x02; /* NIDT == NGUID */
116 ns.id_desc_list[21] = 0x10; /* NIDL */
117 memset(&ns.id_desc_list[24], 0xCC, 0x10);
118 uuid = spdk_nvme_ns_get_uuid(&ns);
119 SPDK_CU_ASSERT_FATAL(uuid != NULL);
120 CU_ASSERT(memcmp(uuid, &expected_uuid, sizeof(*uuid)) == 0);
121
122 /* NGUID followed by UUID */
123 memset(ns.id_desc_list, 0, sizeof(ns.id_desc_list));
124 ns.id_desc_list[0] = 0x02; /* NIDT == NGUID */
125 ns.id_desc_list[1] = 0x10; /* NIDL */
126 memset(&ns.id_desc_list[4], 0xCC, 0x10);
127 ns.id_desc_list[20] = 0x03; /* NIDT = UUID */
128 ns.id_desc_list[21] = 0x10; /* NIDL */
129 memcpy(&ns.id_desc_list[24], &expected_uuid, sizeof(expected_uuid));
130 uuid = spdk_nvme_ns_get_uuid(&ns);
131 SPDK_CU_ASSERT_FATAL(uuid != NULL);
132 CU_ASSERT(memcmp(uuid, &expected_uuid, sizeof(*uuid)) == 0);
7c673cae
FG
133}
134
135int main(int argc, char **argv)
136{
137 CU_pSuite suite = NULL;
138 unsigned int num_failures;
139
f67539c2
TL
140 CU_set_error_action(CUEA_ABORT);
141 CU_initialize_registry();
7c673cae
FG
142
143 suite = CU_add_suite("nvme", NULL, NULL);
f67539c2
TL
144
145 CU_ADD_TEST(suite, test_nvme_ns_construct);
146 CU_ADD_TEST(suite, test_nvme_ns_uuid);
7c673cae
FG
147
148 CU_basic_set_mode(CU_BRM_VERBOSE);
149 CU_basic_run_tests();
150 num_failures = CU_get_number_of_failures();
151 CU_cleanup_registry();
152 return num_failures;
153}