]>
Commit | Line | Data |
---|---|---|
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 | ||
11fdf7f2 | 34 | #include "spdk/stdinc.h" |
7c673cae FG |
35 | |
36 | #include "CUnit/Basic.h" | |
37 | ||
9f95a23c | 38 | #include "common/lib/ut_multithread.c" |
7c673cae FG |
39 | |
40 | #include "spdk_cunit.h" | |
11fdf7f2 TL |
41 | #include "blobfs/blobfs.c" |
42 | #include "blobfs/tree.c" | |
9f95a23c TL |
43 | #include "blob/blobstore.h" |
44 | ||
45 | #include "spdk_internal/thread.h" | |
7c673cae | 46 | |
11fdf7f2 | 47 | #include "unit/lib/blob/bs_dev_common.c" |
7c673cae FG |
48 | |
49 | struct spdk_filesystem *g_fs; | |
50 | struct spdk_file *g_file; | |
51 | int g_fserrno; | |
9f95a23c TL |
52 | struct spdk_trace_histories *g_trace_histories; |
53 | DEFINE_STUB_V(spdk_trace_add_register_fn, (struct spdk_trace_register_fn *reg_fn)); | |
54 | DEFINE_STUB_V(spdk_trace_register_description, (const char *name, | |
55 | uint16_t tpoint_id, uint8_t owner_type, | |
56 | uint8_t object_type, uint8_t new_object, | |
57 | uint8_t arg1_is_ptr, const char *arg1_name)); | |
58 | DEFINE_STUB_V(_spdk_trace_record, (uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id, | |
59 | uint32_t size, uint64_t object_id, uint64_t arg1)); | |
7c673cae | 60 | |
11fdf7f2 TL |
61 | /* Return NULL to test hardcoded defaults. */ |
62 | struct spdk_conf_section * | |
63 | spdk_conf_find_section(struct spdk_conf *cp, const char *name) | |
64 | { | |
65 | return NULL; | |
66 | } | |
67 | ||
68 | /* Return -1 to test hardcoded defaults. */ | |
69 | int | |
70 | spdk_conf_section_get_intval(struct spdk_conf_section *sp, const char *key) | |
71 | { | |
72 | return -1; | |
73 | } | |
74 | ||
7c673cae FG |
75 | static void |
76 | fs_op_complete(void *ctx, int fserrno) | |
77 | { | |
78 | g_fserrno = fserrno; | |
79 | } | |
80 | ||
81 | static void | |
82 | fs_op_with_handle_complete(void *ctx, struct spdk_filesystem *fs, int fserrno) | |
83 | { | |
84 | g_fs = fs; | |
85 | g_fserrno = fserrno; | |
86 | } | |
87 | ||
88 | static void | |
89 | fs_init(void) | |
90 | { | |
91 | struct spdk_filesystem *fs; | |
11fdf7f2 | 92 | struct spdk_bs_dev *dev; |
7c673cae | 93 | |
11fdf7f2 | 94 | dev = init_dev(); |
7c673cae | 95 | |
11fdf7f2 | 96 | spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); |
9f95a23c | 97 | poll_threads(); |
11fdf7f2 | 98 | SPDK_CU_ASSERT_FATAL(g_fs != NULL); |
7c673cae FG |
99 | CU_ASSERT(g_fserrno == 0); |
100 | fs = g_fs; | |
9f95a23c | 101 | SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); |
7c673cae | 102 | |
11fdf7f2 | 103 | g_fserrno = 1; |
7c673cae | 104 | spdk_fs_unload(fs, fs_op_complete, NULL); |
9f95a23c | 105 | poll_threads(); |
7c673cae | 106 | CU_ASSERT(g_fserrno == 0); |
7c673cae FG |
107 | } |
108 | ||
109 | static void | |
110 | create_cb(void *ctx, int fserrno) | |
111 | { | |
112 | g_fserrno = fserrno; | |
113 | } | |
114 | ||
115 | static void | |
116 | open_cb(void *ctx, struct spdk_file *f, int fserrno) | |
117 | { | |
118 | g_fserrno = fserrno; | |
119 | g_file = f; | |
120 | } | |
121 | ||
122 | static void | |
123 | delete_cb(void *ctx, int fserrno) | |
124 | { | |
125 | g_fserrno = fserrno; | |
126 | } | |
127 | ||
128 | static void | |
129 | fs_open(void) | |
130 | { | |
131 | struct spdk_filesystem *fs; | |
132 | spdk_fs_iter iter; | |
11fdf7f2 | 133 | struct spdk_bs_dev *dev; |
7c673cae | 134 | struct spdk_file *file; |
11fdf7f2 | 135 | char name[257] = {'\0'}; |
7c673cae | 136 | |
11fdf7f2 TL |
137 | dev = init_dev(); |
138 | memset(name, 'a', sizeof(name) - 1); | |
7c673cae | 139 | |
11fdf7f2 | 140 | spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); |
9f95a23c | 141 | poll_threads(); |
11fdf7f2 | 142 | SPDK_CU_ASSERT_FATAL(g_fs != NULL); |
7c673cae FG |
143 | CU_ASSERT(g_fserrno == 0); |
144 | fs = g_fs; | |
9f95a23c | 145 | SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); |
7c673cae | 146 | |
11fdf7f2 TL |
147 | g_fserrno = 0; |
148 | /* Open should fail, because the file name is too long. */ | |
149 | spdk_fs_open_file_async(fs, name, SPDK_BLOBFS_OPEN_CREATE, open_cb, NULL); | |
9f95a23c | 150 | poll_threads(); |
11fdf7f2 TL |
151 | CU_ASSERT(g_fserrno == -ENAMETOOLONG); |
152 | ||
7c673cae FG |
153 | g_fserrno = 0; |
154 | spdk_fs_open_file_async(fs, "file1", 0, open_cb, NULL); | |
9f95a23c | 155 | poll_threads(); |
7c673cae FG |
156 | CU_ASSERT(g_fserrno == -ENOENT); |
157 | ||
158 | g_file = NULL; | |
159 | g_fserrno = 1; | |
160 | spdk_fs_open_file_async(fs, "file1", SPDK_BLOBFS_OPEN_CREATE, open_cb, NULL); | |
9f95a23c | 161 | poll_threads(); |
7c673cae FG |
162 | CU_ASSERT(g_fserrno == 0); |
163 | SPDK_CU_ASSERT_FATAL(g_file != NULL); | |
164 | CU_ASSERT(!strcmp("file1", g_file->name)); | |
165 | CU_ASSERT(g_file->ref_count == 1); | |
166 | ||
167 | iter = spdk_fs_iter_first(fs); | |
168 | CU_ASSERT(iter != NULL); | |
169 | file = spdk_fs_iter_get_file(iter); | |
170 | SPDK_CU_ASSERT_FATAL(file != NULL); | |
171 | CU_ASSERT(!strcmp("file1", file->name)); | |
172 | iter = spdk_fs_iter_next(iter); | |
173 | CU_ASSERT(iter == NULL); | |
174 | ||
175 | g_fserrno = 0; | |
11fdf7f2 | 176 | /* Delete should successful, we will mark the file as deleted. */ |
7c673cae | 177 | spdk_fs_delete_file_async(fs, "file1", delete_cb, NULL); |
9f95a23c | 178 | poll_threads(); |
11fdf7f2 | 179 | CU_ASSERT(g_fserrno == 0); |
7c673cae FG |
180 | CU_ASSERT(!TAILQ_EMPTY(&fs->files)); |
181 | ||
182 | g_fserrno = 1; | |
183 | spdk_file_close_async(g_file, fs_op_complete, NULL); | |
9f95a23c | 184 | poll_threads(); |
7c673cae | 185 | CU_ASSERT(g_fserrno == 0); |
11fdf7f2 TL |
186 | CU_ASSERT(TAILQ_EMPTY(&fs->files)); |
187 | ||
188 | g_fserrno = 1; | |
189 | spdk_fs_unload(fs, fs_op_complete, NULL); | |
9f95a23c | 190 | poll_threads(); |
11fdf7f2 | 191 | CU_ASSERT(g_fserrno == 0); |
11fdf7f2 TL |
192 | } |
193 | ||
194 | static void | |
195 | fs_create(void) | |
196 | { | |
197 | struct spdk_filesystem *fs; | |
198 | struct spdk_bs_dev *dev; | |
199 | char name[257] = {'\0'}; | |
200 | ||
201 | dev = init_dev(); | |
202 | memset(name, 'a', sizeof(name) - 1); | |
11fdf7f2 TL |
203 | |
204 | spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); | |
9f95a23c | 205 | poll_threads(); |
11fdf7f2 TL |
206 | SPDK_CU_ASSERT_FATAL(g_fs != NULL); |
207 | CU_ASSERT(g_fserrno == 0); | |
208 | fs = g_fs; | |
9f95a23c | 209 | SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); |
7c673cae FG |
210 | |
211 | g_fserrno = 0; | |
11fdf7f2 TL |
212 | /* Create should fail, because the file name is too long. */ |
213 | spdk_fs_create_file_async(fs, name, create_cb, NULL); | |
9f95a23c | 214 | poll_threads(); |
11fdf7f2 TL |
215 | CU_ASSERT(g_fserrno == -ENAMETOOLONG); |
216 | ||
217 | g_fserrno = 1; | |
218 | spdk_fs_create_file_async(fs, "file1", create_cb, NULL); | |
9f95a23c | 219 | poll_threads(); |
11fdf7f2 TL |
220 | CU_ASSERT(g_fserrno == 0); |
221 | ||
222 | g_fserrno = 1; | |
223 | spdk_fs_create_file_async(fs, "file1", create_cb, NULL); | |
9f95a23c | 224 | poll_threads(); |
11fdf7f2 | 225 | CU_ASSERT(g_fserrno == -EEXIST); |
7c673cae FG |
226 | |
227 | g_fserrno = 1; | |
228 | spdk_fs_delete_file_async(fs, "file1", delete_cb, NULL); | |
9f95a23c | 229 | poll_threads(); |
7c673cae FG |
230 | CU_ASSERT(g_fserrno == 0); |
231 | CU_ASSERT(TAILQ_EMPTY(&fs->files)); | |
232 | ||
11fdf7f2 | 233 | g_fserrno = 1; |
7c673cae | 234 | spdk_fs_unload(fs, fs_op_complete, NULL); |
9f95a23c | 235 | poll_threads(); |
7c673cae | 236 | CU_ASSERT(g_fserrno == 0); |
7c673cae FG |
237 | } |
238 | ||
239 | static void | |
240 | fs_truncate(void) | |
241 | { | |
242 | struct spdk_filesystem *fs; | |
11fdf7f2 | 243 | struct spdk_bs_dev *dev; |
7c673cae | 244 | |
11fdf7f2 | 245 | dev = init_dev(); |
7c673cae | 246 | |
11fdf7f2 | 247 | spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); |
9f95a23c | 248 | poll_threads(); |
7c673cae FG |
249 | SPDK_CU_ASSERT_FATAL(g_fs != NULL); |
250 | CU_ASSERT(g_fserrno == 0); | |
251 | fs = g_fs; | |
9f95a23c | 252 | SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); |
7c673cae FG |
253 | |
254 | g_file = NULL; | |
255 | g_fserrno = 1; | |
256 | spdk_fs_open_file_async(fs, "file1", SPDK_BLOBFS_OPEN_CREATE, open_cb, NULL); | |
9f95a23c | 257 | poll_threads(); |
7c673cae FG |
258 | CU_ASSERT(g_fserrno == 0); |
259 | SPDK_CU_ASSERT_FATAL(g_file != NULL); | |
260 | ||
261 | g_fserrno = 1; | |
262 | spdk_file_truncate_async(g_file, 18 * 1024 * 1024 + 1, fs_op_complete, NULL); | |
9f95a23c | 263 | poll_threads(); |
7c673cae FG |
264 | CU_ASSERT(g_fserrno == 0); |
265 | CU_ASSERT(g_file->length == 18 * 1024 * 1024 + 1); | |
266 | ||
267 | g_fserrno = 1; | |
268 | spdk_file_truncate_async(g_file, 1, fs_op_complete, NULL); | |
9f95a23c | 269 | poll_threads(); |
7c673cae FG |
270 | CU_ASSERT(g_fserrno == 0); |
271 | CU_ASSERT(g_file->length == 1); | |
272 | ||
273 | g_fserrno = 1; | |
274 | spdk_file_truncate_async(g_file, 18 * 1024 * 1024 + 1, fs_op_complete, NULL); | |
9f95a23c | 275 | poll_threads(); |
7c673cae FG |
276 | CU_ASSERT(g_fserrno == 0); |
277 | CU_ASSERT(g_file->length == 18 * 1024 * 1024 + 1); | |
278 | ||
279 | g_fserrno = 1; | |
280 | spdk_file_close_async(g_file, fs_op_complete, NULL); | |
9f95a23c | 281 | poll_threads(); |
7c673cae FG |
282 | CU_ASSERT(g_fserrno == 0); |
283 | CU_ASSERT(g_file->ref_count == 0); | |
284 | ||
285 | g_fserrno = 1; | |
286 | spdk_fs_delete_file_async(fs, "file1", delete_cb, NULL); | |
9f95a23c | 287 | poll_threads(); |
7c673cae FG |
288 | CU_ASSERT(g_fserrno == 0); |
289 | CU_ASSERT(TAILQ_EMPTY(&fs->files)); | |
290 | ||
11fdf7f2 | 291 | g_fserrno = 1; |
7c673cae | 292 | spdk_fs_unload(fs, fs_op_complete, NULL); |
9f95a23c | 293 | poll_threads(); |
7c673cae | 294 | CU_ASSERT(g_fserrno == 0); |
7c673cae FG |
295 | } |
296 | ||
297 | static void | |
298 | fs_rename(void) | |
299 | { | |
300 | struct spdk_filesystem *fs; | |
9f95a23c | 301 | struct spdk_file *file, *file2, *file_iter; |
11fdf7f2 | 302 | struct spdk_bs_dev *dev; |
7c673cae | 303 | |
11fdf7f2 | 304 | dev = init_dev(); |
7c673cae | 305 | |
11fdf7f2 | 306 | spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); |
9f95a23c | 307 | poll_threads(); |
7c673cae FG |
308 | SPDK_CU_ASSERT_FATAL(g_fs != NULL); |
309 | CU_ASSERT(g_fserrno == 0); | |
310 | fs = g_fs; | |
9f95a23c | 311 | SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); |
7c673cae FG |
312 | |
313 | g_fserrno = 1; | |
314 | spdk_fs_create_file_async(fs, "file1", create_cb, NULL); | |
9f95a23c | 315 | poll_threads(); |
7c673cae FG |
316 | CU_ASSERT(g_fserrno == 0); |
317 | ||
318 | g_file = NULL; | |
319 | g_fserrno = 1; | |
320 | spdk_fs_open_file_async(fs, "file1", 0, open_cb, NULL); | |
9f95a23c | 321 | poll_threads(); |
7c673cae FG |
322 | CU_ASSERT(g_fserrno == 0); |
323 | SPDK_CU_ASSERT_FATAL(g_file != NULL); | |
324 | CU_ASSERT(g_file->ref_count == 1); | |
325 | ||
326 | file = g_file; | |
327 | g_file = NULL; | |
328 | g_fserrno = 1; | |
329 | spdk_file_close_async(file, fs_op_complete, NULL); | |
9f95a23c | 330 | poll_threads(); |
7c673cae FG |
331 | CU_ASSERT(g_fserrno == 0); |
332 | SPDK_CU_ASSERT_FATAL(file->ref_count == 0); | |
333 | ||
334 | g_file = NULL; | |
335 | g_fserrno = 1; | |
336 | spdk_fs_open_file_async(fs, "file2", SPDK_BLOBFS_OPEN_CREATE, open_cb, NULL); | |
9f95a23c | 337 | poll_threads(); |
7c673cae FG |
338 | CU_ASSERT(g_fserrno == 0); |
339 | SPDK_CU_ASSERT_FATAL(g_file != NULL); | |
340 | CU_ASSERT(g_file->ref_count == 1); | |
341 | ||
342 | file2 = g_file; | |
343 | g_file = NULL; | |
344 | g_fserrno = 1; | |
345 | spdk_file_close_async(file2, fs_op_complete, NULL); | |
9f95a23c | 346 | poll_threads(); |
7c673cae FG |
347 | CU_ASSERT(g_fserrno == 0); |
348 | SPDK_CU_ASSERT_FATAL(file2->ref_count == 0); | |
349 | ||
350 | /* | |
351 | * Do a 3-way rename. This should delete the old "file2", then rename | |
352 | * "file1" to "file2". | |
353 | */ | |
354 | g_fserrno = 1; | |
355 | spdk_fs_rename_file_async(fs, "file1", "file2", fs_op_complete, NULL); | |
9f95a23c | 356 | poll_threads(); |
7c673cae FG |
357 | CU_ASSERT(g_fserrno == 0); |
358 | CU_ASSERT(file->ref_count == 0); | |
359 | CU_ASSERT(!strcmp(file->name, "file2")); | |
360 | CU_ASSERT(TAILQ_FIRST(&fs->files) == file); | |
361 | CU_ASSERT(TAILQ_NEXT(file, tailq) == NULL); | |
362 | ||
363 | g_fserrno = 0; | |
364 | spdk_fs_delete_file_async(fs, "file1", delete_cb, NULL); | |
9f95a23c | 365 | poll_threads(); |
7c673cae FG |
366 | CU_ASSERT(g_fserrno == -ENOENT); |
367 | CU_ASSERT(!TAILQ_EMPTY(&fs->files)); | |
9f95a23c TL |
368 | TAILQ_FOREACH(file_iter, &fs->files, tailq) { |
369 | if (file_iter == NULL) { | |
370 | SPDK_CU_ASSERT_FATAL(false); | |
371 | } | |
372 | } | |
7c673cae FG |
373 | |
374 | g_fserrno = 1; | |
375 | spdk_fs_delete_file_async(fs, "file2", delete_cb, NULL); | |
9f95a23c | 376 | poll_threads(); |
7c673cae FG |
377 | CU_ASSERT(g_fserrno == 0); |
378 | CU_ASSERT(TAILQ_EMPTY(&fs->files)); | |
379 | ||
11fdf7f2 | 380 | g_fserrno = 1; |
7c673cae | 381 | spdk_fs_unload(fs, fs_op_complete, NULL); |
9f95a23c | 382 | poll_threads(); |
7c673cae | 383 | CU_ASSERT(g_fserrno == 0); |
7c673cae FG |
384 | } |
385 | ||
386 | static void | |
387 | tree_find_buffer_ut(void) | |
388 | { | |
389 | struct cache_tree *root; | |
390 | struct cache_tree *level1_0; | |
391 | struct cache_tree *level0_0_0; | |
392 | struct cache_tree *level0_0_12; | |
393 | struct cache_buffer *leaf_0_0_4; | |
394 | struct cache_buffer *leaf_0_12_8; | |
395 | struct cache_buffer *leaf_9_23_15; | |
396 | struct cache_buffer *buffer; | |
397 | ||
398 | level1_0 = calloc(1, sizeof(struct cache_tree)); | |
399 | SPDK_CU_ASSERT_FATAL(level1_0 != NULL); | |
400 | level0_0_0 = calloc(1, sizeof(struct cache_tree)); | |
401 | SPDK_CU_ASSERT_FATAL(level0_0_0 != NULL); | |
402 | level0_0_12 = calloc(1, sizeof(struct cache_tree)); | |
403 | SPDK_CU_ASSERT_FATAL(level0_0_12 != NULL); | |
404 | leaf_0_0_4 = calloc(1, sizeof(struct cache_buffer)); | |
405 | SPDK_CU_ASSERT_FATAL(leaf_0_0_4 != NULL); | |
406 | leaf_0_12_8 = calloc(1, sizeof(struct cache_buffer)); | |
407 | SPDK_CU_ASSERT_FATAL(leaf_0_12_8 != NULL); | |
408 | leaf_9_23_15 = calloc(1, sizeof(struct cache_buffer)); | |
409 | SPDK_CU_ASSERT_FATAL(leaf_9_23_15 != NULL); | |
410 | ||
411 | level1_0->level = 1; | |
412 | level0_0_0->level = 0; | |
413 | level0_0_12->level = 0; | |
414 | ||
415 | leaf_0_0_4->offset = CACHE_BUFFER_SIZE * 4; | |
416 | level0_0_0->u.buffer[4] = leaf_0_0_4; | |
417 | level0_0_0->present_mask |= (1ULL << 4); | |
418 | ||
419 | leaf_0_12_8->offset = CACHE_TREE_LEVEL_SIZE(1) * 12 + CACHE_BUFFER_SIZE * 8; | |
420 | level0_0_12->u.buffer[8] = leaf_0_12_8; | |
421 | level0_0_12->present_mask |= (1ULL << 8); | |
422 | ||
423 | level1_0->u.tree[0] = level0_0_0; | |
424 | level1_0->present_mask |= (1ULL << 0); | |
425 | level1_0->u.tree[12] = level0_0_12; | |
426 | level1_0->present_mask |= (1ULL << 12); | |
427 | ||
428 | buffer = spdk_tree_find_buffer(NULL, 0); | |
429 | CU_ASSERT(buffer == NULL); | |
430 | ||
431 | buffer = spdk_tree_find_buffer(level0_0_0, 0); | |
432 | CU_ASSERT(buffer == NULL); | |
433 | ||
434 | buffer = spdk_tree_find_buffer(level0_0_0, CACHE_TREE_LEVEL_SIZE(0) + 1); | |
435 | CU_ASSERT(buffer == NULL); | |
436 | ||
437 | buffer = spdk_tree_find_buffer(level0_0_0, leaf_0_0_4->offset); | |
438 | CU_ASSERT(buffer == leaf_0_0_4); | |
439 | ||
440 | buffer = spdk_tree_find_buffer(level1_0, leaf_0_0_4->offset); | |
441 | CU_ASSERT(buffer == leaf_0_0_4); | |
442 | ||
443 | buffer = spdk_tree_find_buffer(level1_0, leaf_0_12_8->offset); | |
444 | CU_ASSERT(buffer == leaf_0_12_8); | |
445 | ||
446 | buffer = spdk_tree_find_buffer(level1_0, leaf_0_12_8->offset + CACHE_BUFFER_SIZE - 1); | |
447 | CU_ASSERT(buffer == leaf_0_12_8); | |
448 | ||
449 | buffer = spdk_tree_find_buffer(level1_0, leaf_0_12_8->offset - 1); | |
450 | CU_ASSERT(buffer == NULL); | |
451 | ||
452 | leaf_9_23_15->offset = CACHE_TREE_LEVEL_SIZE(2) * 9 + | |
453 | CACHE_TREE_LEVEL_SIZE(1) * 23 + | |
454 | CACHE_BUFFER_SIZE * 15; | |
455 | root = spdk_tree_insert_buffer(level1_0, leaf_9_23_15); | |
456 | CU_ASSERT(root != level1_0); | |
457 | buffer = spdk_tree_find_buffer(root, leaf_9_23_15->offset); | |
458 | CU_ASSERT(buffer == leaf_9_23_15); | |
459 | spdk_tree_free_buffers(root); | |
460 | free(root); | |
461 | } | |
462 | ||
11fdf7f2 TL |
463 | static void |
464 | channel_ops(void) | |
465 | { | |
466 | struct spdk_filesystem *fs; | |
467 | struct spdk_bs_dev *dev; | |
468 | struct spdk_io_channel *channel; | |
469 | ||
470 | dev = init_dev(); | |
11fdf7f2 TL |
471 | |
472 | spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); | |
9f95a23c | 473 | poll_threads(); |
11fdf7f2 TL |
474 | SPDK_CU_ASSERT_FATAL(g_fs != NULL); |
475 | CU_ASSERT(g_fserrno == 0); | |
476 | fs = g_fs; | |
9f95a23c | 477 | SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); |
11fdf7f2 TL |
478 | |
479 | channel = spdk_fs_alloc_io_channel(fs); | |
480 | CU_ASSERT(channel != NULL); | |
481 | ||
482 | spdk_fs_free_io_channel(channel); | |
483 | ||
484 | g_fserrno = 1; | |
485 | spdk_fs_unload(fs, fs_op_complete, NULL); | |
9f95a23c | 486 | poll_threads(); |
11fdf7f2 TL |
487 | CU_ASSERT(g_fserrno == 0); |
488 | g_fs = NULL; | |
11fdf7f2 TL |
489 | } |
490 | ||
491 | static void | |
492 | channel_ops_sync(void) | |
493 | { | |
494 | struct spdk_filesystem *fs; | |
495 | struct spdk_bs_dev *dev; | |
9f95a23c | 496 | struct spdk_fs_thread_ctx *channel; |
11fdf7f2 TL |
497 | |
498 | dev = init_dev(); | |
11fdf7f2 TL |
499 | |
500 | spdk_fs_init(dev, NULL, NULL, fs_op_with_handle_complete, NULL); | |
9f95a23c | 501 | poll_threads(); |
11fdf7f2 TL |
502 | SPDK_CU_ASSERT_FATAL(g_fs != NULL); |
503 | CU_ASSERT(g_fserrno == 0); | |
504 | fs = g_fs; | |
9f95a23c | 505 | SPDK_CU_ASSERT_FATAL(fs->bs->dev == dev); |
11fdf7f2 | 506 | |
9f95a23c | 507 | channel = spdk_fs_alloc_thread_ctx(fs); |
11fdf7f2 TL |
508 | CU_ASSERT(channel != NULL); |
509 | ||
9f95a23c | 510 | spdk_fs_free_thread_ctx(channel); |
11fdf7f2 TL |
511 | |
512 | g_fserrno = 1; | |
513 | spdk_fs_unload(fs, fs_op_complete, NULL); | |
9f95a23c | 514 | poll_threads(); |
11fdf7f2 TL |
515 | CU_ASSERT(g_fserrno == 0); |
516 | g_fs = NULL; | |
11fdf7f2 TL |
517 | } |
518 | ||
7c673cae FG |
519 | int main(int argc, char **argv) |
520 | { | |
521 | CU_pSuite suite = NULL; | |
522 | unsigned int num_failures; | |
523 | ||
524 | if (CU_initialize_registry() != CUE_SUCCESS) { | |
525 | return CU_get_error(); | |
526 | } | |
527 | ||
11fdf7f2 | 528 | suite = CU_add_suite("blobfs_async_ut", NULL, NULL); |
7c673cae FG |
529 | if (suite == NULL) { |
530 | CU_cleanup_registry(); | |
531 | return CU_get_error(); | |
532 | } | |
533 | ||
534 | if ( | |
535 | CU_add_test(suite, "fs_init", fs_init) == NULL || | |
536 | CU_add_test(suite, "fs_open", fs_open) == NULL || | |
11fdf7f2 | 537 | CU_add_test(suite, "fs_create", fs_create) == NULL || |
7c673cae FG |
538 | CU_add_test(suite, "fs_truncate", fs_truncate) == NULL || |
539 | CU_add_test(suite, "fs_rename", fs_rename) == NULL || | |
11fdf7f2 TL |
540 | CU_add_test(suite, "tree_find_buffer", tree_find_buffer_ut) == NULL || |
541 | CU_add_test(suite, "channel_ops", channel_ops) == NULL || | |
542 | CU_add_test(suite, "channel_ops_sync", channel_ops_sync) == NULL | |
7c673cae FG |
543 | ) { |
544 | CU_cleanup_registry(); | |
545 | return CU_get_error(); | |
546 | } | |
547 | ||
9f95a23c TL |
548 | allocate_threads(1); |
549 | set_thread(0); | |
550 | ||
7c673cae FG |
551 | g_dev_buffer = calloc(1, DEV_BUFFER_SIZE); |
552 | CU_basic_set_mode(CU_BRM_VERBOSE); | |
553 | CU_basic_run_tests(); | |
554 | num_failures = CU_get_number_of_failures(); | |
555 | CU_cleanup_registry(); | |
556 | free(g_dev_buffer); | |
9f95a23c TL |
557 | |
558 | free_threads(); | |
559 | ||
7c673cae FG |
560 | return num_failures; |
561 | } |