!1666 Fix TDD failure

Merge pull request !1666 from 张亚菲/zyf
This commit is contained in:
openharmony_ci
2022-04-28 02:46:18 +00:00
committed by Gitee
8 changed files with 164 additions and 17 deletions
@@ -74,6 +74,8 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
void OnStartAms();
void OnStopAms();
public:
std::shared_ptr<AbilityManagerService> abilityMs_ {nullptr};
@@ -93,10 +95,8 @@ void StartOptionDisplayIdTest::TearDownTestCase()
void StartOptionDisplayIdTest::SetUp()
{
abilityMs_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
abilityMs_->OnStart();
WaitUntilTaskFinished();
OnStartAms();
abilityMs_->StartUser(USER_ID_U100);
auto missionListMgr = abilityMs_->GetListManagerByUserId(USER_ID_U100);
if (!missionListMgr) {
return;
@@ -110,10 +110,59 @@ void StartOptionDisplayIdTest::SetUp()
void StartOptionDisplayIdTest::TearDown()
{
abilityMs_->OnStop();
OnStopAms();
OHOS::DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
void StartOptionDisplayIdTest::OnStartAms()
{
if (abilityMs_) {
if (abilityMs_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
abilityMs_->state_ = ServiceRunningState::STATE_RUNNING;
abilityMs_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
EXPECT_TRUE(abilityMs_->eventLoop_);
abilityMs_->handler_ = std::make_shared<AbilityEventHandler>(abilityMs_->eventLoop_, abilityMs_);
EXPECT_TRUE(abilityMs_->handler_);
// 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_);
abilityMs_->amsConfigResolver_ = std::make_shared<AmsConfigurationParameter>();
EXPECT_TRUE(abilityMs_->amsConfigResolver_);
abilityMs_->amsConfigResolver_->Parse();
abilityMs_->InitMissionListManager(userId, true);
abilityMs_->connectManager_->SetEventHandler(abilityMs_->handler_);
abilityMs_->eventLoop_->Run();
WaitUntilTaskFinished();
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
void StartOptionDisplayIdTest::OnStopAms()
{
abilityMs_->eventLoop_.reset();
abilityMs_->handler_.reset();
abilityMs_->state_ = ServiceRunningState::STATE_NOT_START;
}
/*
* Feature: AbilityManagerService
* Function: StartAbility
@@ -155,7 +155,7 @@ void AppMgrServiceInner::LoadAbility(const sptr<IRemoteObject> &token, const spt
HILOG_ERROR("CreateAppRunningRecord failed, appRecord is nullptr");
return;
}
uint32_t startFlags = BuildStartFlags(*want, *abilityInfo);
uint32_t startFlags = (want == nullptr) ? 0 : BuildStartFlags(*want, *abilityInfo);
StartProcess(abilityInfo->applicationName, processName, startFlags, appRecord,
appInfo->uid, appInfo->bundleName);
} else {
@@ -232,7 +232,7 @@ HWTEST_F(AmsAbilityRunningRecordTest, UpdateAbilityRunningRecord_001, TestSize.L
EXPECT_EQ(abilityRunningRecord->GetState(), AbilityState::ABILITY_STATE_FOREGROUND) << "execute fail!";
appRunningRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
EXPECT_CALL(*mockedAppClient_, ScheduleBackgroundApplication()).Times(2);
EXPECT_CALL(*mockedAppClient_, ScheduleBackgroundApplication()).Times(1);
appRunningRecord->UpdateAbilityState(token, AbilityState::ABILITY_STATE_BACKGROUND);
EXPECT_EQ(abilityRunningRecord->GetState(), AbilityState::ABILITY_STATE_BACKGROUND) << "execute fail!";
HILOG_DEBUG("UpdateAbilityRunningRecord_001 end.");
@@ -433,7 +433,7 @@ HWTEST_F(AmsAbilityRunningRecordTest, UpdateAbilityRunningRecord_006, TestSize.L
appRunningRecord->SetState(ApplicationState::APP_STATE_FOREGROUND);
abilityRunningRecord->SetState(AbilityState::ABILITY_STATE_FOREGROUND);
EXPECT_CALL(*mockedAppClient_, ScheduleBackgroundApplication()).Times(1);
EXPECT_CALL(*mockedAppClient_, ScheduleBackgroundApplication()).Times(2);
appRunningRecord->UpdateAbilityState(anotherToken, AbilityState::ABILITY_STATE_FOREGROUND);
auto abilities = appRunningRecord->GetAbilities();
@@ -70,6 +70,31 @@ const std::string KEY_BUNDLE_NAME = "bundleName";
const std::string DEVICE_ID = "ohos-phone1";
const std::string DEF_LABEL1 = "PermissionFormRequireGrant";
template<typename F>
static void WaitUntilTaskCalled(const F &f, const std::shared_ptr<EventHandler> &handler, std::atomic<bool> &taskCalled)
{
const uint32_t maxRetryCount = 1000;
const uint32_t sleepTime = 1000;
uint32_t count = 0;
if (handler->PostTask(f)) {
while (!taskCalled.load()) {
++count;
// if delay more than 1 second, break
if (count >= maxRetryCount) {
break;
}
usleep(sleepTime);
}
}
}
static void WaitUntilTaskDone(const std::shared_ptr<EventHandler> &handler)
{
std::atomic<bool> taskCalled(false);
auto f = [&taskCalled]() { taskCalled.store(true); };
WaitUntilTaskCalled(f, handler, taskCalled);
}
class FmsFormSysEventReceiverTest : public testing::Test {
public:
static void SetUpTestCase();
@@ -198,7 +223,10 @@ HWTEST_F(FmsFormSysEventReceiverTest, OnReceiveEvent_001, TestSize.Level0)
EventFwk::CommonEventData eventData;
eventData.SetWant(want);
FormSysEventReceiver testCase;
auto handler = std::make_shared<EventHandler>(EventRunner::Create());
testCase.SetEventHandler(handler);
testCase.OnReceiveEvent(eventData);
WaitUntilTaskDone(handler);
FormDbCache::GetInstance().GetAllFormInfo(allFormInfo);
FormDBInfo tempFormDBInfo;
EXPECT_EQ(ERR_APPEXECFWK_FORM_NOT_EXIST_ID, FormDbCache::GetInstance().GetDBRecord(formId, tempFormDBInfo));
@@ -231,7 +259,10 @@ HWTEST_F(FmsFormSysEventReceiverTest, OnReceiveEvent_002, TestSize.Level0)
CreateFormRecordAndFormInfo(bundle, formId, callingUid);
FormSysEventReceiver testCase;
auto handler = std::make_shared<EventHandler>(EventRunner::Create());
testCase.SetEventHandler(handler);
testCase.OnReceiveEvent(eventData);
WaitUntilTaskDone(handler);
FormRecord tempFormRecord;
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
@@ -267,7 +298,10 @@ HWTEST_F(FmsFormSysEventReceiverTest, OnReceiveEvent_003, TestSize.Level0)
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
FormSysEventReceiver testCase;
auto handler = std::make_shared<EventHandler>(EventRunner::Create());
testCase.SetEventHandler(handler);
testCase.OnReceiveEvent(eventData);
WaitUntilTaskDone(handler);
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
@@ -297,7 +331,10 @@ HWTEST_F(FmsFormSysEventReceiverTest, OnReceiveEvent_004, TestSize.Level0)
want.SetBundle(bundle);
want.SetParam(KEY_UID, callingUid);
FormSysEventReceiver testCase;
auto handler = std::make_shared<EventHandler>(EventRunner::Create());
testCase.SetEventHandler(handler);
testCase.OnReceiveEvent(eventData);
WaitUntilTaskDone(handler);
GTEST_LOG_(INFO) << "fms_form_sys_event_receiver_test_004 end";
}
@@ -324,7 +361,10 @@ HWTEST_F(FmsFormSysEventReceiverTest, OnReceiveEvent_005, TestSize.Level0)
CreateEventData(bundle, formId, callingUid, actionType, eventData);
FormSysEventReceiver testCase;
auto handler = std::make_shared<EventHandler>(EventRunner::Create());
testCase.SetEventHandler(handler);
testCase.OnReceiveEvent(eventData);
WaitUntilTaskDone(handler);
GTEST_LOG_(INFO) << "fms_form_sys_event_receiver_test_005 end";
}
@@ -372,7 +412,10 @@ HWTEST_F(FmsFormSysEventReceiverTest, OnReceiveEvent_006, TestSize.Level0)
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
FormSysEventReceiver testCase;
auto handler = std::make_shared<EventHandler>(EventRunner::Create());
testCase.SetEventHandler(handler);
testCase.OnReceiveEvent(eventData);
WaitUntilTaskDone(handler);
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
@@ -407,9 +450,12 @@ HWTEST_F(FmsFormSysEventReceiverTest, OnReceiveEvent_007, TestSize.Level0)
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
FormSysEventReceiver testCase;
auto handler = std::make_shared<EventHandler>(EventRunner::Create());
testCase.SetEventHandler(handler);
testCase.OnReceiveEvent(eventData);
WaitUntilTaskDone(handler);
ASSERT_FALSE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
ClearFormRecord(formId);
@@ -458,7 +504,10 @@ HWTEST_F(FmsFormSysEventReceiverTest, OnReceiveEvent_008, TestSize.Level0)
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
FormSysEventReceiver testCase;
auto handler = std::make_shared<EventHandler>(EventRunner::Create());
testCase.SetEventHandler(handler);
testCase.OnReceiveEvent(eventData);
WaitUntilTaskDone(handler);
ASSERT_TRUE(FormDataMgr::GetInstance().GetFormRecord(formId, tempFormRecord));
@@ -693,7 +693,7 @@ HWTEST_F(AmsAppServiceFlowModuleTest, ServiceFlow_ScreenOnAndOff_001, TestSize.L
ApplicationState::APP_STATE_BACKGROUND);
EXPECT_CALL(*(testAppA.mockAppScheduler_), ScheduleForegroundApplication()).Times(CYCLE_NUMBER + 1);
EXPECT_CALL(*(testAppA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(CYCLE_NUMBER + 1);
EXPECT_CALL(*(testAppA.mockAppScheduler_), ScheduleBackgroundApplication()).Times(CYCLE_NUMBER + 2);
for (uint32_t i = 0; i < CYCLE_NUMBER; i++) {
// simulate press ScreenOn key
@@ -16,7 +16,7 @@ import("//foundation/aafwk/standard/aafwk.gni")
module_output_path = "ability_runtime/mstabilitymgrservice"
ohos_moduletest("start_option_display_id_test") {
ohos_moduletest("start_option_module_test") {
module_out_path = module_output_path
include_dirs = [
@@ -65,5 +65,5 @@ ohos_moduletest("start_option_display_id_test") {
group("moduletest") {
testonly = true
deps = [ ":start_option_display_id_test" ]
deps = [ ":start_option_module_test" ]
}
@@ -74,6 +74,8 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
void OnStartAms();
void OnStopAms();
public:
std::shared_ptr<AbilityManagerService> abilityMgrServ_ {nullptr};
@@ -93,10 +95,7 @@ void StartOptionDisplayIdTest::TearDownTestCase()
void StartOptionDisplayIdTest::SetUp()
{
abilityMgrServ_ = OHOS::DelayedSingleton<AbilityManagerService>::GetInstance();
abilityMgrServ_->OnStart();
WaitUntilTaskFinished();
abilityMgrServ_->StartUser(USER_ID_U100);
OnStartAms();
auto missionListMgr = abilityMgrServ_->GetListManagerByUserId(USER_ID_U100);
if (!missionListMgr) {
return;
@@ -110,10 +109,59 @@ void StartOptionDisplayIdTest::SetUp()
void StartOptionDisplayIdTest::TearDown()
{
abilityMgrServ_->OnStop();
OnStopAms();
OHOS::DelayedSingleton<AbilityManagerService>::DestroyInstance();
}
void StartOptionDisplayIdTest::OnStartAms()
{
if (abilityMgrServ_) {
if (abilityMgrServ_->state_ == ServiceRunningState::STATE_RUNNING) {
return;
}
abilityMgrServ_->state_ = ServiceRunningState::STATE_RUNNING;
abilityMgrServ_->eventLoop_ = AppExecFwk::EventRunner::Create(AbilityConfig::NAME_ABILITY_MGR_SERVICE);
EXPECT_TRUE(abilityMgrServ_->eventLoop_);
abilityMgrServ_->handler_ = std::make_shared<AbilityEventHandler>(abilityMgrServ_->eventLoop_, abilityMgrServ_);
EXPECT_TRUE(abilityMgrServ_->handler_);
// init user controller.
abilityMgrServ_->userController_ = std::make_shared<UserController>();
EXPECT_TRUE(abilityMgrServ_->userController_);
abilityMgrServ_->userController_->Init();
int userId = USER_ID_U100;
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_);
abilityMgrServ_->amsConfigResolver_ = std::make_shared<AmsConfigurationParameter>();
EXPECT_TRUE(abilityMgrServ_->amsConfigResolver_);
abilityMgrServ_->amsConfigResolver_->Parse();
abilityMgrServ_->InitMissionListManager(userId, true);
abilityMgrServ_->connectManager_->SetEventHandler(abilityMgrServ_->handler_);
abilityMgrServ_->eventLoop_->Run();
WaitUntilTaskFinished();
return;
}
GTEST_LOG_(INFO) << "OnStart fail";
}
void StartOptionDisplayIdTest::OnStopAms()
{
abilityMgrServ_->eventLoop_.reset();
abilityMgrServ_->handler_.reset();
abilityMgrServ_->state_ = ServiceRunningState::STATE_NOT_START;
}
/*
* Feature: AbilityManagerService
* Function: StartAbility
+2 -1
View File
@@ -21,7 +21,8 @@ group("fuzztest") {
"finishusertest_fuzzer:fuzztest",
"getwantsender_fuzzer:fuzztest",
"setmissionlabel_fuzzer:fuzztest",
"startability_fuzzer:fuzztest",
#"startability_fuzzer:fuzztest",
"startcontinuation_fuzzer:fuzztest",
"stopserviceability_fuzzer:fuzztest",
"updateconfiguration_fuzzer:fuzztest",