From 97444a0fa4517bc670281c30ef8cc0cbe23b8d34 Mon Sep 17 00:00:00 2001 From: yanghang Date: Tue, 23 Apr 2024 11:39:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?test=5Fservice=5Fskeleton=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yanghang --- .../native/include/test_service_skeleton.h | 3 + .../native/src/test_service_skeleton.cpp | 130 ++++++++---------- 2 files changed, 60 insertions(+), 73 deletions(-) diff --git a/ipc/test/auxiliary/native/include/test_service_skeleton.h b/ipc/test/auxiliary/native/include/test_service_skeleton.h index cdf68709..a89f1093 100644 --- a/ipc/test/auxiliary/native/include/test_service_skeleton.h +++ b/ipc/test/auxiliary/native/include/test_service_skeleton.h @@ -142,6 +142,9 @@ public: int TestEnableSerialInvokeFlag() override; private: static inline BrokerDelegator 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" }; }; diff --git a/ipc/test/auxiliary/native/src/test_service_skeleton.cpp b/ipc/test/auxiliary/native/src/test_service_skeleton.cpp index afddccb4..f8e2d78d 100644 --- a/ipc/test/auxiliary/native/src/test_service_skeleton.cpp +++ b/ipc/test/auxiliary/native/src/test_service_skeleton.cpp @@ -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, ftoken:%{public}llu", 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,83 +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); + int32_t ret = 0; + 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); 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); - return -1; - } return 0; } From 4791f3e0c7c09a7f90279ac799e6b4bb50197544 Mon Sep 17 00:00:00 2001 From: yanghang Date: Fri, 26 Apr 2024 01:46:25 +0000 Subject: [PATCH 2/3] update ipc/test/auxiliary/native/src/test_service_skeleton.cpp. Signed-off-by: yanghang --- ipc/test/auxiliary/native/src/test_service_skeleton.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ipc/test/auxiliary/native/src/test_service_skeleton.cpp b/ipc/test/auxiliary/native/src/test_service_skeleton.cpp index f8e2d78d..a3a0b400 100644 --- a/ipc/test/auxiliary/native/src/test_service_skeleton.cpp +++ b/ipc/test/auxiliary/native/src/test_service_skeleton.cpp @@ -387,7 +387,7 @@ bool TestServiceProxy::CheckTokenSelf(uint64_t token, uint64_t tokenSelf, uint64 return false; } if (ftoken != ftoken_expected) { - ZLOGE(LABEL, "ftoken != ftoken_expected, ftoken:%{public}llu", ftoken_expected); + ZLOGE(LABEL, "ftoken != ftoken_expected"); return false; } return true; @@ -483,7 +483,6 @@ 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); - int32_t ret = 0; if (!CheckTokenSelf(token, tokenSelf, ftoken, 0)) { ZLOGE(LABEL, "first"); return -1; @@ -491,7 +490,7 @@ int TestServiceProxy::TestAccessTokenID(int32_t ftoken_expected) if (!CheckSetFirstToken(ftoken_expected)) { return -1; } - 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; @@ -518,6 +517,9 @@ int TestServiceProxy::TestAccessTokenID(int32_t ftoken_expected) } ret = RpcSetFirstCallerTokenID(0); ret = RpcSetSelfTokenID(0); + if (ret != ERR_NONE) { + retuen -1; + } return 0; } From c90df02fbf1175f7bef71e2eb54db537bd8b317c Mon Sep 17 00:00:00 2001 From: yanghang Date: Fri, 26 Apr 2024 03:30:27 +0000 Subject: [PATCH 3/3] update ipc/test/auxiliary/native/src/test_service_skeleton.cpp. Signed-off-by: yanghang --- ipc/test/auxiliary/native/src/test_service_skeleton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipc/test/auxiliary/native/src/test_service_skeleton.cpp b/ipc/test/auxiliary/native/src/test_service_skeleton.cpp index a3a0b400..faab137a 100644 --- a/ipc/test/auxiliary/native/src/test_service_skeleton.cpp +++ b/ipc/test/auxiliary/native/src/test_service_skeleton.cpp @@ -518,7 +518,7 @@ int TestServiceProxy::TestAccessTokenID(int32_t ftoken_expected) ret = RpcSetFirstCallerTokenID(0); ret = RpcSetSelfTokenID(0); if (ret != ERR_NONE) { - retuen -1; + return -1; } return 0; }