mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 23:21:05 +00:00
ressched fuzz
Signed-off-by: zhaojian@huawei.com <zhaojian2@huawei.com>
This commit is contained in:
parent
a4254dbccf
commit
277247e6c0
@ -44,11 +44,6 @@ class MockAceApplicationInfo : public AceApplicationInfo {
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string& GetPackageName() const
|
||||
{
|
||||
return packageName_;
|
||||
}
|
||||
|
||||
public:
|
||||
static MockAceApplicationInfo& GetInstance()
|
||||
{
|
||||
@ -60,9 +55,23 @@ private:
|
||||
std::string packageName_;
|
||||
};
|
||||
|
||||
const std::string& AceApplicationInfo::GetAbilityName() const
|
||||
{
|
||||
return abilityName_;
|
||||
}
|
||||
|
||||
int32_t AceApplicationInfo::GetUid() const
|
||||
{
|
||||
return uid_;
|
||||
}
|
||||
|
||||
const std::string& AceApplicationInfo::GetPackageName() const
|
||||
{
|
||||
return packageName_;
|
||||
}
|
||||
|
||||
AceApplicationInfo& AceApplicationInfo::GetInstance()
|
||||
{
|
||||
return MockAceApplicationInfo::GetInstance();
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
75
test/fuzztest/ressched_fuzzer/BUILD.gn
Normal file
75
test/fuzztest/ressched_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,75 @@
|
||||
# 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")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
|
||||
#####################hydra-fuzz###################
|
||||
import("//foundation/arkui/ace_engine/ace_config.gni")
|
||||
module_output_path = "arkui/ressched"
|
||||
|
||||
##############################fuzztest##########################################
|
||||
ohos_fuzztest("ResschedFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "//foundation/arkui/ace_engine/test/fuzztest/ressched_fuzzer"
|
||||
include_dirs = []
|
||||
cflags = [
|
||||
"-g",
|
||||
"-O0",
|
||||
"-Wno-unused-variable",
|
||||
"-fno-omit-frame-pointer",
|
||||
]
|
||||
sources = [
|
||||
"$ace_root/frameworks/base/json/json_util.cpp",
|
||||
"$ace_root/frameworks/base/ressched/ressched_report.cpp",
|
||||
"$ace_root/adapter/ohos/osal/log_wrapper.cpp",
|
||||
"//third_party/cJSON/cJSON.c",
|
||||
"ressched_fuzzer.cpp",
|
||||
"$ace_root/adapter/ohos/osal/ressched_report.cpp",
|
||||
"$ace_root/frameworks/core/mock/mock_ace_application_info.cpp",
|
||||
"$ace_root/adapter/ohos/osal/system_properties.cpp",
|
||||
]
|
||||
include_dirs = [
|
||||
"$ace_root/frameworks/base/json",
|
||||
"$ace_root/frameworks/base/ressched",
|
||||
"$ace_root/frameworks/base/",
|
||||
"$ace_root/frameworks",
|
||||
"$ace_root",
|
||||
cjson_root,
|
||||
]
|
||||
|
||||
if (is_standard_system) {
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"init:libbegetutil",
|
||||
]
|
||||
#deps += [ "$ace_flutter_engine_root/icu:ace_libicu_ohos" ]
|
||||
} else {
|
||||
external_deps = [
|
||||
"hilog:libhilog",
|
||||
"init_lite:libbegetutil",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [
|
||||
# deps file
|
||||
":ResschedFuzzTest",
|
||||
]
|
||||
}
|
||||
###############################################################################
|
1
test/fuzztest/ressched_fuzzer/corpus/init
Normal file
1
test/fuzztest/ressched_fuzzer/corpus/init
Normal file
@ -0,0 +1 @@
|
||||
FUZZ
|
25
test/fuzztest/ressched_fuzzer/project.xml
Normal file
25
test/fuzztest/ressched_fuzzer/project.xml
Normal file
@ -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>80</max_total_time>
|
||||
<!-- memory usage limit in Mb -->
|
||||
<rss_limit_mb>4096</rss_limit_mb>
|
||||
</fuzztest>
|
||||
</fuzz_config>
|
61
test/fuzztest/ressched_fuzzer/ressched_fuzzer.cpp
Normal file
61
test/fuzztest/ressched_fuzzer/ressched_fuzzer.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 "ressched_fuzzer.h"
|
||||
|
||||
#include "base/ressched/ressched_report.h"
|
||||
#define U16 65535
|
||||
|
||||
|
||||
namespace OHOS::Ace {
|
||||
using namespace std;
|
||||
void veryfi(string& s, const uint8_t* data, size_t size){
|
||||
bool ok = true;
|
||||
auto ri = size % U16;
|
||||
for ( size_t i = 0 ; i < size ; i++ ) {
|
||||
if (( data[i] < '0' || data[i] > '9') && (data[i] < 'a' || data[i] > 'z' )) {
|
||||
ok =false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( ri==0 || ok == false ){
|
||||
s = "123";
|
||||
return;
|
||||
}
|
||||
s = string(s, ri);
|
||||
}
|
||||
|
||||
bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
|
||||
{
|
||||
bool result = false;
|
||||
string s;
|
||||
auto& resch = ResSchedReport::GetInstance();
|
||||
veryfi(s, data, size);
|
||||
resch.ResSchedDataReport(s.c_str());
|
||||
resch.ResSchedDataReport(1);
|
||||
ResSchedReportScope(s.c_str());
|
||||
resch.OnTouchEvent(TouchType::DOWN);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
/* Run your code on data */
|
||||
OHOS::Ace::DoSomethingInterestingWithMyAPI(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
20
test/fuzztest/ressched_fuzzer/ressched_fuzzer.h
Normal file
20
test/fuzztest/ressched_fuzzer/ressched_fuzzer.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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_RESSCHED_FUZZER_H
|
||||
#define TEST_FUZZTEST_RESSCHED_FUZZER_H
|
||||
|
||||
|
||||
#define FUZZ_PROJECT_NAME "ressched_fuzzer"
|
||||
#endif //TEST_FUZZTEST_RESSCHED_FUZZER_H
|
Loading…
Reference in New Issue
Block a user