• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2024 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 "erofs_mount_overlay.h"
16 #include "securec.h"
17 #include "param_stub.h"
18 #include "init_utils.h"
19 using namespace std;
20 using namespace testing::ext;
21 namespace init_ut {
22 class ErofsMountUnitTest : public testing::Test {
23 public:
SetUpTestCase(void)24     static void SetUpTestCase(void) {};
TearDownTestCase(void)25     static void TearDownTestCase(void) {};
SetUp(void)26     void SetUp(void) {};
TearDown(void)27     void TearDown(void) {};
28 };
29 HWTEST_F(ErofsMountUnitTest, Init_AllocDmName_001, TestSize.Level0)
30 {
31     char nameExt4[MAX_BUFFER_LEN] = {0};
32     char nameRofs[MAX_BUFFER_LEN] = {0};
33     const char *devName = STARTUP_INIT_UT_PATH"/data/erofs/mount/rofs";
34     AllocDmName(devName, nameRofs, MAX_BUFFER_LEN, nameExt4, MAX_BUFFER_LEN);
35     EXPECT_STRNE(nameExt4, nameRofs);
36 }
37 HWTEST_F(ErofsMountUnitTest, Init_LookupErofsEnd_001, TestSize.Level0)
38 {
39     const char *devMount = STARTUP_INIT_UT_PATH"/data/erofs/mount/lookup";
40     int ret = LookupErofsEnd(devMount);
41     EXPECT_EQ(ret, 0);
42     mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
43     CheckAndCreatFile(devMount, mode);
44     int fd = open(devMount, O_WRONLY | O_TRUNC);
45     void *data = calloc(1, EROFS_SUPER_BLOCK_START_POSITION);
46     ret = write(fd, data, EROFS_SUPER_BLOCK_START_POSITION);
47     EXPECT_EQ(ret, EROFS_SUPER_BLOCK_START_POSITION);
48 
49     close(fd);
50     free(data);
51     ret = LookupErofsEnd(devMount);
52     EXPECT_EQ(ret, 0);
53     struct erofs_super_block sb;
54     sb.magic = EROFS_SUPER_MAGIC;
55     sb.blocks = 1;
56     data = calloc(1, sizeof(sb));
57     memcpy_s(data, EROFS_SUPER_BLOCK_START_POSITION, &sb, sizeof(sb));
58     fd = open(devMount, O_WRONLY | O_APPEND);
59     ret = write(fd, data, sizeof(sb));
60     EXPECT_EQ(ret, sizeof(sb));
61 
62     close(fd);
63     free(data);
64     ret = LookupErofsEnd(devMount);
65     EXPECT_NE(ret, 0);
66     remove(devMount);
67 }
68 
69 }