]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/test/unit/lib/bdev/part.c/part_ut.c
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / unit / lib / bdev / part.c / part_ut.c
CommitLineData
11fdf7f2
TL
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
9f95a23c 36#include "common/lib/ut_multithread.c"
11fdf7f2
TL
37#include "unit/lib/json_mock.c"
38
39#include "spdk/config.h"
40/* HACK: disable VTune integration so the unit test doesn't need VTune headers and libs to build */
41#undef SPDK_CONFIG_VTUNE
42
9f95a23c
TL
43#include "spdk_internal/thread.h"
44
11fdf7f2
TL
45#include "bdev/bdev.c"
46#include "bdev/part.c"
47
48DEFINE_STUB(spdk_conf_find_section, struct spdk_conf_section *, (struct spdk_conf *cp,
49 const char *name), NULL);
50DEFINE_STUB(spdk_conf_section_get_nmval, char *,
51 (struct spdk_conf_section *sp, const char *key, int idx1, int idx2), NULL);
52DEFINE_STUB(spdk_conf_section_get_intval, int, (struct spdk_conf_section *sp, const char *key), -1);
53
54struct spdk_trace_histories *g_trace_histories;
55DEFINE_STUB_V(spdk_trace_add_register_fn, (struct spdk_trace_register_fn *reg_fn));
56DEFINE_STUB_V(spdk_trace_register_owner, (uint8_t type, char id_prefix));
57DEFINE_STUB_V(spdk_trace_register_object, (uint8_t type, char id_prefix));
9f95a23c 58DEFINE_STUB_V(spdk_trace_register_description, (const char *name,
11fdf7f2
TL
59 uint16_t tpoint_id, uint8_t owner_type,
60 uint8_t object_type, uint8_t new_object,
9f95a23c 61 uint8_t arg1_type, const char *arg1_name));
11fdf7f2
TL
62DEFINE_STUB_V(_spdk_trace_record, (uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id,
63 uint32_t size, uint64_t object_id, uint64_t arg1));
9f95a23c
TL
64DEFINE_STUB(spdk_notify_send, uint64_t, (const char *type, const char *ctx), 0);
65DEFINE_STUB(spdk_notify_type_register, struct spdk_notify_type *, (const char *type), NULL);
11fdf7f2
TL
66
67static void
68_part_cleanup(struct spdk_bdev_part *part)
69{
70 free(part->internal.bdev.name);
71 free(part->internal.bdev.product_name);
72}
73
74void
75spdk_scsi_nvme_translate(const struct spdk_bdev_io *bdev_io,
76 int *sc, int *sk, int *asc, int *ascq)
77{
78}
79
80struct spdk_bdev_module bdev_ut_if = {
81 .name = "bdev_ut",
82};
83
84static void vbdev_ut_examine(struct spdk_bdev *bdev);
85
86struct spdk_bdev_module vbdev_ut_if = {
87 .name = "vbdev_ut",
88 .examine_config = vbdev_ut_examine,
89};
90
9f95a23c
TL
91SPDK_BDEV_MODULE_REGISTER(bdev_ut, &bdev_ut_if)
92SPDK_BDEV_MODULE_REGISTER(vbdev_ut, &vbdev_ut_if)
11fdf7f2
TL
93
94static void
95vbdev_ut_examine(struct spdk_bdev *bdev)
96{
97 spdk_bdev_module_examine_done(&vbdev_ut_if);
98}
99
100static int
101__destruct(void *ctx)
102{
103 return 0;
104}
105
106static struct spdk_bdev_fn_table base_fn_table = {
107 .destruct = __destruct,
108};
109static struct spdk_bdev_fn_table part_fn_table = {
110 .destruct = __destruct,
111};
112
113static void
114part_test(void)
115{
116 struct spdk_bdev_part_base *base;
117 struct spdk_bdev_part part1 = {};
118 struct spdk_bdev_part part2 = {};
119 struct spdk_bdev bdev_base = {};
120 SPDK_BDEV_PART_TAILQ tailq = TAILQ_HEAD_INITIALIZER(tailq);
121 int rc;
122
123 bdev_base.name = "base";
124 bdev_base.fn_table = &base_fn_table;
125 bdev_base.module = &bdev_ut_if;
126 rc = spdk_bdev_register(&bdev_base);
127 CU_ASSERT(rc == 0);
128 base = spdk_bdev_part_base_construct(&bdev_base, NULL, &vbdev_ut_if,
129 &part_fn_table, &tailq, NULL,
130 NULL, 0, NULL, NULL);
131
132 SPDK_CU_ASSERT_FATAL(base != NULL);
133
134 rc = spdk_bdev_part_construct(&part1, base, "test1", 0, 100, "test");
135 SPDK_CU_ASSERT_FATAL(rc == 0);
136 rc = spdk_bdev_part_construct(&part2, base, "test2", 100, 100, "test");
137 SPDK_CU_ASSERT_FATAL(rc == 0);
138
9f95a23c 139 spdk_bdev_part_base_hotremove(base, &tailq);
11fdf7f2
TL
140
141 spdk_bdev_part_base_free(base);
142 _part_cleanup(&part1);
143 _part_cleanup(&part2);
144 spdk_bdev_unregister(&bdev_base, NULL, NULL);
9f95a23c
TL
145
146 poll_threads();
11fdf7f2
TL
147}
148
149int
150main(int argc, char **argv)
151{
9f95a23c
TL
152 CU_pSuite suite = NULL;
153 unsigned int num_failures;
11fdf7f2 154
f67539c2
TL
155 CU_set_error_action(CUEA_ABORT);
156 CU_initialize_registry();
11fdf7f2
TL
157
158 suite = CU_add_suite("bdev_part", NULL, NULL);
f67539c2
TL
159
160 CU_ADD_TEST(suite, part_test);
11fdf7f2 161
9f95a23c
TL
162 allocate_threads(1);
163 set_thread(0);
164
11fdf7f2
TL
165 CU_basic_set_mode(CU_BRM_VERBOSE);
166 CU_basic_run_tests();
167 num_failures = CU_get_number_of_failures();
168 CU_cleanup_registry();
9f95a23c
TL
169
170 free_threads();
171
11fdf7f2
TL
172 return num_failures;
173}