!951 修复CES TDD单测crash

Merge pull request !951 from CheerfulRicky/work
This commit is contained in:
openharmony_ci 2024-05-16 14:10:14 +00:00 committed by Gitee
commit d22674d3c9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 52 additions and 8 deletions

View File

@ -172,8 +172,8 @@ void CommonEventListener::Stop()
EVENT_LOGE("commonEventSubscriber_ == nullptr");
return;
}
EVENT_LOGD("event size: %{public}u",
(uint32_t)commonEventSubscriber_->GetSubscribeInfo().GetMatchingSkills().CountEntities());
EVENT_LOGD("event size: %{public}zu",
commonEventSubscriber_->GetSubscribeInfo().GetMatchingSkills().CountEvent());
if (CommonEventSubscribeInfo::HANDLER == commonEventSubscriber_->GetSubscribeInfo().GetThreadMode()) {
EVENT_LOGD("stop listener in HANDLER mode");
return;

View File

@ -16,12 +16,13 @@
#ifndef FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MANAGER_SERVICE_H
#define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MANAGER_SERVICE_H
#include <singleton.h>
#include "common_event_stub.h"
#include "event_handler.h"
#include "ffrt.h"
#include "inner_common_event_manager.h"
#include "nocopyable.h"
#include "refbase.h"
#include <mutex>
namespace OHOS {
namespace EventFwk {
@ -29,6 +30,7 @@ enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
class CommonEventManagerService : public CommonEventStub {
public:
static sptr<CommonEventManagerService> GetInstance();
CommonEventManagerService();
virtual ~CommonEventManagerService();
/**
@ -170,6 +172,9 @@ private:
void GetHidumpInfo(const std::vector<std::u16string> &args, std::string &result);
private:
static sptr<CommonEventManagerService> instance_;
static std::mutex instanceMutex_;
std::shared_ptr<InnerCommonEventManager> innerCommonEventManager_;
ServiceRunningState serviceRunningState_ = ServiceRunningState::STATE_NOT_START;
std::shared_ptr<EventRunner> runner_;

View File

@ -16,6 +16,7 @@
#ifndef FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MANAGER_SERVICE_ABILITY_H
#define FOUNDATION_EVENT_CESFWK_SERVICES_INCLUDE_COMMON_EVENT_MANAGER_SERVICE_ABILITY_H
#include "refbase.h"
#include "system_ability.h"
#include "common_event_manager_service.h"
@ -45,7 +46,7 @@ private:
DECLARE_SYSTEM_ABILITY(CommonEventManagerServiceAbility);
private:
std::shared_ptr<CommonEventManagerService> service_;
sptr<CommonEventManagerService> service_;
};
} // namespace EventFwk
} // namespace OHOS

View File

@ -26,9 +26,12 @@
#include "ipc_skeleton.h"
#include "parameters.h"
#include "publish_manager.h"
#include "refbase.h"
#include "system_ability_definition.h"
#include "xcollie/watchdog.h"
#include "ces_inner_error_code.h"
#include <mutex>
#include <new>
namespace OHOS {
namespace EventFwk {
@ -38,6 +41,22 @@ const std::string NOTIFICATION_CES_CHECK_SA_PERMISSION = "notification.ces.check
using namespace OHOS::Notification;
sptr<CommonEventManagerService> CommonEventManagerService::instance_;
std::mutex CommonEventManagerService::instanceMutex_;
sptr<CommonEventManagerService> CommonEventManagerService::GetInstance()
{
std::lock_guard<std::mutex> lock(instanceMutex_);
if (instance_ == nullptr) {
instance_ = new (std::nothrow) CommonEventManagerService();
if (instance_ == nullptr) {
EVENT_LOGE("Failed to create CommonEventManagerService instance.");
return nullptr;
}
}
return instance_;
}
CommonEventManagerService::CommonEventManagerService()
: serviceRunningState_(ServiceRunningState::STATE_NOT_START),
runner_(nullptr),

View File

@ -15,7 +15,9 @@
#include "common_event_manager_service_ability.h"
#include "common_event_manager_service.h"
#include "event_log_wrapper.h"
#include <new>
namespace OHOS {
namespace EventFwk {
@ -38,14 +40,14 @@ void CommonEventManagerServiceAbility::OnStart()
return;
}
service_ = DelayedSingleton<CommonEventManagerService>::GetInstance();
service_ = CommonEventManagerService::GetInstance();
ErrCode errorCode = service_->Init();
if (errorCode != ERR_OK) {
EVENT_LOGE("Failed to init the commonEventManagerService instance.");
return;
}
if (!Publish(service_.get())) {
if (!Publish(service_)) {
EVENT_LOGE("Failed to publish CommonEventManagerService to SystemAbilityMgr");
return;
}

View File

@ -77,7 +77,7 @@ sptr<CommonEventManagerService> cesModuleTest::commonEventManagerService_ = null
void cesModuleTest::SetUpTestCase()
{
commonEventManagerService_ = new CommonEventManagerService();
commonEventManagerService_ = CommonEventManagerService::GetInstance();
commonEventManagerService_->Init();
bundleObject = new OHOS::AppExecFwk::MockBundleMgrService();

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "refbase.h"
#include <gtest/gtest.h>
#include <numeric>
#define private public
@ -63,7 +64,7 @@ HWTEST_F(CommonEventManagerServiceAbilityTest, CommonEventManagerServiceAbility_
std::shared_ptr<CommonEventManagerServiceAbility> commonEventManagerServiceAbility =
std::make_shared<CommonEventManagerServiceAbility>(systemAbilityId, runOnCreate);
ASSERT_NE(nullptr, commonEventManagerServiceAbility);
commonEventManagerServiceAbility->service_ = std::make_shared<CommonEventManagerService>();
commonEventManagerServiceAbility->service_ = sptr<CommonEventManagerService>();
commonEventManagerServiceAbility->OnStart();
GTEST_LOG_(INFO) << "CommonEventManagerServiceAbility_0100 end";
}

View File

@ -17,6 +17,14 @@ import("//build/test.gni")
module_output_path = "common_event_service/systemtest"
ohos_systemtest("cesSystemTest") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
debug = false
}
module_out_path = module_output_path
sources = [ "common_event_services_system_test.cpp" ]

View File

@ -49,6 +49,14 @@ ohos_systemtest("common_event_command_dump_system_test") {
}
ohos_systemtest("common_event_command_publish_system_test") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
debug = false
}
module_out_path = module_output_path
include_dirs = [ "${ability_runtime_path}/tools/test/systemtest/aa" ]