diff --git a/bundle.json b/bundle.json index 7cf142abc43f4c9b7bee3604c2db0b9e33dc3f77..5407eee174ea2c9bac9247eb4f2f51d3edefa53f 100644 --- a/bundle.json +++ b/bundle.json @@ -78,7 +78,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..12ff0d36f1a2471a6d166765156a726a2d5a7a36 --- /dev/null +++ b/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright (c) 2021-2022 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 +# +# 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 = "access_token/interfaces_kit" + +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("NapiAtmanagerTest") { + 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 = [ ":NapiAtmanagerTest" ] +} 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..9b08c8398438f812e067cabb13f53bbaa4f8baf6 --- /dev/null +++ b/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2021-2022 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 + * + * 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 NapiAtmanagerTest : 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(NapiAtmanagerTest, VerifyAccessTokenTestCase001)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "NapiAtmanagerTest VerifyAccessTokenTestCase001 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::VerifyAccessToken(TOKENID, BENCHMARK_TEST_PERMISSION_NAME_ALPHA), -1); + } +} + +BENCHMARK_REGISTER_F(NapiAtmanagerTest, VerifyAccessTokenTestCase001)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + +/** + * @tc.name: GetPermissionFlagsTestCase002 + * @tc.desc: GetPermissionFlags + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(NapiAtmanagerTest, GetPermissionFlagsTestCase002)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "NapiAtmanagerTest GetPermissionFlagsTestCase002 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::GetPermissionFlag(TOKENID, BENCHMARK_TEST_PERMISSION_NAME_ALPHA), 0); + } +} + +BENCHMARK_REGISTER_F(NapiAtmanagerTest, GetPermissionFlagsTestCase002)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + +/** + * @tc.name: GetDefPermissionTestCase003 + * @tc.desc: GetDefPermission + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(NapiAtmanagerTest, GetDefPermissionTestCase003)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "NapiAtmanagerTest GetDefPermissionTestCase003 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::GetDefPermission(BENCHMARK_TEST_PERMISSION_NAME_ALPHA, PERMISSIONDEF), -1); + } +} + +BENCHMARK_REGISTER_F(NapiAtmanagerTest, GetDefPermissionTestCase003)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + +/** + * @tc.name: RevokeUserGrantedPermissionTestCase004 + * @tc.desc: RevokeUserGrantedPermission + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(NapiAtmanagerTest, RevokeUserGrantedPermissionTestCase004)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "NapiAtmanagerTest RevokeUserGrantedPermissionTestCase004 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::RevokePermission(TOKENID, BENCHMARK_TEST_PERMISSION_NAME_ALPHA, 0), -1); + } +} + +BENCHMARK_REGISTER_F(NapiAtmanagerTest, RevokeUserGrantedPermissionTestCase004)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + +/** + * @tc.name: GrantPermissionTestCase005 + * @tc.desc: GrantPermission + * @tc.type: FUNC + * @tc.require: + */ +BENCHMARK_F(NapiAtmanagerTest, GrantPermissionTestCase005)( + benchmark::State &st) +{ + GTEST_LOG_(INFO) << "NapiAtmanagerTest GrantPermissionTestCase005 start!"; + for (auto _ : st) { + EXPECT_EQ(AccessTokenKit::GrantPermission(TOKENID, BENCHMARK_TEST_PERMISSION_NAME_ALPHA, 0), -1); + } +} + +BENCHMARK_REGISTER_F(NapiAtmanagerTest, GrantPermissionTestCase005)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); +} // namespace + +BENCHMARK_MAIN(); \ No newline at end of file