mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-12-01 03:50:50 +00:00
fix:Add multi-threaded scenario use cases
Signed-off-by: chenchong_666 <chenchong57@huawei.com>
This commit is contained in:
parent
0355448be8
commit
ad3fe4ca13
@ -55,6 +55,7 @@ public:
|
||||
int TestUnRegisterRemoteStub(const char *descriptor) override;
|
||||
sptr<IRemoteObject> TestQueryRemoteProxy(const char *descriptor) override;
|
||||
int TestSendTooManyRequest(int data, int &reply) override;
|
||||
int TestMultiThreadSendRequest(int data, int &reply) override;
|
||||
private:
|
||||
int testFd_;
|
||||
std::mutex remoteObjectsMutex_;
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
void TestRegisterRemoteStub();
|
||||
void TestUnRegisterRemoteStub();
|
||||
void TestSendTooManyRequest();
|
||||
void TestMultiThreadSendRequest();
|
||||
|
||||
private:
|
||||
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_TEST, "TestServiceClient" };
|
||||
|
@ -31,5 +31,6 @@ enum TestCommand {
|
||||
TEST_CMD_NATIVE_IPC_REGISTER_REMOTE_STUB_OBJECT = 12,
|
||||
TEST_CMD_NATIVE_IPC_REQUESTS = 13,
|
||||
TEST_CMD_TOO_MANY_SENDREQUEST = 14,
|
||||
TEST_CMD_MULTI_THREAD_SEND = 15,
|
||||
};
|
||||
#endif // OHOS_IPC_TEST_SERVICE_COMMAND_H
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
virtual int TestUnRegisterRemoteStub(const char *descriptor) = 0;
|
||||
virtual sptr<IRemoteObject> TestQueryRemoteProxy(const char *descriptor) = 0;
|
||||
virtual int TestSendTooManyRequest(int data, int &reply) = 0;
|
||||
virtual int TestMultiThreadSendRequest(int data, int &reply) = 0;
|
||||
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"test.ipc.ITestService");
|
||||
@ -158,6 +159,7 @@ public:
|
||||
int TestUnRegisterRemoteStub(const char *descriptor) override;
|
||||
sptr<IRemoteObject> TestQueryRemoteProxy(const char *descriptor) override;
|
||||
int TestSendTooManyRequest(int data, int &reply) override;
|
||||
int TestMultiThreadSendRequest(int data, int &reply) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<TestServiceProxy> delegator_;
|
||||
|
@ -121,6 +121,9 @@ int main(int argc, char *argv[])
|
||||
testClient->TestSendTooManyRequest();
|
||||
testClient->StartSyncTransaction();
|
||||
}},
|
||||
{TestCommand::TEST_CMD_MULTI_THREAD_SEND, [&]() {
|
||||
testClient->TestMultiThreadSendRequest();
|
||||
}},
|
||||
};
|
||||
|
||||
auto it = commandMap.find(commandId);
|
||||
|
@ -331,5 +331,10 @@ int TestService::TestSendTooManyRequest(int data, int &reply)
|
||||
(void)reply;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestService::TestMultiThreadSendRequest(int data, int &reply)
|
||||
{
|
||||
(void)data;
|
||||
(void)reply;
|
||||
return 0;
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -232,4 +232,14 @@ void TestServiceClient::TestSendTooManyRequest()
|
||||
}
|
||||
}
|
||||
|
||||
void TestServiceClient::TestMultiThreadSendRequest()
|
||||
{
|
||||
if (testService_ != nullptr) {
|
||||
ZLOGD(LABEL, "TestMultiThreadSendRequest");
|
||||
int ret = 0;
|
||||
int value = 2024;
|
||||
testService_->TestMultiThreadSendRequest(value, ret);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OHOS
|
||||
|
@ -40,6 +40,7 @@ using namespace OHOS::HiviewDFX;
|
||||
|
||||
constexpr int32_t MAX_RECURSIVE_SENDS = 5;
|
||||
constexpr int32_t SEDNREQUEST_TIMES = 50000;
|
||||
constexpr int32_t NUMBER_OF_THREADS = 20;
|
||||
|
||||
void TestServiceStub::InitMessageProcessMap()
|
||||
{
|
||||
@ -132,6 +133,35 @@ int TestServiceProxy::TestSendTooManyRequest(int data, int &reply)
|
||||
return error;
|
||||
}
|
||||
|
||||
int TestServiceProxy::TestMultiThreadSendRequest(int data, int &reply)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
sptr<IRemoteObject> proxyObject = Remote();
|
||||
for (int32_t i = 0; i < NUMBER_OF_THREADS; i++) {
|
||||
// Different threads correspond to different sets of parcels.
|
||||
std::thread t([&proxyObject, &data, &reply] {
|
||||
MessageParcel dataParcel;
|
||||
MessageParcel replyParcel;
|
||||
MessageOption option;
|
||||
if (data > 0) {
|
||||
dataParcel.WriteInt32(data);
|
||||
dataParcel.WriteInt32(0);
|
||||
}
|
||||
int error = proxyObject->SendRequest(TRANS_ID_SYNC_TRANSACTION, dataParcel, replyParcel, option);
|
||||
if (error != 0) {
|
||||
ZLOGD(LABEL, "SendRequest is failed: %{public}d", error);
|
||||
return;
|
||||
}
|
||||
reply = replyParcel.ReadInt32();
|
||||
});
|
||||
t.detach();
|
||||
std::cout << "Thead: " << i << std::endl;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int TestServiceProxy::TestAsyncTransaction(int data, int timeout)
|
||||
{
|
||||
MessageOption option = { MessageOption::TF_ASYNC };
|
||||
|
Loading…
Reference in New Issue
Block a user