add fuzztest

Signed-off-by: xiaojianfeng <xiaojianfeng3@huawei.com>
Change-Id: Id7a67daa4a7d85b7ef8376aa4a7135b39b6e4d63
This commit is contained in:
xiaojianfeng
2022-04-21 20:56:16 +08:00
parent 1e41e4a560
commit 7ef3d3514d
35 changed files with 1652 additions and 3 deletions
+1
View File
@@ -14,6 +14,7 @@
group("test") {
testonly = true
deps = [
"fuzztest:fuzztest",
"systemtest:systemtest",
"unittest:unittest",
]
+22
View File
@@ -0,0 +1,22 @@
# Copyright (c) 2022 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.
group("fuzztest") {
testonly = true
deps = [
"displaymanager_fuzzer:fuzztest",
"screen_fuzzer:fuzztest",
"screenmanager_fuzzer:fuzztest",
]
}
@@ -0,0 +1,53 @@
# Copyright (c) 2022 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.
import("//build/config/features.gni")
import("//build/test.gni")
module_output_path = "window_manager/dm"
##############################fuzztest##########################################
ohos_fuzztest("DisplayManagerFuzzTest") {
fuzz_config_file =
"//foundation/windowmanager/dm/test/fuzztest/displaymanager_fuzzer"
module_out_path = module_output_path
include_dirs = [
"//foundation/windowmanager/interfaces/innerkits/dm",
"//utils/native/base/include",
"//foundation/graphic/standard/interfaces/innerkits/surface",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "displaymanager_fuzzer.cpp" ]
public_deps = [
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
"//foundation/windowmanager/dm:libdm",
"//utils/native/base:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":DisplayManagerFuzzTest",
]
}
###############################################################################
@@ -0,0 +1,14 @@
# Copyright (c) 2022 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.
FUZZ
@@ -0,0 +1,188 @@
/*
* Copyright (c) 2022 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 "displaymanager_fuzzer.h"
#include "display_manager.h"
namespace OHOS ::Rosen {
class DisplayListener : public DisplayManager::IDisplayListener {
public:
virtual void OnCreate(DisplayId) override
{
}
virtual void OnDestroy(DisplayId) override
{
}
virtual void OnChange(DisplayId) override
{
}
};
class DisplayPowerEventListener : public IDisplayPowerEventListener {
public:
virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) override
{
}
};
template<class T>
size_t GetObject(T &object, const uint8_t *data, size_t size)
{
size_t objectSize = sizeof(object);
if (objectSize > size) {
return 0;
}
std::memcpy(&object, data, objectSize);
return objectSize;
}
bool DisplayFuzzTest(const uint8_t* data, size_t size)
{
DisplayId displayId;
ScreenId screenId;
if (data == nullptr || size < sizeof(displayId) + sizeof(screenId)) {
return false;
}
size_t startPos = 0;
DisplayManager& displayManager = DisplayManager::GetInstance();
sptr<DisplayListener> displayListener = new DisplayListener();
std::vector<sptr<Display>> displays = displayManager.GetAllDisplays();
std::vector<DisplayId> displayIds = displayManager.GetAllDisplayIds();
displayManager.GetDefaultDisplayId();
sptr<Display> defaultDisplay = displayManager.GetDefaultDisplay();
startPos += GetObject<DisplayId>(displayId, data + startPos, size - startPos);
displayManager.GetDisplayById(displayId);
startPos += GetObject<ScreenId>(screenId, data + startPos, size - startPos);
displayManager.GetDisplayByScreen(screenId);
displayManager.RegisterDisplayListener(displayListener);
displayManager.UnregisterDisplayListener(displayListener);
return true;
}
bool GetScreenshotFuzzTest(const uint8_t* data, size_t size)
{
DisplayId displayId;
Media::Rect rect;
Media::Size mediaSize;
int rotation;
if (data == nullptr || size < sizeof(displayId) + sizeof(rect) + sizeof(size) + sizeof(rotation)) {
return false;
}
size_t startPos = 0;
DisplayManager& displayManager = DisplayManager::GetInstance();
startPos += GetObject<DisplayId>(displayId, data + startPos, size - startPos);
displayManager.GetScreenshot(displayId);
startPos += GetObject<Media::Rect>(rect, data + startPos, size - startPos);
startPos += GetObject<Media::Size>(mediaSize, data + startPos, size - startPos);
startPos += GetObject<int>(rotation, data + startPos, size - startPos);
displayManager.GetScreenshot(displayId, rect, mediaSize, rotation);
return true;
}
bool DisplayPowerFuzzTest(const uint8_t* data, size_t size)
{
uint32_t reason;
DisplayId displayId;
uint32_t state;
if (data == nullptr || size < sizeof(reason) + sizeof(displayId) + sizeof(state)) {
return false;
}
size_t startPos = 0;
DisplayManager& displayManager = DisplayManager::GetInstance();
sptr<IDisplayPowerEventListener> listener = new DisplayPowerEventListener();
displayManager.RegisterDisplayPowerEventListener(listener);
startPos += GetObject<uint32_t>(reason, data + startPos, size - startPos);
displayManager.WakeUpBegin(static_cast<PowerStateChangeReason>(reason));
displayManager.WakeUpEnd();
displayManager.SuspendBegin(static_cast<PowerStateChangeReason>(reason));
displayManager.SuspendEnd();
startPos += GetObject<uint32_t>(state, data + startPos, size - startPos);
DisplayStateCallback callback = [](DisplayState state) {
};
displayManager.SetDisplayState(static_cast<DisplayState>(state), callback);
startPos += GetObject<DisplayId>(displayId, data + startPos, size - startPos);
displayManager.GetDisplayState(displayId);
displayManager.UnregisterDisplayPowerEventListener(listener);
return true;
}
bool ScreenBrightnessFuzzTest(const uint8_t* data, size_t size)
{
uint64_t screenId;
uint32_t level;
if (data == nullptr || size < sizeof(screenId) + sizeof(level)) {
return false;
}
size_t startPos = 0;
DisplayManager& displayManager = DisplayManager::GetInstance();
startPos += GetObject<uint64_t>(screenId, data + startPos, size - startPos);
startPos += GetObject<uint32_t>(level, data + startPos, size - startPos);
displayManager.SetScreenBrightness(screenId, level);
displayManager.GetScreenBrightness(screenId);
return true;
}
bool FreezeFuzzTest(const uint8_t* data, size_t size)
{
// 10 displays
if (data == nullptr || size < sizeof(DisplayId) * 10) {
return false;
}
size_t startPos = 0;
DisplayManager& displayManager = DisplayManager::GetInstance();
// 10 displays
std::vector<DisplayId> displays(10);
for (DisplayId& id : displays) {
startPos += GetObject<DisplayId>(id, data + startPos, size - startPos);
}
displayManager.Freeze(displays);
displayManager.Unfreeze(displays);
return true;
}
bool NotifyDisplayEventFuzzTest(const uint8_t* data, size_t size)
{
// 10 displays
if (data == nullptr || size < sizeof(DisplayEvent)) {
return false;
}
size_t startPos = 0;
DisplayManager& displayManager = DisplayManager::GetInstance();
uint32_t event;
startPos += GetObject<uint32_t>(event, data + startPos, size - startPos);
displayManager.NotifyDisplayEvent(static_cast<DisplayEvent>(event));
return true;
}
} // namespace.OHOS::Rosen
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::Rosen::DisplayFuzzTest(data, size);
OHOS::Rosen::GetScreenshotFuzzTest(data, size);
OHOS::Rosen::DisplayPowerFuzzTest(data, size);
OHOS::Rosen::ScreenBrightnessFuzzTest(data, size);
OHOS::Rosen::FreezeFuzzTest(data, size);
OHOS::Rosen::NotifyDisplayEventFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef TEST_FUZZTEST_DISPLAY_MANAGER_FUZZER_H
#define TEST_FUZZTEST_DISPLAY_MANAGER_FUZZER_H
#define FUZZ_PROJECT_NAME "displaymanager_fuzzer"
#endif
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
+52
View File
@@ -0,0 +1,52 @@
# Copyright (c) 2022 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.
import("//build/config/features.gni")
import("//build/test.gni")
module_output_path = "window_manager/dm"
##############################fuzztest##########################################
ohos_fuzztest("ScreenFuzzTest") {
fuzz_config_file = "//foundation/windowmanager/dm/test/fuzztest/screen_fuzzer"
module_out_path = module_output_path
include_dirs = [
"//foundation/windowmanager/interfaces/innerkits/dm",
"//utils/native/base/include",
"//foundation/graphic/standard/interfaces/innerkits/surface",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "screen_fuzzer.cpp" ]
public_deps = [
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
"//foundation/windowmanager/dm:libdm",
"//utils/native/base:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":ScreenFuzzTest",
]
}
###############################################################################
@@ -0,0 +1,14 @@
# Copyright (c) 2022 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.
FUZZ
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2022 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 "screen_fuzzer.h"
#include <iostream>
#include "display_manager.h"
#include "display.h"
#include "dm_common.h"
#include "screen.h"
#include "screen_manager.h"
namespace OHOS::Rosen {
template<class T>
size_t GetObject(T &object, const uint8_t *data, size_t size)
{
size_t objectSize = sizeof(object);
if (objectSize > size) {
return 0;
}
std::memcpy(&object, data, objectSize);
return objectSize;
}
bool ScreenFuzzTest(const uint8_t *data, size_t size)
{
DisplayManager& displayManager = DisplayManager::GetInstance();
sptr<Display> display = displayManager.GetDefaultDisplay();
if (display == nullptr) {
return false;
}
ScreenId screenId = display->GetScreenId();
sptr<Screen> screen = ScreenManager::GetInstance().GetScreenById(screenId);
if (screen == nullptr) {
return false;
}
uint32_t modeId;
Orientation orientation;
if (data == nullptr || size < sizeof(modeId) + sizeof(orientation)) {
return false;
}
size_t startPos = 0;
startPos += GetObject<uint32_t>(modeId, data + startPos, size - startPos);
startPos += GetObject<Orientation>(orientation, data + startPos, size - startPos);
screen->SetScreenActiveMode(modeId);
screen->SetOrientation(orientation);
screen->SetScreenActiveMode(0);
screen->SetOrientation(Orientation::UNSPECIFIED);
return true;
}
bool ColorGamutsFuzzTest(const uint8_t *data, size_t size)
{
DisplayManager& displayManager = DisplayManager::GetInstance();
sptr<Display> display = displayManager.GetDefaultDisplay();
if (display == nullptr) {
return false;
}
ScreenId screenId = display->GetScreenId();
sptr<Screen> screen = ScreenManager::GetInstance().GetScreenById(screenId);
if (screen == nullptr) {
return false;
}
int32_t colorGamutIdx;
uint32_t gamutMap;
if (data == nullptr || size < sizeof(colorGamutIdx) + sizeof(gamutMap)) {
return false;
}
size_t startPos = 0;
startPos += GetObject<int32_t>(colorGamutIdx, data + startPos, size - startPos);
startPos += GetObject<uint32_t>(gamutMap, data + startPos, size - startPos);
std::vector<ScreenColorGamut> colorGamuts;
screen->GetScreenSupportedColorGamuts(colorGamuts);
size_t colorGamutsSize = colorGamuts.size();
if (colorGamutsSize == 0) {
return false;
}
int32_t index = colorGamutIdx % colorGamutsSize;
screen->SetScreenColorGamut(index);
ScreenColorGamut colorGamut;
screen->GetScreenColorGamut(colorGamut);
if (colorGamuts[index] != colorGamut) {
std::cout << "colorGamuts not equals." << std::endl;
}
screen->SetScreenGamutMap(static_cast<ScreenGamutMap>(gamutMap));
ScreenGamutMap screenGamutMap;
screen->GetScreenGamutMap(screenGamutMap);
if (static_cast<ScreenGamutMap>(gamutMap) != screenGamutMap) {
std::cout << "screenGamutMaps not equals." << std::endl;
}
return true;
}
} // namespace.OHOS::Rosen
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::Rosen::ScreenFuzzTest(data, size);
OHOS::Rosen::ColorGamutsFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef TEST_FUZZTEST_SCREEN_FUZZER_H
#define TEST_FUZZTEST_SCREEN_FUZZER_H
#define FUZZ_PROJECT_NAME "screen_fuzzer"
#endif
@@ -0,0 +1,53 @@
# Copyright (c) 2022 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.
import("//build/config/features.gni")
import("//build/test.gni")
module_output_path = "window_manager/dm"
##############################fuzztest##########################################
ohos_fuzztest("ScreenManagerFuzzTest") {
fuzz_config_file =
"//foundation/windowmanager/dm/test/fuzztest/screenmanager_fuzzer"
module_out_path = module_output_path
include_dirs = [
"//foundation/windowmanager/interfaces/innerkits/dm",
"//utils/native/base/include",
"//foundation/graphic/standard/interfaces/innerkits/surface",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "screenmanager_fuzzer.cpp" ]
public_deps = [
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
"//foundation/windowmanager/dm:libdm",
"//utils/native/base:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":ScreenManagerFuzzTest",
]
}
###############################################################################
@@ -0,0 +1,14 @@
# Copyright (c) 2022 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.
FUZZ
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -0,0 +1,325 @@
/*
* Copyright (c) 2022 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 "screenmanager_fuzzer.h"
#include <iostream>
#include "dm_common.h"
#include "screen.h"
#include "screen_manager.h"
namespace OHOS::Rosen {
class ScreenListener : public ScreenManager::IScreenListener {
public:
virtual void OnConnect(ScreenId screenId) override
{
};
virtual void OnDisconnect(ScreenId screenId) override
{
}
virtual void OnChange(ScreenId screenId) override
{
}
};
class ScreenGroupListener : public ScreenManager::IScreenGroupListener {
public:
virtual void OnChange(const std::vector<ScreenId>& screenIds, ScreenGroupChangeEvent event) override
{
}
};
template<class T>
size_t GetObject(T &object, const uint8_t *data, size_t size)
{
size_t objectSize = sizeof(object);
if (objectSize > size) {
return 0;
}
std::memcpy(&object, data, objectSize);
return objectSize;
}
bool ScreenPowerFuzzTest(const uint8_t *data, size_t size)
{
uint32_t screenPowerState;
uint32_t powerStateChangeReason;
if (data == nullptr || size < sizeof(screenPowerState) + sizeof(powerStateChangeReason)) {
return false;
}
size_t startPos = 0;
ScreenManager &screenManager = ScreenManager::GetInstance();
sptr<ScreenManager::IScreenListener> screenListener = new ScreenListener();
screenManager.RegisterScreenListener(screenListener);
sptr<ScreenManager::IScreenGroupListener> screenGroupListener = new ScreenGroupListener();
screenManager.RegisterScreenGroupListener(screenGroupListener);
startPos += GetObject<uint32_t>(screenPowerState, data + startPos, size - startPos);
startPos += GetObject<uint32_t>(powerStateChangeReason, data + startPos, size - startPos);
screenManager.SetScreenPowerForAll(static_cast<ScreenPowerState>(screenPowerState),
static_cast<PowerStateChangeReason>(startPos));
auto allScreen = screenManager.GetAllScreens();
for (auto screen: allScreen) {
ScreenPowerState powerState = screenManager.GetScreenPower(screen->GetId());
if (powerState != static_cast<ScreenPowerState>(screenPowerState)) {
std::cout << "ScreenPowerState is not equals to powerState." << std::endl;
}
}
screenManager.UnregisterScreenGroupListener(screenGroupListener);
screenManager.UnregisterScreenListener(screenListener);
return true;
}
bool MakeMirrorWithVirtualScreenFuzzTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < sizeof(VirtualScreenOption)) {
return false;
}
size_t startPos = 0;
ScreenManager &screenManager = ScreenManager::GetInstance();
sptr<ScreenManager::IScreenListener> screenListener = new ScreenListener();
screenManager.RegisterScreenListener(screenListener);
sptr<ScreenManager::IScreenGroupListener> screenGroupListener = new ScreenGroupListener();
screenManager.RegisterScreenGroupListener(screenGroupListener);
std::string name;
startPos += GetObject<std::string>(name, data + startPos, size - startPos);
VirtualScreenOption option = { name };
startPos += GetObject<uint32_t>(option.width_, data + startPos, size - startPos);
startPos += GetObject<uint32_t>(option.height_, data + startPos, size - startPos);
startPos += GetObject<float>(option.density_, data + startPos, size - startPos);
startPos += GetObject<int32_t>(option.flags_, data + startPos, size - startPos);
startPos += GetObject<bool>(option.isForShot_, data + startPos, size - startPos);
ScreenId screenId = screenManager.CreateVirtualScreen(option);
if (screenId == SCREEN_ID_INVALID) {
return false;
}
screenManager.SetVirtualScreenSurface(screenId, nullptr);
auto screes = screenManager.GetAllScreens();
auto iter = std::find_if(screes.begin(), screes.end(), [screenId](sptr<Screen> screen) {
return screenId == screen->GetId();
});
if (iter == screes.end()) {
std::cout << "screenId is not in all screens." << std::endl;
}
// make mirror
ScreenId groupId = screenManager.MakeMirror(0, { screenId });
if (groupId == SCREEN_ID_INVALID) {
screenManager.DestroyVirtualScreen(screenId);
return false;
}
sptr<ScreenGroup> group = screenManager.GetScreenGroup(groupId);
if (group == nullptr) {
screenManager.DestroyVirtualScreen(screenId);
return false;
}
std::vector<ScreenId> ids = group->GetChildIds();
if (std::find(ids.begin(), ids.end(), screenId) == ids.end()) {
std::cout << "screenId is not in group children." << std::endl;
}
screenManager.RemoveVirtualScreenFromGroup(ids);
screenManager.DestroyVirtualScreen(screenId);
screenManager.UnregisterScreenGroupListener(screenGroupListener);
screenManager.UnregisterScreenListener(screenListener);
return true;
}
bool MakeExpandWithVirtualScreenFuzzTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < sizeof(VirtualScreenOption)) {
return false;
}
size_t startPos = 0;
ScreenManager &screenManager = ScreenManager::GetInstance();
sptr<ScreenManager::IScreenListener> screenListener = new ScreenListener();
screenManager.RegisterScreenListener(screenListener);
sptr<ScreenManager::IScreenGroupListener> screenGroupListener = new ScreenGroupListener();
screenManager.RegisterScreenGroupListener(screenGroupListener);
std::string name;
startPos += GetObject<std::string>(name, data + startPos, size - startPos);
VirtualScreenOption option = { name };
startPos += GetObject<uint32_t>(option.width_, data + startPos, size - startPos);
startPos += GetObject<uint32_t>(option.height_, data + startPos, size - startPos);
startPos += GetObject<float>(option.density_, data + startPos, size - startPos);
startPos += GetObject<int32_t>(option.flags_, data + startPos, size - startPos);
startPos += GetObject<bool>(option.isForShot_, data + startPos, size - startPos);
ScreenId screenId = screenManager.CreateVirtualScreen(option);
if (screenId == SCREEN_ID_INVALID) {
return false;
}
screenManager.SetVirtualScreenSurface(screenId, nullptr);
auto screes = screenManager.GetAllScreens();
auto iter = std::find_if(screes.begin(), screes.end(), [screenId](sptr<Screen> screen) {
return screenId == screen->GetId();
});
if (iter == screes.end()) {
std::cout << "screenId is not in all screens." << std::endl;
}
// make expand
std::vector<ExpandOption> options = {{0, 0, 0}, {screenId, 0, 0}};
ScreenId groupId = screenManager.MakeExpand(options);
if (groupId == SCREEN_ID_INVALID) {
screenManager.DestroyVirtualScreen(screenId);
return false;
}
sptr<ScreenGroup> group = screenManager.GetScreenGroup(groupId);
if (group == nullptr) {
screenManager.DestroyVirtualScreen(screenId);
return false;
}
std::vector<ScreenId> ids = group->GetChildIds();
if (std::find(ids.begin(), ids.end(), screenId) == ids.end()) {
std::cout << "screenId is not in group children." << std::endl;
}
screenManager.RemoveVirtualScreenFromGroup(ids);
screenManager.DestroyVirtualScreen(screenId);
screenManager.UnregisterScreenGroupListener(screenGroupListener);
screenManager.UnregisterScreenListener(screenListener);
return true;
}
bool CreateAndDestroyVirtualScreenFuzzTest(const uint8_t *data, size_t size)
{
if (data == nullptr || size < sizeof(VirtualScreenOption)) {
return false;
}
size_t startPos = 0;
ScreenManager &screenManager = ScreenManager::GetInstance();
sptr<ScreenManager::IScreenListener> screenListener = new ScreenListener();
screenManager.RegisterScreenListener(screenListener);
sptr<ScreenManager::IScreenGroupListener> screenGroupListener = new ScreenGroupListener();
screenManager.RegisterScreenGroupListener(screenGroupListener);
std::string name;
startPos += GetObject<std::string>(name, data + startPos, size - startPos);
VirtualScreenOption option = { name };
startPos += GetObject<uint32_t>(option.width_, data + startPos, size - startPos);
startPos += GetObject<uint32_t>(option.height_, data + startPos, size - startPos);
startPos += GetObject<float>(option.density_, data + startPos, size - startPos);
startPos += GetObject<int32_t>(option.flags_, data + startPos, size - startPos);
startPos += GetObject<bool>(option.isForShot_, data + startPos, size - startPos);
ScreenId screenId = screenManager.CreateVirtualScreen(option);
if (screenId == SCREEN_ID_INVALID) {
return false;
}
screenManager.DestroyVirtualScreen(screenId);
startPos += GetObject<ScreenId>(screenId, data + startPos, size - startPos);
screenManager.DestroyVirtualScreen(screenId);
screenManager.UnregisterScreenGroupListener(screenGroupListener);
screenManager.UnregisterScreenListener(screenListener);
return true;
}
bool SetVirtualScreenSurfaceFuzzTest(const uint8_t *data, size_t size)
{
ScreenId screenId;
if (data == nullptr || size < sizeof(screenId)) {
return false;
}
size_t startPos = 0;
ScreenManager &screenManager = ScreenManager::GetInstance();
startPos += GetObject<ScreenId>(screenId, data + startPos, size - startPos);
screenManager.SetVirtualScreenSurface(screenId, nullptr);
return true;
}
bool RemoveVirtualScreenFromGroupFuzzTest(const uint8_t *data, size_t size)
{
ScreenId screenId;
if (data == nullptr || size < sizeof(screenId)) {
return false;
}
size_t startPos = 0;
ScreenManager &screenManager = ScreenManager::GetInstance();
startPos += GetObject<ScreenId>(screenId, data + startPos, size - startPos);
std::vector<ScreenId> screenIds = {screenId, screenId, screenId};
screenManager.RemoveVirtualScreenFromGroup(screenIds);
return true;
}
bool MakeMirrorFuzzTest(const uint8_t *data, size_t size)
{
ScreenId screenId;
// 10 screens.
if (data == nullptr || size < sizeof(ScreenId) * 10) {
return false;
}
size_t startPos = 0;
ScreenManager &screenManager = ScreenManager::GetInstance();
sptr<ScreenManager::IScreenListener> screenListener = new ScreenListener();
screenManager.RegisterScreenListener(screenListener);
sptr<ScreenManager::IScreenGroupListener> screenGroupListener = new ScreenGroupListener();
screenManager.RegisterScreenGroupListener(screenGroupListener);
std::vector<ScreenId> screenIds;
// 10 screens
for (size_t i = 0; i < 10; i++) {
startPos += GetObject<ScreenId>(screenId, data + startPos, size - startPos);
screenIds.emplace_back(screenId);
}
startPos += GetObject<ScreenId>(screenId, data + startPos, size - startPos);
screenManager.MakeMirror(screenId, screenIds);
screenManager.UnregisterScreenGroupListener(screenGroupListener);
screenManager.UnregisterScreenListener(screenListener);
return true;
}
bool MakeExpandFuzzTest(const uint8_t *data, size_t size)
{
ScreenId screenId;
// 10 screens.
if (data == nullptr || size < sizeof(ScreenId) * 10) {
return false;
}
size_t startPos = 0;
ScreenManager &screenManager = ScreenManager::GetInstance();
sptr<ScreenManager::IScreenListener> screenListener = new ScreenListener();
screenManager.RegisterScreenListener(screenListener);
sptr<ScreenManager::IScreenGroupListener> screenGroupListener = new ScreenGroupListener();
screenManager.RegisterScreenGroupListener(screenGroupListener);
std::vector<ExpandOption> options;
// 10 screens
for (size_t i = 0; i < 10; i++) {
startPos += GetObject<ScreenId>(screenId, data + startPos, size - startPos);
ExpandOption option = {screenId, 0, 0};
options.emplace_back(option);
}
screenManager.MakeExpand(options);
screenManager.UnregisterScreenGroupListener(screenGroupListener);
screenManager.UnregisterScreenListener(screenListener);
return true;
}
} // namespace.OHOS::Rosen
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::Rosen::ScreenPowerFuzzTest(data, size);
OHOS::Rosen::MakeMirrorWithVirtualScreenFuzzTest(data, size);
OHOS::Rosen::MakeMirrorFuzzTest(data, size);
OHOS::Rosen::MakeExpandWithVirtualScreenFuzzTest(data, size);
OHOS::Rosen::MakeExpandFuzzTest(data, size);
OHOS::Rosen::CreateAndDestroyVirtualScreenFuzzTest(data, size);
OHOS::Rosen::SetVirtualScreenSurfaceFuzzTest(data, size);
OHOS::Rosen::RemoveVirtualScreenFromGroupFuzzTest(data, size);
return 0;
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef TEST_FUZZTEST_SCREEN_MANAGER_FUZZER_H
#define TEST_FUZZTEST_SCREEN_MANAGER_FUZZER_H
#define FUZZ_PROJECT_NAME "screenmanager_fuzzer"
#endif
+3 -3
View File
@@ -54,7 +54,7 @@ public:
sptr<IRemoteObject> abilityToken_;
};
class IFocusChangedListener : public RefBase {
class IFocusChangedListener : virtual public RefBase {
public:
virtual void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) = 0;
@@ -82,7 +82,7 @@ public:
bool isVisible_ { false };
};
class IVisibilityChangedListener : public RefBase {
class IVisibilityChangedListener : virtual public RefBase {
public:
virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) = 0;
};
@@ -118,7 +118,7 @@ private:
bool VectorMarshalling(Parcel& parcel) const;
static void VectorUnmarshalling(Parcel& parcel, AccessibilityWindowInfo* windowInfo);
};
class IWindowUpdateListener : public RefBase {
class IWindowUpdateListener : virtual public RefBase {
public:
virtual void OnWindowUpdate(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) = 0;
};
+1
View File
@@ -14,6 +14,7 @@
group("test") {
testonly = true
deps = [
"fuzztest:fuzztest",
"systemtest:systemtest",
"unittest:unittest",
]
+22
View File
@@ -0,0 +1,22 @@
# Copyright (c) 2022 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.
group("fuzztest") {
testonly = true
deps = [
"window_fuzzer:fuzztest",
"windowmanager_fuzzer:fuzztest",
"windowscene_fuzzer:fuzztest",
]
}
+52
View File
@@ -0,0 +1,52 @@
# Copyright (c) 2022 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.
import("//build/config/features.gni")
import("//build/test.gni")
module_output_path = "window_manager/wm"
##############################fuzztest##########################################
ohos_fuzztest("WindowFuzzTest") {
fuzz_config_file = "//foundation/windowmanager/wm/test/fuzztest/window_fuzzer"
module_out_path = module_output_path
include_dirs = [
"//foundation/windowmanager/wmserver/include",
"//foundation/windowmanager/interfaces/innerkits/wm",
"//utils/native/base/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "window_fuzzer.cpp" ]
public_deps = [
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wmserver:libwms",
"//utils/native/base:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":WindowFuzzTest",
]
}
###############################################################################
@@ -0,0 +1,14 @@
# Copyright (c) 2022 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.
FUZZ
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2022 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 "parcel.h"
#include "window.h"
#include "window_manager.h"
using namespace OHOS::Rosen;
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 2;
}
class FocusChangedListener : public IFocusChangedListener {
public:
virtual void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) override
{
}
virtual void OnUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo) override
{
}
};
class SystemBarChangedListener : public ISystemBarChangedListener {
public:
virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override
{
}
};
class VisibilityChangedListener : public IVisibilityChangedListener {
public:
virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) override
{
}
};
class WindowUpdateListener : public IWindowUpdateListener {
public:
virtual void OnWindowUpdate(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) override
{
}
};
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
std::string name = "WindowFuzzTest";
sptr<WindowOption> option = nullptr;
sptr<Window> window = Window::Create(name, option);
if (window == nullptr) {
return false;
}
window->Show(0);
Orientation orientation = static_cast<Orientation>(data[0]);
window->SetRequestedOrientation(static_cast<Orientation>(data[0]));
if (window->GetRequestedOrientation() != orientation) {
return false;
}
window->Hide(0);
window->Destroy();
return true;
}
} // namespace.OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DoSomethingInterestingWithMyAPI(data, size);
return 0;
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef TEST_FUZZTEST_WINDOW_FUZZER_H
#define TEST_FUZZTEST_WINDOW_FUZZER_H
#define FUZZ_PROJECT_NAME "window_fuzzer"
#endif
@@ -0,0 +1,53 @@
# Copyright (c) 2022 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.
import("//build/config/features.gni")
import("//build/test.gni")
module_output_path = "window_manager/wm"
##############################fuzztest##########################################
ohos_fuzztest("WindowManagerFuzzTest") {
fuzz_config_file =
"//foundation/windowmanager/wm/test/fuzztest/windowmanager_fuzzer"
module_out_path = module_output_path
include_dirs = [
"//foundation/windowmanager/wmserver/include",
"//foundation/windowmanager/interfaces/innerkits/wm",
"//utils/native/base/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "windowmanager_fuzzer.cpp" ]
public_deps = [
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wmserver:libwms",
"//utils/native/base:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":WindowManagerFuzzTest",
]
}
###############################################################################
@@ -0,0 +1,14 @@
# Copyright (c) 2022 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.
FUZZ
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -0,0 +1,122 @@
/*
* Copyright (c) 2022 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 "parcel.h"
#include "window_manager.h"
using namespace OHOS::Rosen;
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 2;
}
class FocusChangedListener : public IFocusChangedListener {
public:
virtual void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) override
{
}
virtual void OnUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo) override
{
}
};
class SystemBarChangedListener : public ISystemBarChangedListener {
public:
virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override
{
}
};
class VisibilityChangedListener : public IVisibilityChangedListener {
public:
virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) override
{
}
};
class WindowUpdateListener : public IWindowUpdateListener {
public:
virtual void OnWindowUpdate(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) override
{
}
};
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
WindowManager& windowManager = WindowManager::GetInstance();
Parcel accessibilityWindowInfoParcel;
if (accessibilityWindowInfoParcel.WriteBuffer(data, size)) {
sptr<AccessibilityWindowInfo> windowInfo =
AccessibilityWindowInfo::Unmarshalling(accessibilityWindowInfoParcel);
windowManager.GetAccessibilityWindowInfo(windowInfo);
}
Parcel focusChangeInfoParcel;
if (focusChangeInfoParcel.WriteBuffer(data, size)) {
FocusChangeInfo::Unmarshalling(focusChangeInfoParcel);
}
Parcel parcel;
sptr<FocusChangeInfo> focusChangeInfo = new FocusChangeInfo();
focusChangeInfo->Marshalling(parcel);
Parcel windowVisibilityInfoParcel;
if (windowVisibilityInfoParcel.WriteBuffer(data, size)) {
WindowVisibilityInfo::Unmarshalling(windowVisibilityInfoParcel);
}
sptr<WindowVisibilityInfo> windowVisibilityInfo = new WindowVisibilityInfo();
windowVisibilityInfo->Marshalling(parcel);
Parcel windowInfoParcel;
if (windowInfoParcel.WriteBuffer(data, size)) {
WindowInfo::Unmarshalling(windowInfoParcel);
}
sptr<WindowInfo> windowInfo = new WindowInfo();
windowInfo->Marshalling(parcel);
sptr<AccessibilityWindowInfo> accessibilityWindowInfo = new AccessibilityWindowInfo();
accessibilityWindowInfo->currentWindowInfo_ = windowInfo;
accessibilityWindowInfo->windowList_.emplace_back(windowInfo);
accessibilityWindowInfo->Marshalling(parcel);
windowManager.MinimizeAllAppWindows(static_cast<DisplayId>(data[0]));
sptr<IFocusChangedListener> focusChangedListener = new FocusChangedListener();
windowManager.RegisterFocusChangedListener(focusChangedListener);
sptr<ISystemBarChangedListener> systemBarChangedListener = new SystemBarChangedListener();
windowManager.RegisterSystemBarChangedListener(systemBarChangedListener);
sptr<IVisibilityChangedListener> visibilityChangedListener = new VisibilityChangedListener();
windowManager.RegisterVisibilityChangedListener(visibilityChangedListener);
sptr<IWindowUpdateListener> windowUpdateListener = new WindowUpdateListener();
windowManager.RegisterWindowUpdateListener(windowUpdateListener);
windowManager.SetWindowLayoutMode(static_cast<WindowLayoutMode>(data[1]), static_cast<DisplayId>(data[0]));
windowManager.UnregisterFocusChangedListener(focusChangedListener);
windowManager.UnregisterSystemBarChangedListener(systemBarChangedListener);
windowManager.UnregisterVisibilityChangedListener(visibilityChangedListener);
windowManager.UnregisterWindowUpdateListener(windowUpdateListener);
return true;
}
} // namespace.OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DoSomethingInterestingWithMyAPI(data, size);
return 0;
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef TEST_FUZZTEST_WINDOW_MANAGER_FUZZER_H
#define TEST_FUZZTEST_WINDOW_MANAGER_FUZZER_H
#define FUZZ_PROJECT_NAME "windowmanager_fuzzer"
#endif
@@ -0,0 +1,53 @@
# Copyright (c) 2022 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.
import("//build/config/features.gni")
import("//build/test.gni")
module_output_path = "window_manager/wm"
##############################fuzztest##########################################
ohos_fuzztest("WindowSceneFuzzTest") {
fuzz_config_file =
"//foundation/windowmanager/wm/test/fuzztest/windowscene_fuzzer"
module_out_path = module_output_path
include_dirs = [
"//foundation/windowmanager/wmserver/include",
"//foundation/windowmanager/interfaces/innerkits/wm",
"//utils/native/base/include",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [ "windowscene_fuzzer.cpp" ]
public_deps = [
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wmserver:libwms",
"//utils/native/base:utils",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":WindowSceneFuzzTest",
]
}
###############################################################################
@@ -0,0 +1,14 @@
# Copyright (c) 2022 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.
FUZZ
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 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.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2022 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 "parcel.h"
#include "window.h"
#include "window_manager.h"
using namespace OHOS::Rosen;
namespace OHOS {
namespace {
constexpr size_t DATA_MIN_SIZE = 2;
}
class FocusChangedListener : public IFocusChangedListener {
public:
virtual void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) override
{
}
virtual void OnUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo) override
{
}
};
class SystemBarChangedListener : public ISystemBarChangedListener {
public:
virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override
{
}
};
class VisibilityChangedListener : public IVisibilityChangedListener {
public:
virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) override
{
}
};
class WindowUpdateListener : public IWindowUpdateListener {
public:
virtual void OnWindowUpdate(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) override
{
}
};
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
{
if (data == nullptr || size < DATA_MIN_SIZE) {
return false;
}
std::string name = "WindowFuzzTest";
sptr<WindowOption> option = nullptr;
sptr<Window> window = Window::Create(name, option);
if (window == nullptr) {
return false;
}
window->Show(0);
Orientation orientation = static_cast<Orientation>(data[0]);
window->SetRequestedOrientation(static_cast<Orientation>(data[0]));
if (window->GetRequestedOrientation() != orientation) {
return false;
}
window->Hide(0);
window->Destroy();
return true;
}
} // namespace.OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
/* Run your code on data */
OHOS::DoSomethingInterestingWithMyAPI(data, size);
return 0;
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 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.
*/
#ifndef TEST_FUZZTEST_WINDOW_SCENE_FUZZER_H
#define TEST_FUZZTEST_WINDOW_SCENE_FUZZER_H
#define FUZZ_PROJECT_NAME "windowscene_fuzzer"
#endif