diff --git a/test/bechmarktest/notification_services_test/mock/include/mock_ipc_skeleton.h b/test/bechmarktest/notification_services_test/mock/include/mock_ipc_skeleton.h index a954c7e984fcb213bbf424da29454bba3de76e6d..1659b037d59405dc3c832a9baf63e2449d2a46ed 100644 --- a/test/bechmarktest/notification_services_test/mock/include/mock_ipc_skeleton.h +++ b/test/bechmarktest/notification_services_test/mock/include/mock_ipc_skeleton.h @@ -37,6 +37,8 @@ public: static pid_t GetCallingUid(); + static uint32_t GetCallingTokenID(); + static std::string GetLocalDeviceID(); static std::string GetCallingDeviceID(); @@ -56,6 +58,8 @@ public: static bool SetCallingIdentity(std::string &identity); static void SetCallingUid(pid_t uid); + + static uint32_t SetCallingTokenID(pid_t tokenId); }; } // namespace OHOS #endif // OHOS_MOCK_IPC_SKELETON_H diff --git a/test/bechmarktest/notification_services_test/mock/mock_ipc.cpp b/test/bechmarktest/notification_services_test/mock/mock_ipc.cpp index e533d584f9b55b9ada190103f22a6ba1139e71f1..73625076b123613dc95ea79b647a228a155fa0f8 100644 --- a/test/bechmarktest/notification_services_test/mock/mock_ipc.cpp +++ b/test/bechmarktest/notification_services_test/mock/mock_ipc.cpp @@ -20,7 +20,8 @@ namespace OHOS { using namespace IPC_SINGLE; #endif -pid_t uid_ = 1000; +pid_t uid_ = 0; +pid_t tokenId_ = 0; pid_t IPCSkeleton::GetCallingUid() { @@ -36,4 +37,14 @@ void IPCSkeleton::SetCallingUid(pid_t uid) { uid_ = uid; } + +uint32_t IPCSkeleton::GetCallingTokenID() +{ + return tokenId_; +} + +uint32_t IPCSkeleton::SetCallingTokenID(pid_t tokenId) +{ + return tokenId_ = tokenId; +} } // namespace OHOS diff --git a/test/bechmarktest/notification_services_test/notification_service_test.cpp b/test/bechmarktest/notification_services_test/notification_service_test.cpp index 778ded400a53d66e6aaa6e485727ac40997d2615..4f5fe344798abde0f9b16b3ebc5386e941e4c565 100644 --- a/test/bechmarktest/notification_services_test/notification_service_test.cpp +++ b/test/bechmarktest/notification_services_test/notification_service_test.cpp @@ -32,6 +32,8 @@ using namespace OHOS::Notification; using namespace OHOS::AbilityRuntime; namespace { +const uint32_t TOKEN_ID = 0x08000000; + class TestAnsSubscriber : public NotificationSubscriber { public: void OnConnected() override @@ -73,7 +75,9 @@ public: ~BenchmarkNotificationService() override = default; void SetUp(const ::benchmark::State &state) override - {} + { + IPCSkeleton::SetCallingTokenID(TOKEN_ID); + } void TearDown(const ::benchmark::State &state) override {} @@ -155,6 +159,7 @@ BENCHMARK_F(BenchmarkNotificationService, SubscribeTestCase)(benchmark::State &s */ BENCHMARK_F(BenchmarkNotificationService, PublishNotificationTestCase001)(benchmark::State &state) { + IPCSkeleton::SetCallingTokenID(0); sptr req = new (std::nothrow) NotificationRequest(1); EXPECT_NE(req, nullptr); req->SetSlotType(NotificationConstant::SlotType::OTHER); @@ -184,6 +189,7 @@ BENCHMARK_F(BenchmarkNotificationService, PublishNotificationTestCase001)(benchm */ BENCHMARK_F(BenchmarkNotificationService, CancelNotificationTestCase001)(benchmark::State &state) { + IPCSkeleton::SetCallingTokenID(0); sptr req = new (std::nothrow) NotificationRequest(0); EXPECT_NE(req, nullptr); req->SetSlotType(NotificationConstant::SlotType::OTHER);