Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
3203c419
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,发现更多精彩内容 >>
提交
3203c419
编写于
4月 21, 2022
作者:
Y
yangguangzhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
RPC testcases for version control and access token
Signed-off-by:
N
yangguangzhao
<
yangguangzhao1@huawei.com
>
上级
d3d52ceb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
77 addition
and
185 deletion
+77
-185
ipc/native/c/rpc/src/rpc_feature_set.c
ipc/native/c/rpc/src/rpc_feature_set.c
+8
-8
services/dbinder/test/moduletest/BUILD.gn
services/dbinder/test/moduletest/BUILD.gn
+1
-2
services/dbinder/test/moduletest/include/rpc_test.h
services/dbinder/test/moduletest/include/rpc_test.h
+13
-33
services/dbinder/test/moduletest/src/rpc_client_test.cpp
services/dbinder/test/moduletest/src/rpc_client_test.cpp
+30
-35
services/dbinder/test/moduletest/src/rpc_server_test.cpp
services/dbinder/test/moduletest/src/rpc_server_test.cpp
+7
-21
services/dbinder/test/moduletest/src/rpc_test.cpp
services/dbinder/test/moduletest/src/rpc_test.cpp
+18
-86
未找到文件。
ipc/native/c/rpc/src/rpc_feature_set.c
浏览文件 @
3203c419
...
...
@@ -15,14 +15,14 @@
#include "rpc_feature_set.h"
#define RPC_FEATURE_LAST
(43)
#define RPC_FEATURE_LAST
43
#define RPC_ACCESS_TOKEN_FLAG 0x1
static
const
uint32_t
RPC_FEATURE_MAGIC_NUM
=
(
'R'
<<
24
)
|
(
'F'
<<
16
)
|
(
'S'
<<
8
)
|
RPC_FEATURE_LAST
;
static
const
uint32_t
RPC_ACCESS_TOKEN
=
0
;
static
const
uint32_t
R
pcFeatureFlag
=
0x1
;
static
const
uint32_t
T
okenIdSize
=
4
;
static
const
uint32_t
R
pcFeatureAck
=
0x80000000
;
static
const
uint32_t
R
PC_FEATURE_FLAG
=
0x1
;
static
const
uint32_t
T
OKEN_ID_SIZE
=
4
;
static
const
uint32_t
R
PC_FEATURE_ACK
=
0x80000000
;
uint32_t
GetFeatureMagicNumber
(
void
)
{
...
...
@@ -36,12 +36,12 @@ uint32_t GetFeatureATTag(void)
uint32_t
GetLocalRpcFeature
(
void
)
{
return
R
pcFeatureFlag
;
return
R
PC_FEATURE_FLAG
;
}
uint32_t
GetRpcFeatureAck
(
void
)
{
return
R
pcFeatureAck
;
return
R
PC_FEATURE_ACK
;
}
bool
IsATEnable
(
uint32_t
featureSet
)
...
...
@@ -51,7 +51,7 @@ bool IsATEnable(uint32_t featureSet)
bool
IsFeatureAck
(
uint32_t
featureSet
)
{
return
(
featureSet
&
R
pcFeatureAck
)
>
0
;
return
(
featureSet
&
R
PC_FEATURE_ACK
)
>
0
;
}
size_t
GetATSize
(
uint32_t
featureSet
)
...
...
@@ -65,5 +65,5 @@ size_t GetATSize(uint32_t featureSet)
uint32_t
GetTokenIdSize
(
void
)
{
return
T
okenIdSize
;
return
T
OKEN_ID_SIZE
;
}
\ No newline at end of file
services/dbinder/test/moduletest/BUILD.gn
浏览文件 @
3203c419
...
...
@@ -24,6 +24,7 @@ ohos_moduletest("RPCCLIENTTEST") {
"include",
"${SUBSYSTEM_DIR}/utils/include",
"${SUBSYSTEM_DIR}/ipc/native/c/adapter/access_token/include",
"${SUBSYSTEM_DIR}/ipc/native/c/rpc/include",
]
sources = [
"src/rpc_client_test.cpp",
...
...
@@ -37,7 +38,6 @@ ohos_moduletest("RPCCLIENTTEST") {
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr_standard:samgr_proxy",
]
...
...
@@ -61,7 +61,6 @@ ohos_moduletest("RPCSERVERTEST") {
external_deps = [
"dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"samgr_standard:samgr_proxy",
]
...
...
services/dbinder/test/moduletest/include/rpc_test.h
浏览文件 @
3203c419
...
...
@@ -16,16 +16,12 @@
#ifndef OHOS_RPC_FOO_TEST_H
#define OHOS_RPC_FOO_TEST_H
#include <mutex>
#include <condition_variable>
#include "iremote_broker.h"
#include "iremote_proxy.h"
#include "iremote_stub.h"
#include "hilog/log.h"
#include "log_tags.h"
namespace
OHOS
{
class
I
Foo
:
public
IRemoteBroker
{
class
I
RpcFooTest
:
public
IRemoteBroker
{
public:
enum
FooInterFaceId
{
GET_FOO_NAME
=
0
,
...
...
@@ -33,47 +29,31 @@ public:
SEND_WRONG_REPLY
=
2
,
GET_TOKENID
=
3
,
};
virtual
std
::
string
GetFooName
()
=
0
;
virtual
void
SendAsyncReply
(
int
&
reply
)
=
0
;
virtual
int
TestNestingSend
(
int
sendCode
)
=
0
;
std
::
string
GetFooName
(
void
);
virtual
std
::
string
TestGetFooName
(
void
)
=
0
;
virtual
uint32_t
TestAccessToken
(
void
)
=
0
;
public:
DECLARE_INTERFACE_DESCRIPTOR
(
u"test.ipc.IFoo"
);
DECLARE_INTERFACE_DESCRIPTOR
(
u"test.rpc.IRpcFooTest"
);
private:
std
::
string
fooName_
=
"IRpcFooTest"
;
};
class
FooStub
:
public
IRemoteStub
<
IFoo
>
{
class
RpcFooStub
:
public
IRemoteStub
<
IRpcFooTest
>
{
public:
virtual
~
FooStub
();
int
OnRemoteRequest
(
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
)
override
;
std
::
string
GetFooName
()
override
;
void
SendAsyncReply
(
int
&
reply
)
override
;
int
WaitForAsyncReply
(
int
timeout
);
static
void
CleanDecTimes
();
static
int
GetDecTimes
();
int
TestNestingSend
(
int
sendCode
)
override
;
std
::
string
TestGetFooName
(
void
)
override
;
uint32_t
TestAccessToken
(
void
)
override
;
public:
static
std
::
mutex
decTimeMutex_
;
static
int
decTimes_
;
private:
int
asyncReply_
=
{
0
};
std
::
mutex
mutex_
;
std
::
condition_variable
cv_
;
static
constexpr
HiviewDFX
::
HiLogLabel
LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"FooStub"
};
};
class
FooProxy
:
public
IRemoteProxy
<
IFoo
>
{
class
RpcFooProxy
:
public
IRemoteProxy
<
IRpcFooTest
>
{
public:
explicit
FooProxy
(
const
sptr
<
IRemoteObject
>
&
impl
);
~
FooProxy
()
=
default
;
std
::
string
GetFooName
()
override
;
void
SendAsyncReply
(
int
&
reply
)
override
;
int
TestNestingSend
(
int
sendCode
)
override
;
explicit
RpcFooProxy
(
const
sptr
<
IRemoteObject
>
&
impl
);
~
RpcFooProxy
()
=
default
;
std
::
string
TestGetFooName
(
void
)
override
;
uint32_t
TestAccessToken
(
void
)
override
;
private:
static
constexpr
HiviewDFX
::
HiLogLabel
LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"FooProxy"
};
static
inline
BrokerDelegator
<
FooProxy
>
delegator_
;
static
inline
BrokerDelegator
<
RpcFooProxy
>
delegator_
;
};
}
// namespace OHOS
#endif // OHOS_RPC_FOO_TEST_H
...
...
services/dbinder/test/moduletest/src/rpc_client_test.cpp
浏览文件 @
3203c419
...
...
@@ -22,67 +22,62 @@
#include "ipc_object_proxy.h"
#include "rpc_test.h"
#include "access_token_adapter.h"
#include "
log_tags
.h"
#include "
rpc_feature_set
.h"
namespace
OHOS
{
#ifndef TITLE
#define TITLE __PRETTY_FUNCTION__
#endif
using
namespace
testing
::
ext
;
using
namespace
OHOS
;
using
namespace
OHOS
::
HiviewDFX
;
static
constexpr
HiLogLabel
LOG_LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"RPCClientTest"
};
#define DBINDER_LOGE(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
#define DBINDER_LOGI(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
static
std
::
string
g_deviceId
;
class
RPCClientTest
:
public
testing
::
Test
{
static
sptr
<
IRpcFooTest
>
g_rpcTestProxy
;
class
RpcClientTest
:
public
testing
::
Test
{
public:
static
constexpr
int
saId
=
RPC_TEST_SERVICE
;
static
constexpr
char
DBINDER_PKG_NAME
[]
=
"DBinderService"
;
static
constexpr
int
NODE_NUM
=
4
;
static
void
SetUpTestCase
(
void
);
static
void
TearDownTestCase
(
void
);
};
void
R
PC
ClientTest
::
SetUpTestCase
()
void
R
pc
ClientTest
::
SetUpTestCase
()
{
NodeBasicInfo
*
nodeInfo
[
NODE_NUM
];
int32_t
infoNum
=
NODE_NUM
;
int32_t
ret
=
GetAllNodeDeviceInfo
(
DBINDER_PKG_NAME
,
nodeInfo
,
&
infoNum
);
if
(
ret
!=
0
)
{
DBINDER_LOGE
(
"get local node ret %{public}d"
,
ret
);
return
;
}
if
(
infoNum
==
0
)
{
DBINDER_LOGE
(
"get no online nodes"
);
return
;
}
ASSERT_EQ
(
ret
,
0
);
ASSERT_NE
(
infoNum
,
0
);
g_deviceId
=
nodeInfo
[
0
]
->
networkId
;
DBINDER_LOGI
(
"get deviceid %{public}s"
,
g_deviceId
.
c_str
());
}
void
R
PC
ClientTest
::
TearDownTestCase
()
{}
void
R
pc
ClientTest
::
TearDownTestCase
()
{}
HWTEST_F
(
R
PC
ClientTest
,
function_test_001
,
TestSize
.
Level1
)
HWTEST_F
(
R
pc
ClientTest
,
function_test_001
,
TestSize
.
Level1
)
{
DBINDER_LOGI
(
"Start RPCClient Testcase001"
);
// service instance
auto
saMgr
=
SystemAbilityManagerClient
::
GetInstance
().
GetSystemAbilityManager
();
EXPECT_TRUE
(
saMgr
!
=
nullptr
);
ASSERT_FALSE
(
saMgr
=
=
nullptr
);
sptr
<
IRemoteObject
>
object
=
saMgr
->
GetSystemAbility
(
I
PC_TEST_SERVICE
,
g_deviceId
);
ASSERT_TRUE
(
object
!=
nullptr
);
sptr
<
IRemoteObject
>
object
=
saMgr
->
GetSystemAbility
(
R
PC_TEST_SERVICE
,
g_deviceId
);
ASSERT_TRUE
(
object
!=
nullptr
)
<<
"deviceid is "
<<
g_deviceId
;
sptr
<
IFoo
>
testService
=
iface_cast
<
IFoo
>
(
object
);
ASSERT_TRUE
(
testService
!=
nullptr
);
g_rpcTestProxy
=
iface_cast
<
IRpcFooTest
>
(
object
);
ASSERT_TRUE
(
g_rpcTestProxy
!=
nullptr
);
}
HWTEST_F
(
RpcClientTest
,
function_test_002
,
TestSize
.
Level1
)
{
std
::
string
fooName
=
g_rpcTestProxy
->
TestGetFooName
();
std
::
string
selfFooName
=
g_rpcTestProxy
->
GetFooName
();
ASSERT_TRUE
(
fooName
==
selfFooName
)
<<
"fooName: "
<<
fooName
<<
" fooName_: "
<<
selfFooName
;
}
HWTEST_F
(
RpcClientTest
,
function_test_003
,
TestSize
.
Level1
)
{
uint32_t
tokenId
=
RpcGetSelfTokenID
();
uint32_t
getTokenId
=
testService
->
TestAccessToken
();
ASSERT_EQ
(
tokenId
,
getTokenId
);
uint32_t
getTokenId
=
g_rpcTestProxy
->
TestAccessToken
();
if
(
IsATEnable
(
GetLocalRpcFeature
())
==
true
)
{
ASSERT_EQ
(
tokenId
,
getTokenId
)
<<
"deviceid is "
<<
g_deviceId
;
}
else
{
ASSERT_EQ
(
getTokenId
,
0
)
<<
"deviceid is "
<<
g_deviceId
;
}
}
}
\ No newline at end of file
services/dbinder/test/moduletest/src/rpc_server_test.cpp
浏览文件 @
3203c419
...
...
@@ -19,43 +19,29 @@
#include "iservice_registry.h"
#include "ipc_skeleton.h"
#include "rpc_test.h"
#include "log_tags.h"
namespace
OHOS
{
#ifndef TITLE
#define TITLE __PRETTY_FUNCTION__
#endif
using
namespace
testing
::
ext
;
using
namespace
OHOS
;
using
namespace
OHOS
::
HiviewDFX
;
static
constexpr
HiLogLabel
LOG_LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"RPCServerTest"
};
#define DBINDER_LOGE(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
#define DBINDER_LOGI(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
class
R
PC
ServerTest
:
public
testing
::
Test
{
class
R
pc
ServerTest
:
public
testing
::
Test
{
public:
static
constexpr
int
saId
=
RPC_TEST_SERVICE
;
static
void
SetUpTestCase
(
void
);
static
void
TearDownTestCase
(
void
);
};
void
R
PC
ServerTest
::
SetUpTestCase
()
{}
void
R
pc
ServerTest
::
SetUpTestCase
()
{}
void
R
PC
ServerTest
::
TearDownTestCase
()
{}
void
R
pc
ServerTest
::
TearDownTestCase
()
{}
HWTEST_F
(
R
PC
ServerTest
,
function_test_001
,
TestSize
.
Level1
)
HWTEST_F
(
R
pc
ServerTest
,
function_test_001
,
TestSize
.
Level1
)
{
DBINDER_LOGI
(
"Start RPCServer Testcase001"
);
auto
saMgr
=
SystemAbilityManagerClient
::
GetInstance
().
GetSystemAbilityManager
();
EXPEC
T_TRUE
(
saMgr
!=
nullptr
);
ASSER
T_TRUE
(
saMgr
!=
nullptr
);
ISystemAbilityManager
::
SAExtraProp
saExtra
;
saExtra
.
isDistributed
=
true
;
// 设置为分布式SA
int
result
=
saMgr
->
AddSystemAbility
(
saId
,
new
FooStub
(),
saExtra
);
saExtra
.
isDistributed
=
true
;
int
result
=
saMgr
->
AddSystemAbility
(
RPC_TEST_SERVICE
,
new
Rpc
FooStub
(),
saExtra
);
ASSERT_EQ
(
result
,
0
);
IPCSkeleton
::
JoinWorkThread
();
...
...
services/dbinder/test/moduletest/src/rpc_test.cpp
浏览文件 @
3203c419
/*
* Copyright (C) 202
1
Huawei Device Co., Ltd.
* Copyright (C) 202
2
Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
...
...
@@ -15,32 +15,24 @@
#include "rpc_test.h"
#include "ipc_skeleton.h"
#include "ipc_debug.h"
#include "ipc_types.h"
namespace
OHOS
{
std
::
mutex
FooStub
::
decTimeMutex_
;
int
FooStub
::
decTimes_
=
0
;
std
::
string
IRpcFooTest
::
GetFooName
()
{
return
fooName_
;
}
int
FooStub
::
OnRemoteRequest
(
uint32_t
code
,
int
Rpc
FooStub
::
OnRemoteRequest
(
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
)
{
int
result
=
ERR_NONE
;
switch
(
code
)
{
case
GET_FOO_NAME
:
{
ZLOGI
(
LABEL
,
"%{public}s:called
\n
"
,
__func__
);
reply
.
WriteString
(
GetFooName
());
break
;
}
case
SEND_ASYNC_REPLY
:
{
int32_t
replyData
=
data
.
ReadInt32
();
SendAsyncReply
(
replyData
);
reply
.
WriteString
(
TestGetFooName
());
break
;
}
case
SEND_WRONG_REPLY
:
{
return
TestNestingSend
(
data
.
ReadInt32
());
}
case
GET_TOKENID
:
{
uint32_t
tokenId
=
TestAccessToken
();
reply
.
WriteUint32
(
tokenId
);
...
...
@@ -53,99 +45,39 @@ int FooStub::OnRemoteRequest(uint32_t code,
return
result
;
}
std
::
string
FooStub
::
GetFooName
()
{
return
"ReallFoo"
;
}
int
FooStub
::
WaitForAsyncReply
(
int
timeout
)
std
::
string
RpcFooStub
::
TestGetFooName
(
void
)
{
asyncReply_
=
0
;
std
::
unique_lock
<
std
::
mutex
>
lck
(
mutex_
);
cv_
.
wait_for
(
lck
,
std
::
chrono
::
milliseconds
(
timeout
),
[
&
]()
{
return
asyncReply_
!=
0
;
});
return
asyncReply_
;
return
GetFooName
();
}
void
FooStub
::
SendAsyncReply
(
int
&
replyValue
)
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
mutex_
);
asyncReply_
=
replyValue
;
cv_
.
notify_all
();
}
FooStub
::~
FooStub
()
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
decTimeMutex_
);
decTimes_
++
;
}
void
FooStub
::
CleanDecTimes
()
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
decTimeMutex_
);
decTimes_
=
0
;
}
int
FooStub
::
GetDecTimes
()
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
decTimeMutex_
);
return
decTimes_
;
}
int
FooStub
::
TestNestingSend
(
int
sendCode
)
{
return
sendCode
;
}
uint32_t
FooStub
::
TestAccessToken
(
void
)
uint32_t
RpcFooStub
::
TestAccessToken
(
void
)
{
uint32_t
tokenId
=
IPCSkeleton
::
GetCallingTokenID
();
return
tokenId
;
}
FooProxy
::
FooProxy
(
const
sptr
<
IRemoteObject
>
&
impl
)
:
IRemoteProxy
<
I
Foo
>
(
impl
)
RpcFooProxy
::
Rpc
FooProxy
(
const
sptr
<
IRemoteObject
>
&
impl
)
:
IRemoteProxy
<
I
RpcFooTest
>
(
impl
)
{
}
std
::
string
FooProxy
::
GetFooName
()
{
ZLOGI
(
LABEL
,
"%{public}s:called
\n
"
,
__func__
);
MessageParcel
data
,
reply
;
MessageOption
option
;
Remote
()
->
SendRequest
(
GET_FOO_NAME
,
data
,
reply
,
option
);
return
reply
.
ReadString
();
}
void
FooProxy
::
SendAsyncReply
(
int
&
replyValue
)
{
ZLOGI
(
LABEL
,
"%{public}s:called
\n
"
,
__func__
);
MessageParcel
data
,
reply
;
MessageOption
option
=
{
MessageOption
::
TF_ASYNC
};
data
.
WriteInt32
(
replyValue
);
Remote
()
->
SendRequest
(
SEND_ASYNC_REPLY
,
data
,
reply
,
option
);
}
int
FooProxy
::
TestNestingSend
(
int
sendCode
)
std
::
string
RpcFooProxy
::
TestGetFooName
(
void
)
{
MessageOption
option
;
MessageParcel
dataParcel
,
replyParcel
;
if
(
!
dataParcel
.
WriteInt32
(
sendCode
))
{
return
-
1
;
int
err
=
Remote
()
->
SendRequest
(
GET_FOO_NAME
,
dataParcel
,
replyParcel
,
option
);
if
(
err
!=
0
)
{
return
""
;
}
int
error
=
Remote
()
->
SendRequest
(
SEND_WRONG_REPLY
,
dataParcel
,
replyParcel
,
option
);
ZLOGE
(
LABEL
,
"send foo result = %{public}d"
,
error
);
return
error
;
return
replyParcel
.
ReadString
();
}
uint32_t
FooProxy
::
TestAccessToken
(
void
)
uint32_t
Rpc
FooProxy
::
TestAccessToken
(
void
)
{
MessageOption
option
;
MessageParcel
dataParcel
,
replyParcel
;
int
err
=
Remote
()
->
SendRequest
(
GET_TOKENID
,
dataParcel
,
replyParcel
,
option
);
if
(
err
!=
0
)
{
ZLOGE
(
LABEL
,
"get tokenid failed %{public}d"
,
err
);
return
0
;
}
return
replyParcel
.
ReadUint32
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录