From 5c6ec8c31c1c469dbc48f8e57e9f1a91cb9843c9 Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Thu, 28 Apr 2022 15:27:01 +0800 Subject: [PATCH 1/3] test_cwm_0428 Signed-off-by: cc_ggboy --- bundle.json | 3 +- .../accesstoken/test/benchmarktest/BUILD.gn | 62 +++++++ .../benchmarktest/napi_atmanager_test.cpp | 151 ++++++++++++++++++ .../test/resource/access_token/ohos_test.xml | 8 + 4 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn create mode 100644 interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp create mode 100644 interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml diff --git a/bundle.json b/bundle.json index 9dc4094a9..9d09646dc 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 000000000..8a127ad8e --- /dev/null +++ b/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn @@ -0,0 +1,62 @@ +# 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" ] + } + + # defines = [ + # "ACCOUNT_LOG_TAG = \"OsAccountBenchmarkTest\"", + # "LOG_DOMAIN = 0xD001B00", + # ] +} + +ohos_benchmarktest("napi_atmanager_test") { + + module_out_path = module_output_path + + resource_config_file = "//base/security/access_token/interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml" + + 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 000000000..29e70fb1d --- /dev/null +++ b/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp @@ -0,0 +1,151 @@ +/* + * 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 = 12345; + +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!"; + int32_t i = 0; + for (auto _ : st) { + i++; + std::string STRING_NAME = "name_"; + STRING_NAME += to_string(i); + EXPECT_EQ(AccessTokenKit::VerifyAccessToken(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA), 0);//ERR_OK + } +} + +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), 0); + } +} + +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), 0); + } +} + +BENCHMARK_REGISTER_F(AccessTokenNapiBenchmarkTest, GrantPermissionTestCase005)->Iterations(100)-> + Repetitions(3)->ReportAggregatesOnly(); + + } //namespace + +// Run the benchmark +BENCHMARK_MAIN(); diff --git a/interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml b/interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml new file mode 100644 index 000000000..8a2762510 --- /dev/null +++ b/interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file -- Gitee From 8006c75d1756cfd701ae4c068d0cf1c41e9f865c Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Fri, 29 Apr 2022 14:54:25 +0800 Subject: [PATCH 2/3] cwm_0429_js_c_benchmark Signed-off-by: cc_ggboy --- .../accesstoken/test/benchmarktest/BUILD.gn | 8 +------- .../test/benchmarktest/napi_atmanager_test.cpp | 18 +++++++----------- .../test/resource/access_token/ohos_test.xml | 8 -------- 3 files changed, 8 insertions(+), 26 deletions(-) delete mode 100644 interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml diff --git a/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn b/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn index 8a127ad8e..062f91d5b 100644 --- a/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn +++ b/interfaces/kits/accesstoken/test/benchmarktest/BUILD.gn @@ -25,7 +25,7 @@ config("access_token_kits_config_benchmarktest") { "//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" + "//base/security/access_token/interfaces/innerkits/accesstoken/include/permission_def.h" ] cflags = [] @@ -33,17 +33,11 @@ config("access_token_kits_config_benchmarktest") { cflags += [ "-DBINDER_IPC_32BIT" ] } - # defines = [ - # "ACCOUNT_LOG_TAG = \"OsAccountBenchmarkTest\"", - # "LOG_DOMAIN = 0xD001B00", - # ] } ohos_benchmarktest("napi_atmanager_test") { module_out_path = module_output_path - - resource_config_file = "//base/security/access_token/interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml" sources = [ "napi_atmanager_test.cpp" ] configs = [ ":access_token_kits_config_benchmarktest" ] diff --git a/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp b/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp index 29e70fb1d..4271f40ff 100644 --- a/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp +++ b/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp @@ -29,7 +29,7 @@ using namespace OHOS; using namespace OHOS::Security::AccessToken; namespace { -int32_t TOKENID = 12345; +int32_t TOKENID = 0; static const std::string BENCHMARK_TEST_PERMISSION_NAME_ALPHA = "ohos.permission.ALPHA"; PermissionDef PERMISSIONDEF = { @@ -60,13 +60,9 @@ public: BENCHMARK_F(AccessTokenNapiBenchmarkTest, VerifyAccessTokenTestCase001)( benchmark::State &st) { - GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest VerifyAccessTokenTestCase001 start!"; - int32_t i = 0; + GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest VerifyAccessTokenTestCase001&&&&&&&&&&&&& start!"; for (auto _ : st) { - i++; - std::string STRING_NAME = "name_"; - STRING_NAME += to_string(i); - EXPECT_EQ(AccessTokenKit::VerifyAccessToken(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA), 0);//ERR_OK + EXPECT_EQ(AccessTokenKit::VerifyAccessToken(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA),-1);//ERR_OK } } @@ -84,7 +80,7 @@ BENCHMARK_F(AccessTokenNapiBenchmarkTest, GetPermissionFlagsTestCase002)( { GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest GetPermissionFlagsTestCase002 start!"; for (auto _ : st) { - EXPECT_EQ(AccessTokenKit::GetPermissionFlag(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA), 0); + EXPECT_EQ(AccessTokenKit::GetPermissionFlag(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA),0); } } @@ -102,7 +98,7 @@ BENCHMARK_F(AccessTokenNapiBenchmarkTest,GetDefPermissionTestCase003)( { GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest GetDefPermissionTestCase003 start!"; for (auto _ : st) { - EXPECT_EQ(AccessTokenKit::GetDefPermission(BENCHMARK_TEST_PERMISSION_NAME_ALPHA,PERMISSIONDEF), 0); + EXPECT_EQ(AccessTokenKit::GetDefPermission(BENCHMARK_TEST_PERMISSION_NAME_ALPHA,PERMISSIONDEF),0); } } @@ -120,7 +116,7 @@ BENCHMARK_F(AccessTokenNapiBenchmarkTest,RevokeUserGrantedPermissionTestCase004) { GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest RevokeUserGrantedPermissionTestCase004 start!"; for (auto _ : st) { - EXPECT_EQ(AccessTokenKit::RevokePermission(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA,0), 0); + EXPECT_EQ(AccessTokenKit::RevokePermission(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA,0), -1); } } @@ -138,7 +134,7 @@ BENCHMARK_F(AccessTokenNapiBenchmarkTest, GrantPermissionTestCase005)( { GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest GrantPermissionTestCase005 start!"; for (auto _ : st) { - EXPECT_EQ(AccessTokenKit::GrantPermission(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA,0), 0); + EXPECT_EQ(AccessTokenKit::GrantPermission(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA,0),-1); } } diff --git a/interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml b/interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml deleted file mode 100644 index 8a2762510..000000000 --- a/interfaces/kits/accesstoken/test/resource/access_token/ohos_test.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file -- Gitee From d0775d6c1950b780163ce228b502b8b46e0bdf9c Mon Sep 17 00:00:00 2001 From: cc_ggboy Date: Fri, 29 Apr 2022 14:56:34 +0800 Subject: [PATCH 3/3] cwm_042901_js_c_benchmark Signed-off-by: cc_ggboy --- .../accesstoken/test/benchmarktest/napi_atmanager_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp b/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp index 4271f40ff..9499c9ea5 100644 --- a/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp +++ b/interfaces/kits/accesstoken/test/benchmarktest/napi_atmanager_test.cpp @@ -60,9 +60,9 @@ public: BENCHMARK_F(AccessTokenNapiBenchmarkTest, VerifyAccessTokenTestCase001)( benchmark::State &st) { - GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest VerifyAccessTokenTestCase001&&&&&&&&&&&&& start!"; + GTEST_LOG_(INFO) << "AccessTokenNapiBenchmarkTest VerifyAccessTokenTestCase001 start!"; for (auto _ : st) { - EXPECT_EQ(AccessTokenKit::VerifyAccessToken(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA),-1);//ERR_OK + EXPECT_EQ(AccessTokenKit::VerifyAccessToken(TOKENID,BENCHMARK_TEST_PERMISSION_NAME_ALPHA),-1); } } -- Gitee