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 16 #include <gtest/gtest.h> 17 #include "sp_utils.h" 18 #include "parse_radar.h" 19 #include <string> 20 #include <vector> 21 #include <iostream> 22 #include <sstream> 23 #include "Dubai.h" 24 25 using namespace testing::ext; 26 using namespace std; 27 28 namespace OHOS { 29 namespace SmartPerf { 30 class DubaiTest : public testing::Test { 31 public: SetUpTestCase()32 static void SetUpTestCase() {} TearDownTestCase()33 static void TearDownTestCase() {} 34 SetUp()35 void SetUp() {} TearDown()36 void TearDown() {} 37 }; 38 39 HWTEST_F(DubaiTest, DubaiBeginTest, TestSize.Level1) 40 { 41 Dubai &dubai = Dubai::GetInstance(); 42 std::string result; 43 auto ret = OHOS::SmartPerf::SPUtils::LoadCmd("hidumper -s 1213 -a '-b'", result); 44 dubai.DumpDubaiBegin(); 45 46 EXPECT_EQ(ret, true); 47 } 48 49 HWTEST_F(DubaiTest, DubaiFinishTest, TestSize.Level1) 50 { 51 Dubai &dubai = Dubai::GetInstance(); 52 std::string result; 53 auto ret = OHOS::SmartPerf::SPUtils::LoadCmd("hidumper -s 1213 -a '-f'", result); 54 dubai.DumpDubaiFinish(); 55 56 EXPECT_EQ(ret, true); 57 } 58 59 HWTEST_F(DubaiTest, DubaiMoveTest, TestSize.Level1) 60 { 61 Dubai &dubai = Dubai::GetInstance(); 62 std::string result; 63 const std::string dubaiXpower = "/data/service/el2/100/xpower/dubai.db"; 64 const std::string database = "/data/app/el2/100/database/"; 65 const std::string pkgEntry = "/entry/rdb"; 66 const std::string cpDubai = "cp " + dubaiXpower + " " + database + dubai.dubaiPkgName + pkgEntry; 67 const std::string dubaiPathChmod = "chmod 777 " + database + dubai.dubaiPkgName + pkgEntry + "/dubai.db"; 68 if (!dubai.IsFileAccessible(dubaiXpower)) { 69 sleep(1); 70 } 71 auto retCp = OHOS::SmartPerf::SPUtils::LoadCmd(cpDubai, result); 72 auto retChmod = OHOS::SmartPerf::SPUtils::LoadCmd(dubaiPathChmod, result); 73 dubai.MoveDubaiDb(); 74 75 EXPECT_EQ(retCp, true); 76 EXPECT_EQ(retChmod, true); 77 } 78 79 HWTEST_F(DubaiTest, CallMoveDubaiDbFinished01, TestSize.Level1) 80 { 81 OHOS::SmartPerf::Dubai::isDumpDubaiFinish = false; 82 std::string result = OHOS::SmartPerf::Dubai::GetInstance().CallMoveDubaiDbFinished(); 83 EXPECT_EQ(result, "get_dubai_db"); 84 } 85 86 HWTEST_F(DubaiTest, CallMoveDubaiDbFinished02, TestSize.Level1) 87 { 88 OHOS::SmartPerf::Dubai::isDumpDubaiFinish = true; 89 std::string result = OHOS::SmartPerf::Dubai::GetInstance().CallMoveDubaiDbFinished(); 90 EXPECT_EQ(result, "get_dubai_db"); 91 } 92 93 HWTEST_F(DubaiTest, IsFileAccessible01, TestSize.Level1) 94 { 95 std::string existingFile = "existing_file.txt"; 96 std::ofstream file(existingFile); 97 file << "Test content"; 98 file.close(); 99 bool result = Dubai::GetInstance().IsFileAccessible(existingFile); 100 EXPECT_TRUE(result); 101 std::remove(existingFile.c_str()); 102 } 103 104 HWTEST_F(DubaiTest, IsFileAccessible02, TestSize.Level1) 105 { 106 std::string nonExistingFile = "non_existing_file.txt"; 107 bool result = Dubai::GetInstance().IsFileAccessible(nonExistingFile); 108 EXPECT_FALSE(result); 109 } 110 } 111 }