Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
bb83984e
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
大约 1 年 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bb83984e
编写于
1月 06, 2022
作者:
L
liubb_0516
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ipc gtest test case
Signed-off-by:
N
liubb_0516
<
liubeibei8@huawei.com
>
上级
886f8df1
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
46 addition
and
51 deletion
+46
-51
ipc/test/unittest/ipc/client/client.cpp
ipc/test/unittest/ipc/client/client.cpp
+16
-15
ipc/test/unittest/ipc/include/ipc_proxy.h
ipc/test/unittest/ipc/include/ipc_proxy.h
+0
-4
ipc/test/unittest/ipc/samgr/samgr.cpp
ipc/test/unittest/ipc/samgr/samgr.cpp
+11
-13
ipc/test/unittest/ipc/server/server.cpp
ipc/test/unittest/ipc/server/server.cpp
+19
-19
未找到文件。
ipc/test/unittest/ipc/client/client.cpp
浏览文件 @
bb83984e
...
...
@@ -15,17 +15,17 @@
#include "gtest/gtest.h"
#include <time.h>
#include <stdlib.h>
#include <ctime>
#include "ipc_proxy.h"
#include "rpc_log.h"
#include "rpc_errno.h"
#include "ipc_skeleton.h"
#include "rpc_errno.h"
#include "rpc_log.h"
#include "serializer.h"
static
SvcIdentity
sidServer
;
namespace
{
constexpr
int32_t
PERFORMANCE_TEST_TIMES
=
100
;
SvcIdentity
sidServer
;
MessageOption
g_option
=
TF_OP_SYNC
;
uint32_t
cbId1
=
-
1
;
...
...
@@ -82,6 +82,7 @@ void ServerDead3()
{
RPC_LOG_INFO
(
"#### server dead callback33 called ... "
);
}
}
using
namespace
testing
::
ext
;
...
...
@@ -168,15 +169,15 @@ HWTEST_F(IpcClientTest, IpcClientTest003, TestSize.Level1)
HWTEST_F
(
IpcClientTest
,
IpcClientTest004
,
TestSize
.
Level0
)
{
RPC_LOG_INFO
(
"============= test case for add death callback ============"
);
int
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead1
,
NULL
,
&
cbId1
);
int
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead1
,
nullptr
,
&
cbId1
);
EXPECT_EQ
(
ret
,
ERR_NONE
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead2
,
NULL
,
&
cbId2
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead2
,
nullptr
,
&
cbId2
);
EXPECT_EQ
(
ret
,
ERR_NONE
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead3
,
NULL
,
&
cbId3
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead3
,
nullptr
,
&
cbId3
);
EXPECT_EQ
(
ret
,
ERR_NONE
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead3
,
NULL
,
&
cbId4
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead3
,
nullptr
,
&
cbId4
);
EXPECT_EQ
(
ret
,
ERR_NONE
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead3
,
NULL
,
&
cbId5
);
// failed
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead3
,
nullptr
,
&
cbId5
);
// failed
EXPECT_EQ
(
ret
,
ERR_INVALID_PARAM
);
}
...
...
@@ -196,7 +197,7 @@ HWTEST_F(IpcClientTest, IpcClientTest005, TestSize.Level0)
HWTEST_F
(
IpcClientTest
,
IpcClientTest006
,
TestSize
.
Level1
)
{
++
sidServer
.
handle
;
int
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead3
,
NULL
,
&
cbId5
);
// failed
int
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead3
,
nullptr
,
&
cbId5
);
// failed
EXPECT_EQ
(
ret
,
ERR_INVALID_PARAM
);
ret
=
RemoveDeathRecipient
(
sidServer
,
cbId3
);
// failed
...
...
@@ -246,7 +247,7 @@ HWTEST_F(IpcClientTest, IpcClientTest008, TestSize.Level2) // 异步性能测
clock_gettime
(
CLOCK_REALTIME
,
&
start
);
for
(
int
i
=
0
;
i
<
PERFORMANCE_TEST_TIMES
;
i
++
)
{
SendRequest
(
sidServer
,
SERVER_OP_ADD
,
&
data2
,
NULL
,
option
,
NULL
);
SendRequest
(
sidServer
,
SERVER_OP_ADD
,
&
data2
,
nullptr
,
option
,
nullptr
);
}
clock_gettime
(
CLOCK_REALTIME
,
&
end
);
...
...
@@ -256,9 +257,9 @@ HWTEST_F(IpcClientTest, IpcClientTest008, TestSize.Level2) // 异步性能测
HWTEST_F
(
IpcClientTest
,
IpcClientTest009
,
TestSize
.
Level0
)
{
int
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead1
,
NULL
,
&
cbId1
);
int
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead1
,
nullptr
,
&
cbId1
);
EXPECT_EQ
(
ret
,
ERR_NONE
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead2
,
NULL
,
&
cbId2
);
ret
=
AddDeathRecipient
(
sidServer
,
(
OnRemoteDead
)
ServerDead2
,
nullptr
,
&
cbId2
);
EXPECT_EQ
(
ret
,
ERR_NONE
);
JoinWorkThread
();
}
...
...
ipc/test/unittest/ipc/include/ipc_proxy.h
浏览文件 @
bb83984e
...
...
@@ -41,10 +41,6 @@ enum {
SERVER_SA_ID2
=
18
,
};
#define IPC_TEST_TIME_INTERVAL 120
#define PERFORMANCE_TEST_TIMES 100
#define OP_A 12
#define OP_B 17
...
...
ipc/test/unittest/ipc/samgr/samgr.cpp
浏览文件 @
bb83984e
...
...
@@ -13,16 +13,12 @@
* limitations under the License.
*/
#include "ipc_proxy.h"
#include "gtest/gtest.h"
#include <stdlib.h>
#include <string.h>
#include "rpc_log.h"
#include "rpc_errno.h"
#include "ipc_proxy.h"
#include "ipc_skeleton.h"
#include "rpc_errno.h"
#include "rpc_log.h"
#include "serializer.h"
#include "utils_list.h"
...
...
@@ -32,12 +28,13 @@ typedef struct {
SvcIdentity
*
sid
;
}
SvcInfo
;
static
UTILS_DL_LIST
*
g_saList
=
NULL
;
static
int32_t
g_saSum
=
0
;
namespace
{
UTILS_DL_LIST
*
g_saList
=
nullptr
;
int32_t
g_saSum
=
0
;
int32_t
AddSystemAbility
(
int32_t
saId
,
SvcIdentity
*
sid
)
{
if
(
g_saList
==
NULL
)
{
if
(
g_saList
==
nullptr
)
{
return
ERR_FAILED
;
}
...
...
@@ -52,8 +49,8 @@ int32_t AddSystemAbility(int32_t saId, SvcIdentity *sid)
int32_t
GetSystemAbility
(
int32_t
saId
,
const
char
*
deviceId
,
SvcIdentity
*
sid
)
{
SvcInfo
*
node
=
NULL
;
SvcInfo
*
next
=
NULL
;
SvcInfo
*
node
=
nullptr
;
SvcInfo
*
next
=
nullptr
;
UTILS_DL_LIST_FOR_EACH_ENTRY_SAFE
(
node
,
next
,
g_saList
,
SvcInfo
,
list
)
{
if
(
node
->
saId
==
saId
)
{
...
...
@@ -103,12 +100,13 @@ int32_t mainFunc(void)
RPC_LOG_INFO
(
"Enter System Ability Manager .... "
);
g_saList
=
(
UTILS_DL_LIST
*
)
calloc
(
1
,
sizeof
(
UTILS_DL_LIST
));
if
(
g_saList
==
NULL
)
{
if
(
g_saList
==
nullptr
)
{
return
-
1
;
}
UtilsListInit
(
g_saList
);
return
ERR_NONE
;
}
}
using
namespace
testing
::
ext
;
...
...
ipc/test/unittest/ipc/server/server.cpp
浏览文件 @
bb83984e
...
...
@@ -13,25 +13,24 @@
* limitations under the License.
*/
#include "ipc_proxy.h"
#include "gtest/gtest.h"
#include <stdlib.h>
#include <pthread.h>
#include "rpc_log.h"
#include "rpc_errno.h"
#include "rpc_log.h"
#include "ipc_proxy.h"
#include "ipc_skeleton.h"
#include "serializer.h"
#include <unistd.h>
static
SvcIdentity
*
sid
=
NULL
;
namespace
{
constexpr
uint32_t
IPC_TEST_TIME_INTERVAL
=
120
;
SvcIdentity
*
sid
=
nullptr
;
MessageOption
g_option
=
TF_OP_SYNC
;
static
void
CallAnonymosFunc
(
const
char
*
str
)
void
CallAnonymosFunc
(
const
char
*
str
)
{
if
(
sid
==
NULL
)
{
if
(
sid
==
nullptr
)
{
RPC_LOG_INFO
(
"invalid anonymous client"
);
return
;
}
...
...
@@ -43,7 +42,7 @@ static void CallAnonymosFunc(const char *str)
IpcIo
reply
;
MessageOption
option
=
TF_OP_ASYNC
;
SendRequest
(
*
sid
,
CLIENT_OP_PRINT
,
&
data
,
&
reply
,
option
,
NULL
);
SendRequest
(
*
sid
,
CLIENT_OP_PRINT
,
&
data
,
&
reply
,
option
,
nullptr
);
}
int32_t
RemoteRequestOne
(
uint32_t
code
,
IpcIo
*
data
,
IpcIo
*
reply
,
MessageOption
option
)
...
...
@@ -123,37 +122,38 @@ int32_t RemoteRequestTwo(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption
return
result
;
}
static
void
*
ThreadHandler
(
void
*
args
)
void
*
ThreadHandler
(
void
*
args
)
{
sleep
(
IPC_TEST_TIME_INTERVAL
);
// sleep 2 min
const
char
*
str
=
"server call anonymos service new thread."
;
CallAnonymosFunc
(
str
);
return
NULL
;
return
nullptr
;
}
static
IpcObjectStub
objectStubOne
=
{
IpcObjectStub
objectStubOne
=
{
.
func
=
RemoteRequestOne
,
.
isRemote
=
false
};
static
IpcObjectStub
objectStubTwo
=
{
IpcObjectStub
objectStubTwo
=
{
.
func
=
RemoteRequestTwo
,
.
isRemote
=
false
};
static
SvcIdentity
svcOne
=
{
SvcIdentity
svcOne
=
{
.
handle
=
-
1
,
.
token
=
(
uintptr_t
)
&
objectStubOne
,
.
cookie
=
(
uintptr_t
)
&
objectStubOne
};
static
SvcIdentity
svcTwo
=
{
SvcIdentity
svcTwo
=
{
.
handle
=
-
1
,
.
token
=
(
uintptr_t
)
&
objectStubTwo
,
.
cookie
=
(
uintptr_t
)
&
objectStubTwo
};
static
SvcIdentity
sidOne
;
SvcIdentity
sidOne
;
}
using
namespace
testing
::
ext
;
...
...
@@ -178,7 +178,7 @@ HWTEST_F(IpcServerTest, IpcServerTest001, TestSize.Level1)
uint8_t
tmpData1
[
IPC_MAX_SIZE
];
IpcIoInit
(
&
data
,
tmpData1
,
IPC_MAX_SIZE
,
1
);
WriteInt32
(
&
data
,
SERVER_SA_ID1
);
bool
res
=
WriteRemoteObject
(
NULL
,
&
svcOne
);
bool
res
=
WriteRemoteObject
(
nullptr
,
&
svcOne
);
EXPECT_EQ
(
res
,
false
);
}
...
...
@@ -188,7 +188,7 @@ HWTEST_F(IpcServerTest, IpcServerTest002, TestSize.Level1)
uint8_t
tmpData1
[
IPC_MAX_SIZE
];
IpcIoInit
(
&
data
,
tmpData1
,
IPC_MAX_SIZE
,
1
);
WriteInt32
(
&
data
,
SERVER_SA_ID1
);
bool
res
=
WriteRemoteObject
(
&
data
,
NULL
);
bool
res
=
WriteRemoteObject
(
&
data
,
nullptr
);
EXPECT_EQ
(
res
,
false
);
}
...
...
@@ -275,7 +275,7 @@ HWTEST_F(IpcServerTest, IpcServerTest006, TestSize.Level0)
HWTEST_F
(
IpcServerTest
,
IpcServerTest007
,
TestSize
.
Level0
)
{
pthread_t
pid
;
pthread_create
(
&
pid
,
NULL
,
ThreadHandler
,
NULL
);
pthread_create
(
&
pid
,
nullptr
,
ThreadHandler
,
nullptr
);
pthread_detach
(
pid
);
JoinWorkThread
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录