• 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 
16 #include "dsched_sync_e2e_test.h"
17 
18 #include <thread>
19 #include "distributed_sched_test_util.h"
20 #include "dtbschedmgr_device_info_storage.h"
21 #include "test_log.h"
22 
23 namespace OHOS {
24 namespace DistributedSchedule {
25 using namespace std;
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS::DistributedKv;
29 using namespace OHOS::DistributedHardware;
30 namespace {
31 const std::string BASEDIR = "/data/service/el1/public/database/DistributedSchedule";
32 constexpr int32_t TASK_ID_1 = 11;
33 constexpr int32_t TASK_ID_2 = 12;
34 constexpr size_t BYTESTREAM_LENGTH = 100;
35 constexpr uint8_t ONE_BYTE = '6';
36 }
37 
SetUpTestCase()38 void DmsKvSyncE2ETest::SetUpTestCase()
39 {
40     mkdir(BASEDIR.c_str(), (S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH));
41     DTEST_LOG << "DmsKvSyncE2ETest::SetUpTestCase" << std::endl;
42 }
43 
TearDownTestCase()44 void DmsKvSyncE2ETest::TearDownTestCase()
45 {
46     (void)remove(BASEDIR.c_str());
47     DTEST_LOG << "DmsKvSyncE2ETest::TearDownTestCase" << std::endl;
48 }
49 
SetUp()50 void DmsKvSyncE2ETest::SetUp()
51 {
52     DistributedSchedUtil::MockPermission();
53     dmsKvSyncE2E_ = std::make_shared<DmsKvSyncE2E>();
54     DTEST_LOG << "DmsKvSyncE2ETest::SetUp" << std::endl;
55 }
56 
TearDown()57 void DmsKvSyncE2ETest::TearDown()
58 {
59     DTEST_LOG << "DmsKvSyncE2ETest::TearDown" << std::endl;
60 }
61 
62 
GetDmsKvSyncE2E()63 std::shared_ptr<DmsKvSyncE2E> DmsKvSyncE2ETest::GetDmsKvSyncE2E()
64 {
65     if (dmsKvSyncE2E_ == nullptr) {
66         dmsKvSyncE2E_ = std::make_unique<DmsKvSyncE2E>();
67     }
68     return dmsKvSyncE2E_;
69 }
70 
71 /**
72  * @tc.name: PushAndPullDataTest_001
73  * @tc.desc: test insert DmsKvSyncE2E
74  * @tc.type: FUNC
75  */
76 HWTEST_F(DmsKvSyncE2ETest, PushAndPullDataTest_001, TestSize.Level1)
77 {
78     DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_001 start" << std::endl;
79     ASSERT_NE(dmsKvSyncE2E_, nullptr);
80     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
81     EXPECT_NE(dmsKvSyncE2E, nullptr);
82     if (dmsKvSyncE2E != nullptr) {
83         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_.clear();
84         bool ret = dmsKvSyncE2E_->GetInstance()->PushAndPullData();
85         EXPECT_EQ(ret, false);
86     }
87     DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_001 end" << std::endl;
88 }
89 
90 /**
91  * @tc.name: PushAndPullDataTest_002
92  * @tc.desc: test insert DmsKvSyncE2E
93  * @tc.type: FUNC
94  */
95 HWTEST_F(DmsKvSyncE2ETest, PushAndPullDataTest_002, TestSize.Level1)
96 {
97     DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_002 start" << std::endl;
98     ASSERT_NE(dmsKvSyncE2E_, nullptr);
99     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
100     EXPECT_NE(dmsKvSyncE2E, nullptr);
101     if (dmsKvSyncE2E != nullptr) {
102         const std::string networkId = "123";
103         bool ret = dmsKvSyncE2E_->GetInstance()->PushAndPullData(networkId);
104         EXPECT_EQ(ret, false);
105     }
106     DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_002 end" << std::endl;
107 }
108 
109 /**
110  * @tc.name: PushAndPullDataTest_003
111  * @tc.desc: test insert DmsKvSyncE2E
112  * @tc.type: FUNC
113  */
114 HWTEST_F(DmsKvSyncE2ETest, PushAndPullDataTest_003, TestSize.Level1)
115 {
116     DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_003 start" << std::endl;
117     ASSERT_NE(dmsKvSyncE2E_, nullptr);
118     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
119     EXPECT_NE(dmsKvSyncE2E, nullptr);
120     if (dmsKvSyncE2E != nullptr) {
121         auto deviceInfo = std::make_shared<DmsDeviceInfo>("", 0, "");
122         auto deviceInfo1 = std::make_shared<DmsDeviceInfo>("", 1, "");
123         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_["deviceInfo"] = deviceInfo;
124         DtbschedmgrDeviceInfoStorage::GetInstance().remoteDevices_["deviceInfo1"] = deviceInfo1;
125         bool ret = dmsKvSyncE2E_->GetInstance()->PushAndPullData();
126         EXPECT_EQ(ret, false);
127     }
128     DTEST_LOG << "DmsKvSyncE2ETest PushAndPullDataTest_003 end" << std::endl;
129 }
130 
131 /**
132  * @tc.name: SetDeviceCfgTest_001
133  * @tc.desc: test insert DmsKvSyncE2E
134  * @tc.type: FUNC
135  */
136 HWTEST_F(DmsKvSyncE2ETest, SetDeviceCfgTest_001, TestSize.Level1)
137 {
138     DTEST_LOG << "DmsKvSyncE2ETest SetDeviceCfgTest_001 start" << std::endl;
139     ASSERT_NE(dmsKvSyncE2E_, nullptr);
140     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
141     EXPECT_NE(dmsKvSyncE2E, nullptr);
142     if (dmsKvSyncE2E != nullptr) {
143         dmsKvSyncE2E_->GetInstance()->SetDeviceCfg();
144     }
145     DTEST_LOG << "DmsKvSyncE2ETest SetDeviceCfgTest_001 end" << std::endl;
146 }
147 
148 /**
149  * @tc.name: CheckDeviceCfgTest_001
150  * @tc.desc: test insert DmsKvSyncE2E
151  * @tc.type: FUNC
152  */
153 HWTEST_F(DmsKvSyncE2ETest, CheckDeviceCfgTest_001, TestSize.Level1)
154 {
155     DTEST_LOG << "DmsKvSyncE2ETest CheckDeviceCfgTest_001 start" << std::endl;
156     ASSERT_NE(dmsKvSyncE2E_, nullptr);
157     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
158     EXPECT_NE(dmsKvSyncE2E, nullptr);
159     if (dmsKvSyncE2E != nullptr) {
160         bool ret = dmsKvSyncE2E_->GetInstance()->CheckDeviceCfg();
161     }
162     DTEST_LOG << "DmsKvSyncE2ETest CheckDeviceCfgTest_001 end" << std::endl;
163 }
164 
165 /**
166  * @tc.name: CheckCtrlRuleTest_001
167  * @tc.desc: test insert DmsKvSyncE2E
168  * @tc.type: FUNC
169  */
170 HWTEST_F(DmsKvSyncE2ETest, CheckCtrlRuleTest_001, TestSize.Level1)
171 {
172     DTEST_LOG << "DmsKvSyncE2ETest CheckCtrlRuleTest_001 start" << std::endl;
173     ASSERT_NE(dmsKvSyncE2E_, nullptr);
174     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
175     EXPECT_NE(dmsKvSyncE2E, nullptr);
176     if (dmsKvSyncE2E != nullptr) {
177         dmsKvSyncE2E_->GetInstance()->CheckCtrlRule();
178     }
179     DTEST_LOG << "DmsKvSyncE2ETest CheckCtrlRuleTest_001 end" << std::endl;
180 }
181 
182 /**
183  * @tc.name: CheckCtrlRuleTest_002
184  * @tc.desc: test insert DmsKvSyncE2E
185  * @tc.type: FUNC
186  */
187 HWTEST_F(DmsKvSyncE2ETest, CheckCtrlRuleTest_002, TestSize.Level1)
188 {
189     DTEST_LOG << "DmsKvSyncE2ETest CheckCtrlRuleTest_002 start" << std::endl;
190     ASSERT_NE(dmsKvSyncE2E_, nullptr);
191     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
192     EXPECT_NE(dmsKvSyncE2E, nullptr);
193     if (dmsKvSyncE2E != nullptr) {
194         dmsKvSyncE2E_->GetInstance()->isForbidSendAndRecv_ = true;
195         bool ret = dmsKvSyncE2E_->GetInstance()->CheckCtrlRule();
196         EXPECT_EQ(ret, true);
197 
198         dmsKvSyncE2E_->GetInstance()->isCfgDevices_ = true;
199         ret = dmsKvSyncE2E_->GetInstance()->CheckCtrlRule();
200         EXPECT_EQ(ret, false);
201 
202         dmsKvSyncE2E_->GetInstance()->isForbidSendAndRecv_ = false;
203         ret = dmsKvSyncE2E_->GetInstance()->CheckCtrlRule();
204         EXPECT_EQ(ret, true);
205     }
206     DTEST_LOG << "DmsKvSyncE2ETest CheckCtrlRuleTest_002 end" << std::endl;
207 }
208 
209 /**
210  * @tc.name: CheckBundleContinueConfigTest_001
211  * @tc.desc: test insert DmsKvSyncE2E
212  * @tc.type: FUNC
213  */
214 HWTEST_F(DmsKvSyncE2ETest, CheckBundleContinueConfigTest_001, TestSize.Level1)
215 {
216     DTEST_LOG << "DmsKvSyncE2ETest CheckBundleContinueConfigTest_001 start" << std::endl;
217     ASSERT_NE(dmsKvSyncE2E_, nullptr);
218     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
219     EXPECT_NE(dmsKvSyncE2E, nullptr);
220     if (dmsKvSyncE2E != nullptr) {
221         const std::string bundleName = "123";
222         dmsKvSyncE2E_->GetInstance()->isCfgDevices_ = false;
223         bool ret = dmsKvSyncE2E_->GetInstance()->CheckBundleContinueConfig(bundleName);
224         EXPECT_EQ(ret, true);
225     }
226     DTEST_LOG << "DmsKvSyncE2ETest CheckBundleContinueConfigTest_001 end" << std::endl;
227 }
228 
229 /**
230  * @tc.name: CheckBundleContinueConfigTest_002
231  * @tc.desc: test insert DmsKvSyncE2E
232  * @tc.type: FUNC
233  */
234 HWTEST_F(DmsKvSyncE2ETest, CheckBundleContinueConfigTest_002, TestSize.Level1)
235 {
236     DTEST_LOG << "DmsKvSyncE2ETest CheckBundleContinueConfigTest_002 start" << std::endl;
237     ASSERT_NE(dmsKvSyncE2E_, nullptr);
238     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
239     EXPECT_NE(dmsKvSyncE2E, nullptr);
240     if (dmsKvSyncE2E != nullptr) {
241         const std::string bundleName = "123";
242         dmsKvSyncE2E_->GetInstance()->isCfgDevices_ = true;
243         dmsKvSyncE2E_->GetInstance()->whiteList_.clear();
244         bool ret = dmsKvSyncE2E_->GetInstance()->CheckBundleContinueConfig(bundleName);
245         EXPECT_EQ(ret, false);
246 
247         dmsKvSyncE2E_->GetInstance()->isCfgDevices_ = true;
248         dmsKvSyncE2E_->GetInstance()->whiteList_.clear();
249         dmsKvSyncE2E_->GetInstance()->whiteList_.push_back(bundleName);
250         dmsKvSyncE2E_->GetInstance()->whiteList_.push_back(bundleName);
251         ret = dmsKvSyncE2E_->GetInstance()->CheckBundleContinueConfig(bundleName);
252         EXPECT_EQ(ret, true);
253     }
254     DTEST_LOG << "DmsKvSyncE2ETest CheckBundleContinueConfigTest_002 end" << std::endl;
255 }
256 
257 /**
258  * @tc.name: IsValidPath_001
259  * @tc.desc: test IsValidPath
260  * @tc.type: FUNC
261  */
262 HWTEST_F(DmsKvSyncE2ETest, IsValidPath_001, TestSize.Level1)
263 {
264     DTEST_LOG << "DmsKvSyncE2ETest CheckCtrlRuleTest_001 start" << std::endl;
265     ASSERT_NE(dmsKvSyncE2E_, nullptr);
266     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
267     EXPECT_NE(dmsKvSyncE2E, nullptr);
268     if (dmsKvSyncE2E != nullptr) {
269         std::string inFilePath = "";
270         std::string realFilePath;
271         bool ret = dmsKvSyncE2E_->GetInstance()->IsValidPath(inFilePath, realFilePath);
272         EXPECT_EQ(ret, false);
273 
274         inFilePath = "inFilePath";
275         ret = dmsKvSyncE2E_->GetInstance()->IsValidPath(inFilePath, realFilePath);
276         EXPECT_EQ(ret, false);
277     }
278     DTEST_LOG << "DmsKvSyncE2ETest IsValidPath_001 end" << std::endl;
279 }
280 
281 /**
282  * @tc.name: UpdateWhiteListTest_001
283  * @tc.desc: test UpdateWhiteList
284  * @tc.type: FUNC
285  */
286 HWTEST_F(DmsKvSyncE2ETest, UpdateWhiteListTest_001, TestSize.Level1)
287 {
288     DTEST_LOG << "DmsKvSyncE2ETest UpdateWhiteListTest_001 start" << std::endl;
289     ASSERT_NE(dmsKvSyncE2E_, nullptr);
290     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
291     EXPECT_NE(dmsKvSyncE2E, nullptr);
292     if (dmsKvSyncE2E != nullptr) {
293         const std::string cfgJsonStr = "cfgJsonStr";
294         bool ret = dmsKvSyncE2E_->GetInstance()->UpdateWhiteList(cfgJsonStr);
295         EXPECT_EQ(ret, false);
296     }
297     DTEST_LOG << "DmsKvSyncE2ETest UpdateWhiteListTest_001 end" << std::endl;
298 }
299 
300 /**
301  * @tc.name: CheckKvStoreTest_001
302  * @tc.desc: test CheckKvStore
303  * @tc.type: FUNC
304  */
305 HWTEST_F(DmsKvSyncE2ETest, CheckKvStoreTest_001, TestSize.Level1)
306 {
307     DTEST_LOG << "DmsKvSyncE2ETest CheckKvStoreTest_001 start" << std::endl;
308     ASSERT_NE(dmsKvSyncE2E_, nullptr);
309     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
310     EXPECT_NE(dmsKvSyncE2E, nullptr);
311     if (dmsKvSyncE2E != nullptr) {
312         dmsKvSyncE2E_->GetInstance()->kvStorePtr_ = nullptr;
313         bool ret = dmsKvSyncE2E_->GetInstance()->CheckKvStore();
314         EXPECT_EQ(ret, true);
315     }
316     DTEST_LOG << "DmsKvSyncE2ETest CheckKvStoreTest_001 end" << std::endl;
317 }
318 
319 /**
320  * @tc.name: CheckMDMCtrlRuleTest_001
321  * @tc.desc: test insert CheckMDMCtrlRule
322  * @tc.type: FUNC
323  */
324 HWTEST_F(DmsKvSyncE2ETest, CheckMDMCtrlRuleTest_001, TestSize.Level1)
325 {
326     DTEST_LOG << "DmsKvSyncE2ETest CheckMDMCtrlRuleTest_001 start" << std::endl;
327     ASSERT_NE(dmsKvSyncE2E_, nullptr);
328     std::string bundleName = "bundleName";
329     auto dmsKvSyncE2E = GetDmsKvSyncE2E();
330     EXPECT_NE(dmsKvSyncE2E, nullptr);
331     if (dmsKvSyncE2E != nullptr) {
332         dmsKvSyncE2E_->GetInstance()->isMDMControl_ = true;
333         bool ret = dmsKvSyncE2E_->GetInstance()->CheckMDMCtrlRule(bundleName);
334         EXPECT_EQ(ret, true);
335 
336         dmsKvSyncE2E_->GetInstance()->isMDMControl_ = false;
337         ret = dmsKvSyncE2E_->GetInstance()->CheckMDMCtrlRule(bundleName);
338         EXPECT_EQ(ret, false);
339     }
340     DTEST_LOG << "DmsKvSyncE2ETest CheckMDMCtrlRuleTest_001 end" << std::endl;
341 }
342 } // namespace DistributedSchedule
343 } // namespace OHOS
344