add RS TDD

Signed-off-by: 李蔚 <liwei576@huawei.com>
This commit is contained in:
李蔚 2024-10-28 19:34:53 +08:00
parent e6f0fa161c
commit 11d19ff515
2 changed files with 1095 additions and 0 deletions

View File

@ -0,0 +1,686 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <hilog/log.h>
#include <memory>
#include <unistd.h>
#include "gtest/gtest.h"
#include "common/rs_common_def.h"
#include "pipeline/rs_dirty_region_manager.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS::Rosen {
namespace {
const RectI DEFAULT_RECT = {0, 0, 100, 100};
}
class RSDirtyRegionTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
static inline std::shared_ptr<RSDirtyRegionManager> rsDirtyManager = nullptr;
static inline RectI defaultRect = RectI();
static constexpr HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, 0xD001400, "RSDirtyRegionTest" };
};
void RSDirtyRegionTest::SetUpTestCase() {}
void RSDirtyRegionTest::TearDownTestCase() {}
void RSDirtyRegionTest::SetUp()
{
rsDirtyManager = std::make_shared<RSDirtyRegionManager>();
}
void RSDirtyRegionTest::TearDown() {}
/**
* @tc.name: GetPixelAlignedRect001
* @tc.desc: test results of GetPixelAlignedRect
* @tc.type:FUNC
* @tc.require: issueI5HRIF
*/
HWTEST_F(RSDirtyRegionTest, GetPixelAlignedRect001, TestSize.Level1)
{
/**
* @tc.steps: step1. GetPixelAlignedRect
*/
RectI rect = RectI(0, 0, 10, 10);
int32_t alignedBits = 1;
ASSERT_EQ(rsDirtyManager->GetPixelAlignedRect(rect, alignedBits), rect);
alignedBits = 11;
ASSERT_EQ(rsDirtyManager->GetPixelAlignedRect(rect, alignedBits), RectI(0, 0, 11, 11));
}
/**
* @tc.name: SetBufferAge001
* @tc.desc: test results of SetBufferAge
* @tc.type:FUNC
* @tc.require: issueI5HRIF
*/
HWTEST_F(RSDirtyRegionTest, SetBufferAge001, TestSize.Level1)
{
/**
* @tc.steps: step1. SetBufferAge
*/
int age = -1;
ASSERT_FALSE(rsDirtyManager->SetBufferAge(age));
age = 1;
ASSERT_TRUE(rsDirtyManager->SetBufferAge(age));
}
/**
* @tc.name: SetSurfaceSize001
* @tc.desc: test results of SetSurfaceSize
* @tc.type:FUNC
* @tc.require: issueI5HRIF
*/
HWTEST_F(RSDirtyRegionTest, SetSurfaceSize001, TestSize.Level1)
{
/**
* @tc.steps: step1. SetSurfaceSize
*/
int32_t width = -1;
int32_t height = -1;
ASSERT_FALSE(rsDirtyManager->SetSurfaceSize(width, height));
width = 1;
height = 1;
ASSERT_TRUE(rsDirtyManager->SetSurfaceSize(width, height));
}
/*
* @tc.name: GetDefaultDirtyRegion
* @tc.desc: Get dirtyManager's default dirty region
* @tc.type: FUNC
* @tc.require: issueI5PWM0
*/
HWTEST_F(RSDirtyRegionTest, GetDefaultDirtyRegion, Function | SmallTest | Level2)
{
RectI dirtyRect = rsDirtyManager->GetDirtyRegion();
EXPECT_EQ(dirtyRect, defaultRect);
}
/*
* @tc.name: MergeDirtyRectInvalid
* @tc.desc: DirtyManager's dirty region will not be changed if it merges invalid rect
* @tc.type: FUNC
* @tc.require: issueI5PWM0
*/
HWTEST_F(RSDirtyRegionTest, MergeDirtyRectInvalid, Function | SmallTest | Level2)
{
std::vector<RectI> invalidRects;
// invalid rect with negative width and height
invalidRects.push_back(RectI(0, 0, -360, -360));
// invalid rect with empty height
invalidRects.push_back(RectI(0, 0, 0, 360));
// invalid rect with empty width
invalidRects.push_back(RectI(0, 0, 360, 0));
RectI joinedRect = RectI();
RectI curDirtyRect = rsDirtyManager->GetCurrentFrameDirtyRegion();
EXPECT_EQ(curDirtyRect, defaultRect);
for (auto invalidRect : invalidRects) {
rsDirtyManager->MergeDirtyRect(invalidRect);
if (!invalidRect.IsEmpty()) {
joinedRect = joinedRect.JoinRect(invalidRect);
}
curDirtyRect = rsDirtyManager->GetCurrentFrameDirtyRegion();
HiviewDFX::HiLog::Info(LOG_LABEL, "MergeDirtyRectInvalid curDirtyRect %s invalidRect %s",
curDirtyRect.ToString().c_str(), invalidRect.ToString().c_str());
EXPECT_EQ(curDirtyRect, joinedRect);
}
}
/*
* @tc.name: MergeDirtyRectValid
* @tc.desc: DirtyManager's dirty region will be changed if it merges valid rects
* @tc.type: FUNC
* @tc.require: issueI5PWM0
*/
HWTEST_F(RSDirtyRegionTest, MergeDirtyRectValid, Function | SmallTest | Level2)
{
std::vector<RectI> validRects;
validRects.push_back(RectI(0, 0, 360, 360));
validRects.push_back(RectI(-100, 10, 30, 540));
validRects.push_back(RectI(20, -50, 180, 360));
RectI joinedRect = RectI();
RectI curDirtyRect = rsDirtyManager->GetCurrentFrameDirtyRegion();
EXPECT_EQ(curDirtyRect, defaultRect);
for (auto validRect : validRects) {
rsDirtyManager->MergeDirtyRect(validRect);
joinedRect = joinedRect.JoinRect(validRect);
curDirtyRect = rsDirtyManager->GetCurrentFrameDirtyRegion();
HiviewDFX::HiLog::Info(LOG_LABEL, "MergeDirtyRectValid curDirtyRect %s validRect %s",
curDirtyRect.ToString().c_str(), validRect.ToString().c_str());
EXPECT_EQ(curDirtyRect, joinedRect);
}
}
/*
* @tc.name: ClearDirtyRegion
* @tc.desc: Reset dirtyManager's dirty region
* @tc.type: FUNC
* @tc.require: issueI5PWM0
*/
HWTEST_F(RSDirtyRegionTest, ClearDirtyRegion, Function | SmallTest | Level2)
{
rsDirtyManager->Clear();
RectI dirtyRect = rsDirtyManager->GetDirtyRegion();
RectI currFrameDirtyRect = rsDirtyManager->GetCurrentFrameDirtyRegion();
EXPECT_EQ(dirtyRect, defaultRect);
EXPECT_EQ(currFrameDirtyRect, defaultRect);
}
/*
* @tc.name: UpdateDirtyInvalid
* @tc.desc: DirtyManager's dirty history will not be changed if dirtyRegion_ is invalid
* @tc.type: FUNC
* @tc.require: issueI5PWM0
*/
HWTEST_F(RSDirtyRegionTest, UpdateDirtyInvalid, Function | SmallTest | Level2)
{
std::vector<RectI> invalidRects;
// invalid rect with negative width and height
invalidRects.push_back(RectI(0, 0, -360, -360));
// invalid rect with empty height
invalidRects.push_back(RectI(0, 0, 0, 360));
// invalid rect with empty width
invalidRects.push_back(RectI(0, 0, 360, 0));
RectI curDirtyRect = RectI();
for (int i = 0; i < invalidRects.size(); ++i) {
rsDirtyManager->Clear();
rsDirtyManager->SetBufferAge(i + 1);
auto invalidRect = invalidRects[i];
rsDirtyManager->MergeDirtyRect(invalidRect);
rsDirtyManager->UpdateDirty();
// get current frame's dirty
curDirtyRect = rsDirtyManager->GetLatestDirtyRegion();
HiviewDFX::HiLog::Info(LOG_LABEL, "UpdateDirtyInvalid curDirtyRect %s invalidRect %s",
curDirtyRect.ToString().c_str(), invalidRect.ToString().c_str());
EXPECT_EQ(curDirtyRect, defaultRect);
// get merged frames' dirty(buffer age)
curDirtyRect = rsDirtyManager->GetDirtyRegion();
EXPECT_EQ(curDirtyRect, defaultRect);
}
}
/*
* @tc.name: UpdateDirtyValid
* @tc.desc: DirtyManager's dirty history will be pushed if dirtyRegion_ is valid
* @tc.type: FUNC
* @tc.require: issueI5PWM0
*/
HWTEST_F(RSDirtyRegionTest, UpdateDirtyValid, Function | SmallTest | Level2)
{
std::vector<RectI> validRects;
validRects.push_back(RectI(0, 0, 360, 360));
validRects.push_back(RectI(-100, 10, 30, 540));
validRects.push_back(RectI(20, -50, 180, 360));
RectI joinedRect = RectI();
RectI curDirtyRect = RectI();
for (int i = 0; i < validRects.size(); ++i) {
rsDirtyManager->Clear();
rsDirtyManager->SetBufferAge(i + 1);
auto validRect = validRects[i];
rsDirtyManager->MergeDirtyRect(validRect);
rsDirtyManager->UpdateDirty();
// get current frame's dirty
curDirtyRect = rsDirtyManager->GetLatestDirtyRegion();
HiviewDFX::HiLog::Info(LOG_LABEL, "UpdateDirtyValid curDirtyRect %s validRect %s",
curDirtyRect.ToString().c_str(), validRect.ToString().c_str());
EXPECT_EQ(curDirtyRect, validRect);
joinedRect = joinedRect.JoinRect(validRect);
// get merged frames' dirty(buffer age)
curDirtyRect = rsDirtyManager->GetDirtyRegion();
HiviewDFX::HiLog::Info(LOG_LABEL, "UpdateDirtyValid hisDirtyRect %s joinedRect %s",
curDirtyRect.ToString().c_str(), joinedRect.ToString().c_str());
EXPECT_EQ(curDirtyRect, joinedRect);
}
}
/*
* @tc.name: SetSurfaceSizeInvalid
* @tc.desc: Set surface size invalid and get return false
* @tc.type: FUNC
* @tc.require: issueI5SXX0
*/
HWTEST_F(RSDirtyRegionTest, SetSurfaceSizeInvalid, Function | SmallTest | Level2)
{
int32_t validWidth = 1920;
int32_t validHeight = 1080;
int32_t invalidVal = -1;
bool ret = rsDirtyManager->SetSurfaceSize(invalidVal, invalidVal);
EXPECT_EQ(ret, false);
ret = rsDirtyManager->SetSurfaceSize(invalidVal, validHeight);
EXPECT_EQ(ret, false);
ret = rsDirtyManager->SetSurfaceSize(validWidth, invalidVal);
EXPECT_EQ(ret, false);
}
/*
* @tc.name: SetSurfaceSizeValid
* @tc.desc: Set surface size valid and get return true
* @tc.type: FUNC
* @tc.require: issueI5SXX0
*/
HWTEST_F(RSDirtyRegionTest, SetSurfaceSizeValid, Function | SmallTest | Level2)
{
int32_t validWidth = 1920;
int32_t validHeight = 1080;
bool ret = rsDirtyManager->SetSurfaceSize(validWidth, validHeight);
EXPECT_EQ(ret, true);
validWidth = 1;
validHeight = 1;
ret = rsDirtyManager->SetSurfaceSize(validWidth, validHeight);
EXPECT_EQ(ret, true);
}
/*
* @tc.name: GetRectFlipWithinSurface
* @tc.desc: Set surface size and get rect flipped within surface
* @tc.type: FUNC
* @tc.require: issueI5SXX0
*/
HWTEST_F(RSDirtyRegionTest, GetRectFlipWithinSurface, Function | SmallTest | Level2)
{
int32_t surfaceWidth = 1920;
int32_t surfaceHeight = 1080;
bool ret = rsDirtyManager->SetSurfaceSize(surfaceWidth, surfaceHeight);
EXPECT_EQ(ret, true);
RectI oriRect = RectI(31, 31, 32, 65);
if (RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL) {
RectI flippedRect = rsDirtyManager->GetRectFlipWithinSurface(oriRect);
int32_t flippedTop = surfaceHeight - oriRect.top_ - oriRect.height_;
RectI expectedRect = RectI(oriRect.left_, flippedTop, oriRect.width_, oriRect.height_);
EXPECT_EQ(flippedRect, expectedRect);
}
else {
RectI flippedRect = rsDirtyManager->GetRectFlipWithinSurface(oriRect);
EXPECT_EQ(flippedRect, oriRect);
}
}
/*
* @tc.name: GetPixelAlignedRect
* @tc.desc: Get pixel aligned rect by assigned aligned bits
* @tc.type: FUNC
* @tc.require: issueI5SXX0
*/
HWTEST_F(RSDirtyRegionTest, GetPixelAlignedRect, Function | SmallTest | Level2)
{
// When aligned bits is no more than 1, aligned rect does not change
int32_t alignedBits = 1;
RectI oriRect = RectI(31, 31, 32, 65);
RectI alignedRect = RSDirtyRegionManager::GetPixelAlignedRect(oriRect, alignedBits);
EXPECT_EQ(alignedRect, oriRect);
// When aligned bits is more than 1, aligned rect zooms to fit aligned area
alignedBits = RSDirtyRegionManager::ALIGNED_BITS;
RectI expectedRect = RectI(0, 0, 64, 96);
alignedRect = RSDirtyRegionManager::GetPixelAlignedRect(oriRect, alignedBits);
EXPECT_EQ(alignedRect, expectedRect);
}
/**
* @tc.name: UpdateDirtyRegionInfoForDfxTest001
* @tc.desc:
* @tc.type:FUNC
*/
HWTEST_F(RSDirtyRegionTest, UpdateDirtyRegionInfoForDfxTest001, TestSize.Level1)
{
RSDirtyRegionManager fun;
NodeId id = 0;
DirtyRegionType dirtyRegionType = DirtyRegionType::TYPE_AMOUNT;
RSRenderNodeType nodeType = RSRenderNodeType::RS_NODE;
RectI rect;
fun.Clear();
fun.UpdateDirtyRegionInfoForDfx(id, nodeType, dirtyRegionType, rect);
std::map<NodeId, RectI> target;
fun.GetDirtyRegionInfo(target, nodeType, dirtyRegionType);
EXPECT_TRUE(target[id].IsEmpty());
}
/**
* @tc.name: UpdateDirtyRegionInfoForDfxTest002
* @tc.desc:
* @tc.type:FUNC
*/
HWTEST_F(RSDirtyRegionTest, UpdateDirtyRegionInfoForDfxTest002, TestSize.Level1)
{
RSDirtyRegionManager fun;
NodeId id = 0;
DirtyRegionType dirtyRegionType = DirtyRegionType::UPDATE_DIRTY_REGION;
RSRenderNodeType nodeType = RSRenderNodeType::CANVAS_NODE;
RectI rect = RectI(1, 2, 3, 4);
fun.Clear();
fun.UpdateDirtyRegionInfoForDfx(id, nodeType, dirtyRegionType, rect);
std::map<NodeId, RectI> target;
fun.GetDirtyRegionInfo(target, nodeType, dirtyRegionType);
EXPECT_TRUE(target[id] == rect);
}
/**
* @tc.name: UpdateDirtyRegionInfoForDfxTest003
* @tc.desc:
* @tc.type:FUNC
*/
HWTEST_F(RSDirtyRegionTest, UpdateDirtyRegionInfoForDfxTest003, TestSize.Level1)
{
RSDirtyRegionManager fun;
NodeId id = 0;
DirtyRegionType dirtyRegionType = DirtyRegionType::UPDATE_DIRTY_REGION;
RSRenderNodeType nodeType = RSRenderNodeType::SURFACE_NODE;
RectI rect = RectI(1, 2, 3, 4);
fun.Clear();
fun.UpdateDirtyRegionInfoForDfx(id, nodeType, dirtyRegionType, rect);
std::map<NodeId, RectI> target;
fun.GetDirtyRegionInfo(target, nodeType, dirtyRegionType);
EXPECT_TRUE(target[id] == rect);
}
/**
* @tc.name: UpdateDebugRegionTypeEnableTest001
* @tc.desc:
* @tc.type:FUNC
*/
HWTEST_F(RSDirtyRegionTest, UpdateDebugRegionTypeEnableTest001, TestSize.Level1)
{
RSDirtyRegionManager fun;
auto dirtyDebugType01 = DirtyRegionDebugType::CURRENT_SUB;
fun.UpdateDebugRegionTypeEnable(dirtyDebugType01);
auto var = DebugRegionType::CURRENT_SUB;
auto res = fun.IsDebugRegionTypeEnable(var);
EXPECT_TRUE(res);
auto dirtyDebugType02 = DirtyRegionDebugType::CURRENT_WHOLE;
fun.UpdateDebugRegionTypeEnable(dirtyDebugType02);
EXPECT_TRUE(fun.IsDebugRegionTypeEnable(DebugRegionType::CURRENT_WHOLE));
auto dirtyDebugType03 = DirtyRegionDebugType::MULTI_HISTORY;
fun.UpdateDebugRegionTypeEnable(dirtyDebugType03);
EXPECT_TRUE(fun.IsDebugRegionTypeEnable(DebugRegionType::MULTI_HISTORY));
auto dirtyDebugType04 = DirtyRegionDebugType::CURRENT_SUB_AND_WHOLE;
fun.UpdateDebugRegionTypeEnable(dirtyDebugType04);
EXPECT_TRUE(fun.IsDebugRegionTypeEnable(DebugRegionType::CURRENT_SUB));
EXPECT_TRUE(fun.IsDebugRegionTypeEnable(DebugRegionType::CURRENT_WHOLE));
auto dirtyDebugType05 = DirtyRegionDebugType::CURRENT_WHOLE_AND_MULTI_HISTORY;
fun.UpdateDebugRegionTypeEnable(dirtyDebugType05);
EXPECT_TRUE(fun.IsDebugRegionTypeEnable(DebugRegionType::CURRENT_WHOLE));
EXPECT_TRUE(fun.IsDebugRegionTypeEnable(DebugRegionType::MULTI_HISTORY));
auto dirtyDebugType06 = DirtyRegionDebugType::EGL_DAMAGE;
fun.UpdateDebugRegionTypeEnable(dirtyDebugType06);
EXPECT_TRUE(fun.IsDebugRegionTypeEnable(DebugRegionType::EGL_DAMAGE));
}
/**
* @tc.name: MergeDirtyRectAfterMergeHistory
* @tc.desc: test results of MergeDirtyRectAfterMergeHistory
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, MergeDirtyRectAfterMergeHistory, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI rect = { 0, 0, 100, 100 };
fun.MergeDirtyRectAfterMergeHistory(rect);
fun.MergeDirtyRectAfterMergeHistory(RectI());
fun.MergeDirtyRect(rect);
fun.isDisplayDirtyManager_ = true;
fun.MergeDirtyRect(rect, true);
EXPECT_FALSE(fun.dirtyRegion_.IsEmpty());
}
/**
* @tc.name: MergeHwcDirtyRect
* @tc.desc: test if MergeHwcDirtyRect can merge successfully
* @tc.type:FUNC
* @tc.require:IAHN26
*/
HWTEST_F(RSDirtyRegionTest, MergeHwcDirtyRect, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI rect = DEFAULT_RECT;
fun.MergeHwcDirtyRect(rect);
EXPECT_FALSE(fun.hwcDirtyRegion_.IsEmpty());
fun.MergeHwcDirtyRect(RectI());
fun.MergeHwcDirtyRect(rect);
EXPECT_FALSE(fun.hwcDirtyRegion_.IsEmpty());
}
/**
* @tc.name: MergeDirtyRectIfIntersect
* @tc.desc: test if MergeDirtyRectIfIntersect can merge successfully
* @tc.type:FUNC
* @tc.require:IAHN26
*/
HWTEST_F(RSDirtyRegionTest, MergeDirtyRectIfIntersect, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI rect = DEFAULT_RECT;
fun.MergeDirtyRectIfIntersect(rect);
EXPECT_TRUE(fun.GetCurrentFrameDirtyRegion().IsEmpty());
fun.MergeDirtyRect(rect);
fun.MergeDirtyRectIfIntersect(rect);
EXPECT_FALSE(fun.GetCurrentFrameDirtyRegion().IsEmpty());
fun.isDisplayDirtyManager_ = true;
fun.MergeDirtyRectIfIntersect(rect);
EXPECT_FALSE(fun.mergedDirtyRegions_.empty());
}
/**
* @tc.name: IntersectDirtyRect
* @tc.desc: test IntersectDirtyRect can intersect successfully
* @tc.type:FUNC
* @tc.require:IAHN26
*/
HWTEST_F(RSDirtyRegionTest, IntersectDirtyRect, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI rect = DEFAULT_RECT;
fun.IntersectDirtyRect(rect);
EXPECT_TRUE(fun.GetCurrentFrameDirtyRegion().IsEmpty());
}
/**
* @tc.name: SetCurrentFrameDirtyRect
* @tc.desc: test SetCurrentFrameDirtyRect can set successfully
* @tc.type:FUNC
* @tc.require:IAHN26
*/
HWTEST_F(RSDirtyRegionTest, SetCurrentFrameDirtyRect, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI rect = DEFAULT_RECT;
fun.SetCurrentFrameDirtyRect(rect);
EXPECT_FALSE(fun.GetCurrentFrameDirtyRegion().IsEmpty());
}
/**
* @tc.name: IsCurrentFrameDirty
* @tc.desc: test IsCurrentFrameDirty can get successfully
* @tc.type:FUNC
* @tc.require:IAHN26
*/
HWTEST_F(RSDirtyRegionTest, IsCurrentFrameDirty, TestSize.Level1)
{
RSDirtyRegionManager fun;
EXPECT_FALSE(fun.IsCurrentFrameDirty());
EXPECT_FALSE(fun.IsDirty());
}
/**
* @tc.name: UpdateVisitedDirtyRects
* @tc.desc: test results of UpdateVisitedDirtyRects
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, UpdateVisitedDirtyRects, TestSize.Level1)
{
RSDirtyRegionManager fun;
std::vector<RectI> rects;
fun.UpdateVisitedDirtyRects(rects);
RectI rect = { 1, 1, 1, 1 };
rects.push_back(rect);
fun.UpdateVisitedDirtyRects(rects);
EXPECT_TRUE(true);
}
/**
* @tc.name: GetIntersectedVisitedDirtyRect
* @tc.desc: test results of GetIntersectedVisitedDirtyRect
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, GetIntersectedVisitedDirtyRect, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI absRect;
fun.GetIntersectedVisitedDirtyRect(absRect);
RectI rect = { 1, 1, 1, 1 };
fun.GetIntersectedVisitedDirtyRect(rect);
EXPECT_TRUE(true);
}
/**
* @tc.name: UpdateCacheableFilterRect
* @tc.desc: test results of UpdateCacheableFilterRect
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, UpdateCacheableFilterRect, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI Rect;
fun.UpdateCacheableFilterRect(Rect);
RectI rectTwo = { 1, 1, 1, 1 };
fun.UpdateCacheableFilterRect(rectTwo);
EXPECT_TRUE(true);
}
/**
* @tc.name: IfCacheableFilterRectFullyCover
* @tc.desc: test results of IfCacheableFilterRectFullyCover
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, IfCacheableFilterRectFullyCover, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI Rect;
fun.cacheableFilterRects_.push_back(Rect);
EXPECT_TRUE(fun.IfCacheableFilterRectFullyCover(Rect));
fun.cacheableFilterRects_.clear();
fun.cacheableFilterRects_.push_back(RectI(1, 1, 1, 1));
EXPECT_FALSE(fun.IfCacheableFilterRectFullyCover(Rect));
}
/**
* @tc.name: GetDirtyRegionFlipWithinSurface
* @tc.desc: test results of GetDirtyRegionFlipWithinSurface
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, GetDirtyRegionFlipWithinSurface, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI Rect;
fun.GetDirtyRegionFlipWithinSurface();
fun.isDirtyRegionAlignedEnable_ = true;
fun.GetDirtyRegionFlipWithinSurface();
EXPECT_TRUE(true);
}
/**
* @tc.name: GetLatestDirtyRegion
* @tc.desc: test results of GetLatestDirtyRegion
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, GetLatestDirtyRegion, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI Rect;
fun.GetLatestDirtyRegion();
fun.historyHead_ = 1;
fun.GetLatestDirtyRegion();
EXPECT_TRUE(true);
}
/**
* @tc.name: UpdateDirty
* @tc.desc: test results of UpdateDirty
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, UpdateDirty, TestSize.Level1)
{
RSDirtyRegionManager fun;
RectI Rect;
fun.UpdateDirty(true);
fun.isDirtyRegionAlignedEnable_ = true;
fun.UpdateDirty(true);
EXPECT_TRUE(true);
}
/**
* @tc.name: GetHistory
* @tc.desc: test results of GetHistory
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, GetHistory, TestSize.Level1)
{
RSDirtyRegionManager fun;
unsigned int i = 1;
fun.GetHistory(i);
i = 10;
fun.historySize_ = 10;
fun.GetHistory(i);
EXPECT_TRUE(true);
}
/**
* @tc.name: AlignHistory
* @tc.desc: test results of AlignHistory
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDirtyRegionTest, AlignHistory, TestSize.Level1)
{
RSDirtyRegionManager fun;
fun.dirtyHistory_.push_back(RectI(1, 1, 1, 1));
fun.AlignHistory();
EXPECT_TRUE(true);
}
} // namespace OHOS::Rosen

View File

@ -0,0 +1,409 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "common/rs_obj_abs_geometry.h"
#include "pipeline/rs_canvas_render_node.h"
#include "pipeline/rs_display_render_node.h"
#include "pipeline/rs_render_thread_visitor.h"
#include "pipeline/rs_surface_render_node.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS::Rosen {
class RSDisplayNodeTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
static inline NodeId id;
RSDisplayNodeConfig config;
static inline std::weak_ptr<RSContext> context = {};
};
void RSDisplayNodeTest::SetUpTestCase() {}
void RSDisplayNodeTest::TearDownTestCase() {}
void RSDisplayNodeTest::SetUp() {}
void RSDisplayNodeTest::TearDown() {}
/**
* @tc.name: PrepareTest
* @tc.desc: test results of Prepare
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, PrepareTest, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
std::shared_ptr<RSNodeVisitor> visitor = nullptr;
node->QuickPrepare(visitor);
node->Prepare(visitor);
visitor = std::make_shared<RSRenderThreadVisitor>();
node->QuickPrepare(visitor);
node->Prepare(visitor);
ASSERT_TRUE(true);
}
/**
* @tc.name: SkipFrameTest001
* @tc.desc: test SkipFrame for refreshRate 0 and skipFrameInterval 0
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest001, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 0;
uint32_t skipFrameInterval = 0;
ASSERT_FALSE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest002
* @tc.desc: test SkipFrame for skipFrameInterval 0
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest002, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 0;
ASSERT_FALSE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest003
* @tc.desc: test SkipFrame for skipFrameInterval 1
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest003, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 1;
ASSERT_FALSE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest004
* @tc.desc: test SkipFrame for time within skipFrameInterval 2
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest004, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 2; // skipFrameInterval 2
node->SkipFrame(refreshRate, skipFrameInterval);
ASSERT_TRUE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest005
* @tc.desc: test SkipFrame for time over skipFrameInterval 2
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest005, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 2; // skipFrameInterval 2
node->SkipFrame(refreshRate, skipFrameInterval);
usleep(50000); // 50000us == 50ms
ASSERT_FALSE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest006
* @tc.desc: test SkipFrame for time within skipFrameInterval 6
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest006, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 6; // skipFrameInterval 6
node->SkipFrame(refreshRate, skipFrameInterval);
usleep(50000); // 50000us == 50ms
ASSERT_TRUE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest007
* @tc.desc: test SkipFrame for time over skipFrameInterval 6
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest007, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 6; // skipFrameInterval 6
node->SkipFrame(refreshRate, skipFrameInterval);
usleep(150000); // 150000us == 150ms
ASSERT_FALSE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest008
* @tc.desc: test SkipFrame for time over skipFrameInterval 55
* @tc.type:FUNC
* @tc.require: issuesIAVK8D
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest008, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 55; // skipFrameInterval 55
node->SkipFrame(refreshRate, skipFrameInterval);
usleep(16666); // 16666us == 16.666ms
ASSERT_FALSE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest009
* @tc.desc: test SkipFrame for time over skipFrameInterval 45
* @tc.type:FUNC
* @tc.require: issuesIAVK8D
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest009, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 45; // skipFrameInterval 45
node->SkipFrame(refreshRate, skipFrameInterval);
usleep(16666); // 16666us == 16.666ms
ASSERT_TRUE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SkipFrameTest010
* @tc.desc: test SkipFrame for time over skipFrameInterval 25
* @tc.type:FUNC
* @tc.require: issuesIAVK8D
*/
HWTEST_F(RSDisplayNodeTest, SkipFrameTest010, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
uint32_t refreshRate = 60; // 60hz
uint32_t skipFrameInterval = 25; // skipFrameInterval 25
node->SkipFrame(refreshRate, skipFrameInterval);
usleep(16666); // 16666us == 16.666ms
ASSERT_TRUE(node->SkipFrame(refreshRate, skipFrameInterval));
}
/**
* @tc.name: SetMirrorSourceTest
* @tc.desc: test results of SetMirrorSource
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SetMirrorSourceTest, TestSize.Level1)
{
std::shared_ptr<RSDisplayRenderNode> rsDisplayRenderNode = nullptr;
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
node->SetMirrorSource(rsDisplayRenderNode);
node->isMirroredDisplay_ = true;
node->SetMirrorSource(rsDisplayRenderNode);
rsDisplayRenderNode = std::make_shared<RSDisplayRenderNode>(id + 1, config, context);
node->SetMirrorSource(rsDisplayRenderNode);
ASSERT_NE(node->mirrorSource_.lock(), nullptr);
}
/**
* @tc.name: GetRotationTest
* @tc.desc: test results of GetRotation
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, GetRotationTest, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
node->InitRenderParams();
node->UpdateRotation();
node->GetRotation();
RSProperties& properties = const_cast<RSProperties&>(node->GetRenderProperties());
properties.boundsGeo_.reset(new RSObjAbsGeometry());
node->GetRotation();
ASSERT_TRUE(true);
}
/**
* @tc.name: IsRotationChangedTest
* @tc.desc: test results of IsRotationChanged
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, IsRotationChangedTest, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
node->InitRenderParams();
node->UpdateRotation();
ASSERT_FALSE(node->IsRotationChanged());
RSProperties& properties = const_cast<RSProperties&>(node->GetRenderProperties());
properties.boundsGeo_.reset(new RSObjAbsGeometry());
node->IsRotationChanged();
ASSERT_TRUE(true);
}
/**
* @tc.name: SetBootAnimationTest
* @tc.desc: test results of SetBootAnimation
* @tc.type:FUNC
* @tc.require:SR000HSUII
*/
HWTEST_F(RSDisplayNodeTest, SetBootAnimationTest, TestSize.Level1)
{
std::shared_ptr<RSRenderNode> node = std::make_shared<RSRenderNode>(id, context);
auto childNode = std::make_shared<RSDisplayRenderNode>(id + 1, config, context);
node->AddChild(childNode);
childNode->SetBootAnimation(true);
ASSERT_EQ(childNode->GetBootAnimation(), true);
node->SetBootAnimation(false);
childNode->SetBootAnimation(false);
ASSERT_FALSE(node->GetBootAnimation());
}
/**
* @tc.name: GetBootAnimationTest
* @tc.desc: test results of GetBootAnimation
* @tc.type:FUNC
* @tc.require:SR000HSUII
*/
HWTEST_F(RSDisplayNodeTest, GetBootAnimationTest, TestSize.Level1)
{
auto node = std::make_shared<RSDisplayRenderNode>(id, config, context);
node->SetBootAnimation(true);
ASSERT_TRUE(node->GetBootAnimation());
node->SetBootAnimation(false);
ASSERT_FALSE(node->GetBootAnimation());
}
/**
* @tc.name: CollectSurface
* @tc.desc: test results of CollectSurface
* @tc.type:FUNC
* @tc.require:issueI981R9
*/
HWTEST_F(RSDisplayNodeTest, CollectSurface, TestSize.Level2)
{
auto displayNode = std::make_shared<RSDisplayRenderNode>(id, config, context);
RSContext* rsContext = new RSContext();
std::shared_ptr<RSContext> sharedContext(rsContext);
std::shared_ptr<RSBaseRenderNode> node = std::make_shared<RSRenderNode>(1, sharedContext);
std::vector<RSBaseRenderNode::SharedPtr> vec;
bool isUniRender = true;
bool onlyFirstLevel = true;
displayNode->CollectSurface(node, vec, isUniRender, onlyFirstLevel);
ASSERT_TRUE(true);
}
/**
* @tc.name: ProcessTest
* @tc.desc: test results of Process
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, ProcessTest, TestSize.Level1)
{
std::shared_ptr<RSNodeVisitor> visitor = nullptr;
auto displayNode = std::make_shared<RSDisplayRenderNode>(id, config, context);
displayNode->Process(visitor);
visitor = std::make_shared<RSRenderThreadVisitor>();
displayNode->Process(visitor);
ASSERT_TRUE(true);
}
/**
* @tc.name: SetIsOnTheTree
* @tc.desc: test results of SetIsOnTheTree
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SetIsOnTheTree, TestSize.Level1)
{
auto displayNode = std::make_shared<RSDisplayRenderNode>(id, config, context);
bool flag = true;
displayNode->SetIsOnTheTree(flag, id, id, id, id);
ASSERT_TRUE(true);
}
/**
* @tc.name: SetCompositeType
* @tc.desc: test results of SetCompositeType
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SetCompositeType, TestSize.Level1)
{
auto displayNode = std::make_shared<RSDisplayRenderNode>(id, config, context);
RSDisplayRenderNode::CompositeType type = RSDisplayRenderNode::CompositeType::UNI_RENDER_COMPOSITE;
displayNode->SetCompositeType(type);
ASSERT_EQ(displayNode->GetCompositeType(), type);
}
/**
* @tc.name: SetForceSoftComposite
* @tc.desc: test results of SetForceSoftComposite
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, SetForceSoftComposite, TestSize.Level1)
{
auto displayNode = std::make_shared<RSDisplayRenderNode>(id, config, context);
bool flag = true;
displayNode->SetForceSoftComposite(flag);
ASSERT_EQ(displayNode->IsForceSoftComposite(), flag);
}
/**
* @tc.name: UpdateRenderParams
* @tc.desc: test results of UpdateRenderParams
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, UpdateRenderParams, TestSize.Level1)
{
auto displayNode = std::make_shared<RSDisplayRenderNode>(id, config, context);
displayNode->UpdateRenderParams();
ASSERT_TRUE(true);
}
/**
* @tc.name: UpdateScreenRenderParams
* @tc.desc: test results of UpdateRenderParams
* @tc.type:FUNC
* @tc.require:
*/
HWTEST_F(RSDisplayNodeTest, UpdateScreenRenderParams, TestSize.Level1)
{
auto displayNode = std::make_shared<RSDisplayRenderNode>(id, config, context);
RSDisplayRenderNode::ScreenRenderParams screenRenderParams;
displayNode->UpdateScreenRenderParams(screenRenderParams);
ASSERT_TRUE(true);
}
} // namespace OHOS::Rosen