!16696 fuzz用例补充

Merge pull request !16696 from 郭林川/master
This commit is contained in:
openharmony_ci 2024-11-04 12:55:24 +00:00 committed by Gitee
commit 49cb11c85a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 450 additions and 2 deletions

View File

@ -27,11 +27,13 @@
#include <securec.h>
#include <unistd.h>
#include "common/rs_color.h"
#include "draw/canvas.h"
#include "pipeline/rs_paint_filter_canvas.h"
#include "pipeline/rs_render_content.h"
#include "property/rs_properties.h"
#include "property/rs_property_drawable_bounds_geometry.h"
#include "skia_adapter/skia_surface.h"
namespace OHOS {
namespace Rosen {
@ -75,7 +77,9 @@ bool DoDraw(const uint8_t* data, size_t size)
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
RSRenderContent content;
RSProperties properties;
auto& properties = content.GetMutableRenderProperties();
float value = GetData<float>();
properties.SetBounds(value);
auto rsBound = std::make_shared<RSBoundsGeometryDrawable>();
rsBound->Draw(content, cacheCanvas);
auto rsPoint = std::make_shared<RSPointLightDrawable>();
@ -109,17 +113,58 @@ bool DoGenerate(const uint8_t* data, size_t size)
RSRenderContent content;
RSBoundsGeometryDrawable::Generate(content);
RSPointLightDrawable::Generate(content);
RSShadowBaseDrawable::Generate(content);
Brush brush;
Pen pen;
RSBorderDrawable::Generate(content);
RSOutlineDrawable::Generate(content);
RSMaskDrawable::Generate(content);
float value = GetData<float>();
uint32_t color = GetData<uint32_t>();
BorderStyle borderStyle = static_cast<BorderStyle>(GetData<uint32_t>() % 4);
auto& properties = content.GetMutableRenderProperties();
properties.SetBorderWidth(value);
properties.SetBorderColor(RSColor::FromArgbInt(color));
properties.SetBorderStyle(static_cast<uint32_t>(borderStyle));
RSBorderDrawable::Generate(content);
Vector4f radius = GetData<Vector4f>();
properties.SetOutlineRadius(radius);
properties.GetOutline()->SetWidth(value);
properties.GetOutline()->SetColor(RSColor::FromArgbInt(color));
properties.GetOutline()->SetStyle(borderStyle);
RSOutlineDrawable::Generate(content);
auto mask = std::make_shared<RSMask>();
MaskType maskType = static_cast<MaskType>(GetData<uint32_t>() % 5);
mask->SetMaskType(maskType);
RSMaskDrawable::Generate(content);
RSShadowBaseDrawable::Generate(content);
return true;
}
bool DoRSClipBoundsDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
RSRenderContent content;
int32_t width = GetData<int32_t>();
int32_t height = GetData<int32_t>();
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
auto rsClipBoundsDrawable = std::make_shared<RSClipBoundsDrawable>();
rsClipBoundsDrawable->Generate(content);
rsClipBoundsDrawable->Draw(content, cacheCanvas);
return true;
}
bool DoRSBorderDRRectDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
@ -171,13 +216,90 @@ bool DoRSBorderFourLineDrawable(const uint8_t* data, size_t size)
Drawing::Pen pen;
pen.SetAntiAlias(true);
brush.SetAntiAlias(true);
RSProperties properties;
int32_t width = GetData<int32_t>();
int32_t height = GetData<int32_t>();
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
RSRenderContent content;
RSProperties& properties = content.GetMutableRenderProperties();
auto rsBorderFourLineDrawable =
std::make_shared<RSBorderFourLineDrawable>(std::move(brush), std::move(pen), properties, true);
Vector4f borderWidth = GetData<Vector4f>();
properties.SetBorderWidth(borderWidth);
rsBorderFourLineDrawable->Draw(content, cacheCanvas);
rsBorderFourLineDrawable->OnBoundsChange(properties);
return true;
}
bool DoRSBorderPathDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
uint32_t r = GetData<uint32_t>();
uint32_t g = GetData<uint32_t>();
uint32_t b = GetData<uint32_t>();
uint32_t a = GetData<uint32_t>();
Color c(r, g, b, a);
Brush brush(c);
Drawing::Pen pen;
pen.SetAntiAlias(true);
brush.SetAntiAlias(true);
RSProperties properties;
auto border = std::make_shared<RSBorder>();
float value = GetData<float>();
properties.SetBorderWidth(value);
properties.SetOutlineWidth(value);
auto rsBorderPath =
std::make_shared<RSBorderPathDrawable>(std::move(brush), std::move(pen), properties, true);
RSRenderContent content;
int32_t width = GetData<int32_t>();
int32_t height = GetData<int32_t>();
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
rsBorderPath->Draw(content, cacheCanvas);
rsBorderPath->OnBoundsChange(properties);
return true;
}
bool DoRSBorderFourLineRoundCornerDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
uint32_t r = GetData<uint32_t>();
uint32_t g = GetData<uint32_t>();
uint32_t b = GetData<uint32_t>();
uint32_t a = GetData<uint32_t>();
Color c(r, g, b, a);
Brush brush(c);
Drawing::Pen pen;
pen.SetAntiAlias(true);
brush.SetAntiAlias(true);
int32_t width = GetData<int32_t>();
int32_t height = GetData<int32_t>();
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
RSRenderContent content;
RSProperties& properties = content.GetMutableRenderProperties();
auto rsBorderFourLineRoundCornerDrawable =
std::make_shared<RSBorderFourLineRoundCornerDrawable>(std::move(brush), std::move(pen), properties, true);
Vector4f borderWidth = GetData<Vector4f>();
properties.SetBorderWidth(borderWidth);
rsBorderFourLineRoundCornerDrawable->Draw(content, cacheCanvas);
rsBorderFourLineRoundCornerDrawable->OnBoundsChange(properties);
return true;
}
@ -324,6 +446,29 @@ bool DoRSBackgroundFilterDrawable(const uint8_t* data, size_t size)
return true;
}
bool DoRSCompositingFilterDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
auto rsCompositingFilterDrawable = std::make_shared<RSCompositingFilterDrawable>();
RSRenderContent content;
int32_t width = GetData<int32_t>();
int32_t height = GetData<int32_t>();
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
rsCompositingFilterDrawable->Draw(content, cacheCanvas);
RSCompositingFilterDrawable::Generate(content);
rsCompositingFilterDrawable->Update(content);
return true;
}
bool DoRSForegroundFilterDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
@ -341,12 +486,41 @@ bool DoRSForegroundFilterDrawable(const uint8_t* data, size_t size)
int32_t height = GetData<int32_t>();
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
std::shared_ptr<Drawing::SkiaSurface> skiaSurface = std::make_shared<Drawing::SkiaSurface>();
sk_sp<SkSurface> skSurface = SkSurface::MakeRasterN32Premul(1, 1);
auto surface = std::make_shared<Drawing::Surface>();
skiaSurface->skSurface_ = skSurface;
surface->impl_ = skiaSurface;
cacheCanvas.surface_ = surface.get();
rsForegroundFilterDrawable->Draw(content, cacheCanvas);
RSForegroundFilterDrawable::Generate(content);
rsForegroundFilterDrawable->Update(content);
return true;
}
bool DoRSForegroundFilterRestoreDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
auto rsForegroundFilterRestoreDrawable = std::make_shared<RSForegroundFilterRestoreDrawable>();
RSRenderContent content;
int32_t width = GetData<int32_t>();
int32_t height = GetData<int32_t>();
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
rsForegroundFilterRestoreDrawable->Draw(content, cacheCanvas);
RSForegroundFilterRestoreDrawable::Generate(content);
rsForegroundFilterRestoreDrawable->Update(content);
return true;
}
bool DoRSEffectDataGenerateDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
@ -368,6 +542,7 @@ bool DoRSEffectDataGenerateDrawable(const uint8_t* data, size_t size)
rsEffectDataGenerateDrawable->Update(content);
return true;
}
bool DoRSEffectDataApplyDrawable(const uint8_t* data, size_t size)
{
if (data == nullptr) {
@ -546,6 +721,7 @@ bool DoRSBackgroundImageDrawable(const uint8_t* data, size_t size)
Canvas canvas(width, height);
RSPaintFilterCanvas cacheCanvas(&canvas);
rsBackgroundImageDrawable->Update(content);
rsBackgroundImageDrawable->Draw(content, cacheCanvas);
return true;
}
@ -632,6 +808,24 @@ bool DoRSBlendFastRestoreDrawable(const uint8_t* data, size_t size)
rsBlendFastRestoreDrawable->Draw(content, cacheCanvas);
return true;
}
bool DoBlendSaveDrawableGenerate(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
RSRenderContent content;
auto result1 = BlendSaveDrawableGenerate(content);
auto result2 = BlendRestoreDrawableGenerate(content);
return true;
}
} // namespace Rosen
} // namespace OHOS
@ -663,5 +857,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::Rosen::DoRSBlendFastDrawable(data, size);
OHOS::Rosen::DoRSBlendSaveLayerRestoreDrawable(data, size);
OHOS::Rosen::DoRSBlendFastRestoreDrawable(data, size);
OHOS::Rosen::DoRSClipBoundsDrawable(data, size);
OHOS::Rosen::DoRSBorderPathDrawable(data, size);
OHOS::Rosen::DoRSBorderFourLineRoundCornerDrawable(data, size);
OHOS::Rosen::DoRSCompositingFilterDrawable(data, size);
OHOS::Rosen::DoRSForegroundFilterRestoreDrawable(data, size);
OHOS::Rosen::DoBlendSaveDrawableGenerate(data, size);
return 0;
}

View File

@ -30,6 +30,7 @@ ohos_fuzztest("RSClientPropertyFuzzTest") {
"../../../../../modules/render_service:librender_service",
"../../../../../modules/render_service_base:librender_service_base",
"../../../../../modules/render_service_client:librender_service_client",
"../../../../../modules/render_service_client:render_service_client_src",
]
cflags = [
"-g",

View File

@ -439,6 +439,246 @@ bool DoUpdateOnAllAnimationFinish(const uint8_t* data, size_t size)
prop->UpdateOnAllAnimationFinish();
return true;
}
bool DoRSPropertyBase(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
// test
RSPropertyBase propertyBase;
propertyBase.MarkModifierDirty();
propertyBase.MarkNodeDirty();
return true;
}
bool DoOperator(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
// test
auto a = std::make_shared<RSPropertyBase>();
auto b = std::make_shared<RSPropertyBase>();
a += b;
a -= b;
float value = GetData<float>();
a *= value;
a = a + b;
a = a - b;
a = a * value;
if (a == b) {
}
if (a != b) {
}
return true;
}
bool DoUpdateToRender001(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
// test
PropertyUpdateType EnumNumber = static_cast<PropertyUpdateType>(GetData<int>() % 3);
bool valuebool = GetData<bool>();
RSProperty rsPropertyBool(valuebool);
rsPropertyBool.UpdateToRender(valuebool, EnumNumber);
float valuefloat = GetData<float>();
RSProperty rsPropertyFloat(valuefloat);
rsPropertyFloat.UpdateToRender(valuefloat, EnumNumber);
int valueint = GetData<int>();
RSProperty rsPropertyInt(valueint);
rsPropertyInt.UpdateToRender(valueint, EnumNumber);
Color valueColor = GetData<Color>();
RSProperty rsPropertyColor(valueColor);
rsPropertyColor.UpdateToRender(valueColor, EnumNumber);
Gravity valueGravity = GetData<Gravity>();
RSProperty rsPropertyGravity(valueGravity);
rsPropertyGravity.UpdateToRender(valueGravity, EnumNumber);
Matrix3f valueMatrix3f = GetData<Matrix3f>();
RSProperty rsPropertyMatrix3f(valueMatrix3f);
rsPropertyMatrix3f.UpdateToRender(valueMatrix3f, EnumNumber);
Quaternion valueQuaternion = GetData<Quaternion>();
RSProperty rsPropertyQuaternion(valueQuaternion);
rsPropertyQuaternion.UpdateToRender(valueQuaternion, EnumNumber);
auto rsFilter = std::make_shared<RSFilter>();
RSProperty rsPropertyRSFilter(rsFilter);
rsPropertyRSFilter.UpdateToRender(rsFilter, EnumNumber);
auto rsImage = std::make_shared<RSImage>();
RSProperty rsPropertyRSImage(rsImage);
rsPropertyRSImage.UpdateToRender(rsImage, EnumNumber);
auto rsMask = std::make_shared<RSMask>();
RSProperty rsPropertyRSMask(rsMask);
rsPropertyRSMask.UpdateToRender(rsMask, EnumNumber);
auto rsPath = std::make_shared<RSPath>();
RSProperty rsPropertyRSPath(rsPath);
rsPropertyRSPath.UpdateToRender(rsPath, EnumNumber);
RSDynamicBrightnessPara rsDynamicBrightnessPara;
RSProperty rsPropertyRSDynamicBrightnessPara(rsDynamicBrightnessPara);
rsPropertyRSDynamicBrightnessPara.UpdateToRender(rsDynamicBrightnessPara, EnumNumber);
return true;
}
bool DoUpdateToRender002(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
// test
float valuefloat = GetData<float>();
PropertyUpdateType EnumNumber = static_cast<PropertyUpdateType>(GetData<int>() % 3);
GradientDirection direction = static_cast<GradientDirection>(GetData<int>() % 11);
std::vector<std::pair<float, float>> fractionStops;
auto rsLinearGradientBlurPara = std::make_shared<RSLinearGradientBlurPara>(valuefloat, fractionStops, direction);
RSProperty rsPropertyRSLinearGradientBlurPara(rsLinearGradientBlurPara);
rsPropertyRSLinearGradientBlurPara.UpdateToRender(rsLinearGradientBlurPara, EnumNumber);
RSWaterRipplePara rsWaterRipplePara;
RSProperty rsPropertyRSWaterRipplePara(rsWaterRipplePara);
rsPropertyRSWaterRipplePara.UpdateToRender(rsWaterRipplePara, EnumNumber);
RSFlyOutPara rsFlyOutPara;
RSProperty rsPropertyRSWaterRippleParaRSFlyOutPara(rsFlyOutPara);
rsPropertyRSWaterRippleParaRSFlyOutPara.UpdateToRender(rsFlyOutPara, EnumNumber);
Vector2f valueVector2f = GetData<Vector2f>();
auto motionBlurParam = std::make_shared<MotionBlurParam>(valuefloat, valueVector2f);
RSProperty rsPropertyMotionBlurParam(motionBlurParam);
rsPropertyMotionBlurParam.UpdateToRender(motionBlurParam, EnumNumber);
auto rsMagnifierParams = std::make_shared<RSMagnifierParams>();
RSProperty rsPropertyRSMagnifierParams(rsMagnifierParams);
rsPropertyRSMagnifierParams.UpdateToRender(rsMagnifierParams, EnumNumber);
uint32_t emitterIndex = GetData<uint32_t>();
auto emitterUpdater = std::make_shared<EmitterUpdater>(emitterIndex);
RSProperty rsPropertyEmitterUpdater(emitterUpdater);
rsPropertyEmitterUpdater.UpdateToRender(emitterUpdater, EnumNumber);
auto particleNoiseFields = std::make_shared<ParticleNoiseFields>();
RSProperty rsPropertyParticleNoiseFields(particleNoiseFields);
rsPropertyParticleNoiseFields.UpdateToRender(particleNoiseFields, EnumNumber);
auto rsShader = std::make_shared<RSShader>();
RSProperty rsPropertyRSShader(rsShader);
rsPropertyRSShader.UpdateToRender(rsShader, EnumNumber);
RSProperty rsPropertyVector2f(valueVector2f);
rsPropertyVector2f.UpdateToRender(valueVector2f, EnumNumber);
return true;
}
bool DoUpdateToRender003(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
// test
PropertyUpdateType EnumNumber = static_cast<PropertyUpdateType>(GetData<int>() % 3);
Vector4<uint32_t> valueVector4u32 = GetData<Vector4<uint32_t>>();
RSProperty rsPropertyVector4u32(valueVector4u32);
rsPropertyVector4u32.UpdateToRender(valueVector4u32, EnumNumber);
Vector4<Color> valueVector4Color = GetData<Vector4<Color>>();
RSProperty rsPropertyVector4Color(valueVector4Color);
rsPropertyVector4Color.UpdateToRender(valueVector4Color, EnumNumber);
Vector4f valueVector4f = GetData<Vector4f>();
RSProperty rsPropertyVector4f(valueVector4f);
rsPropertyVector4f.UpdateToRender(valueVector4f, EnumNumber);
RRect valueRRect = GetData<RRect>();
RSProperty rsPropertyRRect(valueRRect);
rsPropertyRRect.UpdateToRender(valueRRect, EnumNumber);
return true;
}
bool DoIsValid(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
// test
float valuefloat = GetData<float>();
RSProperty rsPropertyFloat(valuefloat);
rsPropertyFloat.IsValid(valuefloat);
Vector2f valueVector2f = GetData<Vector2f>();
RSProperty rsPropertyVector2f(valueVector2f);
rsPropertyVector2f.IsValid(valueVector2f);
Vector4f valueVector4f = GetData<Vector4f>();
RSProperty rsPropertyVector4f(valueVector4f);
rsPropertyVector4f.IsValid(valueVector4f);
return true;
}
bool DoGetPropertyType(const uint8_t* data, size_t size)
{
if (data == nullptr) {
return false;
}
// initialize
g_data = data;
g_size = size;
g_pos = 0;
// test
float valuefloat = GetData<float>();
RSAnimatableProperty rsAnimatablePropertyFloat(valuefloat);
rsAnimatablePropertyFloat.GetPropertyType();
Color valueColor = GetData<Color>();
RSAnimatableProperty rsAnimatablePropertyColor(valueColor);
rsAnimatablePropertyColor.GetPropertyType();
Matrix3f valueMatrix3f = GetData<Matrix3f>();
RSAnimatableProperty rsAnimatablePropertyMatrix3f(valueMatrix3f);
rsAnimatablePropertyMatrix3f.GetPropertyType();
Vector2f valueVector2f = GetData<Vector2f>();
RSAnimatableProperty rsAnimatablePropertyVector2f(valueVector2f);
rsAnimatablePropertyVector2f.GetPropertyType();
Vector4f valueVector4f = GetData<Vector4f>();
RSAnimatableProperty rsAnimatablePropertyVector4f(valueVector4f);
rsAnimatablePropertyVector4f.GetPropertyType();
Quaternion valueQuaternion = GetData<Quaternion>();
RSAnimatableProperty rsAnimatablePropertyQuaternion(valueQuaternion);
rsAnimatablePropertyQuaternion.GetPropertyType();
auto rsFilter = std::make_shared<RSFilter>();
RSAnimatableProperty rsAnimatablePropertyRSFilter(rsFilter);
rsAnimatablePropertyRSFilter.GetPropertyType();
Vector4<Color> valueVector4Color = GetData<Vector4<Color>>();
RSAnimatableProperty rsAnimatablePropertyVector4Color(valueVector4Color);
rsAnimatablePropertyVector4Color.GetPropertyType();
RRect valueRRect = GetData<RRect>();
RSAnimatableProperty rsAnimatablePropertyRRect(valueRRect);
rsAnimatablePropertyRRect.GetPropertyType();
return true;
}
} // namespace Rosen
} // namespace OHOS
@ -467,6 +707,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
OHOS::Rosen::DoSetPropertyUnit(data, size);
OHOS::Rosen::DoUpdateCustomAnimation(data, size);
OHOS::Rosen::DoUpdateOnAllAnimationFinish(data, size);
OHOS::Rosen::DoRSPropertyBase(data, size);
OHOS::Rosen::DoOperator(data, size);
OHOS::Rosen::DoUpdateToRender001(data, size);
OHOS::Rosen::DoUpdateToRender002(data, size);
OHOS::Rosen::DoUpdateToRender003(data, size);
OHOS::Rosen::DoIsValid(data, size);
OHOS::Rosen::DoGetPropertyType(data, size);
return 0;
}