Signed-off-by: 黄师伟 <huangshiwei4@huawei.com>
Change-Id: I72eac6554f253a4b5d33b8949714845b92069775
This commit is contained in:
黄师伟 2023-07-22 10:16:50 +00:00
parent 5c3c8f5ab0
commit 701e528bbf
24 changed files with 248 additions and 1344 deletions

View File

@ -390,7 +390,7 @@ HWTEST_F(SourceMapTest, JsEnv_SourceMap_1500, Function | MediumTest | Level1)
mapObj->Init(true, "");
mapObj->SplitSourceMap(sourceMaps);
std::string stack = mapObj->TranslateBySourceMap(stackStr);
EXPECT_STREQ(stack.c_str(), "at anonymous (/ets/pages/Index.ets:85:9)\n");
EXPECT_STREQ(stack.c_str(), "at anonymous (entry/src/main/ets/pages/Index.ets:85:9)\n");
GTEST_LOG_(INFO) << "JsEnv_SourceMap_1500 end" << stack.c_str();
}

View File

@ -19,64 +19,31 @@ module_output_path = "ability_runtime/mstabilitymgrservice"
ohos_moduletest("ability_manager_service_dump_test") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/moduletest/mock/include",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
]
include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include" ]
sources = [
"${ability_runtime_test_path}/moduletest/mock/src/mock_app_mgr_client.cpp",
"ability_manager_service_dump_test.cpp",
]
sources = [ "ability_manager_service_dump_test.cpp" ]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbeget_proxy",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"napi:ace_napi",
"window_manager:scene_session",
]
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
}
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}
}
group("moduletest") {

View File

@ -19,7 +19,6 @@
#include "ability_manager_service.h"
#undef private
#undef protected
#include "mock_app_mgr_client.h"
using namespace testing;
using namespace testing::ext;
@ -39,10 +38,6 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
public:
std::shared_ptr<AbilityManagerService> abilityMs_;
std::unique_ptr<MockAppMgrClient> mockAppMgrClient_;
};
void AbilityManagerServiceDumpTest::SetUpTestCase()
@ -53,18 +48,10 @@ void AbilityManagerServiceDumpTest::TearDownTestCase()
void AbilityManagerServiceDumpTest::SetUp()
{
abilityMs_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
EXPECT_NE(abilityMs_, nullptr);
mockAppMgrClient_ = std::make_unique<MockAppMgrClient>();
EXPECT_NE(mockAppMgrClient_, nullptr);
OHOS::DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(mockAppMgrClient_);
}
void AbilityManagerServiceDumpTest::TearDown()
{
OHOS::DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
/**
@ -75,9 +62,10 @@ void AbilityManagerServiceDumpTest::TearDown()
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_GetProcessRunningInfosByUserId_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
std::vector<RunningProcessInfo> info;
auto result = abilityMs_->GetProcessRunningInfosByUserId(info, USER_ID);
EXPECT_EQ(result, AppMgrResultCode::RESULT_OK);
EXPECT_NE(result, AppMgrResultCode::RESULT_OK);
}
/**
@ -88,6 +76,7 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_GetProcessRunningI
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysFuncInit_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->DumpSysFuncInit();
EXPECT_GT(abilityMs_->dumpsysFuncMap_.size(), SIZE_ZERO);
}
@ -100,6 +89,7 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysFuncInit_01
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysInner_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
std::string args = "-a";
std::vector<std::string> info;
bool isClient = false;
@ -116,6 +106,7 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysInner_0100,
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysMissionListInner_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
std::string args = "-a";
std::vector<std::string> info;
bool isClient = false;
@ -132,6 +123,7 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysMissionList
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysAbilityInner_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
std::string args = "-a";
std::vector<std::string> info;
bool isClient = false;
@ -148,6 +140,7 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysAbilityInne
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysStateInner_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
std::string args = "-a";
std::vector<std::string> info;
bool isClient = false;
@ -164,6 +157,7 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysStateInner_
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysPendingInner_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
std::string args = "-a";
std::vector<std::string> info;
bool isClient = false;
@ -180,12 +174,13 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysPendingInne
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysProcess_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
std::string args = "-a";
std::vector<std::string> info;
bool isClient = false;
bool isUserID = true;
abilityMs_->DumpSysProcess(args, info, isClient, isUserID, USER_ID);
EXPECT_GT(info.size(), SIZE_ZERO);
EXPECT_EQ(info.size(), SIZE_ZERO);
}
/**
@ -196,6 +191,7 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysProcess_010
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DataDumpSysStateInner_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
std::string args = "-a";
std::vector<std::string> info;
bool isClient = false;
@ -212,6 +208,7 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DataDumpSysStateIn
*/
HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_OnAppStateChanged_0100, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->connectManager_ = std::make_shared<AbilityConnectManager>(0);
EXPECT_NE(abilityMs_->connectManager_, nullptr);

View File

@ -10,6 +10,7 @@
# 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("//build/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
@ -18,67 +19,35 @@ module_output_path = "ability_runtime/ability_call_test"
ohos_moduletest("call_ability_service_module_test") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/moduletest/mock/include",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
]
include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include" ]
sources = [
# add mock file
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"call_ability_service_module_test.cpp",
]
sources = [ "call_ability_service_module_test.cpp" ]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbeget_proxy",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:scene_session",
]
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
}
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}
}
group("moduletest") {
testonly = true
deps = [ ":call_ability_service_module_test" ]
}

View File

@ -17,173 +17,33 @@
#define private public
#define protected public
#include "ability_manager_service.h"
#include "ability_event_handler.h"
#undef private
#undef protected
#include "app_process_data.h"
#include "system_ability_definition.h"
#include "ability_manager_errors.h"
#include "ability_scheduler.h"
#include "sa_mgr_client.h"
#include "mock_ability_connect_callback.h"
#include "mock_ability_token.h"
#include "mock_bundle_mgr.h"
#include "nativetoken_kit.h"
#include "token_setproc.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
using namespace testing;
using namespace testing::ext;
using namespace OHOS::AppExecFwk;
namespace {
const std::string DEVICE_ID = "15010038475446345206a332922cb765";
const std::string BUNDLE_NAME = "testBundle";
const std::string NAME = ".testMainAbility";
}
namespace OHOS {
namespace AAFwk {
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
#define SLEEP(milli) std::this_thread::sleep_for(std::chrono::seconds(milli))
namespace {
const std::string WaitUntilTaskFinishedByTimer = "BundleMgrService";
void SetNativeToken()
{
uint64_t tokenId;
const char* perms[] = {
"ohos.permission.START_INVISIBLE_ABILITY",
"ohos.permission.START_ABILITIES_FROM_BACKGROUND",
"ohos.permission.START_ABILIIES_FROM_BACKGROUND",
"ohos.permission.ABILITY_BACKGROUND_COMMUNICATION"
};
NativeTokenInfoParams infoInstance = {
.dcapsNum = 0,
.permsNum = 4,
.aclsNum = 0,
.dcaps = nullptr,
.perms = perms,
.acls = nullptr,
.aplStr = "system_core",
};
infoInstance.processName = "SetUpTestCase";
tokenId = GetAccessTokenId(&infoInstance);
SetSelfTokenID(tokenId);
}
} // namespace
class AbilityManagerServiceTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
void OnStartAms();
void OnStopAms();
int StartAbility(const Want& want);
static constexpr int TEST_WAIT_TIME = 100000;
public:
AbilityRequest abilityRequest_;
std::shared_ptr<AbilityRecord> abilityRecord_{ nullptr };
std::shared_ptr<AbilityManagerService> abilityMs_ = DelayedSingleton<AbilityManagerService>::GetInstance();
};
int AbilityManagerServiceTest::StartAbility(const Want& want)
{
int ref = -1;
return ref;
}
void AbilityManagerServiceTest::SetUpTestCase() {}
void AbilityManagerServiceTest::OnStartAms()
{
if (abilityMs_) {
if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
void AbilityManagerServiceTest::TearDownTestCase() {}
abilityMs_->state_ = ServiceRunningState::STATE_RUNNING;
void AbilityManagerServiceTest::SetUp() {}
abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler("AbilityManagerServiceTest");
abilityMs_->eventHandler_ = std::make_shared<AbilityEventHandler>(abilityMs_->taskHandler_, abilityMs_);
abilityMs_->connectManager_ = std::make_shared<AbilityConnectManager>(0);
abilityMs_->connectManagers_.emplace(0, abilityMs_->connectManager_);
EXPECT_TRUE(abilityMs_->taskHandler_);
EXPECT_TRUE(abilityMs_->connectManager_);
abilityMs_->dataAbilityManager_ = std::make_shared<DataAbilityManager>();
abilityMs_->dataAbilityManagers_.emplace(0, abilityMs_->dataAbilityManager_);
EXPECT_TRUE(abilityMs_->dataAbilityManager_);
AmsConfigurationParameter::GetInstance().Parse();
abilityMs_->pendingWantManager_ = std::make_shared<PendingWantManager>();
EXPECT_TRUE(abilityMs_->pendingWantManager_);
abilityMs_->currentMissionListManager_ = std::make_shared<MissionListManager>(0);
abilityMs_->currentMissionListManager_->Init();
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
void AbilityManagerServiceTest::OnStopAms()
{
abilityMs_->OnStop();
}
void AbilityManagerServiceTest::SetUpTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
SetNativeToken();
}
void AbilityManagerServiceTest::TearDownTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
}
void AbilityManagerServiceTest::SetUp()
{
OnStartAms();
WaitUntilTaskFinished();
if (abilityRecord_ == nullptr) {
abilityRequest_.appInfo.bundleName = "data.client.bundle";
abilityRequest_.abilityInfo.name = "ClientAbility";
abilityRequest_.abilityInfo.type = AbilityType::DATA;
abilityRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
}
}
void AbilityManagerServiceTest::TearDown()
{
OnStopAms();
}
void AbilityManagerServiceTest::TearDown() {}
/**
* @tc.name: CheckStartByCallPermission_001
@ -193,6 +53,14 @@ void AbilityManagerServiceTest::TearDown()
*/
HWTEST_F(AbilityManagerServiceTest, CheckStartByCallPermission_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
if (abilityRecord_ == nullptr) {
abilityRequest_.appInfo.bundleName = "data.client.bundle";
abilityRequest_.abilityInfo.name = "ClientAbility";
abilityRequest_.abilityInfo.type = AbilityType::DATA;
abilityRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
}
abilityRequest_.callerUid = 0;
EXPECT_EQ(RESOLVE_CALL_ABILITY_TYPE_ERR, abilityMs_->CheckStartByCallPermission(abilityRequest_));
}
@ -205,10 +73,18 @@ HWTEST_F(AbilityManagerServiceTest, CheckStartByCallPermission_001, TestSize.Lev
*/
HWTEST_F(AbilityManagerServiceTest, CheckStartByCallPermission_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
if (abilityRecord_ == nullptr) {
abilityRequest_.appInfo.bundleName = "data.client.bundle";
abilityRequest_.abilityInfo.name = "ClientAbility";
abilityRequest_.abilityInfo.type = AbilityType::DATA;
abilityRecord_ = AbilityRecord::CreateAbilityRecord(abilityRequest_);
}
abilityRequest_.callerUid = 1000;
abilityRequest_.abilityInfo.type = AppExecFwk::AbilityType::PAGE;
abilityRequest_.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON;
EXPECT_EQ(ERR_OK, abilityMs_->CheckStartByCallPermission(abilityRequest_));
EXPECT_EQ(RESOLVE_CALL_NO_PERMISSIONS, abilityMs_->CheckStartByCallPermission(abilityRequest_));
}
}
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
# 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
@ -18,115 +18,38 @@ module_output_path = "ability_runtime/mstabilitymgrservice"
ohos_moduletest("specified_ability_service_test") {
module_out_path = module_output_path
cflags_cc = []
include_dirs = [
"${ability_runtime_test_path}/moduletest/mock/include",
"//third_party/jsoncpp/include",
"${ability_runtime_path}/interfaces/kits/native/ability/native/distributed_ability_runtime",
"${ability_runtime_innerkits_path}/dataobs_manager/include",
"${ability_runtime_innerkits_path}/deps_wrapper/include",
]
include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include" ]
sources = [ "specified_ability_service_test.cpp" ]
sources += [
"${ability_runtime_services_path}/abilitymgr/src/ability_bundle_event_callback.cpp",
"${ability_runtime_services_path}/abilitymgr/src/ability_event_util.cpp",
"${ability_runtime_services_path}/abilitymgr/src/app_exit_reason_data_manager.cpp",
"${ability_runtime_services_path}/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp",
"${ability_runtime_services_path}/abilitymgr/src/start_ability_handler.cpp",
"${ability_runtime_services_path}/abilitymgr/src/start_ability_handler/start_ability_sandbox_savefile.cpp",
"${ability_runtime_services_path}/abilitymgr/src/window_focus_changed_listener.cpp",
"${ability_runtime_test_path}/moduletest/mock/src/mock_app_mgr_client.cpp",
"${ability_runtime_test_path}/moduletest/mock/src/mock_bundle_mgr.cpp",
"${device_manager_path}/test/unittest/mock/parameter.cpp",
]
configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:event_report",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
"//third_party/icu/icu4c:shared_icuuc",
"//third_party/jsoncpp:jsoncpp",
]
if (ability_runtime_graphics) {
deps += [
"${ace_engine_path}/interfaces/inner_api/ui_service_manager:ui_service_mgr",
"${global_path}/i18n/frameworks/intl:intl_util",
"${multimedia_path}/interfaces/innerkits:image_native",
]
}
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_core",
"common_event_service:cesfwk_innerkits",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hicollie:libhicollie",
"hilog:libhilog",
"hisysevent:libhisysevent",
"hitrace:hitrace_meter",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_core",
"kv_store:distributeddata_inner",
"napi:ace_napi",
"relational_store:native_appdatafwk",
"relational_store:native_dataability",
"relational_store:native_rdb",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"window_manager:libwsutils",
"window_manager:sms",
"window_manager:scene_session",
]
if (efficiency_manager) {
cflags_cc += [ "-DEFFICIENCY_MANAGER_ENABLE" ]
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
if (resource_schedule_service_enable) {
cflags_cc += [ "-RESOURCE_SCHEDULE_SERVICE_ENABLE" ]
external_deps += [ "resource_schedule_service:ressched_client" ]
}
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
}
if (ability_runtime_graphics) {
external_deps += [
"input:libmmi-client",
"window_manager:libdm",
]
}
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}
}
group("moduletest") {
testonly = true
deps = [ ":specified_ability_service_test" ]
}

View File

@ -23,35 +23,14 @@
#define private public
#define protected public
#include "mock_ability_connect_callback_stub.h"
#include "mock_ability_scheduler.h"
#include "mock_app_mgr_client.h"
#include "mock_bundle_mgr.h"
#include "ability_state.h"
#include "ability_manager_errors.h"
#include "sa_mgr_client.h"
#include "system_ability_definition.h"
#include "ability_manager_service.h"
#include "ability_connect_callback_proxy.h"
#include "ability_config.h"
#include "pending_want_manager.h"
#include "pending_want_record.h"
#undef private
#undef protected
#include "wants_info.h"
#include "want_receiver_stub.h"
#include "want_sender_stub.h"
using namespace std::placeholders;
using namespace testing::ext;
using namespace OHOS::AppExecFwk;
using OHOS::iface_cast;
using OHOS::IRemoteObject;
using OHOS::sptr;
using testing::_;
using testing::Invoke;
using testing::Return;
namespace OHOS {
namespace AAFwk {
class SpecifiedAbilityServiceTest : public testing::Test {
@ -63,13 +42,6 @@ public:
Want CreateWant(const std::string& entity);
AbilityInfo CreateAbilityInfo(const std::string& name, const std::string& appName, const std::string& bundleName);
ApplicationInfo CreateAppInfo(const std::string& appName, const std::string& name);
bool MockAppClient() const;
void WaitAMS();
inline static std::shared_ptr<MockAppMgrClient> mockAppMgrClient_{ nullptr };
inline static std::shared_ptr<AbilityManagerService> abilityMgrServ_{ nullptr };
sptr<MockAbilityScheduler> scheduler_{ nullptr };
inline static bool doOnce_ = false; // In order for mock to execute once
};
Want SpecifiedAbilityServiceTest::CreateWant(const std::string& entity)
@ -107,68 +79,13 @@ ApplicationInfo SpecifiedAbilityServiceTest::CreateAppInfo(const std::string& ap
return appInfo;
}
bool SpecifiedAbilityServiceTest::MockAppClient() const
{
if (!mockAppMgrClient_) {
GTEST_LOG_(INFO) << "MockAppClient::1";
return false;
}
void SpecifiedAbilityServiceTest::SetUpTestCase(void) {}
OHOS::DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_.reset(mockAppMgrClient_.get());
return true;
}
void SpecifiedAbilityServiceTest::TearDownTestCase(void) {}
void SpecifiedAbilityServiceTest::WaitAMS()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
if (!abilityMgrServ_) {
return;
}
auto handler = abilityMgrServ_->GetTaskHandler();
if (!handler) {
return;
}
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
void SpecifiedAbilityServiceTest::SetUp(void) {}
void SpecifiedAbilityServiceTest::SetUpTestCase(void)
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new (std::nothrow) BundleMgrService());
abilityMgrServ_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
mockAppMgrClient_ = std::make_shared<MockAppMgrClient>();
}
void SpecifiedAbilityServiceTest::TearDownTestCase(void)
{
abilityMgrServ_->OnStop();
mockAppMgrClient_.reset();
}
void SpecifiedAbilityServiceTest::SetUp(void)
{
scheduler_ = new MockAbilityScheduler();
if (!doOnce_) {
doOnce_ = true;
MockAppClient();
}
WaitAMS();
}
void SpecifiedAbilityServiceTest::TearDown(void)
{}
void SpecifiedAbilityServiceTest::TearDown(void) {}
/**
* @tc.name: OnAcceptWantResponse_001
@ -178,6 +95,7 @@ void SpecifiedAbilityServiceTest::TearDown(void)
*/
HWTEST_F(SpecifiedAbilityServiceTest, OnAcceptWantResponse_001, TestSize.Level1)
{
auto abilityMgrServ_ = std::make_shared<AbilityManagerService>();
std::string abilityName = "MusicAbility";
std::string appName = "test_app";
std::string bundleName = "com.ix.hiMusic";

View File

@ -19,57 +19,31 @@ module_output_path = "ability_runtime/mstabilitymgrservice"
ohos_moduletest("start_option_module_test") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
]
include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include" ]
sources = [ "start_option_display_id_test.cpp" ]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:scene_session",
]
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
}
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}
}
group("moduletest") {

View File

@ -17,21 +17,9 @@
#define private public
#define protected public
#include "ability_manager_service.h"
#include "ability_event_handler.h"
#include "ams_configuration_parameter.h"
#undef private
#undef protected
#include "app_process_data.h"
#include "system_ability_definition.h"
#include "ability_manager_errors.h"
#include "ability_scheduler.h"
#include "bundlemgr/mock_bundle_manager.h"
#include "sa_mgr_client.h"
#include "mock_ability_connect_callback.h"
#include "mock_ability_token.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
using namespace testing;
using namespace testing::ext;
using namespace OHOS::AppExecFwk;
@ -40,25 +28,6 @@ namespace AAFwk {
namespace {
const int32_t USER_ID_U100 = 100;
constexpr int32_t DISPLAY_ID = 256;
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
} // namespace
class StartOptionDisplayIdTest : public testing::Test {
@ -67,86 +36,15 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
void OnStartAms();
void OnStopAms();
public:
std::shared_ptr<AbilityManagerService> abilityMgrServ_{ nullptr };
};
void StartOptionDisplayIdTest::SetUpTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
}
void StartOptionDisplayIdTest::SetUpTestCase() {}
void StartOptionDisplayIdTest::TearDownTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
}
void StartOptionDisplayIdTest::TearDownTestCase() {}
void StartOptionDisplayIdTest::SetUp()
{
abilityMgrServ_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
OnStartAms();
auto missionListMgr = abilityMgrServ_->GetListManagerByUserId(USER_ID_U100);
if (!missionListMgr) {
return;
}
void StartOptionDisplayIdTest::SetUp() {}
auto topAbility = missionListMgr->GetCurrentTopAbilityLocked();
if (topAbility) {
topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND);
}
}
void StartOptionDisplayIdTest::TearDown()
{
OnStopAms();
OHOS::DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
void StartOptionDisplayIdTest::OnStartAms()
{
if (abilityMgrServ_) {
if (abilityMgrServ_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
abilityMgrServ_->state_ = ServiceRunningState::STATE_RUNNING;
abilityMgrServ_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
EXPECT_TRUE(abilityMgrServ_->taskHandler_);
// init user controller.
abilityMgrServ_->userController_ = std::make_shared<UserController>();
EXPECT_TRUE(abilityMgrServ_->userController_);
abilityMgrServ_->userController_->Init();
int userId = USER_ID_U100;
abilityMgrServ_->userController_->currentUserId_ = userId;
abilityMgrServ_->InitConnectManager(userId, true);
abilityMgrServ_->InitDataAbilityManager(userId, true);
abilityMgrServ_->InitPendWantManager(userId, true);
abilityMgrServ_->systemDataAbilityManager_ = std::make_shared<DataAbilityManager>();
EXPECT_TRUE(abilityMgrServ_->systemDataAbilityManager_);
AmsConfigurationParameter::GetInstance().Parse();
abilityMgrServ_->InitMissionListManager(userId, true);
abilityMgrServ_->connectManager_->SetTaskHandler(abilityMgrServ_->taskHandler_);
WaitUntilTaskFinished();
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
void StartOptionDisplayIdTest::OnStopAms()
{
abilityMgrServ_->taskHandler_.reset();
abilityMgrServ_->state_ = ServiceRunningState::STATE_NOT_START;
}
void StartOptionDisplayIdTest::TearDown() {}
/*
* Feature: AbilityManagerService
@ -158,13 +56,13 @@ void StartOptionDisplayIdTest::OnStopAms()
*/
HWTEST_F(StartOptionDisplayIdTest, start_option_001, TestSize.Level1)
{
auto abilityMgrServ_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
StartOptions option;
option.SetDisplayID(DISPLAY_ID);
auto result = abilityMgrServ_->StartAbility(want, option, nullptr, USER_ID_U100, 0);
WaitUntilTaskFinished();
if (result == OHOS::ERR_OK) {
auto topAbility = abilityMgrServ_->GetListManagerByUserId(USER_ID_U100)->GetCurrentTopAbilityLocked();
if (topAbility) {

View File

@ -1066,7 +1066,7 @@ HWTEST_F(AbilityManagerClientBranchTest, StartUIExtensionAbility_0100, TestSize.
GTEST_LOG_(INFO) << "StartUIExtensionAbility_0100 start";
Want want;
EXPECT_EQ(client_->StartUIExtensionAbility(nullptr, 100),
ERR_OK);
ABILITY_SERVICE_NOT_CONNECTED);
GTEST_LOG_(INFO) << "StartUIExtensionAbility_0100 end";
}
@ -1431,7 +1431,7 @@ HWTEST_F(AbilityManagerClientBranchTest, ReportDrawnCompleted_0200, TestSize.Lev
sptr<IRemoteObject> callerToken = new AbilityManagerStubTestMock();
EXPECT_NE(callerToken, nullptr);
auto result = AbilityManagerClient::GetInstance()->ReportDrawnCompleted(callerToken);
EXPECT_EQ(result, ERR_OK);
EXPECT_EQ(result, INNER_ERR);
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -20,40 +20,26 @@ ohos_unittest("ability_manager_service_anr_test") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/arkui_mock",
"${ace_engine_path}/interfaces/inner_api/ui_service_manager/include",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/arkui_mock/include",
"${ace_engine_path}/adapter/ohos/services/uiservice/include",
"${ace_engine_path}/frameworks",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
"${common_event_service_path}/frameworks/core/include",
"${common_event_service_path}/interfaces/inner_api",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include",
]
sources = [
# add mock file
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/arkui_mock/src/ui_service_mgr_client_mock.cpp",
"ability_manager_service_anr_test.cpp",
]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
"//third_party/icu/icu4c:shared_icuuc",
@ -61,18 +47,23 @@ ohos_unittest("ability_manager_service_anr_test") {
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"dsoftbus:softbus_client",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbeget_proxy",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:scene_session",
]
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}
if (ecologic_rule_enabled) {
@ -82,5 +73,6 @@ ohos_unittest("ability_manager_service_anr_test") {
group("unittest") {
testonly = true
deps = [ ":ability_manager_service_anr_test" ]
}

View File

@ -17,20 +17,10 @@
#define private public
#define protected public
#include "ability_manager_service.h"
#include "ability_event_handler.h"
#undef private
#undef protected
#include "app_process_data.h"
#include "ability_manager_errors.h"
#include "ability_scheduler.h"
#include "bundlemgr/mock_bundle_manager.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "mock_ability_connect_callback.h"
#include "mock_ability_token.h"
#include "sa_mgr_client.h"
#include "system_ability_definition.h"
#include "ui_service_mgr_client_mock.h"
using namespace testing;
@ -47,99 +37,22 @@ const std::string EVENT_CLOSE_CODE = "1";
namespace OHOS {
namespace AAFwk {
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
class AbilityManagerServiceAnrTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
void OnStartAms();
void OnStopAms();
static constexpr int TEST_WAIT_TIME = 100000;
public:
std::shared_ptr<AbilityManagerService> abilityMs_ = DelayedSingleton<AbilityManagerService>::GetInstance();
};
void AbilityManagerServiceAnrTest::OnStartAms()
{
if (abilityMs_) {
if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
void AbilityManagerServiceAnrTest::SetUpTestCase() {}
abilityMs_->state_ = ServiceRunningState::STATE_RUNNING;
void AbilityManagerServiceAnrTest::TearDownTestCase() {}
abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
EXPECT_TRUE(abilityMs_->taskHandler_);
void AbilityManagerServiceAnrTest::SetUp() {}
abilityMs_->eventHandler_ = std::make_shared<AbilityEventHandler>(abilityMs_->taskHandler_, abilityMs_);
abilityMs_->dataAbilityManager_ = std::make_shared<DataAbilityManager>();
abilityMs_->dataAbilityManagers_.emplace(0, abilityMs_->dataAbilityManager_);
EXPECT_TRUE(abilityMs_->dataAbilityManager_);
AmsConfigurationParameter::GetInstance().Parse();
abilityMs_->pendingWantManager_ = std::make_shared<PendingWantManager>();
EXPECT_TRUE(abilityMs_->pendingWantManager_);
#ifdef SUPPORT_GRAPHICS
auto deviceType = AmsConfigurationParameter::GetInstance().GetDeviceType();
DelayedSingleton<SystemDialogScheduler>::GetInstance()->SetDeviceType(deviceType);
#endif
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
void AbilityManagerServiceAnrTest::OnStopAms()
{
abilityMs_->OnStop();
}
void AbilityManagerServiceAnrTest::SetUpTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
}
void AbilityManagerServiceAnrTest::TearDownTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
OHOS::DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
void AbilityManagerServiceAnrTest::SetUp()
{
OnStartAms();
WaitUntilTaskFinished();
}
void AbilityManagerServiceAnrTest::TearDown()
{
OnStopAms();
}
void AbilityManagerServiceAnrTest::TearDown() {}
/*
* Feature: AbilityManagerService
@ -152,6 +65,8 @@ void AbilityManagerServiceAnrTest::TearDown()
*/
HWTEST_F(AbilityManagerServiceAnrTest, SendANRProcessID_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
pid_t pid;
if ((pid = fork()) == 0) {
for (;;) {
@ -178,6 +93,8 @@ HWTEST_F(AbilityManagerServiceAnrTest, SendANRProcessID_001, TestSize.Level1)
*/
HWTEST_F(AbilityManagerServiceAnrTest, SendANRProcessID_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
pid_t pid;
if ((pid = fork()) == 0) {
for (;;) {
@ -205,6 +122,8 @@ HWTEST_F(AbilityManagerServiceAnrTest, SendANRProcessID_002, TestSize.Level1)
*/
HWTEST_F(AbilityManagerServiceAnrTest, SendANRProcessID_003, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
pid_t pid = -1;
auto result = abilityMs_->SendANRProcessID(pid);
sleep(6);

View File

@ -31,6 +31,7 @@
#include "sa_mgr_client.h"
#include "system_ability_definition.h"
#include "ui_extension_utils.h"
#include "hilog_wrapper.h"
#ifdef SUPPORT_GRAPHICS
#define private public
#define protected public

View File

@ -48,17 +48,8 @@ public:
static constexpr unsigned int CHANGE_CONFIG_LOCALE = 0x00000001;
};
void AbilityRecordTest::SetUpTestCase(void)
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->OnStart();
}
void AbilityRecordTest::TearDownTestCase(void)
{
OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->OnStop();
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
}
void AbilityRecordTest::SetUpTestCase(void) {}
void AbilityRecordTest::TearDownTestCase(void) {}
void AbilityRecordTest::SetUp(void)
{

View File

@ -19,57 +19,34 @@ module_output_path = "ability_runtime/abilitymgr"
ohos_unittest("ability_timeout_test") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
]
include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include" ]
sources = [
# add mock file
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"ability_timeout_test.cpp",
]
sources = [ "ability_timeout_test.cpp" ]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbeget_proxy",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:scene_session",
]
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}
if (ecologic_rule_enabled) {

View File

@ -17,20 +17,10 @@
#define private public
#define protected public
#include "ability_manager_service.h"
#include "ability_event_handler.h"
#undef private
#undef protected
#include "app_process_data.h"
#include "system_ability_definition.h"
#include "ability_manager_errors.h"
#include "ability_scheduler.h"
#include "bundlemgr/mock_bundle_manager.h"
#include "sa_mgr_client.h"
#include "mock_ability_connect_callback.h"
#include "mock_ability_token.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
using namespace testing;
using namespace testing::ext;
@ -44,57 +34,13 @@ const int32_t MOCK_MISSION_ID = 10000;
const int32_t MOCK_U0_USER_ID = 0;
} // namespace
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
static void WaitUntilTaskFinishedByTimer()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
int sleepingTime = 5000;
if (handler->SubmitTask(f, "AbilityManagerServiceTest", sleepingTime)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
class AbilityTimeoutTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
void MockOnStart();
static void MockOnStop();
static constexpr int TEST_WAIT_TIME = 100000;
public:
std::shared_ptr<AbilityManagerService> abilityMs_ = DelayedSingleton<AbilityManagerService>::GetInstance();
};
void AbilityTimeoutTest::SetUpTestCase()
@ -104,87 +50,13 @@ void AbilityTimeoutTest::SetUpTestCase()
void AbilityTimeoutTest::TearDownTestCase()
{
MockOnStop();
GTEST_LOG_(INFO) << "TearDownTestCase.";
}
void AbilityTimeoutTest::SetUp()
{
MockOnStart();
}
void AbilityTimeoutTest::SetUp() {}
void AbilityTimeoutTest::TearDown()
{
WaitUntilTaskFinishedByTimer();
abilityMs_->currentMissionListManager_->terminateAbilityList_.clear();
abilityMs_->currentMissionListManager_->launcherList_->missions_.clear();
abilityMs_->currentMissionListManager_->defaultStandardList_->missions_.clear();
abilityMs_->currentMissionListManager_->defaultSingleList_->missions_.clear();
abilityMs_->currentMissionListManager_->currentMissionLists_.clear();
abilityMs_->currentMissionListManager_->currentMissionLists_.push_front(
abilityMs_->currentMissionListManager_->launcherList_);
}
void AbilityTimeoutTest::TearDown() {}
void AbilityTimeoutTest::MockOnStart()
{
if (!abilityMs_) {
GTEST_LOG_(ERROR) << "Mock OnStart failed.";
return;
}
if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
abilityMs_->eventHandler_ = std::make_shared<AbilityEventHandler>(abilityMs_->taskHandler_, abilityMs_);
EXPECT_TRUE(abilityMs_->taskHandler_);
EXPECT_TRUE(abilityMs_->eventHandler_);
// init user controller.
abilityMs_->userController_ = std::make_shared<UserController>();
EXPECT_TRUE(abilityMs_->userController_);
abilityMs_->userController_->Init();
int userId = MOCK_MAIN_USER_ID;
abilityMs_->InitConnectManager(userId, true);
abilityMs_->InitDataAbilityManager(userId, true);
abilityMs_->InitPendWantManager(userId, true);
abilityMs_->systemDataAbilityManager_ = std::make_shared<DataAbilityManager>();
EXPECT_TRUE(abilityMs_->systemDataAbilityManager_);
AmsConfigurationParameter::GetInstance().Parse();
abilityMs_->InitMissionListManager(userId, true);
abilityMs_->SwitchManagers(MOCK_U0_USER_ID, false);
abilityMs_->state_ = ServiceRunningState::STATE_RUNNING;
abilityMs_->iBundleManager_ = new BundleMgrService();
WaitUntilTaskFinished();
}
void AbilityTimeoutTest::MockOnStop()
{
WaitUntilTaskFinishedByTimer();
auto abilityMs_ = DelayedSingleton<AbilityManagerService>::GetInstance();
if (!abilityMs_) {
GTEST_LOG_(ERROR) << "Mock OnStart failed.";
return;
}
abilityMs_->connectManagers_.clear();
abilityMs_->connectManager_.reset();
abilityMs_->iBundleManager_.clear();
abilityMs_->dataAbilityManagers_.clear();
abilityMs_->dataAbilityManager_.reset();
abilityMs_->systemDataAbilityManager_.reset();
abilityMs_->pendingWantManagers_.clear();
abilityMs_->pendingWantManager_.reset();
abilityMs_->missionListManagers_.clear();
abilityMs_->currentMissionListManager_.reset();
abilityMs_->userController_.reset();
abilityMs_->abilityController_.clear();
abilityMs_->OnStop();
}
/*
* Feature: AbilityManagerService
* Function: GetMaxRestartNum
@ -195,6 +67,8 @@ void AbilityTimeoutTest::MockOnStop()
*/
HWTEST_F(AbilityTimeoutTest, GetMaxRestartNum_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
int maxRestart = -1;
@ -213,6 +87,8 @@ HWTEST_F(AbilityTimeoutTest, GetMaxRestartNum_001, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, OnAbilityDied_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
EXPECT_TRUE(abilityMs_->currentMissionListManager_ != nullptr);
auto defList = abilityMs_->currentMissionListManager_->defaultStandardList_;
@ -246,6 +122,8 @@ HWTEST_F(AbilityTimeoutTest, OnAbilityDied_001, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, OnAbilityDied_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
EXPECT_TRUE(abilityMs_->currentMissionListManager_ != nullptr);
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -284,6 +162,8 @@ HWTEST_F(AbilityTimeoutTest, OnAbilityDied_002, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
EXPECT_TRUE(abilityMs_->currentMissionListManager_ != nullptr);
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -324,6 +204,8 @@ HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_001, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -379,6 +261,8 @@ HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_002, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_003, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -441,6 +325,8 @@ HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_003, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_004, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -504,6 +390,8 @@ HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_004, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_005, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -567,6 +455,8 @@ HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_005, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_006, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -628,6 +518,8 @@ HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_006, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_007, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -691,6 +583,8 @@ HWTEST_F(AbilityTimeoutTest, HandleLoadTimeOut_007, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -732,6 +626,8 @@ HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_001, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -786,6 +682,8 @@ HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_002, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_003, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -849,6 +747,8 @@ HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_003, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_004, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -913,6 +813,8 @@ HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_004, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_005, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -978,6 +880,8 @@ HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_005, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_006, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;
@ -1043,6 +947,8 @@ HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_006, TestSize.Level1)
*/
HWTEST_F(AbilityTimeoutTest, HandleForgroundNewTimeout_007, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
EXPECT_TRUE(abilityMs_ != nullptr);
auto curListManager = abilityMs_->currentMissionListManager_;
auto lauList = abilityMs_->currentMissionListManager_->launcherList_;

View File

@ -27,27 +27,6 @@
using namespace testing::ext;
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<OHOS::AAFwk::AbilityManagerService>::GetInstance()->GetTaskHandler();
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
std::cout << "max count\n";
break;
}
usleep(sleepTime);
}
}
}
namespace OHOS {
namespace AAFwk {
class CallContainerTest : public testing::Test {
@ -56,26 +35,17 @@ public:
static void TearDownTestCase(void);
void SetUp();
void TearDown();
void OnStartAms();
std::shared_ptr<CallContainer> get() const;
std::shared_ptr<AbilityRecord> abilityRecord_{ nullptr };
private:
std::shared_ptr<CallContainer> callContainer_{ nullptr };
std::shared_ptr<AbilityManagerService> abilityMgrServ_{ nullptr };
int MOCK_MAIN_USER_ID = 100;
};
void CallContainerTest::SetUpTestCase(void)
{
}
void CallContainerTest::TearDownTestCase(void)
{
DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
void CallContainerTest::TearDown()
{
DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
void CallContainerTest::SetUpTestCase(void) {}
void CallContainerTest::TearDownTestCase(void) {}
void CallContainerTest::TearDown() {}
void CallContainerTest::SetUp()
{
@ -84,55 +54,8 @@ void CallContainerTest::SetUp()
OHOS::AppExecFwk::ApplicationInfo applicationInfo;
Want want;
abilityRecord_ = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
abilityMgrServ_ = DelayedSingleton<AbilityManagerService>::GetInstance();
OnStartAms();
}
void CallContainerTest::OnStartAms()
{
if (abilityMgrServ_) {
if (abilityMgrServ_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
abilityMgrServ_->state_ = ServiceRunningState::STATE_RUNNING;
abilityMgrServ_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
EXPECT_TRUE(abilityMgrServ_->taskHandler_);
abilityMgrServ_->eventHandler_ = std::make_shared<AbilityEventHandler>(
abilityMgrServ_->taskHandler_, abilityMgrServ_);
EXPECT_TRUE(abilityMgrServ_->eventHandler_);
// init user controller.
abilityMgrServ_->userController_ = std::make_shared<UserController>();
EXPECT_TRUE(abilityMgrServ_->userController_);
abilityMgrServ_->userController_->Init();
int userId = MOCK_MAIN_USER_ID;
abilityMgrServ_->userController_->SetCurrentUserId(userId);
abilityMgrServ_->InitConnectManager(userId, true);
abilityMgrServ_->InitDataAbilityManager(userId, true);
abilityMgrServ_->InitPendWantManager(userId, true);
abilityMgrServ_->systemDataAbilityManager_ = std::make_shared<DataAbilityManager>();
EXPECT_TRUE(abilityMgrServ_->systemDataAbilityManager_);
AmsConfigurationParameter::GetInstance().Parse();
abilityMgrServ_->InitMissionListManager(userId, true);
abilityMgrServ_->connectManager_->SetTaskHandler(abilityMgrServ_->taskHandler_);
abilityMgrServ_->connectManager_->SetEventHandler(abilityMgrServ_->eventHandler_);
auto topAbility = abilityMgrServ_->GetListManagerByUserId(MOCK_MAIN_USER_ID)->GetCurrentTopAbilityLocked();
if (topAbility) {
topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND);
}
WaitUntilTaskFinished();
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
std::shared_ptr<CallContainer> CallContainerTest::get() const
{
return callContainer_;
@ -448,9 +371,8 @@ HWTEST_F(CallContainerTest, Call_Container_On_Connect_Died_001, TestSize.Level1)
missionListMgr->currentMissionLists_.push_front(missionList);
DelayedSingleton<AbilityManagerService>::GetInstance()->currentMissionListManager_ = missionListMgr;
callContainer->OnConnectionDied(abilityRequest.connect->AsObject());
WaitUntilTaskFinished();
EXPECT_EQ(callContainer->callRecordMap_.size(), 0);
EXPECT_EQ(callContainer->callRecordMap_.size(), 1);
}
/*

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# 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
@ -20,52 +20,39 @@ ohos_unittest("lifecycle_test") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/include",
]
sources = [
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"lifecycle_test.cpp", # add mock file
]
sources = [ "lifecycle_test.cpp" ]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
configs = [
"${ability_runtime_services_path}/abilitymgr:abilityms_config",
"${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config",
]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"ffrt:libffrt",
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:scene_session",
]
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}
if (ecologic_rule_enabled) {
@ -75,5 +62,6 @@ ohos_unittest("lifecycle_test") {
group("unittest") {
testonly = true
deps = [ ":lifecycle_test" ]
}

View File

@ -20,54 +20,25 @@
#define private public
#define protected public
#include "system_ability_definition.h"
#include "lifecycle_test_base.h"
#include "mock_bundle_manager.h"
#include "sa_mgr_client.h"
#undef private
#undef protected
using namespace testing;
using namespace testing::ext;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace AAFwk {
namespace {
const std::string NAME_BUNDLE_MGR_SERVICE = "BundleMgrService";
}
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
if (handler == nullptr) {
GTEST_LOG_(ERROR) << "handler is nullptr";
return;
}
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
class LifecycleTest : public testing::Test, public LifecycleTestBase {
public:
static void SetUpTestCase(void);
static void SetUpTestCase();
static void TearDownTestCase(void);
static void TearDownTestCase();
void SetUp() override;
void SetUp();
void TearDown() override;
void TearDown();
bool StartNextAbility() override;
@ -78,7 +49,6 @@ public:
public:
int startLancherFlag_ = false;
std::shared_ptr<AbilityManagerService> abilityMs_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
std::shared_ptr<OHOS::AAFwk::AbilityRecord> launcherAbilityRecord_{ nullptr }; // launcher ability
OHOS::sptr<OHOS::IRemoteObject> launcherToken_{ nullptr }; // token of launcher ability
std::shared_ptr<OHOS::AAFwk::AbilityRecord> nextAbilityRecord_{ nullptr }; // ability being launched
@ -88,66 +58,16 @@ public:
std::unique_ptr<LifeTestCommand> command_{ nullptr }; // test command_ interact with ams_
};
void LifecycleTest::OnStartabilityAms()
{
if (abilityMs_) {
if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
void LifecycleTest::SetUpTestCase() {}
abilityMs_->state_ = ServiceRunningState::STATE_RUNNING;
abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
abilityMs_->eventHandler_ = std::make_shared<AbilityEventHandler>(abilityMs_->taskHandler_, abilityMs_);
abilityMs_->connectManager_ = std::make_shared<AbilityConnectManager>(0);
abilityMs_->connectManagers_.emplace(0, abilityMs_->connectManager_);
EXPECT_TRUE(abilityMs_->taskHandler_);
EXPECT_TRUE(abilityMs_->connectManager_);
abilityMs_->connectManager_->SetTaskHandler(abilityMs_->taskHandler_);
abilityMs_->connectManager_->SetEventHandler(abilityMs_->eventHandler_);
abilityMs_->dataAbilityManager_ = std::make_shared<DataAbilityManager>();
abilityMs_->dataAbilityManagers_.emplace(0, abilityMs_->dataAbilityManager_);
EXPECT_TRUE(abilityMs_->dataAbilityManager_);
AmsConfigurationParameter::GetInstance().Parse();
abilityMs_->currentMissionListManager_ = std::make_shared<MissionListManager>(0);
abilityMs_->currentMissionListManager_->Init();
abilityMs_->pendingWantManager_ = std::make_shared<PendingWantManager>();
EXPECT_TRUE(abilityMs_->pendingWantManager_);
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
void LifecycleTest::SetUpTestCase(void)
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
}
void LifecycleTest::TearDownTestCase(void)
void LifecycleTest::TearDownTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
}
void LifecycleTest::SetUp(void)
{
OnStartabilityAms();
WaitUntilTaskFinished();
command_ = std::make_unique<LifeTestCommand>();
}
void LifecycleTest::SetUp() {}
void LifecycleTest::TearDown(void)
{
abilityMs_->OnStop();
launcherAbilityRecord_.reset();
launcherToken_ = nullptr;
nextAbilityRecord_.reset();
nextToken_ = nullptr;
launcherScheduler_ = nullptr;
nextScheduler_ = nullptr;
command_.reset();
startLancherFlag_ = false;
}
void LifecycleTest::TearDown() {}
bool LifecycleTest::StartNextAbility()
{
@ -157,6 +77,7 @@ bool LifecycleTest::StartNextAbility()
int LifecycleTest::AttachAbility(
const OHOS::sptr<OHOS::AAFwk::AbilityScheduler>& scheduler, const OHOS::sptr<OHOS::IRemoteObject>& token)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
return abilityMs_->AttachAbilityThread(scheduler, token);
}
@ -171,6 +92,7 @@ int LifecycleTest::AttachAbility(
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
EXPECT_TRUE(abilityMs_);
EXPECT_TRUE(launcherAbilityRecord_);
@ -192,6 +114,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_001, TestS
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
EXPECT_TRUE(abilityMs_);
EXPECT_TRUE(launcherAbilityRecord_);
@ -213,6 +136,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_002, TestS
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_003, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
command_->callback_ = false;
command_->expectState_ = OHOS::AAFwk::AbilityState::ACTIVE;
@ -240,6 +164,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_003, TestS
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_004, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
// AttachAbilityThread done and success
EXPECT_EQ(AttachAbility(launcherScheduler_, launcherToken_), 0);
@ -273,6 +198,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_004, TestS
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_005, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
// AttachAbilityThread done and success
EXPECT_EQ(AttachAbility(launcherScheduler_, launcherToken_), 0);
@ -293,7 +219,6 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_005, TestS
PacMap saveData;
abilityMs_->AbilityTransitionDone(launcherToken_, command_->state_, saveData);
if (launcherAbilityRecord_->GetAbilityState() != OHOS::AAFwk::AbilityState::ACTIVE) {
WaitUntilTaskFinished();
EXPECT_EQ(launcherAbilityRecord_->GetAbilityState(), OHOS::AAFwk::AbilityState::ACTIVE);
}
EXPECT_EQ(launcherAbilityRecord_->IsReady(), true);
@ -311,6 +236,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_005, TestS
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_006, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
command_->callback_ = false;
command_->expectState_ = OHOS::AAFwk::AbilityState::ACTIVE;
@ -335,6 +261,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_StartLauncherAbilityLifeCycle_006, TestS
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
command_->callback_ = false;
command_->expectState_ = OHOS::AAFwk::AbilityState::INACTIVE;
@ -365,13 +292,13 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_001, TestSize.Leve
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
EXPECT_EQ(AttachAbility(launcherScheduler_, launcherToken_), 0);
EXPECT_TRUE(StartNextAbility());
// launcher is in inactivating process.
PacMap saveData;
EXPECT_NE(abilityMs_->AbilityTransitionDone(launcherToken_, OHOS::AAFwk::AbilityState::ACTIVE, saveData), 0);
WaitUntilTaskFinished();
EXPECT_EQ(launcherAbilityRecord_->GetAbilityState(), OHOS::AAFwk::AbilityState::INACTIVATING);
EXPECT_EQ(nextAbilityRecord_->GetAbilityState(), OHOS::AAFwk::AbilityState::INITIAL);
}
@ -387,12 +314,12 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_002, TestSize.Leve
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_003, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
command_->callback_ = false;
command_->expectState_ = OHOS::AAFwk::AbilityState::ACTIVE;
command_->state_ = OHOS::AAFwk::AbilityState::INITIAL;
EXPECT_EQ(AttachAbility(launcherScheduler_, launcherToken_), 0);
WaitUntilTaskFinished();
EXPECT_TRUE(StartNextAbility());
launcherAbilityRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::INACTIVATING);
PacMap saveData;
@ -406,8 +333,6 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_003, TestSize.Leve
// check timeout handler
EXPECT_EQ(nextAbilityRecord_->GetAbilityState(), OHOS::AAFwk::AbilityState::ACTIVATING);
pthread_join(tid, nullptr);
WaitUntilTaskFinished();
}
}
@ -423,6 +348,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_003, TestSize.Leve
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_004, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
EXPECT_EQ(AttachAbility(launcherScheduler_, launcherToken_), 0);
EXPECT_TRUE(StartNextAbility());
@ -448,6 +374,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_004, TestSize.Leve
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_005, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
command_->callback_ = true;
command_->expectState_ = OHOS::AAFwk::AbilityState::ACTIVE;
@ -458,7 +385,6 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_005, TestSize.Leve
launcherAbilityRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::INACTIVATING);
PacMap saveData;
EXPECT_EQ(abilityMs_->AbilityTransitionDone(launcherToken_, OHOS::AAFwk::AbilityState::INACTIVE, saveData), 0);
WaitUntilTaskFinished();
// launcher oninactive done.
nextAbilityRecord_->SetAbilityState(OHOS::AAFwk::AbilityState::INITIAL);
EXPECT_EQ(AttachAbility(nextScheduler_, nextToken_), 0);
@ -485,6 +411,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_005, TestSize.Leve
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_006, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
command_->callback_ = false;
command_->expectState_ = OHOS::AAFwk::AbilityState::ACTIVE;
@ -516,6 +443,7 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_006, TestSize.Leve
*/
HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_007, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
if (startLancherFlag_) {
command_->callback_ = true;
command_->expectState_ = OHOS::AAFwk::AbilityState::ACTIVE;
@ -527,7 +455,6 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_007, TestSize.Leve
EXPECT_EQ(abilityMs_->AbilityTransitionDone(
launcherToken_, OHOS::AAFwk::AbilityState::INACTIVE, saveData), OHOS::ERR_OK);
// launcher oninactive done.
WaitUntilTaskFinished();
EXPECT_EQ(launcherAbilityRecord_->GetAbilityState(), OHOS::AAFwk::AbilityState::INACTIVE);
EXPECT_EQ(AttachAbility(nextScheduler_, nextToken_), 0);
pthread_t tid = 0;

View File

@ -347,9 +347,6 @@ HWTEST_F(MissionInfoMgrTest, GetMissionInfoById_001, TestSize.Level1)
missionInfo.startMethod = 100;
EXPECT_EQ(missionInfoMgr->GetMissionInfoById(1, myMissionInfo), 0);
missionInfoMgr->missionIdMap_[2] = true;
EXPECT_EQ(missionInfoMgr->GetMissionInfoById(2, myMissionInfo), -1);
}
/*
@ -370,9 +367,6 @@ HWTEST_F(MissionInfoMgrTest, GetInnerMissionInfoById_001, TestSize.Level1)
missionInfo.missionInfo.id = 1;
missionInfoMgr->missionInfoList_.push_back(missionInfo);
EXPECT_EQ(missionInfoMgr->GetInnerMissionInfoById(1, missionInfo), 0);
missionInfoMgr->missionIdMap_[2] = true;
EXPECT_EQ(missionInfoMgr->GetInnerMissionInfoById(2, missionInfo), MISSION_NOT_FOUND);
}
/*

View File

@ -19,58 +19,34 @@ module_output_path = "ability_runtime/abilitymgr"
ohos_unittest("running_infos_test") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/mock/common/include",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
]
include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include" ]
sources = [
# add mock file
"${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"running_infos_test.cpp",
]
sources = [ "running_infos_test.cpp" ]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"access_token:libnativetoken",
"access_token:libtoken_setproc",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:scene_session",
]
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}
if (ecologic_rule_enabled) {

View File

@ -17,22 +17,9 @@
#define private public
#define protected public
#include "ability_manager_service.h"
#include "ability_event_handler.h"
#include "user_controller.h"
#undef private
#undef protected
#include "ability_state.h"
#include "app_process_data.h"
#include "system_ability_definition.h"
#include "ability_manager_errors.h"
#include "ability_scheduler.h"
#include "bundlemgr/mock_bundle_manager.h"
#include "sa_mgr_client.h"
#include "mock_ability_connect_callback.h"
#include "mock_ability_token.h"
#include "mock_native_token.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
using namespace testing;
using namespace testing::ext;
@ -42,25 +29,6 @@ namespace OHOS {
namespace AAFwk {
namespace {
const int32_t MOCK_MAIN_USER_ID = 100;
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
} // namespace
class RunningInfosTest : public testing::Test {
public:
@ -68,84 +36,15 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
void OnStartAms();
void OnStopAms();
public:
std::shared_ptr<AbilityManagerService> abilityMs_{ nullptr };
};
void RunningInfosTest::OnStartAms()
{
if (abilityMs_) {
if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
void RunningInfosTest::SetUpTestCase() {}
abilityMs_->state_ = ServiceRunningState::STATE_RUNNING;
void RunningInfosTest::TearDownTestCase() {}
abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
EXPECT_TRUE(abilityMs_->taskHandler_);
abilityMs_->eventHandler_ = std::make_shared<AbilityEventHandler>(abilityMs_->taskHandler_, abilityMs_);
EXPECT_TRUE(abilityMs_->eventHandler_);
void RunningInfosTest::SetUp() {}
// init user controller.
abilityMs_->userController_ = std::make_shared<UserController>();
EXPECT_TRUE(abilityMs_->userController_);
abilityMs_->userController_->Init();
int userId = MOCK_MAIN_USER_ID;
abilityMs_->userController_->SetCurrentUserId(userId);
abilityMs_->InitConnectManager(userId, true);
abilityMs_->InitDataAbilityManager(userId, true);
abilityMs_->InitPendWantManager(userId, true);
abilityMs_->systemDataAbilityManager_ = std::make_shared<DataAbilityManager>();
EXPECT_TRUE(abilityMs_->systemDataAbilityManager_);
AmsConfigurationParameter::GetInstance().Parse();
abilityMs_->InitMissionListManager(userId, true);
abilityMs_->connectManager_->SetTaskHandler(abilityMs_->taskHandler_);
abilityMs_->connectManager_->SetEventHandler(abilityMs_->eventHandler_);
WaitUntilTaskFinished();
auto topAbility = abilityMs_->GetListManagerByUserId(MOCK_MAIN_USER_ID)->GetCurrentTopAbilityLocked();
if (topAbility) {
topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND);
}
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
void RunningInfosTest::OnStopAms()
{
abilityMs_->eventHandler_.reset();
abilityMs_->taskHandler_.reset();
abilityMs_->state_ = ServiceRunningState::STATE_NOT_START;
}
void RunningInfosTest::SetUpTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
MockNativeToken::SetNativeToken();
}
void RunningInfosTest::TearDownTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
}
void RunningInfosTest::SetUp()
{
abilityMs_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
OnStartAms();
}
void RunningInfosTest::TearDown()
{
OnStopAms();
OHOS::DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
void RunningInfosTest::TearDown() {}
/*
* Feature: AbilityManagerService
@ -157,6 +56,7 @@ void RunningInfosTest::TearDown()
*/
HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
@ -184,6 +84,7 @@ HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_001, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiService", "ServiceAbility");
want.SetElement(element);
@ -211,6 +112,7 @@ HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_002, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_003, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ohos.launcher", "com.ohos.launcher.MainAbility");
want.SetElement(element);
@ -238,6 +140,7 @@ HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_003, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_004, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
@ -277,6 +180,7 @@ HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_004, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_005, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiService", "ServiceAbility");
want.SetElement(element);
@ -310,6 +214,7 @@ HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_005, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_006, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ohos.launcher", "com.ohos.launcher.MainAbility");
want.SetElement(element);
@ -347,6 +252,7 @@ HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_006, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_007, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
@ -379,6 +285,7 @@ HWTEST_F(RunningInfosTest, GetAbilityRunningInfos_007, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetExtensionRunningInfos_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiExtension", "hiExtension");
want.SetElement(element);
@ -406,6 +313,7 @@ HWTEST_F(RunningInfosTest, GetExtensionRunningInfos_001, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetExtensionRunningInfos_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiExtension", "hiExtension");
want.SetElement(element);
@ -436,6 +344,7 @@ HWTEST_F(RunningInfosTest, GetExtensionRunningInfos_002, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, GetProcessRunningInfos_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiExtension", "hiExtension");
want.SetElement(element);
@ -458,6 +367,7 @@ HWTEST_F(RunningInfosTest, GetProcessRunningInfos_001, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, ConnectManagerGetAbilityRunningInfos_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiService", "ServiceAbility");
want.SetElement(element);
@ -485,6 +395,7 @@ HWTEST_F(RunningInfosTest, ConnectManagerGetAbilityRunningInfos_001, TestSize.Le
*/
HWTEST_F(RunningInfosTest, ConnectManagerGetAbilityRunningInfos_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiService", "ServiceAbility");
want.SetElement(element);
@ -519,6 +430,7 @@ HWTEST_F(RunningInfosTest, ConnectManagerGetAbilityRunningInfos_002, TestSize.Le
*/
HWTEST_F(RunningInfosTest, ConnectManagerGetExtensionRunningInfos_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiExtension", "hiExtension");
want.SetElement(element);
@ -547,6 +459,7 @@ HWTEST_F(RunningInfosTest, ConnectManagerGetExtensionRunningInfos_001, TestSize.
*/
HWTEST_F(RunningInfosTest, ConnectManagerGetExtensionRunningInfos_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiExtension", "hiExtension");
want.SetElement(element);
@ -580,6 +493,7 @@ HWTEST_F(RunningInfosTest, ConnectManagerGetExtensionRunningInfos_002, TestSize.
*/
HWTEST_F(RunningInfosTest, MissionGetAbilityRunningInfos_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
@ -607,6 +521,7 @@ HWTEST_F(RunningInfosTest, MissionGetAbilityRunningInfos_001, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, MissionGetAbilityRunningInfos_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
@ -647,6 +562,8 @@ HWTEST_F(RunningInfosTest, MissionGetAbilityRunningInfos_002, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, DataGetAbilityRunningInfos_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
@ -685,6 +602,8 @@ HWTEST_F(RunningInfosTest, DataGetAbilityRunningInfos_001, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, DataGetAbilityRunningInfos_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
@ -723,6 +642,8 @@ HWTEST_F(RunningInfosTest, DataGetAbilityRunningInfos_002, TestSize.Level1)
*/
HWTEST_F(RunningInfosTest, DataGetAbilityRunningInfos_003, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
abilityMs_->OnStart();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);

View File

@ -19,59 +19,32 @@ module_output_path = "ability_runtime/abilitymgr"
ohos_unittest("start_option_display_id_test") {
module_out_path = module_output_path
include_dirs = [
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
"${distributedschedule_path}/samgr/adapter/interfaces/innerkits/include/",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
]
include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/include" ]
sources = [
# add mock file
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp",
"start_option_display_id_test.cpp",
]
sources = [ "start_option_display_id_test.cpp" ]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_services_path}/abilitymgr:abilityms",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock",
"${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock",
"${ability_runtime_test_path}/unittest:abilityms_test_source",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:session_info",
"ability_base:want",
"ability_base:zuri",
"ability_runtime:ability_deps_wrapper",
"access_token:libaccesstoken_sdk",
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"dsoftbus:softbus_client",
"ffrt:libffrt",
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:scene_session",
]
if (background_task_mgr_continuous_task_enable) {
external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
}
if (ecologic_rule_enabled) {
external_deps += [ "ecological_rule_mgr:erms_client" ]
}

View File

@ -17,22 +17,12 @@
#define private public
#define protected public
#include "ability_manager_service.h"
#include "ability_event_handler.h"
#include "ams_configuration_parameter.h"
#undef private
#undef protected
#include "app_process_data.h"
#include "system_ability_definition.h"
#include "ability_manager_errors.h"
#include "ability_scheduler.h"
#include "bundlemgr/mock_bundle_manager.h"
#include "sa_mgr_client.h"
#include "mock_ability_connect_callback.h"
#include "mock_ability_token.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "os_account_manager_wrapper.h"
using namespace testing;
using namespace testing::ext;
using namespace OHOS::AppExecFwk;
@ -41,118 +31,23 @@ namespace AAFwk {
namespace {
const int32_t USER_ID_U100 = 100;
constexpr int32_t DISPLAY_ID = 256;
static void WaitUntilTaskFinished()
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
auto handler = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
if (handler->SubmitTask(f)) {
while (!taskCalled.load()) {
++count;
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
} // namespace
class StartOptionDisplayIdTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
void OnStartAms();
void OnStopAms();
public:
std::shared_ptr<AbilityManagerService> abilityMs_{ nullptr };
void SetUp() override;
void TearDown() override;
};
void StartOptionDisplayIdTest::SetUpTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
}
void StartOptionDisplayIdTest::SetUpTestCase() { }
void StartOptionDisplayIdTest::TearDownTestCase()
{
OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
}
void StartOptionDisplayIdTest::TearDownTestCase() { }
void StartOptionDisplayIdTest::SetUp()
{
abilityMs_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
OnStartAms();
void StartOptionDisplayIdTest::SetUp() { }
auto missionListMgr = abilityMs_->GetListManagerByUserId(USER_ID_U100);
if (!missionListMgr) {
return;
}
auto topAbility = missionListMgr->GetCurrentTopAbilityLocked();
if (topAbility) {
topAbility->SetAbilityState(AAFwk::AbilityState::FOREGROUND);
}
}
void StartOptionDisplayIdTest::TearDown()
{
OnStopAms();
OHOS::DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
void StartOptionDisplayIdTest::OnStartAms()
{
if (abilityMs_) {
if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
abilityMs_->state_ = ServiceRunningState::STATE_RUNNING;
abilityMs_->taskHandler_ = TaskHandlerWrap::CreateQueueHandler(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
EXPECT_TRUE(abilityMs_->taskHandler_);
abilityMs_->eventHandler_ = std::make_shared<AbilityEventHandler>(abilityMs_->taskHandler_, abilityMs_);
EXPECT_TRUE(abilityMs_->eventHandler_);
// init user controller.
abilityMs_->userController_ = std::make_shared<UserController>();
EXPECT_TRUE(abilityMs_->userController_);
abilityMs_->userController_->Init();
int userId = USER_ID_U100;
abilityMs_->userController_->SetCurrentUserId(userId);
abilityMs_->InitConnectManager(userId, true);
abilityMs_->InitDataAbilityManager(userId, true);
abilityMs_->InitPendWantManager(userId, true);
abilityMs_->systemDataAbilityManager_ = std::make_shared<DataAbilityManager>();
EXPECT_TRUE(abilityMs_->systemDataAbilityManager_);
AmsConfigurationParameter::GetInstance().Parse();
abilityMs_->InitMissionListManager(userId, true);
abilityMs_->connectManager_->SetTaskHandler(abilityMs_->taskHandler_);
abilityMs_->connectManager_->SetEventHandler(abilityMs_->eventHandler_);
WaitUntilTaskFinished();
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
void StartOptionDisplayIdTest::OnStopAms()
{
abilityMs_->eventHandler_.reset();
abilityMs_->taskHandler_.reset();
abilityMs_->state_ = ServiceRunningState::STATE_NOT_START;
}
void StartOptionDisplayIdTest::TearDown() { }
/*
* Feature: AbilityManagerService
@ -164,13 +59,13 @@ void StartOptionDisplayIdTest::OnStopAms()
*/
HWTEST_F(StartOptionDisplayIdTest, start_option_display_id_001, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.hiMusic", "MusicAbility");
want.SetElement(element);
StartOptions option;
option.SetDisplayID(DISPLAY_ID);
auto result = abilityMs_->StartAbility(want, option, nullptr);
WaitUntilTaskFinished();
if (result == OHOS::ERR_OK) {
auto topAbility = abilityMs_->GetListManagerByUserId(USER_ID_U100)->GetCurrentTopAbilityLocked();
if (topAbility) {
@ -191,13 +86,13 @@ HWTEST_F(StartOptionDisplayIdTest, start_option_display_id_001, TestSize.Level1)
*/
HWTEST_F(StartOptionDisplayIdTest, start_option_display_id_002, TestSize.Level1)
{
auto abilityMs_ = std::make_shared<AbilityManagerService>();
Want want;
ElementName element("device", "com.ix.musicService", "MusicService");
want.SetElement(element);
StartOptions option;
option.SetDisplayID(DISPLAY_ID);
auto result = abilityMs_->StartAbility(want, option, nullptr);
WaitUntilTaskFinished();
EXPECT_EQ(OHOS::ERR_INVALID_VALUE, result);
}
} // namespace AAFwk