1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "libfs_dm_snapshot_test.h"
16 #include <gtest/gtest.h>
17 #include "func_wrapper.h"
18 #include "fs_dm_mock.h"
19 #include <sys/stat.h>
20 #include <sys/mount.h>
21 #include <sys/ioctl.h>
22 #include "init_utils.h"
23 #include "securec.h"
24 using namespace testing;
25 using namespace testing::ext;
26 #define STRSIZE 64
27 #define TESTIODATA "10 10 10"
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C"
31 {
32 #endif
33 #endif
34
35 #ifdef __cplusplus
36 #if __cplusplus
37 }
38 #endif
39 #endif
40 const static int FD_ID = 100000;
41 namespace OHOS {
42 class LibFsDmSnapshotTest : public testing::Test {
43 public:
44 static void SetUpTestCase();
45 static void TearDownTestCase();
46 void SetUp();
47 void TearDown();
48 };
49
SetUpTestCase()50 void LibFsDmSnapshotTest::SetUpTestCase()
51 {
52 GTEST_LOG_(INFO) << "LibFsDmSnapshotTest SetUpTestCase";
53 }
54
TearDownTestCase()55 void LibFsDmSnapshotTest::TearDownTestCase()
56 {
57 GTEST_LOG_(INFO) << "LibFsDmSnapshotTest TearDownTestCase";
58 }
59
SetUp()60 void LibFsDmSnapshotTest::SetUp()
61 {
62 GTEST_LOG_(INFO) << "LibFsDmSnapshotTest SetUp";
63 }
64
TearDown()65 void LibFsDmSnapshotTest::TearDown()
66 {
67 GTEST_LOG_(INFO) << "LibFsDmSnapshotTest TearDown";
68 }
69
70 HWTEST_F(LibFsDmSnapshotTest, FsDmCreateSnapshotDevice_001, TestSize.Level0)
71 {
72 int ret = FsDmCreateSnapshotDevice(nullptr, nullptr, 0, nullptr);
73 EXPECT_EQ(ret, -1);
74 }
75
76 HWTEST_F(LibFsDmSnapshotTest, FsDmCreateSnapshotDevice_002, TestSize.Level0)
77 {
__anond4677cdc0102(const char *path, int flags) 78 OpenFunc func = [](const char *path, int flags) -> int {
79 return -1;
80 };
81 UpdateOpenFunc(func);
82 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(DmSnapshotTarget));
83 char devpath[PATH_MAX] = "devpath";
84 int ret = FsDmCreateSnapshotDevice("devName", devpath, strlen(devpath), target);
85 UpdateOpenFunc(nullptr);
86
87 free(target);
88 EXPECT_EQ(ret, -1);
89 }
90
91 HWTEST_F(LibFsDmSnapshotTest, FsDmCreateSnapshotDevice_003, TestSize.Level0)
92 {
__anond4677cdc0202(const char *path, int flags) 93 OpenFunc func = [](const char *path, int flags) -> int {
94 return 1;
95 };
__anond4677cdc0302(int, const char *) 96 CreatedmdevFunc dmFunc = [](int, const char *) {
97 return -1;
98 };
__anond4677cdc0402(int) 99 CloseFunc closeFunc = [](int) -> int {
100 return 0;
101 };
102 UpdateCloseFunc(closeFunc);
103 UpdateOpenFunc(func);
104 UpdateCreatedmdevFunc(dmFunc);
105 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(DmSnapshotTarget));
106 char devpath[PATH_MAX] = "devpath";
107 int ret = FsDmCreateSnapshotDevice("devName", devpath, strlen(devpath), target);
108 UpdateOpenFunc(nullptr);
109 UpdateCreatedmdevFunc(nullptr);
110 UpdateCloseFunc(nullptr);
111 free(target);
112 EXPECT_EQ(ret, -1);
113 }
114
115 HWTEST_F(LibFsDmSnapshotTest, FsDmCreateSnapshotDevice_004, TestSize.Level0)
116 {
__anond4677cdc0502(const char *path, int flags) 117 OpenFunc func = [](const char *path, int flags) -> int {
118 return 1;
119 };
__anond4677cdc0602(int, const char *) 120 CreatedmdevFunc dmFunc = [](int, const char *) {
121 return 0;
122 };
__anond4677cdc0702(int, const char *, DmVerityTarget *, int) 123 LoaddmdevicetableFunc loadFunc = [](int, const char *, DmVerityTarget *, int) -> int {
124 return -1;
125 };
__anond4677cdc0802(int) 126 CloseFunc closeFunc = [](int) -> int {
127 return 0;
128 };
129 UpdateCloseFunc(closeFunc);
130 UpdateOpenFunc(func);
131 UpdateCreatedmdevFunc(dmFunc);
132 UpdateLoaddmdevicetableFunc(loadFunc);
133 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(DmSnapshotTarget));
134 char devpath[PATH_MAX] = "devpath";
135 int ret = FsDmCreateSnapshotDevice("devName", devpath, strlen(devpath), target);
136 UpdateOpenFunc(nullptr);
137 UpdateCreatedmdevFunc(nullptr);
138 UpdateLoaddmdevicetableFunc(nullptr);
139 UpdateCloseFunc(nullptr);
140
141 free(target);
142 EXPECT_EQ(ret, -1);
143 }
144
145 HWTEST_F(LibFsDmSnapshotTest, FsDmCreateSnapshotDevice_005, TestSize.Level0)
146 {
__anond4677cdc0902(const char *path, int flags) 147 OpenFunc func = [](const char *path, int flags) -> int {
148 return 1;
149 };
__anond4677cdc0a02(int, const char *) 150 CreatedmdevFunc dmFunc = [](int, const char *) -> int {
151 return 0;
152 };
__anond4677cdc0b02(int, const char *, DmVerityTarget *, int) 153 LoaddmdevicetableFunc loadFunc = [](int, const char *, DmVerityTarget *, int) -> int {
154 return 0;
155 };
__anond4677cdc0c02(int, const char *) 156 ActivedmdeviceFunc activeDmDeviceFunc = [](int, const char *) -> int {
157 return -1;
158 };
__anond4677cdc0d02(int) 159 CloseFunc closeFunc = [](int) -> int {
160 return 0;
161 };
162 UpdateOpenFunc(func);
163 UpdateCreatedmdevFunc(dmFunc);
164 UpdateActivedmdeviceFunc(activeDmDeviceFunc);
165 UpdateLoaddmdevicetableFunc(loadFunc);
166 UpdateCloseFunc(closeFunc);
167
168 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(DmSnapshotTarget));
169 char devpath[PATH_MAX] = "devpath";
170 int ret = FsDmCreateSnapshotDevice("devName", devpath, strlen(devpath), target);
171 UpdateOpenFunc(nullptr);
172 UpdateCreatedmdevFunc(nullptr);
173 UpdateActivedmdeviceFunc(nullptr);
174 UpdateLoaddmdevicetableFunc(nullptr);
175 UpdateCloseFunc(nullptr);
176
177 free(target);
178 EXPECT_EQ(ret, -1);
179 }
180
181 HWTEST_F(LibFsDmSnapshotTest, FsDmCreateSnapshotDevice_006, TestSize.Level0)
182 {
__anond4677cdc0e02(const char *path, int flags) 183 OpenFunc func = [](const char *path, int flags) -> int {
184 return 1;
185 };
__anond4677cdc0f02(int, const char *) 186 CreatedmdevFunc dmFunc = [](int, const char *) -> int {
187 return 0;
188 };
__anond4677cdc1002(int, const char *, DmVerityTarget *, int) 189 LoaddmdevicetableFunc loadFunc = [](int, const char *, DmVerityTarget *, int) -> int {
190 return 0;
191 };
__anond4677cdc1102(int, const char *) 192 ActivedmdeviceFunc activeDmDeviceFunc = [](int, const char *) -> int {
193 return 0;
194 };
__anond4677cdc1202(int, const char *, char *, const uint64_t) 195 DmgetdevicenameFunc deviceNameFunc = [](int, const char *, char *, const uint64_t) -> int {
196 return -1;
197 };
__anond4677cdc1302(int) 198 CloseFunc closeFunc = [](int) -> int {
199 return 0;
200 };
201 UpdateOpenFunc(func);
202 UpdateCreatedmdevFunc(dmFunc);
203 UpdateActivedmdeviceFunc(activeDmDeviceFunc);
204 UpdateDmgetdevicenameFunc(deviceNameFunc);
205 UpdateLoaddmdevicetableFunc(loadFunc);
206 UpdateCloseFunc(closeFunc);
207
208 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(DmSnapshotTarget));
209 char devpath[PATH_MAX] = "devpath";
210 int ret = FsDmCreateSnapshotDevice("devName", devpath, strlen(devpath), target);
211 UpdateOpenFunc(nullptr);
212 UpdateCreatedmdevFunc(nullptr);
213 UpdateActivedmdeviceFunc(nullptr);
214 UpdateDmgetdevicenameFunc(nullptr);
215 UpdateLoaddmdevicetableFunc(nullptr);
216 UpdateCloseFunc(nullptr);
217 free(target);
218 EXPECT_EQ(ret, -1);
219 }
220
221 HWTEST_F(LibFsDmSnapshotTest, FsDmCreateSnapshotDevice_007, TestSize.Level0)
222 {
__anond4677cdc1402(const char *path, int flags) 223 OpenFunc func = [](const char *path, int flags) -> int {
224 return 1;
225 };
__anond4677cdc1502(int, const char *) 226 CreatedmdevFunc dmFunc = [](int, const char *) -> int {
227 return 0;
228 };
229
__anond4677cdc1602(int, const char *, DmVerityTarget *, int) 230 LoaddmdevicetableFunc loadFunc = [](int, const char *, DmVerityTarget *, int) -> int {
231 return 0;
232 };
__anond4677cdc1702(int, const char *) 233 ActivedmdeviceFunc activeDmDeviceFunc = [](int, const char *) -> int {
234 return 0;
235 };
__anond4677cdc1802(int, const char *, char *, const uint64_t) 236 DmgetdevicenameFunc deviceNameFunc = [](int, const char *, char *, const uint64_t) -> int {
237 return 0;
238 };
__anond4677cdc1902(int) 239 CloseFunc closeFunc = [](int) -> int {
240 return 0;
241 };
242 UpdateOpenFunc(func);
243 UpdateCreatedmdevFunc(dmFunc);
244 UpdateActivedmdeviceFunc(activeDmDeviceFunc);
245 UpdateDmgetdevicenameFunc(deviceNameFunc);
246 UpdateLoaddmdevicetableFunc(loadFunc);
247 UpdateCloseFunc(closeFunc);
248
249 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(DmSnapshotTarget));
250 char devpath[PATH_MAX] = "devpath";
251 int ret = FsDmCreateSnapshotDevice("devName", devpath, strlen(devpath), target);
252 UpdateOpenFunc(nullptr);
253 UpdateCreatedmdevFunc(nullptr);
254 UpdateActivedmdeviceFunc(nullptr);
255 UpdateDmgetdevicenameFunc(nullptr);
256 UpdateLoaddmdevicetableFunc(nullptr);
257 UpdateCloseFunc(nullptr);
258
259 free(target);
260 EXPECT_EQ(ret, 0);
261 }
262
263 HWTEST_F(LibFsDmSnapshotTest, FsDmSwitchToSnapshotMerge_001, TestSize.Level0)
264 {
265 int ret = FsDmSwitchToSnapshotMerge(nullptr, nullptr);
266 EXPECT_EQ(ret, -1);
267 }
268
269 HWTEST_F(LibFsDmSnapshotTest, FsDmSwitchToSnapshotMerge_002, TestSize.Level0)
270 {
__anond4677cdc1a02(const char*, int) 271 OpenFunc openFunc = [](const char*, int) -> int {
272 return -1;
273 };
274 UpdateOpenFunc(openFunc);
275 char devName[PATH_MAX] = "devName";
276 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(target));
277 int ret = FsDmSwitchToSnapshotMerge(devName, target);
278 free(target);
279 UpdateOpenFunc(nullptr);
280 EXPECT_EQ(ret, -1);
281 }
282
283 HWTEST_F(LibFsDmSnapshotTest, FsDmSwitchToSnapshotMerge_003, TestSize.Level0)
284 {
__anond4677cdc1b02(const char*, int) 285 OpenFunc openFunc = [](const char*, int) -> int {
286 return 0;
287 };
288 UpdateOpenFunc(openFunc);
__anond4677cdc1c02(int, const char*, DmSnapshotTarget *, int) 289 LoaddmdevicetableFunc loadFunc = [](int, const char*, DmSnapshotTarget *, int) -> int {
290 return -1;
291 };
292 UpdateLoaddmdevicetableFunc(loadFunc);
__anond4677cdc1d02(int) 293 CloseFunc closeFunc = [](int) -> int {
294 return 0;
295 };
296 UpdateCloseFunc(closeFunc);
297
298 char devName[PATH_MAX] = "devName";
299 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(target));
300 int ret = FsDmSwitchToSnapshotMerge(devName, target);
301 free(target);
302
303 UpdateOpenFunc(nullptr);
304 UpdateLoaddmdevicetableFunc(nullptr);
305 UpdateCloseFunc(nullptr);
306
307 EXPECT_EQ(ret, -1);
308 }
309
310
311 HWTEST_F(LibFsDmSnapshotTest, FsDmSwitchToSnapshotMerge_004, TestSize.Level0)
312 {
__anond4677cdc1e02(const char*, int) 313 OpenFunc openFunc = [](const char*, int) -> int {
314 return 0;
315 };
316 UpdateOpenFunc(openFunc);
__anond4677cdc1f02(int, const char*, DmSnapshotTarget *, int) 317 LoaddmdevicetableFunc loadFunc = [](int, const char*, DmSnapshotTarget *, int) -> int {
318 return 0;
319 };
320 UpdateLoaddmdevicetableFunc(loadFunc);
__anond4677cdc2002(int) 321 CloseFunc closeFunc = [](int) -> int {
322 return 0;
323 };
324 UpdateCloseFunc(closeFunc);
__anond4677cdc2102(int, const char *) 325 ActivedmdeviceFunc activeDmDeviceFunc = [](int, const char *) -> int {
326 return -1;
327 };
328 UpdateActivedmdeviceFunc(activeDmDeviceFunc);
329 char devName[PATH_MAX] = "devName";
330 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(target));
331 int ret = FsDmSwitchToSnapshotMerge(devName, target);
332 free(target);
333
334 UpdateOpenFunc(nullptr);
335 UpdateLoaddmdevicetableFunc(nullptr);
336 UpdateCloseFunc(nullptr);
337 UpdateActivedmdeviceFunc(nullptr);
338
339 EXPECT_EQ(ret, -1);
340 }
341
342 HWTEST_F(LibFsDmSnapshotTest, FsDmSwitchToSnapshotMerge_005, TestSize.Level0)
343 {
__anond4677cdc2202(const char*, int) 344 OpenFunc openFunc = [](const char*, int) -> int {
345 return 0;
346 };
347 UpdateOpenFunc(openFunc);
__anond4677cdc2302(int, const char*, DmSnapshotTarget *, int) 348 LoaddmdevicetableFunc loadFunc = [](int, const char*, DmSnapshotTarget *, int) -> int {
349 return 0;
350 };
351 UpdateLoaddmdevicetableFunc(loadFunc);
__anond4677cdc2402(int) 352 CloseFunc closeFunc = [](int) -> int {
353 return 0;
354 };
355 UpdateCloseFunc(closeFunc);
__anond4677cdc2502(int, const char *) 356 ActivedmdeviceFunc activeDmDeviceFunc = [](int, const char *) -> int {
357 return 0;
358 };
359 UpdateActivedmdeviceFunc(activeDmDeviceFunc);
360 char devName[PATH_MAX] = "devName";
361 DmSnapshotTarget *target = (DmSnapshotTarget *)malloc(sizeof(target));
362 int ret = FsDmSwitchToSnapshotMerge(devName, target);
363 free(target);
364
365 UpdateOpenFunc(nullptr);
366 UpdateLoaddmdevicetableFunc(nullptr);
367 UpdateCloseFunc(nullptr);
368 UpdateActivedmdeviceFunc(nullptr);
369
370 EXPECT_EQ(ret, 0);
371 }
372
373 HWTEST_F(LibFsDmSnapshotTest, ParseStatusText_001, TestSize.Level0)
374 {
375 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
376 char data[PATH_MAX] = "10 10 10";
377 bool ret = ParseStatusText(data, info);
378 EXPECT_EQ(ret, true);
379 }
380
381 HWTEST_F(LibFsDmSnapshotTest, ParseStatusText_002, TestSize.Level0)
382 {
383 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
384 char data[PATH_MAX] = "10 1011asasdfdasfasdfasdfasdfas";
385 bool ret = ParseStatusText(data, info);
386 EXPECT_EQ(ret, false);
387 }
388
389 HWTEST_F(LibFsDmSnapshotTest, ParseStatusText_003, TestSize.Level0)
390 {
__anond4677cdc2602(char *, size_t, const char *) 391 StrcpySFunc strcpyFunc = [](char *, size_t, const char *) -> int {
392 return -1;
393 };
394 UpdateStrcpySFunc(strcpyFunc);
395 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
396 char data[PATH_MAX] = "10 10";
397 bool ret = ParseStatusText(data, info);
398 UpdateStrcpySFunc(nullptr);
399 EXPECT_EQ(ret, false);
400 }
401
402 HWTEST_F(LibFsDmSnapshotTest, ParseStatusText_004, TestSize.Level0)
403 {
404 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
405
406 char data[PATH_MAX] = "Invalid";
407 bool ret = ParseStatusText(data, info);
408 EXPECT_EQ(ret, true);
409 }
410
411 HWTEST_F(LibFsDmSnapshotTest, ParseStatusText_005, TestSize.Level0)
412 {
413 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
414
415 char data[PATH_MAX] = "otherError";
416 bool ret = ParseStatusText(data, info);
417 EXPECT_EQ(ret, false);
418 }
419
420 HWTEST_F(LibFsDmSnapshotTest, GetDmSnapshotStatus_001, TestSize.Level0)
421 {
422 int ret = GetDmSnapshotStatus(nullptr, nullptr, nullptr);
423 EXPECT_EQ(ret, false);
424 }
425
426 HWTEST_F(LibFsDmSnapshotTest, GetDmSnapshotStatus_002, TestSize.Level0)
427 {
__anond4677cdc2702(const char*, int) 428 OpenFunc openFunc = [](const char*, int) -> int {
429 return FD_ID;
430 };
431 UpdateOpenFunc(openFunc);
__anond4677cdc2802(struct dm_ioctl *, const char*) 432 InitdmioFunc initdmioFunc = [](struct dm_ioctl *, const char*) -> int {
433 return -1;
434 };
435 UpdateInitdmioFunc(initdmioFunc);
436 char name[PATH_MAX] = "name";
437 char targetType[PATH_MAX] = "targetType";
438 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
439 int ret = GetDmSnapshotStatus(name, targetType, info);
440 UpdateOpenFunc(nullptr);
441 UpdateInitdmioFunc(nullptr);
442
443 EXPECT_EQ(ret, false);
444 }
445
446 HWTEST_F(LibFsDmSnapshotTest, GetDmSnapshotStatus_003, TestSize.Level0)
447 {
__anond4677cdc2902(const char*, int) 448 OpenFunc openFunc = [](const char*, int) -> int {
449 return FD_ID;
450 };
451 UpdateOpenFunc(openFunc);
__anond4677cdc2a02(struct dm_ioctl *, const char*) 452 InitdmioFunc initdmioFunc = [](struct dm_ioctl *, const char*) -> int {
453 return 0;
454 };
455 UpdateInitdmioFunc(initdmioFunc);
456
__anond4677cdc2b02(int, int, va_list args) 457 IoctlFunc ioctlFunc = [](int, int, va_list args) -> int {
458 return -1;
459 };
460 UpdateIoctlFunc(ioctlFunc);
461
462 char name[PATH_MAX] = "name";
463 char targetType[PATH_MAX] = "targetType";
464 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
465 int ret = GetDmSnapshotStatus(name, targetType, info);
466 UpdateOpenFunc(nullptr);
467 UpdateInitdmioFunc(nullptr);
468 UpdateIoctlFunc(nullptr);
469
470 EXPECT_EQ(ret, false);
471 }
472
473 HWTEST_F(LibFsDmSnapshotTest, GetDmSnapshotStatus_004, TestSize.Level0)
474 {
__anond4677cdc2c02(const char*, int) 475 OpenFunc openFunc = [](const char*, int) -> int {
476 return FD_ID;
477 };
478 UpdateOpenFunc(openFunc);
__anond4677cdc2d02(struct dm_ioctl *, const char*) 479 InitdmioFunc initdmioFunc = [](struct dm_ioctl *, const char*) -> int {
480 return 0;
481 };
482 UpdateInitdmioFunc(initdmioFunc);
483
__anond4677cdc2e02(int fd, int req, va_list args) 484 IoctlFunc ioctlFunc = [](int fd, int req, va_list args) -> int {
485 struct dm_ioctl *io = va_arg(args, struct dm_ioctl *);
486 io->flags = DM_BUFFER_FULL_FLAG;
487 return 0;
488 };
489 UpdateIoctlFunc(ioctlFunc);
490 char name[PATH_MAX] = "name";
491 char targetType[PATH_MAX] = "targetType";
492 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
493 int ret = GetDmSnapshotStatus(name, targetType, info);
494 UpdateOpenFunc(nullptr);
495 UpdateInitdmioFunc(nullptr);
496 UpdateIoctlFunc(nullptr);
497
498 EXPECT_EQ(ret, false);
499 }
500
501 HWTEST_F(LibFsDmSnapshotTest, GetDmSnapshotStatus_005, TestSize.Level0)
502 {
__anond4677cdc2f02(const char*, int) 503 OpenFunc openFunc = [](const char*, int) -> int {
504 return FD_ID;
505 };
506 UpdateOpenFunc(openFunc);
__anond4677cdc3002(struct dm_ioctl *, const char*) 507 InitdmioFunc initdmioFunc = [](struct dm_ioctl *, const char*) -> int {
508 return 0;
509 };
510 UpdateInitdmioFunc(initdmioFunc);
511
__anond4677cdc3102(int fd, int req, va_list args) 512 IoctlFunc ioctlFunc = [](int fd, int req, va_list args) -> int {
513 struct dm_ioctl *io = va_arg(args, struct dm_ioctl *);
514 io->data_start = sizeof(struct dm_ioctl *);
515 io->data_size =sizeof (struct dm_ioctl *) + sizeof(struct dm_target_spec) - 1;
516 return 0;
517 };
518 UpdateIoctlFunc(ioctlFunc);
519 char name[PATH_MAX] = "name";
520 char targetType[PATH_MAX] = "targetType";
521 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
522 int ret = GetDmSnapshotStatus(name, targetType, info);
523 UpdateOpenFunc(nullptr);
524 UpdateInitdmioFunc(nullptr);
525 UpdateIoctlFunc(nullptr);
526
527 EXPECT_EQ(ret, false);
528 }
529
530 HWTEST_F(LibFsDmSnapshotTest, GetDmSnapshotStatus_006, TestSize.Level0)
531 {
__anond4677cdc3202(const char*, int) 532 OpenFunc openFunc = [](const char*, int) -> int {
533 return FD_ID;
534 };
535 UpdateOpenFunc(openFunc);
__anond4677cdc3302(struct dm_ioctl *, const char*) 536 InitdmioFunc initdmioFunc = [](struct dm_ioctl *, const char*) -> int {
537 return 0;
538 };
539 UpdateInitdmioFunc(initdmioFunc);
540
__anond4677cdc3402(int fd, int req, va_list args) 541 IoctlFunc ioctlFunc = [](int fd, int req, va_list args) -> int {
542 struct dm_ioctl *io = va_arg(args, struct dm_ioctl *);
543 io->data_start = sizeof(struct dm_ioctl *);
544 io->data_size = sizeof(struct dm_ioctl *) + sizeof(struct dm_target_spec);
545 struct dm_target_spec* spec = (struct dm_target_spec*)(&((char*)io)[sizeof(struct dm_ioctl *)]);
546 spec->next = sizeof(struct dm_target_spec);
547 return 0;
548 };
549 UpdateIoctlFunc(ioctlFunc);
550 char name[PATH_MAX] = "name";
551 char targetType[PATH_MAX] = "targetType";
552 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
553 int ret = GetDmSnapshotStatus(name, targetType, info);
554 UpdateOpenFunc(nullptr);
555 UpdateInitdmioFunc(nullptr);
556 UpdateIoctlFunc(nullptr);
557
558 EXPECT_EQ(ret, false);
559 }
560
561 HWTEST_F(LibFsDmSnapshotTest, GetDmSnapshotStatus_007, TestSize.Level0)
562 {
__anond4677cdc3502(const char*, int) 563 OpenFunc openFunc = [](const char*, int) -> int {
564 return FD_ID;
565 };
566 UpdateOpenFunc(openFunc);
__anond4677cdc3602(struct dm_ioctl *, const char*) 567 InitdmioFunc initdmioFunc = [](struct dm_ioctl *, const char*) -> int {
568 return 0;
569 };
570 UpdateInitdmioFunc(initdmioFunc);
571
__anond4677cdc3702(int fd, int req, va_list args) 572 IoctlFunc ioctlFunc = [](int fd, int req, va_list args) -> int {
573 struct dm_ioctl *io = va_arg(args, struct dm_ioctl *);
574 io->data_start = sizeof(struct dm_ioctl *);
575 io->data_size = sizeof(struct dm_ioctl *) + sizeof(struct dm_target_spec);
576 struct dm_target_spec* spec = (struct dm_target_spec*)(&((char*)io)[sizeof(struct dm_ioctl *)]);
577 spec->next = sizeof(struct dm_target_spec) + 1;
578 return 0;
579 };
580 UpdateIoctlFunc(ioctlFunc);
581 char name[PATH_MAX] = "name";
582 char targetType[PATH_MAX] = "targetType";
583 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
584 int ret = GetDmSnapshotStatus(name, targetType, info);
585 UpdateOpenFunc(nullptr);
586 UpdateInitdmioFunc(nullptr);
587 UpdateIoctlFunc(nullptr);
588
589 EXPECT_EQ(ret, false);
590 }
591
592 HWTEST_F(LibFsDmSnapshotTest, GetDmSnapshotStatus_008, TestSize.Level0)
593 {
__anond4677cdc3802(const char*, int) 594 OpenFunc openFunc = [](const char*, int) -> int {
595 return FD_ID;
596 };
597 UpdateOpenFunc(openFunc);
__anond4677cdc3902(struct dm_ioctl *, const char*) 598 InitdmioFunc initdmioFunc = [](struct dm_ioctl *, const char*) -> int {
599 return 0;
600 };
601 UpdateInitdmioFunc(initdmioFunc);
602
__anond4677cdc3a02(int fd, int req, va_list args) 603 IoctlFunc ioctlFunc = [](int fd, int req, va_list args) -> int {
604 struct dm_ioctl *io = va_arg(args, struct dm_ioctl *);
605 io->data_start = sizeof(struct dm_ioctl);
606 io->data_size = sizeof(struct dm_ioctl) + sizeof(struct dm_target_spec);
607 struct dm_target_spec* spec = (struct dm_target_spec*)(&((char*)io)[sizeof(struct dm_ioctl)]);
608 spec->next = sizeof(struct dm_target_spec) + 1 + strlen(TESTIODATA);
609 char *data = (char *)io + sizeof(struct dm_target_spec) + io->data_start;
610 int ret = strcpy_s(spec->target_type, DM_MAX_TYPE_NAME, "targetType");
611 if (ret < 0) {
612 return -1;
613 }
614 ret = strcpy_s(data, spec->next - sizeof(struct dm_target_spec), TESTIODATA);
615 if (ret < 0) {
616 return -1;
617 }
618 return 0;
619 };
620 UpdateIoctlFunc(ioctlFunc);
621 char name[PATH_MAX] = "name";
622 char targetType[PATH_MAX] = "targetType";
623 StatusInfo *info = (StatusInfo *)malloc(sizeof(StatusInfo));
624 int ret = GetDmSnapshotStatus(name, targetType, info);
625 UpdateOpenFunc(nullptr);
626 UpdateInitdmioFunc(nullptr);
627 UpdateIoctlFunc(nullptr);
628
629 EXPECT_EQ(ret, true);
630 }
631
632 HWTEST_F(LibFsDmSnapshotTest, GetDmMergeProcess_001, TestSize.Level0)
633 {
634 bool ret = GetDmMergeProcess(nullptr, nullptr);
635 EXPECT_EQ(ret, false);
636 }
637 }