diff --git a/bundle.json b/bundle.json index 9dc4094a9059685689628f0d73bc595de8a3b06a..9d09646dc4730b2569b2088fd89c1e18097c8f28 100644 --- a/bundle.json +++ b/bundle.json @@ -79,7 +79,8 @@ "//base/security/access_token:accesstoken_build_module_test", "//base/security/access_token/interfaces/innerkits/accesstoken/test:unittest", "//base/security/access_token/interfaces/innerkits/nativetoken/test:unittest", - "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest" + "//base/security/access_token/interfaces/innerkits/token_setproc/test:unittest", + "//base/security/access_token/interfaces/kits/accesstoken/test/benchmarktest:benchmarktest" ] } } diff --git a/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn b/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..062f91d5bf634fb865254b271a10b076caf4300e --- /dev/null +++ b/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (c) 2021 XXXX 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/security/access_token/access_token.gni") +import("//build/test.gni") + +module_output_path = "benchmarktest/access_token" + +config("access_token_kits_config_benchmarktest") { + visibility = [ ":*" ] + + include_dirs = [ + "//utils/native/base/include", + "//third_party/googletest/include", + "//base/security/access_token/interfaces/innerkits/token_setproc/include", + "//base/security/access_token/frameworks/common/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include/permission_def.h" + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + +} + +ohos_benchmarktest("napi_atmanager_test") { + + module_out_path = module_output_path + + sources = [ "napi_atmanager_test.cpp" ] + configs = [ ":access_token_kits_config_benchmarktest" ] + + deps = [ + "//base/security/access_token/interfaces/innerkits/accesstoken:libaccesstoken_sdk", + "//third_party/benchmark", + "//third_party/googletest:gtest_main", + ] +} + +group("benchmarktest") { + testonly = true + deps = [":napi_atmanager_test"] + +} \ No newline at end of file diff --git a/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp b/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9499c9ea521640051af82330b4ae78e7a3b86d74 --- /dev/null +++ b/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2021 XXXX 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#undef private +#include "accesstoken_kit.h" +#include "accesstoken_log.h" +#include "permission_def.h" + +using namespace std; +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::Security::AccessToken; + +namespace { +int32_t TOKENID = 0; + +static const std::string BENCHMARK_TEST_PERMISSION_NAME_ALPHA = "ohos.permission.ALPHA"; +PermissionDef PERMISSIONDEF = { + .permissionName = "ohos.permission.test1", + .bundleName = "accesstoken_test", + .grantMode = 1, + .label = "label", + .labelId = 1, + .description = "open the door", + .descriptionId = 1, + .availableLevel = APL_NORMAL +}; + +class AccessTokenNapiBenchmarkTest : public benchmark::Fixture { +public: + void SetUp(const ::benchmark::State &state) + {} + void TearDown(const ::benchmark::State &state) + {} +}; + +/** + * @tc.name: VerifyAccessTokenTestCase001 + * @tc.desc: VerifyAccessToken + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(AccessTokenNapiBenchmarkTest, VerifyAccessTokenTestCase001)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest VerifyAccessTokenTestCase001 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::VerifyAccessToken(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA),-1); + } +} + +BENCHMARK_REGISTER_F(AccessTokenNapiBenchmarkTest, VerifyAccessTokenTestCase001)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + +/** + * @tc.name: GetPermissionFlagsTestCase002 + * @tc.desc: GetPermissionFlags + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(AccessTokenNapiBenchmarkTest, GetPermissionFlagsTestCase002)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest GetPermissionFlagsTestCase002 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::GetPermissionFlag(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA),0); + } +} + +BENCHMARK_REGISTER_F(AccessTokenNapiBenchmarkTest, GetPermissionFlagsTestCase002)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + +/** + * @tc.name: GetDefPermissionTestCase003 + * @tc.desc: GetDefPermission + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(AccessTokenNapiBenchmarkTest,GetDefPermissionTestCase003)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest GetDefPermissionTestCase003 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::GetDefPermission(BENCHMARK_TEST_PERMISSION_NAME_ALPHA,PERMISSIONDEF),0); + } +} + +BENCHMARK_REGISTER_F(AccessTokenNapiBenchmarkTest, GetDefPermissionTestCase003)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + +/** + * @tc.name: RevokeUserGrantedPermissionTestCase004 + * @tc.desc: RevokeUserGrantedPermission + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(AccessTokenNapiBenchmarkTest,RevokeUserGrantedPermissionTestCase004)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest RevokeUserGrantedPermissionTestCase004 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::RevokePermission(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA,0), -1); + } +} + +BENCHMARK_REGISTER_F(AccessTokenNapiBenchmarkTest, RevokeUserGrantedPermissionTestCase004)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + +/** + * @tc.name: GrantPermissionTestCase005 + * @tc.desc: GrantPermission + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(AccessTokenNapiBenchmarkTest, GrantPermissionTestCase005)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest GrantPermissionTestCase005 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::GrantPermission(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA,0),-1); + } +} + +BENCHMARK_REGISTER_F(AccessTokenNapiBenchmarkTest, GrantPermissionTestCase005)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + + } //namespace + +// Run the benchmark +BENCHMARK_MAIN();