1 /*
2  * Copyright (C) 2021 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 
HWTEST_F(DubaiTest, DubaiBeginTest, TestSize.Level1)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 
HWTEST_F(DubaiTest, DubaiFinishTest, TestSize.Level1)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 
HWTEST_F(DubaiTest, DubaiMoveTest, TestSize.Level1)59 HWTEST_F(DubaiTest, DubaiMoveTest, TestSize.Level1)
60 {
61     Dubai &dubai = Dubai::GetInstance();
62     std::string result;
63     std::string dubaiName = "dubai.db";
64     std::string dubaiPath = "/data/system_ce/0/dubai/" + dubaiName;
65     std::string devicePath = "/data/app/el2/100/database/com.ohos.smartperf/entry/rdb";
66     auto ret = OHOS::SmartPerf::SPUtils::LoadCmd("cp " + dubaiPath + " " + devicePath, result);
67     auto ret1 = OHOS::SmartPerf::SPUtils::LoadCmd("chmod 777 " + devicePath + "/" + dubaiName, result);
68     dubai.MoveDubaiDb();
69 
70     EXPECT_EQ(ret, true);
71     EXPECT_EQ(ret1, true);
72 }
73 }
74 }