!16745 test: 补充 TDD 用例及 Fuzz 用例

Merge pull request !16745 from 花祭/tdd
This commit is contained in:
openharmony_ci 2024-11-05 10:54:52 +00:00 committed by Gitee
commit 8a3dec83a5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 409 additions and 0 deletions

View File

@ -157,6 +157,8 @@ HWTEST_F(HdiBackendTest, RegHwcDeadListener002, Function | MediumTest| Level3)
HWTEST_F(HdiBackendTest, SetVsyncSamplerEnabled, Function | MediumTest| Level3)
{
OutputPtr output = HdiOutput::CreateHdiOutput(0);
hdiBackend_->SetVsyncSamplerEnabled(nullptr, false);
ASSERT_EQ(hdiBackend_->GetVsyncSamplerEnabled(nullptr), false);
hdiBackend_->SetVsyncSamplerEnabled(output, false);
ASSERT_EQ(hdiBackend_->GetVsyncSamplerEnabled(output), false);
}
@ -194,6 +196,60 @@ HWTEST_F(HdiBackendTest, OnPrepareComplete001, Function | MediumTest| Level3)
}
hdiBackend_->OnPrepareComplete(true, output, newLayerInfos);
}
/*
* Function: RegScreenVBlankIdleCallback001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1. call RegScreenVBlankIdleCallback()
* 2. check ret
*/
HWTEST_F(HdiBackendTest, RegScreenVBlankIdleCallback001, Function | MediumTest | Level3)
{
RosenError res = hdiBackend_->RegScreenVBlankIdleCallback(nullptr, nullptr);
EXPECT_EQ(res, ROSEN_ERROR_INVALID_ARGUMENTS);
}
/*
* Function: SetPendingMode001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1. call SetPendingMode()
* 2. check ret
*/
HWTEST_F(HdiBackendTest, SetPendingMode001, Function | MediumTest | Level3)
{
int64_t period = 1;
int64_t timestamp = 1;
hdiBackend_->SetPendingMode(nullptr, period, timestamp);
OutputPtr output = HdiOutput::CreateHdiOutput(0);
hdiBackend_->SetPendingMode(output, period, timestamp);
output->sampler_->Reset();
auto pendingPeriod = output->sampler_->GetHardwarePeriod();
EXPECT_EQ(pendingPeriod, period);
}
/*
* Function: StartSample001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1. call StartSample()
* 2. check ret
*/
HWTEST_F(HdiBackendTest, StartSample001, Function | MediumTest | Level3)
{
hdiBackend_->StartSample(nullptr);
OutputPtr output = HdiOutput::CreateHdiOutput(0);
hdiBackend_->SetPendingMode(output, 0, 0);
output->sampler_->SetHardwareVSyncStatus(false);
hdiBackend_->StartSample(output);
EXPECT_TRUE(output->sampler_->GetHardwareVSyncStatus());
}
} // namespace
} // namespace Rosen
} // namespace OHOS

View File

@ -353,6 +353,7 @@ HWTEST_F(HdiOutputTest, ReleaseLayers, Function | MediumTest | Level1)
sptr<SyncFence> fbFence = SyncFence::INVALID_FENCE;
HdiOutputTest::hdiOutput_->ReleaseLayers(fbFence);
}
/*
* Function: DumpHitchs
* Type: Function
@ -412,6 +413,212 @@ HWTEST_F(HdiOutputTest, DumpFps001, Function | MediumTest | Level1)
std::string arg;
output->DumpFps(result, arg);
}
/*
* Function: DeletePrevLayersLocked001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1.call DeletePrevLayersLocked()
* 2.check ret
*/
HWTEST_F(HdiOutputTest, DeletePrevLayersLocked001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
auto& surfaceIdMap = hdiOutput->surfaceIdMap_;
auto& layerIdMap = hdiOutput->layerIdMap_;
uint64_t id = 0;
LayerPtr layer = std::make_shared<HdiLayer>(id);
layer->isInUsing_ = true;
surfaceIdMap[id] = layer;
layerIdMap[id] = layer;
hdiOutput->DeletePrevLayersLocked();
EXPECT_EQ(surfaceIdMap.count(id), 1);
EXPECT_EQ(layerIdMap.count(id), 1);
layer->isInUsing_ = false;
hdiOutput->DeletePrevLayersLocked();
EXPECT_EQ(surfaceIdMap.count(id), 0);
EXPECT_EQ(layerIdMap.count(id), 0);
}
/*
* Function: RecordCompositionTime001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1.call RecordCompositionTime()
* 2.check ret
*/
HWTEST_F(HdiOutputTest, RecordCompositionTime001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
int64_t timestamp = 100;
hdiOutput->RecordCompositionTime(timestamp);
auto compTimeRcdIndex = hdiOutput->compTimeRcdIndex_;
if (compTimeRcdIndex == 0) {
compTimeRcdIndex = hdiOutput->COMPOSITION_RECORDS_NUM - 1;
} else {
compTimeRcdIndex -= 1;
}
EXPECT_EQ(hdiOutput->compositionTimeRecords_[compTimeRcdIndex], timestamp);
}
/*
* Function: CheckIfDoArsrPre001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1.call CheckIfDoArsrPre()
* 2.check ret
*/
HWTEST_F(HdiOutputTest, CheckIfDoArsrPre001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
LayerInfoPtr layerInfo = std::make_shared<HdiLayerInfo>();
bool res = hdiOutput->CheckIfDoArsrPre(nullptr);
EXPECT_FALSE(res);
layerInfo->cSurface_ = nullptr;
res = hdiOutput->CheckIfDoArsrPre(layerInfo);
EXPECT_FALSE(res);
layerInfo->cSurface_ = IConsumerSurface::Create("xcomponentIdSurface");
layerInfo->sbuffer_ = nullptr;
res = hdiOutput->CheckIfDoArsrPre(layerInfo);
EXPECT_FALSE(res);
layerInfo->sbuffer_ = new SurfaceBufferImpl();
layerInfo->arsrTag_ = true;
res = hdiOutput->CheckIfDoArsrPre(layerInfo);
EXPECT_TRUE(res);
}
/*
* Function: CheckIfDoArsrPreForVm001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1.call CheckIfDoArsrPreForVm()
* 2.check ret
*/
HWTEST_F(HdiOutputTest, CheckIfDoArsrPreForVm001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
LayerInfoPtr layerInfo = std::make_shared<HdiLayerInfo>();
layerInfo->cSurface_ = IConsumerSurface::Create("xcomponentIdSurface");
bool res = hdiOutput->CheckIfDoArsrPreForVm(layerInfo);
EXPECT_FALSE(res);
hdiOutput->vmArsrWhiteList_ = "xcomponentIdSurface";
res = res = hdiOutput->CheckIfDoArsrPreForVm(layerInfo);
EXPECT_TRUE(res);
}
/*
* Function: ReleaseFramebuffer001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1.call ReleaseFramebuffer()
* 2.check ret
*/
HWTEST_F(HdiOutputTest, ReleaseFramebuffer001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
sptr<SyncFence> fence = new SyncFence(0);
hdiOutput->currFrameBuffer_ = nullptr;
int32_t res = hdiOutput->ReleaseFramebuffer(fence);
EXPECT_EQ(res, GRAPHIC_DISPLAY_NULL_PTR);
hdiOutput->currFrameBuffer_ = new SurfaceBufferImpl();
hdiOutput->lastFrameBuffer_ = nullptr;
res = hdiOutput->ReleaseFramebuffer(fence);
EXPECT_EQ(res, GRAPHIC_DISPLAY_SUCCESS);
hdiOutput->currFrameBuffer_ = new SurfaceBufferImpl();
hdiOutput->lastFrameBuffer_ = new SurfaceBufferImpl();
hdiOutput->fbSurface_ = nullptr;
res = hdiOutput->ReleaseFramebuffer(fence);
EXPECT_EQ(res, GRAPHIC_DISPLAY_NULL_PTR);
hdiOutput->currFrameBuffer_ = new SurfaceBufferImpl();
hdiOutput->lastFrameBuffer_ = new SurfaceBufferImpl();
hdiOutput->fbSurface_ = new HdiFramebufferSurface();
res = hdiOutput->ReleaseFramebuffer(fence);
EXPECT_EQ(res, GRAPHIC_DISPLAY_SUCCESS);
}
/*
* Function: GetBufferCacheSize001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1.call GetBufferCacheSize()
* 2.check ret
*/
HWTEST_F(HdiOutputTest, GetBufferCacheSize001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
int res = hdiOutput->GetBufferCacheSize();
EXPECT_EQ(hdiOutput->bufferCache_.size(), res);
}
/*
* Function: StartVSyncSampler
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1.call StartVSyncSampler()
* 2.check ret
*/
HWTEST_F(HdiOutputTest, StartVSyncSampler001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
hdiOutput->enableVsyncSample_.store(false);
int32_t res = hdiOutput->StartVSyncSampler(true);
EXPECT_EQ(res, GRAPHIC_DISPLAY_FAILURE);
hdiOutput->enableVsyncSample_.store(true);
hdiOutput->sampler_ = nullptr;
res = hdiOutput->StartVSyncSampler(false);
EXPECT_EQ(res, GRAPHIC_DISPLAY_SUCCESS);
res = hdiOutput->StartVSyncSampler(true);
EXPECT_EQ(res, GRAPHIC_DISPLAY_SUCCESS);
}
/*
* Function: ClearFpsDump001
* Type: Function
* Rank: Important(1)
* EnvConditions: N/A
* CaseDescription: 1.call ClearFpsDump()
* 2.check ret
*/
HWTEST_F(HdiOutputTest, ClearFpsDump001, Function | MediumTest | Level1)
{
auto hdiOutput = HdiOutputTest::hdiOutput_;
std::string result = "";
std::string arg = "xcomponentIdSurface";
auto& surfaceIdMap = hdiOutput->surfaceIdMap_;
surfaceIdMap.clear();
uint64_t id = 0;
LayerPtr layer = std::make_shared<HdiLayer>(id);
LayerInfoPtr layerInfo = std::make_shared<HdiLayerInfo>();
layer->layerInfo_ = layerInfo;
layer->layerInfo_->cSurface_ = nullptr;
surfaceIdMap[id] = layer;
hdiOutput->ClearFpsDump(result, arg);
EXPECT_EQ(result, static_cast<std::string>("\nlayer is null.\n"));
result = "";
layer->layerInfo_->cSurface_ = IConsumerSurface::Create(arg);
hdiOutput->ClearFpsDump(result, arg);
EXPECT_EQ(
result, static_cast<std::string>("\n\n The fps info of surface [xcomponentIdSurface] Id[0] is cleared.\n"));
}
} // namespace
} // namespace Rosen
} // namespace OHOS

View File

@ -412,6 +412,20 @@ HWTEST_F(HdiScreenTest, SetScreenConstraint001, Function | MediumTest | Level3)
ASSERT_EQ(HdiScreenTest::hdiScreen_->SetScreenConstraint(frameId, timestamp, type), 0);
}
/*
* Function: GetDisplayPropertyForHardCursor001
* Type: Function
* Rank: Important(3)
* EnvConditions: N/A
* CaseDescription: 1. call GetDisplayPropertyForHardCursor
* 2. check ret
*/
HWTEST_F(HdiScreenTest, GetDisplayPropertyForHardCursor001, Function | MediumTest | Level3)
{
uint32_t screenId = 0;
bool res = hdiScreen_->GetDisplayPropertyForHardCursor(screenId);
EXPECT_FALSE(res);
}
} // namespace
} // namespace Rosen
} // namespace OHOS

View File

@ -37,6 +37,7 @@ void ResourceHolderFuzzTest000(const uint8_t* data, size_t size)
resource.HoldResource(img);
resource.ReleaseResource();
resource.IsEmpty();
resource.HaveReleaseableResourceCheck();
}
} // namespace Drawing
} // namespace Rosen

View File

@ -135,4 +135,114 @@ HWTEST_F(RSSKResourceManagerTest, ReleaseResource001, TestSize.Level1)
#endif
}
/**
* @tc.name: ReleaseResource002
* @tc.desc: test release resource
* @tc.type: FUNC
* @tc.require: issueI9IUKU
*/
HWTEST_F(RSSKResourceManagerTest, ReleaseResource002, TestSize.Level1)
{
#ifdef ROSEN_OHOS
RSTaskDispatcher::GetInstance().RegisterTaskDispatchFunc(gettid(), TaskDispatchFunc);
skResManager_.ReleaseResource();
sleep(1); // make sure release clean
{
auto imgptr = std::make_shared<Drawing::Image>();
skResManager_.HoldResource(imgptr);
EXPECT_EQ(skResManager_.images_.size(), 1);
for (auto& images : skResManager_.images_) {
// resource stil hold by imgptr, so HaveReleaseableResourceCheck should reture false
EXPECT_FALSE(images.second->HaveReleaseableResourceCheck());
}
imgptr = nullptr; // imgptr will not hold resource
for (auto& images : skResManager_.images_) {
// only skResManager_ hold resource, HaveReleaseableResourceCheck should reture true
EXPECT_TRUE(images.second->HaveReleaseableResourceCheck());
}
}
{
auto surfacePtr = std::make_shared<Drawing::Surface>();
skResManager_.HoldResource(surfacePtr);
// resource stil hold by surfacePtr, so HaveReleaseableResourceCheck should reture false
EXPECT_FALSE(skResManager_.HaveReleaseableResourceCheck(skResManager_.skSurfaces_[gettid()]));
surfacePtr = nullptr; // surfacePtr will not hold resource
// only skResManager_ hold resource, HaveReleaseableResourceCheck should reture true
EXPECT_TRUE(skResManager_.HaveReleaseableResourceCheck(skResManager_.skSurfaces_[gettid()]));
}
skResManager_.ReleaseResource();
sleep(1); // make sure release clean
EXPECT_FALSE(skResManager_.HaveReleaseableResourceCheck(skResManager_.skSurfaces_[gettid()]));
for (auto& images : skResManager_.images_) {
EXPECT_FALSE(images.second->HaveReleaseableResourceCheck());
}
#endif
}
/**
* @tc.name: ReleaseResource003
* @tc.desc: test release resource
* @tc.type: FUNC
* @tc.require: issueI9IUKU
*/
HWTEST_F(RSSKResourceManagerTest, ReleaseResource003, TestSize.Level1)
{
#ifdef ROSEN_OHOS
const uint32_t MAX_CHECK_SIZE = 20;
RSTaskDispatcher::GetInstance().RegisterTaskDispatchFunc(gettid(), TaskDispatchFunc);
skResManager_.ReleaseResource();
sleep(1); // make sure release clean
{
std::list<std::shared_ptr<Drawing::Image>> imagesMap;
for (uint32_t i = 0; i < MAX_CHECK_SIZE; i++) {
auto imgPtr = std::make_shared<Drawing::Image>();
imagesMap.push_back(imgPtr);
skResManager_.HoldResource(imgPtr);
}
for (auto& images : skResManager_.images_) {
// imagesMap hold resource, so there is no resource need to release
EXPECT_FALSE(images.second->HaveReleaseableResourceCheck());
}
skResManager_.HoldResource(std::make_shared<Drawing::Image>());
for (auto& images : skResManager_.images_) {
/* imagesMap hold resource. but size is over MAX_CHECK_SIZE
* so there maybe have resource need to release
*/
EXPECT_TRUE(images.second->HaveReleaseableResourceCheck());
}
}
{
std::list<std::shared_ptr<Drawing::Surface>> skSurfacesMap;
for (uint32_t i = 0; i < MAX_CHECK_SIZE; i++) {
auto surfacePtr = std::make_shared<Drawing::Surface>();
skResManager_.HoldResource(surfacePtr);
skSurfacesMap.push_back(surfacePtr);
}
// skSurfacesMap hold resource, so there is no resource need to release
EXPECT_FALSE(skResManager_.HaveReleaseableResourceCheck(skResManager_.skSurfaces_[gettid()]));
skResManager_.HoldResource(std::make_shared<Drawing::Surface>());
/* skSurfacesMap hold resource. but size is over MAX_CHECK_SIZE
* so there maybe have resource need to release
*/
EXPECT_TRUE(skResManager_.HaveReleaseableResourceCheck(skResManager_.skSurfaces_[gettid()]));
}
skResManager_.ReleaseResource();
sleep(1); // make sure release clean
EXPECT_FALSE(skResManager_.HaveReleaseableResourceCheck(skResManager_.skSurfaces_[gettid()]));
for (auto& images : skResManager_.images_) {
EXPECT_FALSE(images.second->HaveReleaseableResourceCheck());
}
#endif
}
} // namespace OHOS::Rosen

View File

@ -28,6 +28,7 @@ ohos_unittest("socketpair_test") {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"ipc:ipc_core",
]
}

View File

@ -123,4 +123,24 @@ HWTEST_F(LocalSocketPairTest, Close0Fd, Function | SmallTest | Level2)
int32_t ret = socketPair.CreateChannel(8, 8);
ASSERT_EQ(ret, 0);
}
/*
* Function: SendFdToBinder001
* Type: Function
* Rank: Important(2)
* EnvConditions: N/A
* CaseDescription: test SendFdToBinder
*/
HWTEST_F(LocalSocketPairTest, SendFdToBinder001, Function | SmallTest | Level2)
{
LocalSocketPair socketPair;
MessageParcel data;
int32_t fd = -1;
int32_t res = socketPair.SendFdToBinder(data, fd);
EXPECT_EQ(res, -1);
fd = 1;
res = socketPair.SendFdToBinder(data, fd);
EXPECT_EQ(res, 0);
}
}