From 81d07a030dc3ec9ed56d2e3749b3ebebb7389c82 Mon Sep 17 00:00:00 2001 From: huangxiaolinabc123 Date: Sat, 27 Aug 2022 19:21:51 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=97=E4=BD=99?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaolinabc123 Change-Id: Ibeb03fa2242bc694b737bda56a955b91c336e3a3 --- services/samgr/native/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn index 60a1bceb..75c30035 100644 --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -77,7 +77,6 @@ ohos_executable("samgr") { external_deps += [ "selinux:libservice_checker" ] defines = [ "WITH_SELINUX" ] } - public_deps = [ "//third_party/libxml2:libxml2" ] part_name = "samgr" } subsystem_name = "systemabilitymgr" -- Gitee From 5e53c0dc3885c59e98b5a589f2a4955289f066c4 Mon Sep 17 00:00:00 2001 From: huangxiaolinabc123 Date: Sat, 27 Aug 2022 20:07:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=8D=8F=E5=8A=A9safwk=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=86=97=E4=BD=99gn=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaolinabc123 Change-Id: I05f08343a6b1365cd9cb38c17f009d99b86858c5 --- interfaces/innerkits/common/BUILD.gn | 9 +++++++++ interfaces/innerkits/lsamgr/BUILD.gn | 2 +- interfaces/innerkits/samgr_proxy/BUILD.gn | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/interfaces/innerkits/common/BUILD.gn b/interfaces/innerkits/common/BUILD.gn index e9616a51..718cc06a 100644 --- a/interfaces/innerkits/common/BUILD.gn +++ b/interfaces/innerkits/common/BUILD.gn @@ -13,6 +13,12 @@ import("//build/ohos.gni") +config("all_config_samgr_common") { + include_dirs = [ + "include", + ] +} + config("config_samgr_common") { include_dirs = [ "include", @@ -35,6 +41,9 @@ ohos_shared_library("samgr_common") { ] public_configs = [ ":config_samgr_common" ] + + all_dependent_configs = [ ":all_config_samgr_common" ] + if (is_standard_system) { external_deps = [ "c_utils:utils", diff --git a/interfaces/innerkits/lsamgr/BUILD.gn b/interfaces/innerkits/lsamgr/BUILD.gn index 52180645..4ad4689e 100644 --- a/interfaces/innerkits/lsamgr/BUILD.gn +++ b/interfaces/innerkits/lsamgr/BUILD.gn @@ -35,7 +35,7 @@ ohos_shared_library("lsamgr") { "//foundation/systemabilitymgr/samgr/test/resource:coverage_flags", ] - public_configs = [ ":public_config_lsamgr" ] + all_dependent_configs = [ ":public_config_lsamgr" ] if (is_standard_system) { external_deps = [ diff --git a/interfaces/innerkits/samgr_proxy/BUILD.gn b/interfaces/innerkits/samgr_proxy/BUILD.gn index b419f5b3..4a92478c 100644 --- a/interfaces/innerkits/samgr_proxy/BUILD.gn +++ b/interfaces/innerkits/samgr_proxy/BUILD.gn @@ -42,7 +42,7 @@ ohos_shared_library("samgr_proxy") { "//foundation/systemabilitymgr/samgr/test/resource:coverage_flags", ] - public_configs = [ ":samgr_proxy_config" ] + all_dependent_configs = [ ":samgr_proxy_config" ] if (is_standard_system) { external_deps = [ -- Gitee From fb9d6da260ac9b8cdee3efef868457c4a1ccba86 Mon Sep 17 00:00:00 2001 From: huangxiaolinabc123 Date: Sun, 28 Aug 2022 17:57:18 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaolinabc123 Change-Id: I070a2d2b8d2a26ee183c270c727d94c0e11ed97d --- interfaces/innerkits/common/BUILD.gn | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/common/BUILD.gn b/interfaces/innerkits/common/BUILD.gn index 718cc06a..aa5c9c73 100644 --- a/interfaces/innerkits/common/BUILD.gn +++ b/interfaces/innerkits/common/BUILD.gn @@ -44,6 +44,10 @@ ohos_shared_library("samgr_common") { all_dependent_configs = [ ":all_config_samgr_common" ] + deps = [ + "//third_party/libxml2:libxml2", + ] + if (is_standard_system) { external_deps = [ "c_utils:utils", @@ -54,7 +58,6 @@ ohos_shared_library("samgr_common") { part_name = "samgr" } - public_deps = [ "//third_party/libxml2:libxml2" ] subsystem_name = "systemabilitymgr" } ################################################################################ -- Gitee From e33f324b05aaf8f460b7a6bc7f3a935fe89acaa8 Mon Sep 17 00:00:00 2001 From: huangxiaolinabc123 Date: Mon, 29 Aug 2022 19:53:37 +0800 Subject: [PATCH 4/4] modify TDD Signed-off-by: huangxiaolinabc123 Change-Id: I4adc62ac9c5592393410dfbdf7fd7fce02abc9f2 --- services/samgr/native/test/unittest/BUILD.gn | 7 ++++ .../test/unittest/include/mock_permission.h | 25 +++++++++++ .../test/unittest/src/mock_permission.cpp | 41 +++++++++++++++++++ .../src/system_ability_mgr_proxy_test.cpp | 2 + .../unittest/src/system_ability_mgr_test.cpp | 2 + 5 files changed, 77 insertions(+) create mode 100644 services/samgr/native/test/unittest/include/mock_permission.h create mode 100644 services/samgr/native/test/unittest/src/mock_permission.cpp diff --git a/services/samgr/native/test/unittest/BUILD.gn b/services/samgr/native/test/unittest/BUILD.gn index d6b62ae8..a401bb55 100644 --- a/services/samgr/native/test/unittest/BUILD.gn +++ b/services/samgr/native/test/unittest/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("SystemAbilityMgrTest") { "${samgr_services_dir}/source/system_ability_manager_stub.cpp", "${samgr_services_dir}/source/system_ability_status_change_proxy.cpp", "${samgr_services_dir}/test/unittest/src/itest_transaction_service.cpp", + "${samgr_services_dir}/test/unittest/src/mock_permission.cpp", "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", "${samgr_services_dir}/test/unittest/src/system_ability_mgr_test.cpp", "//foundation/systemabilitymgr/samgr/services/dfx/source/hisysevent_adapter.cpp", @@ -63,6 +64,8 @@ ohos_unittest("SystemAbilityMgrTest") { external_deps = [ "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "eventhandler:libeventhandler", "hisysevent_native:libhisysevent", @@ -79,6 +82,7 @@ ohos_unittest("SystemAbilityMgrProxyTest") { sources = [ "${samgr_services_dir}/test/unittest/src/itest_transaction_service.cpp", + "${samgr_services_dir}/test/unittest/src/mock_permission.cpp", "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", "${samgr_services_dir}/test/unittest/src/system_ability_mgr_proxy_test.cpp", ] @@ -100,6 +104,9 @@ ohos_unittest("SystemAbilityMgrProxyTest") { ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/samgr/native/test/unittest/include/mock_permission.h b/services/samgr/native/test/unittest/include/mock_permission.h new file mode 100644 index 00000000..d6ebb45d --- /dev/null +++ b/services/samgr/native/test/unittest/include/mock_permission.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 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. + */ + +#ifndef SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H +#define SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H + +namespace OHOS { +class TestMockPermission { +public: + static void MockPermission(); +}; +} // namespace OHOS +#endif // SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/mock_permission.cpp b/services/samgr/native/test/unittest/src/mock_permission.cpp new file mode 100644 index 00000000..5a526f61 --- /dev/null +++ b/services/samgr/native/test/unittest/src/mock_permission.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 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 "mock_permission.h" + +#include "nativetoken_kit.h" +#include "token_setproc.h" + +namespace OHOS { +void TestMockPermission::MockPermission() +{ + static const char *PERMS[] = { + "ohos.permission.DISTRIBUTED_DATASYNC" + }; + uint64_t tokenId; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .aclsNum = 0, + .dcaps = nullptr, + .perms = PERMS, + .acls = nullptr, + .processName = "distributedsched", + .aplStr = "system_core", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); +} +} \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp index 19088bb1..04c859a9 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp @@ -16,6 +16,7 @@ #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "itest_transaction_service.h" +#include "mock_permission.h" #include "sa_status_change_mock.h" #include "string_ex.h" #include "system_ability_manager_proxy.h" @@ -45,6 +46,7 @@ void SystemAbilityMgrProxyTest::TearDownTestCase() void SystemAbilityMgrProxyTest::SetUp() { + TestMockPermission::MockPermission(); DTEST_LOG << "SetUp" << std::endl; } diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp index 742a1f3a..dd766a7d 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp @@ -17,6 +17,7 @@ #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "itest_transaction_service.h" +#include "mock_permission.h" #include "parameter.h" #include "sa_status_change_mock.h" #include "string_ex.h" @@ -56,6 +57,7 @@ void SystemAbilityMgrTest::TearDownTestCase() void SystemAbilityMgrTest::SetUp() { + TestMockPermission::MockPermission(); DTEST_LOG << "SetUp" << std::endl; } -- Gitee