]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/unit/lib/vhost/test_vhost.c
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / test / unit / lib / vhost / test_vhost.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright(c) Intel Corporation. All rights reserved.
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/stdinc.h"
35
36 #include "CUnit/Basic.h"
37 #include "spdk_cunit.h"
38 #include "spdk_internal/mock.h"
39 #include "spdk/thread.h"
40
41 #include "unit/lib/json_mock.c"
42
43 struct spdk_conf_section {
44 struct spdk_conf_section *next;
45 char *name;
46 int num;
47 struct spdk_conf_item *item;
48 };
49
50 DEFINE_STUB(spdk_vhost_vq_get_desc, int, (struct spdk_vhost_dev *vdev,
51 struct spdk_vhost_virtqueue *vq, uint16_t req_idx, struct vring_desc **desc,
52 struct vring_desc **desc_table, uint32_t *desc_table_size), 0);
53 DEFINE_STUB(spdk_vhost_vring_desc_is_wr, bool, (struct vring_desc *cur_desc), false);
54 DEFINE_STUB(spdk_vhost_vring_desc_to_iov, int, (struct spdk_vhost_dev *vdev, struct iovec *iov,
55 uint16_t *iov_index, const struct vring_desc *desc), 0);
56 DEFINE_STUB_V(spdk_vhost_vq_used_ring_enqueue, (struct spdk_vhost_dev *vdev,
57 struct spdk_vhost_virtqueue *vq, uint16_t id, uint32_t len));
58 DEFINE_STUB(spdk_vhost_vring_desc_get_next, int, (struct vring_desc **desc,
59 struct vring_desc *desc_table, uint32_t desc_table_size), 0);
60 DEFINE_STUB(spdk_vhost_vq_avail_ring_get, uint16_t, (struct spdk_vhost_virtqueue *vq,
61 uint16_t *reqs, uint16_t reqs_len), 0);
62 DEFINE_STUB(spdk_vhost_vq_used_signal, int, (struct spdk_vhost_dev *vdev,
63 struct spdk_vhost_virtqueue *virtqueue), 0);
64 DEFINE_STUB_V(spdk_vhost_dev_used_signal, (struct spdk_vhost_dev *vdev));
65 DEFINE_STUB_V(spdk_vhost_dev_mem_register, (struct spdk_vhost_dev *vdev));
66 DEFINE_STUB_P(spdk_vhost_dev_find, struct spdk_vhost_dev, (const char *ctrlr_name), {0});
67 DEFINE_STUB_P(spdk_conf_first_section, struct spdk_conf_section, (struct spdk_conf *cp), {0});
68 DEFINE_STUB(spdk_conf_section_match_prefix, bool, (const struct spdk_conf_section *sp,
69 const char *name_prefix), false);
70 DEFINE_STUB_P(spdk_conf_next_section, struct spdk_conf_section, (struct spdk_conf_section *sp), {0});
71 DEFINE_STUB_P(spdk_conf_section_get_name, const char, (const struct spdk_conf_section *sp), {0});
72 DEFINE_STUB(spdk_conf_section_get_boolval, bool, (struct spdk_conf_section *sp, const char *key,
73 bool default_val), false);
74 DEFINE_STUB_P(spdk_conf_section_get_nmval, char, (struct spdk_conf_section *sp, const char *key,
75 int idx1, int idx2), {0});
76 DEFINE_STUB_V(spdk_vhost_dev_mem_unregister, (struct spdk_vhost_dev *vdev));
77 DEFINE_STUB(spdk_vhost_event_send, int, (struct spdk_vhost_dev *vdev, spdk_vhost_event_fn cb_fn,
78 void *arg, unsigned timeout_sec, const char *errmsg), 0);
79 DEFINE_STUB(spdk_env_get_socket_id, uint32_t, (uint32_t core), 0);
80 DEFINE_STUB_V(spdk_vhost_dev_backend_event_done, (void *event_ctx, int response));
81 DEFINE_STUB_V(spdk_vhost_lock, (void));
82 DEFINE_STUB_V(spdk_vhost_unlock, (void));
83 DEFINE_STUB(spdk_env_get_current_core, uint32_t, (void), 0);
84 DEFINE_STUB_V(spdk_vhost_call_external_event, (const char *ctrlr_name, spdk_vhost_event_fn fn,
85 void *arg));
86 DEFINE_STUB(spdk_vhost_vring_desc_has_next, bool, (struct vring_desc *cur_desc), false);
87 DEFINE_STUB_VP(spdk_vhost_gpa_to_vva, (struct spdk_vhost_dev *vdev, uint64_t addr, uint64_t len),
88 {0});
89 DEFINE_STUB(spdk_scsi_dev_get_id, int, (const struct spdk_scsi_dev *dev), {0});
90
91 /* This sets spdk_vhost_dev_unregister to either to fail or success */
92 DEFINE_STUB(spdk_vhost_dev_unregister_fail, bool, (void), false);
93 /* This sets spdk_vhost_dev_register to either to fail or success */
94 DEFINE_STUB(spdk_vhost_dev_register_fail, bool, (void), false);
95
96 static struct spdk_vhost_dev *g_spdk_vhost_device;
97 int
98 spdk_vhost_dev_register(struct spdk_vhost_dev *vdev, const char *name, const char *mask_str,
99 const struct spdk_vhost_dev_backend *backend)
100 {
101 if (spdk_vhost_dev_register_fail()) {
102 return -1;
103 }
104
105 vdev->backend = backend;
106 g_spdk_vhost_device = vdev;
107 vdev->registered = true;
108 return 0;
109 }
110
111 int
112 spdk_vhost_dev_unregister(struct spdk_vhost_dev *vdev)
113 {
114 if (spdk_vhost_dev_unregister_fail()) {
115 return -1;
116 }
117
118 free(vdev->name);
119 g_spdk_vhost_device = NULL;
120 return 0;
121 }