修复TDD执行进程无DISTRIBUTED_DATASYNC权限,导致TDD执行失败问题

Signed-off-by: wangyang2022 <wangyang412@huawei.com>
Change-Id: Ida140445df65d686691ce42a9428443080c84f84
This commit is contained in:
wangyang2022 2022-07-25 19:47:32 +08:00
parent 2402bfb6d2
commit 4e9457edb7
8 changed files with 88 additions and 2 deletions

View File

@ -28,6 +28,7 @@ config("test_config") {
include_dirs = [
"//foundation/ability/dmsfwk/utils/native/include",
"//foundation/ability/dmsfwk/services/base/include",
"//foundation/ability/dmsfwk/services/dtbschedmgr/test/unittest",
]
}
@ -58,6 +59,8 @@ if (dmsfwk_mission_manager) {
}
dsched_public_deps = [
"//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken",
"//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc",
"//foundation/ability/dmsfwk/services/base:dmsbaseinner",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
@ -83,6 +86,7 @@ dtbschedmgr_sources = [
"${distributed_service}/dtbschedmgr/src/dms_free_install_callback_proxy.cpp",
"${distributed_service}/dtbschedmgr/src/dms_free_install_callback_stub.cpp",
"${distributed_service}/dtbschedmgr/src/dms_token_callback.cpp",
"unittest/distributed_sched_util.cpp",
]
if (dmsfwk_mission_manager) {

View File

@ -18,6 +18,7 @@
#define protected public
#include "ability_connect_callback_stub.h"
#include "distributed_sched_service.h"
#include "distributed_sched_util.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
@ -109,6 +110,7 @@ void DistributedSchedConnectTest::TearDownTestCase()
void DistributedSchedConnectTest::SetUp()
{
DistributedSchedUtil::MockPermission();
}
void DistributedSchedConnectTest::TearDown()

View File

@ -14,6 +14,7 @@
*/
#include "distributed_sched_continuation_test.h"
#include "distributed_sched_util.h"
#include "dtbschedmgr_device_info_storage.h"
#include "mock_distributed_sched.h"
@ -42,6 +43,7 @@ void DSchedContinuationTest::TearDownTestCase()
void DSchedContinuationTest::SetUp()
{
DistributedSchedUtil::MockPermission();
dschedContinuation_ = std::make_shared<DSchedContinuation>();
}

View File

@ -15,11 +15,13 @@
#define private public
#define protected public
#include "gtest/gtest.h"
#include "distributed_sched_proxy.h"
#include "distributed_sched_service.h"
#include "distributed_sched_util.h"
#include "dtbschedmgr_device_info_storage.h"
#include "dtbschedmgr_log.h"
#include "gtest/gtest.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
@ -71,7 +73,9 @@ void DistributedSchedServiceTest::TearDownTestCase()
{}
void DistributedSchedServiceTest::SetUp()
{}
{
DistributedSchedUtil::MockPermission();
}
void DistributedSchedServiceTest::TearDown()
{}

View File

@ -0,0 +1,43 @@
/*
* 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 "distributed_sched_util.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"
namespace OHOS {
namespace DistributedSchedule {
void DistributedSchedUtil::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);
}
}
}

View File

@ -0,0 +1,27 @@
/*
* 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 DISTRIBUTED_SCHED_UTIL_H
#define DISTRIBUTED_SCHED_UTIL_H
namespace OHOS {
namespace DistributedSchedule {
class DistributedSchedUtil {
public:
static void MockPermission();
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // DISTRIBUTED_SCHED_UTIL_H

View File

@ -16,6 +16,7 @@
#include "distributed_data_storage_test.h"
#include <thread>
#include "distributed_sched_util.h"
#include "dtbschedmgr_device_info_storage.h"
#include "test_log.h"
@ -44,6 +45,7 @@ void DistributedDataStorageTest::TearDownTestCase()
void DistributedDataStorageTest::SetUp()
{
DistributedSchedUtil::MockPermission();
distributedDataStorage_ = std::make_shared<DistributedDataStorage>();
DTEST_LOG << "DistributedDataStorageTest::SetUp" << std::endl;
}

View File

@ -17,6 +17,7 @@
#include "distributed_sched_proxy.h"
#include "distributed_sched_service.h"
#include "distributed_sched_util.h"
#include "dtbschedmgr_device_info_storage.h"
#include "if_system_ability_manager.h"
#include "ipc_skeleton.h"
@ -53,6 +54,7 @@ void DMSMissionManagerTest::TearDownTestCase()
void DMSMissionManagerTest::SetUp()
{
DistributedSchedUtil::MockPermission();
string localDeviceId;
if (!DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId)) {
DTEST_LOG << "getLocalDevicesId failed!" << std::endl;