mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-11-27 01:51:13 +00:00
!1011 ut test about GetLastRequestTimeTest
Merge pull request !1011 from xdx1921/master
This commit is contained in:
commit
290be6707b
@ -68,6 +68,8 @@ ohos_unittest("IPCNativeUnitTest") {
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
ldflags = [ "-lpthread" ]
|
||||
|
||||
resource_config_file = "$SUBSYSTEM_DIR/test/resource/ipc/ohos_test.xml"
|
||||
}
|
||||
|
||||
|
@ -649,4 +649,30 @@ HWTEST_F(BinderInvokerUnitTest, GetCallerTokenIDTest003, TestSize.Level1)
|
||||
binderInvoker.callerUid_ = 1;
|
||||
auto ret = binderInvoker.GetCallerTokenID();
|
||||
EXPECT_EQ(ret, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetStrongRefCountForStubTest001
|
||||
* @tc.desc: Override GetStrongRefCountForStub branch
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(BinderInvokerUnitTest, GetStrongRefCountForStubTest001, TestSize.Level1)
|
||||
{
|
||||
BinderInvoker binderInvoker;
|
||||
uint32_t count = binderInvoker.GetStrongRefCountForStub(0);
|
||||
EXPECT_EQ(count, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetStrongRefCountForStubTest002
|
||||
* @tc.desc: Override GetStrongRefCountForStub branch
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(BinderInvokerUnitTest, GetStrongRefCountForStubTest002, TestSize.Level1)
|
||||
{
|
||||
BinderInvoker binderInvoker;
|
||||
BinderConnector *binderConnector = BinderConnector::GetInstance();
|
||||
binderInvoker.binderConnector_ = binderConnector;
|
||||
uint32_t count = binderInvoker.GetStrongRefCountForStub(0);
|
||||
EXPECT_EQ(count, 0);
|
||||
}
|
@ -1317,3 +1317,13 @@ HWTEST_F(IPCObjectProxyTest, ReleaseDatabusProtoTest004, TestSize.Level1)
|
||||
object->ReleaseDatabusProto();
|
||||
ASSERT_TRUE(object->handle_ != 0);
|
||||
}
|
||||
|
||||
HWTEST_F(IPCObjectProxyTest, GetStrongRefCountForStubTest001, TestSize.Level1)
|
||||
{
|
||||
sptr<IPCObjectProxy> object = new IPCObjectProxy(
|
||||
1, u"test", IPCProcessSkeleton::DBINDER_HANDLE_BASE);
|
||||
|
||||
object->proto_ = IRemoteObject::IF_PROT_DEFAULT;
|
||||
uint32_t count = object->GetStrongRefCountForStub();
|
||||
ASSERT_TRUE(count == 0);
|
||||
}
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
@ -67,6 +68,19 @@ void IPCObjectStubTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
typedef struct GetLastRequestTimeParamStruct {
|
||||
sptr<IPCObjectStub> obj;
|
||||
int ret;
|
||||
} ParamStruct;
|
||||
|
||||
void *GetLastRequestTimeTestThreadFunc(void *args)
|
||||
{
|
||||
ParamStruct* paramStruct = reinterpret_cast<ParamStruct *>(args);
|
||||
paramStruct->ret = paramStruct->obj->GetLastRequestTime();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteDumpTest001
|
||||
* @tc.desc: Verify the OnRemoteDump function
|
||||
@ -180,6 +194,76 @@ HWTEST_F(IPCObjectStubTest, GetLastRequestTimeTest002, TestSize.Level1)
|
||||
ASSERT_TRUE(ret > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLastRequestTimeTest003
|
||||
* @tc.desc: Verify the GetLastRequestTime function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCObjectStubTest, GetLastRequestTimeTest003, TestSize.Level1)
|
||||
{
|
||||
uint32_t code = LAST_CALL_TRANSACTION;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
int times = 1000;
|
||||
vector<sptr<IPCObjectStub>> objectVector;
|
||||
for (int i = 0; i < times; i++) {
|
||||
std::string descriptor = "testStub1" + std::to_string(i);
|
||||
sptr<IPCObjectStub> testStub = new IPCObjectStub(Str8ToStr16(descriptor));
|
||||
objectVector.push_back(testStub);
|
||||
}
|
||||
for (int i = 0; i < times; i++) {
|
||||
objectVector[i]->SendRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
for (int i = 0; i < times; i++) {
|
||||
uint64_t ret = objectVector[i]->GetLastRequestTime();
|
||||
ASSERT_TRUE(ret > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLastRequestTimeTest004
|
||||
* @tc.desc: Verify the GetLastRequestTime function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(IPCObjectStubTest, GetLastRequestTimeTest004, TestSize.Level1)
|
||||
{
|
||||
uint32_t code = LAST_CALL_TRANSACTION;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
sptr<IPCObjectStub> testStub = new IPCObjectStub(u"testStub");
|
||||
testStub->SendRequest(code, data, reply, option);
|
||||
uint64_t ret = testStub->GetLastRequestTime();
|
||||
ASSERT_TRUE(ret > 0);
|
||||
ParamStruct s1;
|
||||
ParamStruct s2;
|
||||
memset_s(&s1, sizeof(ParamStruct), 0, sizeof(ParamStruct));
|
||||
memset_s(&s2, sizeof(ParamStruct), 0, sizeof(ParamStruct));
|
||||
s1.obj = testStub;
|
||||
s1.ret = 0;
|
||||
s2.obj = testStub;
|
||||
s2.ret = 0;
|
||||
pthread_t thread1, thread2;
|
||||
int ret1 = pthread_create(&thread1, NULL, GetLastRequestTimeTestThreadFunc, &s1);
|
||||
int ret2 = pthread_create(&thread2, NULL, GetLastRequestTimeTestThreadFunc, &s2);
|
||||
|
||||
if (ret1 == 0) {
|
||||
pthread_join(thread1, NULL);
|
||||
}
|
||||
if (ret2 == 0) {
|
||||
pthread_join(thread2, NULL);
|
||||
}
|
||||
EXPECT_NE(s1.ret, 0);
|
||||
EXPECT_NE(s2.ret, 0);
|
||||
EXPECT_EQ(s1.ret, s2.ret);
|
||||
EXPECT_EQ(s1.ret, ret);
|
||||
}
|
||||
|
||||
|
||||
#ifndef CONFIG_IPC_SINGLE
|
||||
/**
|
||||
* @tc.name: SendRequestTest005
|
||||
|
Loading…
Reference in New Issue
Block a user