!2041 add fuzztest cases for ets_runtime

Merge pull request !2041 from zhaozhibo/master
This commit is contained in:
openharmony_ci 2022-08-15 10:20:51 +00:00 committed by Gitee
commit 491ff48904
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 301 additions and 0 deletions

View File

@ -62,6 +62,8 @@ group("fuzztest") {
"objecthas_fuzzer:fuzztest",
"objectset_fuzzer:fuzztest",
"setnativepointerfield_fuzzer:fuzztest",
"startcpuprofilerforfile_fuzzer:fuzztest",
"stopheaptracking2_fuzzer:fuzztest",
"stringrefnewfromutf8_fuzzer:fuzztest",
"stringrefwriteutf8_fuzzer:fuzztest",
"uint16arrayrefnew_fuzzer:fuzztest",

View File

@ -0,0 +1,39 @@
# 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.
#####################################hydra-fuzz###############################
import("//arkcompiler/ets_runtime/js_runtime_config.gni")
import("//arkcompiler/ets_runtime/test/test_helper.gni")
import("//build/config/features.gni")
import("//build/ohos.gni")
import("//build/test.gni")
####################################fuzztest##################################
ohos_fuzztest("StartCpuProfilerForFileFuzzTest") {
module_out_path = "arkcompiler/ets_runtime"
sources = [ "startcpuprofilerforfile_fuzzer.cpp" ]
configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
deps = [
"//arkcompiler/ets_runtime:libark_jsruntime",
sdk_libc_secshared_dep,
]
}
group("fuzztest") {
testonly = true
deps = []
deps += [ ":StartCpuProfilerForFileFuzzTest" ]
}

View File

@ -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

View 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>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,46 @@
/*
* 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 "startcpuprofilerforfile_fuzzer.h"
#include "ecmascript/napi/include/dfx_jsnapi.h"
#include "ecmascript/napi/include/jsnapi.h"
using namespace panda;
using namespace panda::ecmascript;
namespace OHOS {
void ObjectSetFuzzTest(const uint8_t* data, size_t size)
{
RuntimeOption option;
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
EcmaVM *vm = JSNApi::CreateJSVM(option);
[[maybe_unused]] LocalScope scope(vm);
std::string fileName(data, data + size);
#ifndef ECMASCRIPT_SUPPORT_CPUPROFILER
#define ECMASCRIPT_SUPPORT_CPUPROFILER
DFXJSNApi::StartCpuProfilerForFile(vm, fileName);
#endif
JSNApi::DestroyJSVM(vm);
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
// Run your code on data.
OHOS::ObjectSetFuzzTest(data, size);
return 0;
}

View File

@ -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 STARTCPUPROFILERFORFILE_FUZZER_H
#define STARTCPUPROFILERFORFILE_FUZZER_H
#define FUZZ_PROJECT_NAME "startcpuprofilerforfile_fuzzer.h"
#endif

View File

@ -0,0 +1,43 @@
# 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.
#####################################hydra-fuzz###############################
import("//arkcompiler/ets_runtime/js_runtime_config.gni")
import("//arkcompiler/ets_runtime/test/test_helper.gni")
import("//build/config/features.gni")
import("//build/ohos.gni")
import("//build/test.gni")
####################################fuzztest##################################
ohos_fuzztest("StopHeapTracking2FuzzTest") {
module_out_path = "arkcompiler/ets_runtime"
fuzz_config_file =
"//arkcompiler/ets_runtime/test/fuzztest/stopheaptracking2_fuzzer"
sources = [ "stopheaptracking2_fuzzer.cpp" ]
configs = [ "//arkcompiler/ets_runtime:ecma_test_config" ]
deps = [
"//arkcompiler/ets_runtime:libark_jsruntime",
"//arkcompiler/ets_runtime:libark_jsruntime_test",
sdk_libc_secshared_dep,
]
}
group("fuzztest") {
testonly = true
deps = []
deps += [ ":StopHeapTracking2FuzzTest" ]
}

View File

@ -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

View 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>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -0,0 +1,46 @@
/*
* 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 "stopheaptracking2_fuzzer.h"
#include "ecmascript/napi/include/dfx_jsnapi.h"
#include "ecmascript/napi/include/jsnapi.h"
#include "ecmascript/tooling/interface/file_stream.h"
using namespace panda;
using namespace panda::ecmascript;
namespace OHOS {
void ObjectSetFuzzTest(const uint8_t* data, size_t size)
{
RuntimeOption option;
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
EcmaVM *vm = JSNApi::CreateJSVM(option);
[[maybe_unused]] LocalScope scope(vm);
std::string pathStr(data, data + size);
FileStream path(pathStr);
DFXJSNApi::StopHeapTracking(vm, &path, nullptr);
JSNApi::DestroyJSVM(vm);
}
}
// Fuzzer entry point.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
// Run your code on data.
OHOS::ObjectSetFuzzTest(data, size);
return 0;
}

View File

@ -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 STOPHEAPTRACKING2_FUZZER_H
#define STOPHEAPTRACKING2_FUZZER_H
#define FUZZ_PROJECT_NAME "stopheaptracking2_fuzzer.h"
#endif

View File

@ -140,4 +140,9 @@
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
</preparer>
</target>
<target name="StopHeapTracking2FuzzTest">
<preparer>
<option name="push" value="test/test/libark_jsruntime_test.so -> /data/test" src="out"/>
</preparer>
</target>
</configuration>