!1052 test_service_skeleton整改

Merge pull request !1052 from yanghang/0423-4
This commit is contained in:
openharmony_ci 2024-04-26 06:21:22 +00:00 committed by Gitee
commit 180dbbeea0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 61 additions and 72 deletions

View File

@ -142,6 +142,9 @@ public:
int TestEnableSerialInvokeFlag() override;
private:
static inline BrokerDelegator<TestServiceProxy> delegator_;
bool CheckTokenSelf(uint64_t token, uint64_t tokenSelf, uint64_t ftoken, uint64_t ftoken_expected);
bool CheckSetFirstToken(uint64_t ftoken_expected);
bool CheckSetSelfToken(uint64_t token_expected);
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_TEST, "TestServiceProxy" };
};

View File

@ -380,6 +380,51 @@ int RpcSetFirstCallerTokenID(uint64_t tokenID)
return ACCESS_TOKEN_OK;
}
bool TestServiceProxy::CheckTokenSelf(uint64_t token, uint64_t tokenSelf, uint64_t ftoken, uint64_t ftoken_expected)
{
if (token != tokenSelf) {
ZLOGE(LABEL, "token != tokenSelf");
return false;
}
if (ftoken != ftoken_expected) {
ZLOGE(LABEL, "ftoken != ftoken_expected");
return false;
}
return true;
}
bool TestServiceProxy::CheckSetFirstToken(uint64_t ftoken_expected)
{
uint64_t ret = 0;
ret = RpcSetFirstCallerTokenID(ftoken_expected);
if (ret != 0) {
ZLOGE(LABEL, "RpcSetFirstCallerTokenID ret = %{public}llu", ret);
return false;
}
ret = RpcGetFirstCallerTokenID();
if (ret != ftoken_expected) {
ZLOGE(LABEL, "TestServiceProxy get ftoken after set: %{public}llu", ret);
return false;
}
return true;
}
bool TestServiceProxy::CheckSetSelfToken(uint64_t token_expected)
{
uint64_t ret = 0;
ret = RpcSetSelfTokenID(token_expected);
if (ret != 0) {
ZLOGE(LABEL, "RpcSetSelfTokenID ret = %{public}llu", ret);
return false;
}
ret = RpcGetSelfTokenID();
if (ret != token_expected) {
ZLOGE(LABEL, "TestServiceProxy get selftoken after set: %{public}llu", ret);
return false;
}
return true;
}
int TestServiceProxy::TestAccessTokenID64(uint64_t token_expected, uint64_t ftoken_expected)
{
MessageOption option;
@ -390,33 +435,14 @@ int TestServiceProxy::TestAccessTokenID64(uint64_t token_expected, uint64_t ftok
uint64_t oldTokenSelf = tokenSelf;
int32_t ret = 0;
if (token != tokenSelf) {
ZLOGE(LABEL, "token != tokenSelf");
if (!CheckTokenSelf(token, tokenSelf, ftoken, 0)) {
return -1;
}
if (ftoken != 0) {
ZLOGE(LABEL, "ftoken != 0");
return -1;
}
if (RpcSetFirstCallerTokenID(ftoken_expected) != 0) {
ZLOGE(LABEL, "RpcSetFirstCallerTokenID err");
if (!CheckSetFirstToken(ftoken_expected)) {
ret = -1;
goto ERR;
}
if (RpcGetFirstCallerTokenID() != ftoken_expected) {
ZLOGE(LABEL, "RpcGetFirstCallerTokenID err");
ret = -1;
goto ERR;
}
if (RpcSetSelfTokenID(token_expected) != 0) {
ZLOGE(LABEL, "RpcSetSelfTokenID err");
ret = -1;
goto ERR;
}
if (RpcGetSelfTokenID() != token_expected) {
ZLOGE(LABEL, "RpcGetSelfTokenID err");
if (!CheckSetSelfToken(token_expected)) {
ret = -1;
goto ERR;
}
@ -457,81 +483,41 @@ int TestServiceProxy::TestAccessTokenID(int32_t ftoken_expected)
ZLOGE(LABEL, "TestServiceProxy tokenSelf: %{public}d", tokenSelf);
ZLOGE(LABEL, "TestServiceProxy ftoken: %{public}d", ftoken);
ZLOGE(LABEL, "TestServiceProxy ftoken_expected: %{public}d", ftoken_expected);
if (token != tokenSelf) {
ZLOGE(LABEL, "token != tokenSelf 1, token:%{public}d", token);
if (!CheckTokenSelf(token, tokenSelf, ftoken, 0)) {
ZLOGE(LABEL, "first");
return -1;
}
if (ftoken != 0) {
ZLOGE(LABEL, "ftoken != 0 1");
if (!CheckSetFirstToken(ftoken_expected)) {
return -1;
}
int ret = RpcSetFirstCallerTokenID(ftoken_expected);
if (ret != 0) {
ZLOGE(LABEL, "RpcSetFirstCallerTokenID ret = %{public}d", ret);
return -1;
}
ret = RpcGetFirstCallerTokenID();
ZLOGE(LABEL, "TestServiceProxy get ftoken after set: %{public}d", ret);
ret = Remote()->SendRequest(TRANS_ID_ACCESS_TOKENID, dataParcel, replyParcel1, option);
int ret = Remote()->SendRequest(TRANS_ID_ACCESS_TOKENID, dataParcel, replyParcel1, option);
if (ret != ERR_NONE) {
ZLOGE(LABEL, "SendRequest ret = %{public}d", ret);
return ret;
}
token = replyParcel1.ReadInt32();
ftoken = replyParcel1.ReadInt32();
if (token != tokenSelf) {
ZLOGE(LABEL, "token != tokenSelf 2, token:%{public}d", token);
if (!CheckTokenSelf(token, tokenSelf, ftoken, ftoken_expected)) {
ZLOGE(LABEL, "second");
return -1;
}
if (ftoken != ftoken_expected) {
ZLOGE(LABEL, "ftoken != ftoken_expected 2, ftoken:%{public}d", ftoken);
if (!CheckSetSelfToken(666)) { // 666: test data
return -1;
}
ret = RpcSetSelfTokenID(666);
if (ret != 0) {
ZLOGE(LABEL, "RpcSetSelfTokenID ret = %{public}d", ret);
return -1;
}
tokenSelf = RpcGetSelfTokenID();
ZLOGE(LABEL, "TestServiceProxy get token after set: %{public}d", tokenSelf);
ret = Remote()->SendRequest(TRANS_ID_ACCESS_TOKENID, dataParcel, replyParcel2, option);
if (ret != ERR_NONE) {
ZLOGE(LABEL, "ret = %{public}d", ret);
return ret;
}
token = replyParcel2.ReadInt32();
ftoken = replyParcel2.ReadInt32();
if (token != tokenSelf) {
ZLOGE(LABEL, "token != tokenSelf 3, token:%{public}d", token);
if (!CheckTokenSelf(token, tokenSelf, ftoken, ftoken_expected)) {
ZLOGE(LABEL, "third");
return -1;
}
if (ftoken != ftoken_expected) {
ZLOGE(LABEL, "ftoken != ftoken_expected 3, ftoken:%{public}d", ftoken);
return -1;
}
ret = RpcSetFirstCallerTokenID(0);
if (ret != 0) {
ZLOGE(LABEL, "RpcSetFirstCallerTokenID ret = %{public}d", ret);
return -1;
}
ret = RpcSetSelfTokenID(0);
if (ret != 0) {
ZLOGE(LABEL, "RpcSetSelfTokenID ret = %{public}d", ret);
if (ret != ERR_NONE) {
return -1;
}
return 0;