• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <iostream>
17 #include <cstdio>
18 #include <cstring>
19 #include <ctime>
20 #include <chrono>
21 #include <cinttypes>
22 #include <string>
23 #include <unistd.h>
24 #include <gtest/gtest.h>
25 #include <sys/types.h>
26 #include <securec.h>
27 
28 #include "dbinder_service.h"
29 #include "dbinder_service_test_helper.h"
30 #include "dbinder_test_service_skeleton.h"
31 #include "ipc_skeleton.h"
32 #include "ipc_object_proxy.h"
33 #include "ipc_types.h"
34 #include "if_system_ability_manager.h"
35 #include "string_ex.h"
36 #include "iservice_registry.h"
37 #include "system_ability_definition.h"
38 #include "distributed_major.h"
39 #include "log_tags.h"
40 #include "dbinder_test_service.h"
41 
42 using namespace OHOS;
43 using namespace testing::ext;
44 using namespace OHOS::DistributeSystemTest;
45 using namespace OHOS::HiviewDFX;
46 
47 static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC, "DbinderTest" };
48 
49 class DbinderTest : public DistributeTest {
50 public:
51     static const int UNIT = 1024;
52     /* The threshold of packet size is 64 * 1024, including header.
53      * The following definitions are used to test legal and illegal packets.
54      */
55     static const int LEGAL_SIZE_S = 3 * 1024;
56     static const int LEGAL_SIZE_M = 16 * 1024;
57     static const int LEGAL_SIZE_L = 63 * 1024;
58     static const int ILLEGAL_SIZE = 2 * 1024 * 1024;
59     static const int REPEAT_TIMES = 1000;
60     static const int REPEAT_RAW_DATA_TIMES = 100;
61     static const int MULTIPLEX_TIMES = 10;
62     static sptr<ISystemAbilityManager> manager_;
63     static char serverId_[DEVICEID_LENGTH + 1];
64     // Test transferring big data with different sizes
65     const int rawData10K = 10 * 1024;
66     const int rawData100K = 100 * 1024;
67     const int rawData1M = 1024 * 1024;
68     const int rawData10M = 10 * 1024 * 1024;
69     const int rawData100M = 100 * 1024 * 1024;
70 
71     DbinderTest() = default;
72     ~DbinderTest() = default;
73     static void SetUpTestCase();
74     static void TearDownTestCase();
75     virtual void SetUp();
TearDown()76     virtual void TearDown() {}
77     std::string IpToDeviceId(const std::string &localIp);
78     bool GetRemoteDeviceId();
79 };
80 
81 sptr<ISystemAbilityManager> DbinderTest::manager_ = nullptr;
82 char DbinderTest::serverId_[DEVICEID_LENGTH + 1];
83 
SetUpTestCase()84 void DbinderTest::SetUpTestCase()
85 {
86     DBINDER_LOGI(LOG_LABEL, "enter SetUpTestCase");
87     StartDBinderServiceTestService();
88 }
89 
TearDownTestCase()90 void DbinderTest::TearDownTestCase()
91 {
92     DBINDER_LOGI(LOG_LABEL, "enter TearDownTestCase");
93     StopDBinderServiceTestService();
94 }
95 
SetUp()96 void DbinderTest::SetUp()
97 {
98     bool ret = GetRemoteDeviceId();
99     ASSERT_TRUE(ret);
100 
101     sptr<DBinderService> dBinderService = DBinderService::GetInstance();
102     ASSERT_TRUE(dBinderService != nullptr);
103 
104     manager_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
105     ASSERT_TRUE(manager_ != nullptr);
106 }
107 
GetRemoteDeviceId()108 bool DbinderTest::GetRemoteDeviceId()
109 {
110     std::string msg = "Ask Device ID";
111     int ret = SendMessage(AGENT_NO::ONE, msg, strlen(msg.c_str()), [&](const std::string &retId, int retLen) -> bool {
112         if (memcpy_s(serverId_, DEVICEID_LENGTH, retId.c_str(), DEVICEID_LENGTH) != 0 || retLen != DEVICEID_LENGTH) {
113             DBINDER_LOGE(LOG_LABEL, "fail to copy string");
114             return false;
115         }
116         serverId_[DEVICEID_LENGTH] = '\0';
117         return true;
118     });
119 
120     return ret > 0;
121 }
122 
123 /*
124  * @tc.name: DbinderRemoteCall001
125  * @tc.desc: Verify local client can acquire registered system ability
126  * and invoke remote function on remote server.
127  * @tc.type: FUNC
128  * @tc.require: SR000CS1C1 SR000CS1CA SR000CUFFU I5GORX
129  */
130 HWTEST_F(DbinderTest, DbinderRemoteCall001, TestSize.Level3)
131 {
132     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_001);
133     DBINDER_LOGI(LOG_LABEL, "");
134 
135     /*
136      * @tc.steps: step1.Get a proxy (called testService) from remote server.
137      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
138      */
139     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
140     ASSERT_TRUE(object != nullptr);
141 
142     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
143     ASSERT_TRUE(testService != nullptr);
144 
145     /*
146      * @tc.steps: step2.Use the proxy object to invoke remote function.
147      * @tc.expected: step2.Remote call succeeds and returns 0.
148      */
149     int reply = 0;
150     int result = testService->ReverseInt(2019, reply);
151     EXPECT_EQ(result, 0);
152     EXPECT_EQ(reply, 9102);
153 
154     SetCurrentTestCase(DBINDER_TEST_INIT);
155 }
156 /*
157  * @tc.name: DbinderRemoteCall002
158  * @tc.desc: Verify local client cannot acquire unregistered system ability
159  * @tc.type: FUNC
160  * @tc.require: SR000CS1C1 SR000CS1CA SR000CUFFU I5GORX
161  */
162 HWTEST_F(DbinderTest, DbinderRemoteCall002, TestSize.Level3)
163 {
164     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_002);
165     DBINDER_LOGI(LOG_LABEL, "");
166 
167     /*
168      * @tc.steps: step1.Get an unregistered System Ability from remote server.
169      * @tc.expected: step1.Failed to get the SA and return nullptr.
170      */
171     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_UNREGISTERED_TEST_SERVICE, serverId_);
172     ASSERT_TRUE(object == nullptr);
173 
174     SetCurrentTestCase(DBINDER_TEST_INIT);
175 }
176 
177 /*
178  * @tc.name: DbinderRemoteCall003
179  * @tc.desc: Verify the limit to the size of data sent to remote server
180  * @tc.type: FUNC
181  * @tc.require: SR000CS1C1/SR000CS1CA/SR000CUFFU
182  */
183 HWTEST_F(DbinderTest, DbinderRemoteCall003, TestSize.Level3)
184 {
185     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_003);
186     DBINDER_LOGI(LOG_LABEL, "");
187 
188     /*
189      * @tc.steps: step1.Get a proxy (called testService) from remote server.
190      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
191      */
192     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
193     ASSERT_TRUE(object != nullptr);
194 
195     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
196     ASSERT_TRUE(testService != nullptr);
197 
198     /*
199      * @tc.steps: step2.Use the proxy object to invoke remote function with legal and illegal data respectively.
200      * @tc.expected: step2.Succeed in transferring legal data but fail to transfer illegal data.
201      */
202     std::string reply;
203     std::string emptyData;
204     testService->TransOversizedPkt(emptyData, reply);
205     ASSERT_TRUE(emptyData == reply);
206 
207     std::string legalDataS(LEGAL_SIZE_S, 'a');
208     int64_t startTime = GetCurrentTime();
209     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
210         testService->TransOversizedPkt(legalDataS, reply);
211         ASSERT_TRUE(legalDataS == reply);
212     }
213     int64_t finishTime = GetCurrentTime();
214     float speed = GetSpeed(finishTime - startTime, LEGAL_SIZE_S, MULTIPLEX_TIMES);
215     printf("Transfer 3k data with speed of %.2fk/s.\n", speed);
216 
217     std::string legalDataM(LEGAL_SIZE_M, 'a');
218     startTime = GetCurrentTime();
219     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
220         testService->TransOversizedPkt(legalDataM, reply);
221         ASSERT_TRUE(legalDataM == reply);
222     }
223     finishTime = GetCurrentTime();
224     speed = GetSpeed(finishTime - startTime, LEGAL_SIZE_M, MULTIPLEX_TIMES);
225     printf("Transfer 16k data with speed of %.2fk/s.\n", speed);
226 
227     std::string legalDataL(LEGAL_SIZE_L, 'a');
228     startTime = GetCurrentTime();
229     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
230         testService->TransOversizedPkt(legalDataL, reply);
231         ASSERT_TRUE(legalDataL == reply);
232     }
233     finishTime = GetCurrentTime();
234     speed = GetSpeed(finishTime - startTime, LEGAL_SIZE_L, MULTIPLEX_TIMES);
235     printf("Transfer 63k data with speed of %.2fk/s.\n", speed);
236 
237     std::string illegalData(ILLEGAL_SIZE, 'a');
238     testService->TransOversizedPkt(illegalData, reply);
239     ASSERT_TRUE(illegalData != reply);
240 
241     SetCurrentTestCase(DBINDER_TEST_INIT);
242 }
243 
244 /*
245  * @tc.name: DbinderRemoteCall004
246  * @tc.desc: Verify the communication with remote server is stable
247  * @tc.type: PERF
248  * @tc.require: SR000CS1C1/SR000CS1CA/SR000CUFFU
249  */
250 HWTEST_F(DbinderTest, DbinderRemoteCall004, TestSize.Level3)
251 {
252     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_004);
253     DBINDER_LOGI(LOG_LABEL, "");
254 
255     /*
256      * @tc.steps: step1.Get a proxy (called testService) from remote server.
257      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
258      */
259     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
260     ASSERT_TRUE(object != nullptr);
261 
262     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
263     ASSERT_TRUE(testService != nullptr);
264 
265     /*
266      * @tc.steps: step2.Use the proxy object to call remote function repeatedly.
267      * @tc.expected: step2.All remote calls succeed and return 0.
268      */
269     for (int i = 0; i < REPEAT_TIMES; i++) {
270         int reply = 0;
271         int result = testService->ReverseInt(2019, reply);
272         EXPECT_EQ(result, 0);
273         EXPECT_EQ(reply, 9102);
274     }
275 
276     SetCurrentTestCase(DBINDER_TEST_INIT);
277 }
278 
279 /*
280  * @tc.name: DbinderRemoteCall005
281  * @tc.desc: Test the delay of remote call with remote server
282  * @tc.type: PERF
283  * @tc.require: SR000CS1C1/SR000CS1CA/SR000CUFFU
284  */
285 HWTEST_F(DbinderTest, DbinderRemoteCall005, TestSize.Level3)
286 {
287     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_005);
288     DBINDER_LOGI(LOG_LABEL, "");
289 
290     /*
291      * @tc.steps: step1.Get a proxy (called testService) from remote server.
292      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
293      */
294     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
295     ASSERT_TRUE(object != nullptr);
296 
297     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
298     ASSERT_TRUE(testService != nullptr);
299 
300     /*
301      * @tc.steps: step2.Use the proxy object to call remote function, and calculate the time consumption.
302      * @tc.expected: step2.Remote call succeeds and the time delay is close to 15ms.
303      */
304     int64_t startTime = GetCurrentTime();
305     int reply = 0;
306     int result = testService->ReverseInt(2019, reply);
307     int64_t finishTime = GetCurrentTime();
308     EXPECT_GE(finishTime - startTime, 0L);
309     printf("Remote call costs %" PRId64"ms\n", (finishTime - startTime));
310     EXPECT_EQ(result, 0);
311     EXPECT_EQ(reply, 9102);
312 
313     SetCurrentTestCase(DBINDER_TEST_INIT);
314 }
315 
316 /*
317  * @tc.name: DbinderRemoteCall006
318  * @tc.desc: Verify the communications with remote device can be multiplexed
319  * @tc.type: FUNC
320  * @tc.require: SR000CS1C1/SR000CS1CA/SR000CUFFU
321  */
322 HWTEST_F(DbinderTest, DbinderRemoteCall006, TestSize.Level3)
323 {
324     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_006);
325     DBINDER_LOGI(LOG_LABEL, "");
326 
327     vector<sptr<IRemoteObject>> objects;
328     vector<sptr<IDBinderTestService>> testServices;
329     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
330         /*
331          * @tc.steps: step1.Get a proxy from remote server and stores it.
332          * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
333          */
334         objects.push_back(manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_));
335         testServices.push_back(iface_cast<IDBinderTestService>(objects[i]));
336 
337         /*
338          * @tc.steps: step2.Use the proxy object to invoke remote function.
339          * @tc.expected: step2.Remote call succeeds and returns 0.
340          */
341         int reply = 0;
342         int result = testServices[i]->ReverseInt(2019, reply);
343         EXPECT_EQ(result, 0);
344         EXPECT_EQ(reply, 9102);
345     }
346 
347     SetCurrentTestCase(DBINDER_TEST_INIT);
348 }
349 
350 /*
351  * @tc.name: DbinderRemoteCall007
352  * @tc.desc: Verify local client can transfer a local object to remote device.
353  * @tc.type: FUNC
354  * @tc.require: SR000CS1C8/SR000CS1CA/SR000CUFFU
355  */
356 HWTEST_F(DbinderTest, DbinderRemoteCall007, TestSize.Level3)
357 {
358     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_007);
359     DBINDER_LOGI(LOG_LABEL, "");
360 
361     /*
362      * @tc.steps: step1.Get a local binder object and a proxy pointing to remote stub.
363      * @tc.expected: step1.Get both objects successfully.
364      */
365     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE);
366     ASSERT_TRUE(object != nullptr);
367     sptr<IRemoteObject> remoteObject = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
368     ASSERT_TRUE(remoteObject != nullptr);
369 
370     sptr<IDBinderTestService> remoteTestService = iface_cast<IDBinderTestService>(remoteObject);
371     ASSERT_TRUE(remoteTestService != nullptr);
372 
373     /*
374      * @tc.steps: step2.Transfer the binder object to remote device.
375      * @tc.expected: step2.Remote device receives the object and use it to communicate with server.
376      */
377     int reply = 0;
378     int withdrawRes = 0;
379     int result =
380         remoteTestService->TransProxyObject(2019, object, OHOS::DBinderTestServiceProxy::NOT_SAVE, reply, withdrawRes);
381     EXPECT_EQ(result, 0);
382     EXPECT_EQ(reply, 9102);
383     EXPECT_EQ(withdrawRes, 0);
384 
385     SetCurrentTestCase(DBINDER_TEST_INIT);
386 }
387 
388 /*
389  * @tc.name: DbinderRemoteCall008
390  * @tc.desc: Verify local client can transfer two different local objects to remote device.
391  * @tc.type: FUNC
392  * @tc.require: SR000CS1C8/SR000CS1CA/SR000CUFFU
393  */
394 HWTEST_F(DbinderTest, DbinderRemoteCall008, TestSize.Level3)
395 {
396     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_008);
397     DBINDER_LOGI(LOG_LABEL, "");
398 
399     /*
400      * @tc.steps: step1.Get a local binder object and a proxy pointing to remote stub.
401      * @tc.expected: step1.Get both objects successfully.
402      */
403     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE);
404     ASSERT_TRUE(object != nullptr);
405     sptr<IRemoteObject> object2 = manager_->GetSystemAbility(RPC_TEST_SERVICE);
406     ASSERT_TRUE(object2 != nullptr);
407     sptr<IRemoteObject> remoteObject = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
408     ASSERT_TRUE(remoteObject != nullptr);
409 
410     sptr<IDBinderTestService> remoteTestService = iface_cast<IDBinderTestService>(remoteObject);
411     ASSERT_TRUE(remoteTestService != nullptr);
412 
413     /*
414      * @tc.steps: step2.Transfer two binder objects to remote device.
415      * @tc.expected: step2.Remote device receives the objects and use them to communicate with server.
416      */
417     int reply = 0;
418     int withdrawRes = 0;
419     int result =
420         remoteTestService->TransProxyObject(2019, object, OHOS::DBinderTestServiceProxy::NOT_SAVE, reply, withdrawRes);
421     EXPECT_EQ(result, 0);
422     EXPECT_EQ(reply, 9102);
423     EXPECT_EQ(withdrawRes, 0);
424 
425     result =
426         remoteTestService->TransProxyObject(2019, object2, OHOS::DBinderTestServiceProxy::NOT_SAVE, reply, withdrawRes);
427     EXPECT_EQ(result, 0);
428     EXPECT_EQ(reply, 9102);
429     EXPECT_EQ(withdrawRes, 0);
430 
431     SetCurrentTestCase(DBINDER_TEST_INIT);
432 }
433 
434 /*
435  * @tc.name: DbinderRemoteCall009
436  * @tc.desc: Verify local client is transmitting the same proxy every time to server.
437  * @tc.type: FUNC
438  * @tc.require: SR000CS1C8/SR000CS1CA/SR000CUFFU
439  */
440 HWTEST_F(DbinderTest, DbinderRemoteCall009, TestSize.Level3)
441 {
442     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_009);
443     DBINDER_LOGI(LOG_LABEL, "");
444 
445     /*
446      * @tc.steps: step1.Get a local binder object and a proxy pointing to remote stub.
447      * @tc.expected: step1.Get both objects successfully.
448      */
449     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE);
450     ASSERT_TRUE(object != nullptr);
451     sptr<IRemoteObject> remoteObject = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
452     ASSERT_TRUE(remoteObject != nullptr);
453 
454     sptr<IDBinderTestService> remoteTestService = iface_cast<IDBinderTestService>(remoteObject);
455     ASSERT_TRUE(remoteTestService != nullptr);
456 
457     /*
458      * @tc.steps: step2.Transfer the binder object to remote device twice.
459      * @tc.expected: step2.Remote device receives same object in two transmissions.
460      */
461     int reply = 0;
462     int withdrawRes = 0;
463     int result = remoteTestService->TransProxyObject(2019, object, DBinderTestServiceProxy::SAVE, reply, withdrawRes);
464     EXPECT_EQ(result, 0);
465     EXPECT_EQ(reply, 9102);
466     EXPECT_EQ(withdrawRes, 0);
467 
468     result = remoteTestService->TransProxyObject(2019, object, DBinderTestServiceProxy::WITHDRAW, reply, withdrawRes);
469     EXPECT_EQ(result, 0);
470     EXPECT_EQ(reply, 9102);
471     EXPECT_EQ(withdrawRes, 0);
472 
473     SetCurrentTestCase(DBINDER_TEST_INIT);
474 }
475 
476 /*
477  * @tc.name: DbinderRemoteCall011
478  * @tc.desc: Verify transferring objects between remote devices is stable
479  * @tc.type: FUNC
480  * @tc.require: SR000CS1C8/SR000CS1CA/SR000CUFFU
481  */
482 HWTEST_F(DbinderTest, DbinderRemoteCall011, TestSize.Level3)
483 {
484     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_011);
485     DBINDER_LOGI(LOG_LABEL, "");
486 
487     /*
488      * @tc.steps: step1.Get a local binder object and a proxy pointing to remote stub.
489      * @tc.expected: step1.Get both objects successfully.
490      */
491     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE);
492     ASSERT_TRUE(object != nullptr);
493     sptr<IRemoteObject> remoteObject = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
494     ASSERT_TRUE(remoteObject != nullptr);
495 
496     sptr<IDBinderTestService> remoteTestService = iface_cast<IDBinderTestService>(remoteObject);
497     ASSERT_TRUE(remoteTestService != nullptr);
498 
499     /*
500      * @tc.steps: step2.Transfer the binder object to remote device repeatedly.
501      * @tc.expected: step2.Remote device receives the object and use it to communicate with server.
502      */
503     for (int i = 0; i < REPEAT_TIMES; i++) {
504         int reply = 0;
505         int withdrawRes = 0;
506         int result =
507             remoteTestService->TransProxyObject(2019, object, DBinderTestServiceProxy::NOT_SAVE, reply, withdrawRes);
508         EXPECT_EQ(result, 0);
509         EXPECT_EQ(reply, 9102);
510     }
511 
512     SetCurrentTestCase(DBINDER_TEST_INIT);
513 }
514 
515 /*
516  * @tc.name: DbinderRemoteCall012
517  * @tc.desc: Test the delay of transferring an object between remote devices
518  * @tc.type: PERF
519  * @tc.require: SR000CS1C8/SR000CS1CA/SR000CUFFU
520  */
521 HWTEST_F(DbinderTest, DbinderRemoteCall012, TestSize.Level3)
522 {
523     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_012);
524     DBINDER_LOGI(LOG_LABEL, "");
525 
526     /*
527      * @tc.steps: step1.Get a local binder object and a proxy pointing to remote stub.
528      * @tc.expected: step1.Get both objects successfully.
529      */
530     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE);
531     ASSERT_TRUE(object != nullptr);
532     sptr<IRemoteObject> remoteObject = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
533     ASSERT_TRUE(remoteObject != nullptr);
534 
535     sptr<IDBinderTestService> remoteTestService = iface_cast<IDBinderTestService>(remoteObject);
536     ASSERT_TRUE(remoteTestService != nullptr);
537 
538     /*
539      * @tc.steps: step2.Use the proxy object to transfer object, and calculate the time consumption.
540      * @tc.expected: step2.Remote call succeeds and the time delay is close to 50ms.
541      */
542     int64_t startTime = GetCurrentTime();
543     int reply = 0;
544     int withdrawRes = 0;
545     int result =
546         remoteTestService->TransProxyObject(2019, object, DBinderTestServiceProxy::NOT_SAVE, reply, withdrawRes);
547     int64_t finishTime = GetCurrentTime();
548     EXPECT_GE(finishTime - startTime, 0L);
549     printf("Transferring an object costs %" PRId64 "ms\n", (finishTime - startTime));
550     EXPECT_EQ(result, 0);
551     EXPECT_EQ(reply, 9102);
552 
553     SetCurrentTestCase(DBINDER_TEST_INIT);
554 }
555 
556 /*
557  * @tc.name: DbinderRemoteCall014
558  * @tc.desc: Verify adding and removing death recipient successfully
559  * @tc.type: FUNC
560  * @tc.require: SR000CS1C8/SR000CS1CA
561  */
562 HWTEST_F(DbinderTest, DbinderRemoteCall014, TestSize.Level3)
563 {
564     SetCurrentTestCase(DBINDER_TEST_DEATH_RECIPIENT_001);
565     DBINDER_LOGI(LOG_LABEL, "");
566 
567     /*
568      * @tc.steps: step1.Get a proxy (called testService) from remote server.
569      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
570      */
571     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
572     ASSERT_TRUE(object != nullptr);
573 
574     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
575     ASSERT_TRUE(testService != nullptr);
576 
577     /*
578      * @tc.steps: step2.Add death recipient.
579      * @tc.expected: step2.Register death notification successfully.
580      */
581     sptr<IRemoteObject::DeathRecipient> deathRecipient(new DBinderTestDeathRecipient());
582     bool result = object->AddDeathRecipient(deathRecipient);
583     EXPECT_EQ(result, true);
584 
585     /*
586      * @tc.steps: step3.Remove death recipient
587      * @tc.expected: step3.Unregister death notification successfully.
588      */
589     result = object->RemoveDeathRecipient(deathRecipient);
590     EXPECT_EQ(result, true);
591 
592     /*
593      * @tc.steps: step4.Use the proxy object to invoke remote function.
594      * @tc.expected: step4.Remote call succeeds and returns 0.
595      */
596     int reply = 0;
597     int res = testService->ReverseInt(2019, reply);
598     EXPECT_EQ(res, 0);
599     EXPECT_EQ(reply, 9102);
600 
601     SetCurrentTestCase(DBINDER_TEST_INIT);
602 }
603 
604 /*
605  * @tc.name: DbinderRemoteCall015
606  * @tc.desc: Verify adding and removing death recipient successfully
607  * @tc.type: FUNC
608  * @tc.require: SR000CS1C8/SR000CS1CA
609  */
610 HWTEST_F(DbinderTest, DbinderRemoteCall015, TestSize.Level3)
611 {
612     SetCurrentTestCase(DBINDER_TEST_DEATH_RECIPIENT_002);
613     DBINDER_LOGI(LOG_LABEL, "");
614 
615     /*
616      * @tc.steps: step1.Get a proxy (called testService) from remote server.
617      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
618      */
619     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
620     ASSERT_TRUE(object != nullptr);
621 
622     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
623     ASSERT_TRUE(testService != nullptr);
624 
625     sptr<IRemoteObject::DeathRecipient> deathRecipient;
626     bool result = true;
627     int reply = 0, res = 0;
628     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
629         /*
630          * @tc.steps: step2.Add death recipient.
631          * @tc.expected: step2.Register death notification successfully.
632          */
633         deathRecipient = new DBinderTestDeathRecipient();
634         result = object->AddDeathRecipient(deathRecipient);
635         EXPECT_EQ(result, true);
636 
637         /*
638          * @tc.steps: step3.Remove death recipient
639          * @tc.expected: step3.Unregister death notification successfully.
640          */
641         result = object->RemoveDeathRecipient(deathRecipient);
642         EXPECT_EQ(result, true);
643 
644         /*
645          * @tc.steps: step4.Use the proxy object to invoke remote function.
646          * @tc.expected: step4.Remote call succeeds and returns 0.
647          */
648         res = testService->ReverseInt(2019, reply);
649         EXPECT_EQ(res, 0);
650         EXPECT_EQ(reply, 9102);
651     }
652 
653     SetCurrentTestCase(DBINDER_TEST_INIT);
654 }
655 
656 /*
657  * @tc.name: DbinderRemoteCall016
658  * @tc.desc: Verify adding and removing death recipient successfully
659  * @tc.type: FUNC
660  * @tc.require: SR000CS1C8/SR000CS1CA
661  */
662 HWTEST_F(DbinderTest, DbinderRemoteCall016, TestSize.Level3)
663 {
664     SetCurrentTestCase(DBINDER_TEST_DEATH_RECIPIENT_003);
665     DBINDER_LOGI(LOG_LABEL, "");
666 
667     /*
668      * @tc.steps: step1.Get a proxy (called testService) from remote server.
669      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
670      */
671     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
672     ASSERT_TRUE(object != nullptr);
673 
674     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
675     ASSERT_TRUE(testService != nullptr);
676 
677     /*
678      * @tc.steps: step2.Add two death recipients.
679      * @tc.expected: step2.Register two death notifications successfully.
680      */
681     sptr<IRemoteObject::DeathRecipient> deathRecipient(new DBinderTestDeathRecipient());
682     bool result = object->AddDeathRecipient(deathRecipient);
683     EXPECT_EQ(result, true);
684 
685     sptr<IRemoteObject::DeathRecipient> deathRecipientRepeat(new DBinderTestDeathRecipient());
686     result = object->AddDeathRecipient(deathRecipientRepeat);
687     EXPECT_EQ(result, true);
688 
689     /*
690      * @tc.steps: step3.Remove two death recipients.
691      * @tc.expected: step3.Return false when unregisterring 1st death notification because there is another one left.
692      * Return true when unregisterring 2nd death notification because all clean.
693      */
694     result = object->RemoveDeathRecipient(deathRecipient);
695     EXPECT_EQ(result, false);
696 
697     result = object->RemoveDeathRecipient(deathRecipientRepeat);
698     EXPECT_EQ(result, true);
699 
700     /*
701      * @tc.steps: step4.Use the proxy object to invoke remote function.
702      * @tc.expected: step4.Remote call succeeds and returns 0.
703      */
704     int reply = 0;
705     int res = testService->ReverseInt(2019, reply);
706     EXPECT_EQ(res, 0);
707     EXPECT_EQ(reply, 9102);
708 
709     SetCurrentTestCase(DBINDER_TEST_INIT);
710 }
711 
712 /*
713  * @tc.name: DbinderRemoteCall017
714  * @tc.desc: Verify receiving death notification when remote device dies
715  * @tc.type: FUNC
716  * @tc.require: SR000CS1C8/SR000CS1CA
717  */
718 HWTEST_F(DbinderTest, DbinderRemoteCall017, TestSize.Level3)
719 {
720     SetCurrentTestCase(DBINDER_TEST_DEATH_RECIPIENT_004);
721     DBINDER_LOGI(LOG_LABEL, "");
722 
723     /*
724      * @tc.steps: step1.Get a proxy (called testService) from remote server.
725      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
726      */
727     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
728     ASSERT_TRUE(object != nullptr);
729 
730     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
731     ASSERT_TRUE(testService != nullptr);
732 
733     /*
734      * @tc.steps: step2.Add death recipient.
735      * @tc.expected: step2.Register death notification successfully.
736      */
737     sptr<IRemoteObject::DeathRecipient> deathRecipient(new DBinderTestDeathRecipient());
738     bool result = object->AddDeathRecipient(deathRecipient);
739     ASSERT_TRUE(result == true);
740 
741     /*
742      * @tc.steps: step3.Stop remote service. Wait 10s, then check death notification.
743      * @tc.expected: step3.Stop it successfully, and receive death notification.
744      */
745     std::string command = "KILL";
746     std::string cmdArgs = "server";
747     std::string expectValue = "0";
748     bool ret = RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue);
749     EXPECT_EQ(ret, true);
750     EXPECT_EQ(GetReturnVal(), 0);
751 
752     // wait for killing remote service
753     sleep(10);
754     result = DBinderTestDeathRecipient::GotDeathRecipient();
755     EXPECT_EQ(result, true);
756     DBinderTestDeathRecipient::ClearDeathRecipient();
757     printf("Succ! Recv death notification!\n");
758 
759     /*
760      * @tc.steps: step4.Remove death recipient
761      * @tc.expected: step4.Fail to remove death recipient
762      * because when receiving death notification, it remove death recipient automatically.
763      */
764     result = object->RemoveDeathRecipient(deathRecipient);
765     EXPECT_EQ(result, false);
766 
767     /*
768      * @tc.steps: step5.Restart remote service and wait 10s.
769      * @tc.expected: step5.Restart it successfully.
770      */
771     std::string restartCommand = "RESTART";
772     ret = RunCmdOnAgent(AGENT_NO::ONE, restartCommand, cmdArgs, expectValue);
773     EXPECT_EQ(ret, true);
774     EXPECT_EQ(GetReturnVal(), 0);
775 
776     // wait for restarting server
777     sleep(10);
778 
779     /*
780      * @tc.steps: step6.Get a proxy (called testService2) from remote server.
781      * @tc.expected: step6.Get the proxy successfully, and the proxy points to remote stub.
782      */
783     sptr<IRemoteObject> object2 = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
784     ASSERT_TRUE(object2 != nullptr);
785 
786     sptr<IDBinderTestService> testService2 = iface_cast<IDBinderTestService>(object2);
787     ASSERT_TRUE(testService2 != nullptr);
788 
789     /*
790      * @tc.steps: step7.Use the proxy object to invoke remote function.
791      * @tc.expected: step7.Remote call succeeds and returns 0.
792      */
793     int reply = 0;
794     int res = testService2->ReverseInt(2019, reply);
795     EXPECT_EQ(res, 0);
796     EXPECT_EQ(reply, 9102);
797 
798     object = nullptr;
799     testService = nullptr;
800     object2 = nullptr;
801     testService2 = nullptr;
802 
803     SetCurrentTestCase(DBINDER_TEST_INIT);
804 }
805 
806 /*
807  * @tc.name: DbinderRemoteCall018
808  * @tc.desc: Verify transferring raw data
809  * @tc.type: FUNC
810  * @tc.require: AR000ER7PF
811  */
812 HWTEST_F(DbinderTest, DbinderRemoteCall018, TestSize.Level3)
813 {
814     SetCurrentTestCase(DBINDER_TEST_RAW_DATA_001);
815     DBINDER_LOGI(LOG_LABEL, "");
816 
817     /*
818      * @tc.steps: step1.Get a proxy (called testService) from remote server.
819      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
820      */
821     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
822     ASSERT_TRUE(object != nullptr);
823 
824     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
825     ASSERT_TRUE(testService != nullptr);
826 
827     /*
828      * @tc.steps: step2.Use the proxy object to transfer raw data.
829      * @tc.expected: step2.Remote call succeed and return the size of raw data.
830      */
831     // ProxyTransRawData cannot transfer data less than 2.
832     int result = testService->ProxyTransRawData(rawData100M);
833     EXPECT_EQ(result, 0);
834     result = testService->ProxyTransRawData(rawData100M);
835     EXPECT_EQ(result, 0);
836 
837     SetCurrentTestCase(DBINDER_TEST_INIT);
838 }
839 
840 /*
841  * @tc.name: DbinderRemoteCall019
842  * @tc.desc: Test the speed of transferring raw data by proxy
843  * @tc.type: PERF
844  * @tc.require: SR000D48A5
845  */
846 HWTEST_F(DbinderTest, DbinderRemoteCall019, TestSize.Level3)
847 {
848     SetCurrentTestCase(DBINDER_TEST_RAW_DATA_002);
849     DBINDER_LOGI(LOG_LABEL, "");
850 
851     /*
852      * @tc.steps: step1.Get a proxy (called testService) from remote server.
853      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
854      */
855     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
856     ASSERT_TRUE(object != nullptr);
857 
858     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
859     ASSERT_TRUE(testService != nullptr);
860 
861     /*
862      * @tc.steps: step2.Use the proxy object to transfer raw data with different size.
863      * @tc.expected: step2.Remote calls succeed and return the size of raw data.
864      */
865     int result;
866     int64_t startTime = GetCurrentTime();
867     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
868         result = testService->ProxyTransRawData(rawData10K);
869         EXPECT_EQ(result, 0);
870     }
871     int64_t finishTime = GetCurrentTime();
872     float speed = GetSpeed(finishTime - startTime, rawData10K, MULTIPLEX_TIMES);
873     printf("Transfer 10K raw data with speed of %.2fk/s.\n", speed);
874 
875     startTime = GetCurrentTime();
876     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
877         result = testService->ProxyTransRawData(rawData100K);
878         EXPECT_EQ(result, 0);
879     }
880     finishTime = GetCurrentTime();
881     speed = GetSpeed(finishTime - startTime, rawData100K, MULTIPLEX_TIMES);
882     printf("Transfer 100K raw data with speed of %.2fk/s.\n", speed);
883 
884     startTime = GetCurrentTime();
885     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
886         result = testService->ProxyTransRawData(rawData1M);
887         EXPECT_EQ(result, 0);
888     }
889     finishTime = GetCurrentTime();
890     speed = GetSpeed(finishTime - startTime, rawData1M, MULTIPLEX_TIMES);
891     printf("Transfer 1M raw data with speed of %.2fk/s.\n", speed);
892 
893     startTime = GetCurrentTime();
894     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
895         result = testService->ProxyTransRawData(rawData10M);
896         EXPECT_EQ(result, 0);
897     }
898     finishTime = GetCurrentTime();
899     speed = GetSpeed(finishTime - startTime, rawData10M, MULTIPLEX_TIMES);
900     printf("Transfer 10M raw data with speed of %.2fk/s.\n", speed);
901 
902     SetCurrentTestCase(DBINDER_TEST_INIT);
903 }
904 
905 /*
906  * @tc.name: DbinderRemoteCall020
907  * @tc.desc: Verify it is stable to transfer raw data
908  * @tc.type: FUNC
909  * @tc.require: SR000D48A5
910  */
911 HWTEST_F(DbinderTest, DbinderRemoteCall020, TestSize.Level3)
912 {
913     SetCurrentTestCase(DBINDER_TEST_RAW_DATA_003);
914     DBINDER_LOGI(LOG_LABEL, "");
915 
916     /*
917      * @tc.steps: step1.Get a proxy (called testService) from remote server.
918      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
919      */
920     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
921     ASSERT_TRUE(object != nullptr);
922 
923     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
924     ASSERT_TRUE(testService != nullptr);
925 
926     /*
927      * @tc.steps: step2.Use the proxy object to transfer raw data with different size.
928      * @tc.expected: step2.Remote calls succeed and return the size of raw data.
929      */
930     int result;
931     for (int i = 0; i < REPEAT_RAW_DATA_TIMES; i++) {
932         result = testService->ProxyTransRawData(rawData10M);
933         EXPECT_EQ(result, 0);
934     }
935 
936     SetCurrentTestCase(DBINDER_TEST_INIT);
937 }
938 
939 /*
940  * @tc.name: DbinderRemoteCall021
941  * @tc.desc: Verify reply can carry big raw data
942  * @tc.type: FUNC
943  * @tc.require: AR000DAPPO
944  */
945 HWTEST_F(DbinderTest, DbinderRemoteCall021, TestSize.Level3)
946 {
947     SetCurrentTestCase(DBINDER_TEST_RAW_DATA_004);
948     DBINDER_LOGI(LOG_LABEL, "");
949     /*
950      * @tc.steps: step1.Get a proxy (called testService) from remote server.
951      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
952      */
953     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
954     ASSERT_TRUE(object != nullptr);
955 
956     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
957     ASSERT_TRUE(testService != nullptr);
958 
959     /*
960      * @tc.steps: step2.Use the proxy object to ask stub to transfer raw data.
961      * @tc.expected: step2.Remote call succeed and return 0.
962      */
963     // StubTransRawData cannot ask data less than 2.
964     int result = testService->StubTransRawData(rawData10M);
965     EXPECT_EQ(result, 0);
966     result = testService->StubTransRawData(rawData100M);
967     EXPECT_EQ(result, 0);
968 
969     SetCurrentTestCase(DBINDER_TEST_INIT);
970 }
971 
972 
973 /*
974  * @tc.name: DbinderRemoteCall022
975  * @tc.desc: Test the speed of transferring raw data by stub
976  * @tc.type: PERF
977  * @tc.require: AR000DAPPO
978  */
979 HWTEST_F(DbinderTest, DbinderRemoteCall022, TestSize.Level3)
980 {
981     SetCurrentTestCase(DBINDER_TEST_RAW_DATA_005);
982     DBINDER_LOGI(LOG_LABEL, "");
983 
984     /*
985      * @tc.steps: step1.Get a proxy (called testService) from remote server.
986      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
987      */
988     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
989     ASSERT_TRUE(object != nullptr);
990 
991     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
992     ASSERT_TRUE(testService != nullptr);
993 
994     /*
995      * @tc.steps: step2.Use the proxy object to transfer raw data with different size.
996      * @tc.expected: step2.Remote calls succeed and return the size of raw data.
997      */
998     int result;
999     int64_t startTime = GetCurrentTime();
1000     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
1001         result = testService->StubTransRawData(rawData10K);
1002         EXPECT_EQ(result, 0);
1003     }
1004     int64_t finishTime = GetCurrentTime();
1005     float speed = GetSpeed(finishTime - startTime, rawData10K, MULTIPLEX_TIMES);
1006     printf("Receive 10K raw data with speed of %.2fk/s.\n", speed);
1007 
1008     startTime = GetCurrentTime();
1009     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
1010         result = testService->StubTransRawData(rawData100K);
1011         EXPECT_EQ(result, 0);
1012     }
1013     finishTime = GetCurrentTime();
1014     speed = GetSpeed(finishTime - startTime, rawData100K, MULTIPLEX_TIMES);
1015     printf("Receive 100K raw data with speed of %.2fk/s.\n", speed);
1016 
1017     startTime = GetCurrentTime();
1018     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
1019         result = testService->StubTransRawData(rawData1M);
1020         EXPECT_EQ(result, 0);
1021     }
1022     finishTime = GetCurrentTime();
1023     speed = GetSpeed(finishTime - startTime, rawData1M, MULTIPLEX_TIMES);
1024     printf("Receive 1M raw data with speed of %.2fk/s.\n", speed);
1025 
1026     startTime = GetCurrentTime();
1027     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
1028         result = testService->StubTransRawData(rawData10M);
1029         EXPECT_EQ(result, 0);
1030     }
1031     finishTime = GetCurrentTime();
1032     speed = GetSpeed(finishTime - startTime, rawData10M, MULTIPLEX_TIMES);
1033     printf("Receive 10M raw data with speed of %.2fk/s.\n", speed);
1034 
1035     SetCurrentTestCase(DBINDER_TEST_INIT);
1036 }
1037 
1038 /*
1039  * @tc.name: DbinderRemoteCall023
1040  * @tc.desc: Verify it is stable to transfer raw data by stub
1041  * @tc.type: FUNC
1042  * @tc.require: AR000DAPPO
1043  */
1044 HWTEST_F(DbinderTest, DbinderRemoteCall023, TestSize.Level3)
1045 {
1046     SetCurrentTestCase(DBINDER_TEST_RAW_DATA_006);
1047     DBINDER_LOGI(LOG_LABEL, "");
1048 
1049     /*
1050      * @tc.steps: step1.Get a proxy (called testService) from remote server.
1051      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
1052      */
1053     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1054     ASSERT_TRUE(object != nullptr);
1055 
1056     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
1057     ASSERT_TRUE(testService != nullptr);
1058 
1059     /*
1060      * @tc.steps: step2.Use the proxy object to transfer raw data with different size.
1061      * @tc.expected: step2.Remote calls succeed and return the size of raw data.
1062      */
1063     int result;
1064     for (int i = 0; i < REPEAT_RAW_DATA_TIMES; i++) {
1065         result = testService->StubTransRawData(rawData10M);
1066         EXPECT_EQ(result, 0);
1067     }
1068 
1069     SetCurrentTestCase(DBINDER_TEST_INIT);
1070 }
1071 
1072 /*
1073  * @tc.name: DbinderRemoteCall024
1074  * @tc.desc: trace test
1075  * @tc.type: FUNC
1076  * @tc.require: SR000CPN5H AR000CPN5I AR000CPN5J
1077  */
1078 HWTEST_F(DbinderTest, DbinderRemoteCall024, TestSize.Level3)
1079 {
1080     DBINDER_LOGI(LOG_LABEL, "");
1081     SetCurrentTestCase(DBINDER_TEST_TRACE_001);
1082     HiTraceId traceId = HiTraceChain::Begin("rpc hitrace", 0);
1083 
1084     /*
1085      * @tc.steps: step1.Get a proxy (called testService) from remote server.
1086      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
1087      */
1088     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1089     ASSERT_TRUE(object != nullptr);
1090 
1091     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
1092     ASSERT_TRUE(testService != nullptr);
1093 
1094     /*
1095      * @tc.steps: step2.Use the proxy object to transfer trace id.
1096      * @tc.expected: step2.Remote calls succeed and trace id equal local trace id.
1097      */
1098     uint64_t childId = 0;
1099     int result = testService->GetChildId(childId);
1100     EXPECT_EQ(result, 0);
1101     EXPECT_EQ(childId, traceId.GetChainId());
1102 
1103     SetCurrentTestCase(DBINDER_TEST_INIT);
1104 }
1105 
1106 /*
1107  * @tc.name: DbinderRemoteCall025
1108  * @tc.desc: Test trans stub object
1109  * @tc.type: PERF
1110  * @tc.require: SR000CQSAB AR000DAPPM
1111  */
1112 HWTEST_F(DbinderTest, DbinderRemoteCall025, TestSize.Level3)
1113 {
1114     SetCurrentTestCase(DBINDER_TEST_TRANS_STUB_001);
1115     DBINDER_LOGI(LOG_LABEL, "");
1116 
1117     /*
1118      * @tc.steps: step1.Get a local binder object and a proxy pointing to remote stub.
1119      * @tc.expected: step1.Get both objects successfully.
1120      */
1121     sptr<IRemoteObject> object = new DBinderTestService();
1122     ASSERT_TRUE(object != nullptr);
1123     sptr<IRemoteObject> remoteObject = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1124     ASSERT_TRUE(remoteObject != nullptr);
1125 
1126     sptr<IDBinderTestService> remoteTestService = iface_cast<IDBinderTestService>(remoteObject);
1127     ASSERT_TRUE(remoteTestService != nullptr);
1128 
1129     /*
1130      * @tc.steps: step2.Use the proxy object to transfer stub object
1131      * @tc.expected: step2.Remote call succeeds.
1132      */
1133     int reply = 0;
1134     int stubReply = 0;
1135     int result = remoteTestService->TransStubObject(2019, object, reply, stubReply);
1136     EXPECT_EQ(result, 0);
1137     EXPECT_EQ(reply, 9102);
1138     EXPECT_EQ(stubReply, 2019);
1139 
1140     SetCurrentTestCase(DBINDER_TEST_INIT);
1141 }
1142 
1143 /*
1144  * @tc.name: DbinderRemoteCall026
1145  * @tc.desc: Verify it is stable to transfer raw data by stub
1146  * @tc.type: FUNC
1147  * @tc.require: AR000DHOVU SR000DHOVT
1148  */
1149 HWTEST_F(DbinderTest, DbinderRemoteCall026, TestSize.Level3)
1150 {
1151     SetCurrentTestCase(DBINDER_TEST_FLUSH_COMMAND_001);
1152     DBINDER_LOGI(LOG_LABEL, "");
1153 
1154     /*
1155      * @tc.steps: step1.Get a local binder object and a proxy pointing to remote stub.
1156      * @tc.expected: step1.Get both objects successfully.
1157      */
1158     sptr<IRemoteObject> object = new DBinderTestService();
1159     ASSERT_TRUE(object != nullptr);
1160     sptr<IRemoteObject> remoteObject = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1161     ASSERT_TRUE(remoteObject != nullptr);
1162 
1163     sptr<IDBinderTestService> remoteTestService = iface_cast<IDBinderTestService>(remoteObject);
1164     ASSERT_TRUE(remoteTestService != nullptr);
1165 
1166     /*
1167      * @tc.steps: step2.Use the proxy object to flush commands
1168      * @tc.expected: step2.Remote call succeeds.
1169      */
1170     int result = remoteTestService->FlushAsyncCommands(MULTIPLEX_TIMES, rawData10K);
1171     EXPECT_EQ(result, 0);
1172 
1173     SetCurrentTestCase(DBINDER_TEST_INIT);
1174 }
1175 
1176 /*
1177  * @tc.name: DbinderRemoteCall027
1178  * @tc.desc: Death notice for anonymous objects
1179  * @tc.type: FUNC
1180  * @tc.require: SR000DP5BC
1181  */
1182 HWTEST_F(DbinderTest, DbinderRemoteCall027, TestSize.Level3)
1183 {
1184     SetCurrentTestCase(DBINDER_TEST_DEATH_RECIPIENT_007);
1185     DBINDER_LOGI(LOG_LABEL, "");
1186 
1187     /*
1188      * @tc.steps: step1.Get a proxy (called testService) from remote server.
1189      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
1190      */
1191     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1192     ASSERT_TRUE(object != nullptr);
1193 
1194     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
1195     ASSERT_TRUE(testService != nullptr);
1196 
1197     /*
1198      * @tc.steps: step2.Get two anonymous objects.
1199      * @tc.expected: step2.Get the proxy successfully, and the proxy points to remote stub.
1200      */
1201     sptr<IRemoteObject> proxy1 = testService->GetRemoteObject(IDBinderTestService::FIRST_OBJECT);
1202     ASSERT_TRUE(proxy1 != nullptr);
1203 
1204     sptr<IRemoteObject> proxy2 = testService->GetRemoteObject(IDBinderTestService::SECOND_OBJECT);
1205     ASSERT_TRUE(proxy2 != nullptr);
1206 
1207     sptr<IDBinderTestService> remoteTestService1 = iface_cast<IDBinderTestService>(proxy1);
1208     ASSERT_TRUE(remoteTestService1 != nullptr);
1209 
1210     sptr<IDBinderTestService> remoteTestService2 = iface_cast<IDBinderTestService>(proxy2);
1211     ASSERT_TRUE(remoteTestService2 != nullptr);
1212 
1213     /*
1214      * @tc.steps: step3.Use the proxy object to invoke remote function.
1215      * @tc.expected: step3.Remote call succeeds and returns 0.
1216      */
1217     int reply;
1218     int result = remoteTestService1->ReverseInt(2019, reply);
1219     EXPECT_EQ(result, 0);
1220     EXPECT_EQ(reply, 9102);
1221 
1222     result = remoteTestService2->ReverseInt(2019, reply);
1223     EXPECT_EQ(result, 0);
1224     EXPECT_EQ(reply, 9102);
1225 
1226     /*
1227      * @tc.steps: step4.Add death recipient.
1228      * @tc.expected: step4.Register death notification successfully.
1229      */
1230     sptr<IRemoteObject::DeathRecipient> deathRecipient1(new DBinderTestDeathRecipient());
1231     bool ret = proxy1->AddDeathRecipient(deathRecipient1);
1232     ASSERT_TRUE(ret == true);
1233 
1234     sptr<IRemoteObject::DeathRecipient> deathRecipient2(new DBinderTestDeathRecipient());
1235     ret = proxy2->AddDeathRecipient(deathRecipient2);
1236     ASSERT_TRUE(ret == true);
1237 
1238     /*
1239      * @tc.steps: step5.Stop remote service. Wait 10s, then check death notification.
1240      * @tc.expected: step5.Stop it successfully, and receive death notification.
1241      */
1242     std::string command = "KILL";
1243     std::string cmdArgs = "server";
1244     std::string expectValue = "0";
1245     ret = RunCmdOnAgent(AGENT_NO::ONE, command, cmdArgs, expectValue);
1246     EXPECT_EQ(ret, true);
1247     EXPECT_EQ(GetReturnVal(), 0);
1248 
1249     // wait for killing remote service
1250     sleep(10);
1251     EXPECT_EQ(DBinderTestDeathRecipient::GotDeathRecipient(), true);
1252     EXPECT_EQ(DBinderTestDeathRecipient::GotDeathRecipient(), true);
1253     DBinderTestDeathRecipient::ClearDeathRecipient();
1254     printf("Succ! Recv death notification!\n");
1255 
1256     /*
1257      * @tc.steps: step6.Remove death recipient
1258      * @tc.expected: step6.Fail to remove death recipient
1259      * because when receiving death notification, it remove death recipient automatically.
1260      */
1261     ret = proxy1->RemoveDeathRecipient(deathRecipient1);
1262     EXPECT_EQ(ret, false);
1263 
1264     ret = proxy2->RemoveDeathRecipient(deathRecipient2);
1265     EXPECT_EQ(ret, false);
1266 
1267     /*
1268      * @tc.steps: step7.Restart remote service and wait 10s.
1269      * @tc.expected: step7.Restart it successfully.
1270      */
1271     std::string restartCommand = "RESTART";
1272     ret = RunCmdOnAgent(AGENT_NO::ONE, restartCommand, cmdArgs, expectValue);
1273     EXPECT_EQ(ret, true);
1274     EXPECT_EQ(GetReturnVal(), 0);
1275 
1276     // wait for restarting server
1277     sleep(10);
1278 
1279     /*
1280      * @tc.steps: step8.Get a proxy (called testService2) from remote server.
1281      * @tc.expected: step8.Get the proxy successfully, and the proxy points to remote stub.
1282      */
1283     sptr<IRemoteObject> object2 = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1284     ASSERT_TRUE(object2 != nullptr);
1285 
1286     sptr<IDBinderTestService> testService2 = iface_cast<IDBinderTestService>(object2);
1287     ASSERT_TRUE(testService2 != nullptr);
1288 
1289     /*
1290      * @tc.steps: step9.Use the proxy object to invoke remote function.
1291      * @tc.expected: step9.Remote call succeeds and returns 0.
1292      */
1293     result = testService2->ReverseInt(2019, reply);
1294     EXPECT_EQ(result, 0);
1295     EXPECT_EQ(reply, 9102);
1296 
1297     object = nullptr;
1298     testService = nullptr;
1299     object2 = nullptr;
1300     testService2 = nullptr;
1301 
1302     SetCurrentTestCase(DBINDER_TEST_INIT);
1303 }
1304 
1305 /*
1306  * @tc.name: DbinderRemoteCall028
1307  * @tc.desc: Death notice for anonymous objects
1308  * @tc.type: FUNC
1309  * @tc.require: SR000CS1C8/SR000CS1CA
1310  */
1311 HWTEST_F(DbinderTest, DbinderRemoteCall028, TestSize.Level3)
1312 {
1313     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_015);
1314     DBINDER_LOGI(LOG_LABEL, "");
1315 
1316     /*
1317      * @tc.steps: step1.Get a proxy (called testService) from remote server.
1318      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
1319      */
1320     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1321     ASSERT_TRUE(object != nullptr);
1322 
1323     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
1324     ASSERT_TRUE(testService != nullptr);
1325 
1326     /*
1327      * @tc.steps: step2.Get two anonymous objects.
1328      * @tc.expected: step2.Get the proxy successfully, and the proxy points to remote stub.
1329      */
1330     sptr<IRemoteObject> proxy1 = testService->GetRemoteObject(IDBinderTestService::FIRST_OBJECT);
1331     ASSERT_TRUE(proxy1 != nullptr);
1332 
1333     sptr<IRemoteObject> proxy2 = testService->GetRemoteObject(IDBinderTestService::FIRST_OBJECT);
1334     ASSERT_TRUE(proxy2 != nullptr);
1335 
1336     sptr<IDBinderTestService> remoteTestService1 = iface_cast<IDBinderTestService>(proxy1);
1337     ASSERT_TRUE(remoteTestService1 != nullptr);
1338 
1339     sptr<IDBinderTestService> remoteTestService2 = iface_cast<IDBinderTestService>(proxy2);
1340     ASSERT_TRUE(remoteTestService2 != nullptr);
1341 
1342     /*
1343      * @tc.steps: step3.Use the proxy object to invoke remote function.
1344      * @tc.expected: step3.Remote call succeeds and returns 0.
1345      */
1346     int reply;
1347     int result = remoteTestService1->ReverseInt(2019, reply);
1348     EXPECT_EQ(result, 0);
1349     EXPECT_EQ(reply, 9102);
1350 
1351     result = remoteTestService2->ReverseInt(2019, reply);
1352     EXPECT_EQ(result, 0);
1353     EXPECT_EQ(reply, 9102);
1354 
1355     testService->ClearRemoteDecTimes();
1356 
1357     proxy1 = nullptr;
1358     remoteTestService1 = nullptr;
1359     EXPECT_EQ(testService->GetRemoteDecTimes(), 1);
1360 
1361     proxy2 = nullptr;
1362     remoteTestService2 = nullptr;
1363     EXPECT_EQ(testService->GetRemoteDecTimes(), 2);
1364 
1365     object = nullptr;
1366     testService = nullptr;
1367 
1368     SetCurrentTestCase(DBINDER_TEST_INIT);
1369 }
1370 
1371 /*
1372  * @tc.name: DbinderRemoteCall029
1373  * @tc.desc: Death notice for anonymous objects
1374  * @tc.type: FUNC
1375  * @tc.require: SR000CS1C8/SR000CS1CA
1376  */
1377 HWTEST_F(DbinderTest, DbinderRemoteCall029, TestSize.Level3)
1378 {
1379     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_016);
1380     DBINDER_LOGI(LOG_LABEL, "");
1381 
1382     /*
1383      * @tc.steps: step1.Get a proxy (called testService) from remote server.
1384      * @tc.expected: step1.Get the proxy successfully, and the proxy points to remote stub.
1385      */
1386     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1387     ASSERT_TRUE(object != NULL);
1388 
1389     sptr<IDBinderTestService> testService = iface_cast<IDBinderTestService>(object);
1390     ASSERT_TRUE(testService != NULL);
1391 
1392     /*
1393      * @tc.steps: step2.Get two anonymous objects.
1394      * @tc.expected: step2.Get the proxy successfully, and the proxy points to remote stub.
1395      */
1396     sptr<IRemoteObject> proxy1 = testService->GetRemoteObject(IDBinderTestService::SECOND_OBJECT);
1397     ASSERT_TRUE(proxy1 != nullptr);
1398 
1399     sptr<IRemoteObject> proxy2 = testService->GetRemoteObject(IDBinderTestService::SECOND_OBJECT);
1400     ASSERT_TRUE(proxy2 != nullptr);
1401     ASSERT_TRUE(proxy2 == proxy1);
1402 
1403     sptr<IDBinderTestService> remoteTestService1 = iface_cast<IDBinderTestService>(proxy1);
1404     ASSERT_TRUE(remoteTestService1 != nullptr);
1405 
1406     sptr<IDBinderTestService> remoteTestService2 = iface_cast<IDBinderTestService>(proxy2);
1407     ASSERT_TRUE(remoteTestService2 != nullptr);
1408 
1409     /*
1410      * @tc.steps: step3.Use the proxy object to invoke remote function.
1411      * @tc.expected: step3.Remote call succeeds and returns 0.
1412      */
1413     int reply;
1414     int result = remoteTestService1->ReverseInt(2019, reply);
1415     EXPECT_EQ(result, 0);
1416     EXPECT_EQ(reply, 9102);
1417 
1418     result = remoteTestService2->ReverseInt(2019, reply);
1419     EXPECT_EQ(result, 0);
1420     EXPECT_EQ(reply, 9102);
1421 
1422     testService->ClearRemoteDecTimes();
1423 
1424     proxy1 = nullptr;
1425     proxy2 = nullptr;
1426     remoteTestService1 = nullptr;
1427     remoteTestService2 = nullptr;
1428     sleep(1);
1429     EXPECT_EQ(testService->GetRemoteDecTimes(), 1);
1430 
1431     object = nullptr;
1432     testService = nullptr;
1433 
1434     SetCurrentTestCase(DBINDER_TEST_INIT);
1435 }
1436 
1437 /*
1438  * @tc.name: DbinderRemoteCall030
1439  * @tc.desc: Verify transferring objects between remote devices and tranfer to anthor process again
1440  * @tc.type: FUNC
1441  * @tc.require: SR000FL75G
1442  */
1443 HWTEST_F(DbinderTest, DbinderRemoteCall030, TestSize.Level3)
1444 {
1445     SetCurrentTestCase(DBINDER_TEST_REMOTE_CALL_011);
1446     DBINDER_LOGI(LOG_LABEL, "");
1447 
1448     /*
1449      * @tc.steps: step1.Get a local binder object and a proxy pointing to remote stub.
1450      * @tc.expected: step1.Get both objects successfully.
1451      */
1452     sptr<IRemoteObject> object = manager_->GetSystemAbility(RPC_TEST_SERVICE);
1453     ASSERT_TRUE(object != nullptr);
1454     sptr<IRemoteObject> remoteObject = manager_->GetSystemAbility(RPC_TEST_SERVICE, serverId_);
1455     ASSERT_TRUE(remoteObject != nullptr);
1456 
1457     sptr<IDBinderTestService> remoteTestService = iface_cast<IDBinderTestService>(remoteObject);
1458     ASSERT_TRUE(remoteTestService != nullptr);
1459 
1460     /*
1461      * @tc.steps: step2.Transfer the binder object to remote device repeatedly.
1462      * @tc.expected: step2.Remote device receives the object and use it to communicate with server.
1463      */
1464     for (int i = 0; i < MULTIPLEX_TIMES; i++) {
1465         int reply = 0;
1466         int withdrawRes = 0;
1467         int result = remoteTestService->TransProxyObjectAgain(2021, object, DBinderTestServiceProxy::NOT_SAVE,
1468             reply, withdrawRes);
1469         EXPECT_EQ(result, 0);
1470         EXPECT_EQ(reply, 1202);
1471     }
1472 
1473     SetCurrentTestCase(DBINDER_TEST_INIT);
1474 }
1475 
main(int argc,char * argv[])1476 int main(int argc, char *argv[])
1477 {
1478     g_pDistributetestEnv = new DistributeTestEnvironment("major.desc");
1479     testing::AddGlobalTestEnvironment(g_pDistributetestEnv);
1480     testing::GTEST_FLAG(output) = "xml:./";
1481     testing::InitGoogleTest(&argc, argv);
1482     return RUN_ALL_TESTS();
1483 }
1484