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