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 16 #include "erofs_remount_overlay.h" 17 #include "securec.h" 18 #include "param_stub.h" 19 #include "fs_manager.h" 20 using namespace std; 21 using namespace testing::ext; 22 namespace init_ut { 23 class ErofsRemountUnitTest : public testing::Test { 24 public: SetUpTestCase(void)25 static void SetUpTestCase(void) {}; TearDownTestCase(void)26 static void TearDownTestCase(void) {}; SetUp(void)27 void SetUp(void) {}; TearDown(void)28 void TearDown(void) {}; 29 }; 30 31 HWTEST_F(ErofsRemountUnitTest, Init_GetRemountResult_001, TestSize.Level0) 32 { 33 const char *cmdLine; 34 rmdir(REMOUNT_RESULT_PATH); 35 SetRemountResultFlag(); 36 37 CheckAndCreateDir(REMOUNT_RESULT_FLAG); 38 SetRemountResultFlag(); 39 rmdir(REMOUNT_RESULT_PATH); 40 } 41 42 HWTEST_F(ErofsRemountUnitTest, Init_Modem2Exchange_001, TestSize.Level0) 43 { 44 const char *srcPath = STARTUP_INIT_UT_PATH"/data/modem2Exchange"; 45 const char *targetPath = STARTUP_INIT_UT_PATH"/data/modem2Exchangetarget"; 46 47 CheckAndCreateDir(srcPath); 48 CheckAndCreateDir(targetPath); 49 50 SetStubResult(STUB_MOUNT, -1); 51 int ret = Modem2Exchange(srcPath, targetPath); 52 EXPECT_EQ(ret, -1); 53 54 SetStubResult(STUB_MOUNT, 0); 55 ret = Modem2Exchange(srcPath, targetPath); 56 EXPECT_EQ(ret, 0); 57 58 rmdir(srcPath); 59 rmdir(targetPath); 60 } 61 62 HWTEST_F(ErofsRemountUnitTest, Init_ExchangeToMode_001, TestSize.Level0) 63 { 64 const char *srcPath = STARTUP_INIT_UT_PATH"/data/Exchange2Mode"; 65 const char *targetPath = STARTUP_INIT_UT_PATH"/data/Exchange2Modetarget"; 66 67 int ret = Exchange2Modem(srcPath, targetPath); 68 EXPECT_EQ(ret, 0); 69 70 CheckAndCreateDir(srcPath); 71 CheckAndCreateDir(targetPath); 72 73 SetStubResult(STUB_MOUNT, 0); 74 SetStubResult(STUB_UMOUNT, 0); 75 76 ret = Exchange2Modem(srcPath, targetPath); 77 EXPECT_EQ(ret, 0); 78 79 CheckAndCreateDir(targetPath); 80 SetStubResult(STUB_MOUNT, -1); 81 SetStubResult(STUB_UMOUNT, -1); 82 83 Exchange2Modem(srcPath, targetPath); 84 EXPECT_EQ(ret, 0); 85 86 rmdir(srcPath); 87 rmdir(targetPath); 88 } 89 90 HWTEST_F(ErofsRemountUnitTest, Init_OverlayRemountVendorPre_001, TestSize.Level0) 91 { 92 CheckAndCreateDir(MODEM_DRIVER_MNT_PATH); 93 CheckAndCreateDir(MODEM_VENDOR_MNT_PATH); 94 CheckAndCreateDir(MODEM_FW_MNT_PATH); 95 OverlayRemountVendorPre(); 96 rmdir(MODEM_DRIVER_MNT_PATH); 97 rmdir(MODEM_VENDOR_MNT_PATH); 98 rmdir(MODEM_FW_MNT_PATH); 99 100 OverlayRemountVendorPost(); 101 } 102 103 HWTEST_F(ErofsRemountUnitTest, Init_RemountOverlayTest_001, TestSize.Level0) 104 { 105 int ret = RemountOverlay(); 106 EXPECT_EQ(ret, 0); 107 } 108 }