mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
!4078 Add ut and fuzz testcase for heapsamping
Merge pull request !4078 from hunili/master
This commit is contained in:
commit
346f06675a
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -60,10 +60,33 @@ host_unittest_action("HProfTest") {
|
||||
deps += hiviewdfx_deps
|
||||
}
|
||||
|
||||
host_unittest_action("HeapSamplingTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
# test file
|
||||
"heap_sampling_test.cpp",
|
||||
]
|
||||
|
||||
configs = [ "$js_root:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$ark_third_party_root/icu/icu4c:shared_icui18n",
|
||||
"$ark_third_party_root/icu/icu4c:shared_icuuc",
|
||||
"$js_root:libark_jsruntime_test",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
|
||||
# hiviewdfx libraries
|
||||
external_deps = hiviewdfx_ext_deps
|
||||
deps += hiviewdfx_deps
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":HProfTest",
|
||||
":HeapSamplingTest",
|
||||
":HeapTrackerTest",
|
||||
]
|
||||
}
|
||||
@ -72,6 +95,7 @@ group("host_unittest") {
|
||||
testonly = true
|
||||
deps = [
|
||||
":HProfTestAction",
|
||||
":HeapSamplingTestAction",
|
||||
":HeapTrackerTestAction",
|
||||
]
|
||||
}
|
||||
|
104
ecmascript/dfx/hprof/tests/heap_sampling_test.cpp
Normal file
104
ecmascript/dfx/hprof/tests/heap_sampling_test.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "ecmascript/dfx/hprof/heap_profiler_interface.h"
|
||||
#include "ecmascript/dfx/hprof/heap_profiler.h"
|
||||
#include "ecmascript/dfx/hprof/heap_sampling.h"
|
||||
#include "ecmascript/dfx/stackinfo/js_stackgetter.h"
|
||||
#include "ecmascript/tests/test_helper.h"
|
||||
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace panda::test {
|
||||
class HeapSamplingTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "SetUpTestCase";
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
GTEST_LOG_(INFO) << "TearDownCase";
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
|
||||
instance->SetEnableForceGC(false);
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
TestHelper::DestroyEcmaVMWithScope(instance, scope);
|
||||
}
|
||||
|
||||
EcmaVM *instance {nullptr};
|
||||
EcmaHandleScope *scope {nullptr};
|
||||
JSThread *thread {nullptr};
|
||||
};
|
||||
|
||||
HWTEST_F_L0(HeapSamplingTest, StartHeapSampling)
|
||||
{
|
||||
HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(instance);
|
||||
uint64_t samplingInterval = 1 << 15; // default interval
|
||||
int stackDepth = 128; // default depth
|
||||
bool result = heapProfile->StartHeapSampling(samplingInterval, stackDepth);
|
||||
ASSERT_TRUE(result);
|
||||
result = heapProfile->StartHeapSampling(samplingInterval, stackDepth);
|
||||
ASSERT_FALSE(result);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(HeapSamplingTest, StopHeapSampling)
|
||||
{
|
||||
HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(instance);
|
||||
uint64_t samplingInterval = 1 << 15; // default interval
|
||||
int stackDepth = 128; // default depth
|
||||
bool result = heapProfile->StartHeapSampling(samplingInterval, stackDepth);
|
||||
ASSERT_TRUE(result);
|
||||
heapProfile->StopHeapSampling();
|
||||
result = heapProfile->StartHeapSampling(samplingInterval, stackDepth);
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(HeapSamplingTest, GetAllocationProfile)
|
||||
{
|
||||
HeapProfilerInterface *heapProfile = HeapProfilerInterface::GetInstance(instance);
|
||||
const SamplingInfo *result = heapProfile->GetAllocationProfile();
|
||||
ASSERT_TRUE(result == nullptr);
|
||||
uint64_t samplingInterval = 1 << 15; // default interval
|
||||
int stackDepth = 128; // default depth
|
||||
heapProfile->StartHeapSampling(samplingInterval, stackDepth);
|
||||
result = heapProfile->GetAllocationProfile();
|
||||
EXPECT_TRUE(result != nullptr);
|
||||
EXPECT_TRUE(result->head_.callFrameInfo_.functionName_ == "(root)");
|
||||
}
|
||||
|
||||
HWTEST_F_L0(HeapSamplingTest, ImplementSampling)
|
||||
{
|
||||
uint64_t samplingInterval = 1 << 15; // default interval
|
||||
int stackDepth = 128; // default depth
|
||||
std::unique_ptr<HeapSampling> heapSampling = std::make_unique<HeapSampling>(instance,
|
||||
const_cast<Heap *>(instance->GetHeap()), samplingInterval, stackDepth);
|
||||
int size = 1 << 15; // default size
|
||||
Address addr = 0;
|
||||
heapSampling->ImplementSampling(addr, size);
|
||||
const struct SamplingInfo *result = heapSampling->GetAllocationProfile();
|
||||
EXPECT_TRUE(result != nullptr);
|
||||
EXPECT_TRUE(result->samples_[0].size_ == size);
|
||||
}
|
||||
} // namespace panda::test
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -324,4 +324,33 @@ HWTEST_F_L0(DFXJSNApiTests, BuildJsStackInfoList)
|
||||
bool result = DFXJSNApi::BuildJsStackInfoList(vm_, hostTid, jsFrameInfo);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DFXJSNApiTests, StartSampling)
|
||||
{
|
||||
uint64_t samplingInterval = 32768;
|
||||
bool result = DFXJSNApi::StartSampling(vm_, samplingInterval);
|
||||
EXPECT_TRUE(result);
|
||||
result = DFXJSNApi::StartSampling(vm_, samplingInterval);
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DFXJSNApiTests, StopSampling)
|
||||
{
|
||||
uint64_t samplingInterval = 32768;
|
||||
bool result = DFXJSNApi::StartSampling(vm_, samplingInterval);
|
||||
EXPECT_TRUE(result);
|
||||
DFXJSNApi::StopSampling(vm_);
|
||||
result = DFXJSNApi::StartSampling(vm_, samplingInterval);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DFXJSNApiTests, GetAllocationProfile)
|
||||
{
|
||||
const SamplingInfo *result = DFXJSNApi::GetAllocationProfile(vm_);
|
||||
EXPECT_TRUE(result == nullptr);
|
||||
uint64_t samplingInterval = 32768;
|
||||
DFXJSNApi::StartSampling(vm_, samplingInterval);
|
||||
result = DFXJSNApi::GetAllocationProfile(vm_);
|
||||
EXPECT_TRUE(result != nullptr);
|
||||
}
|
||||
} // namespace panda::test
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -206,6 +206,7 @@ group("fuzztest") {
|
||||
"functionrefconstructor_fuzzer:fuzztest",
|
||||
"functionrefnew_fuzzer:fuzztest",
|
||||
"functionrefnewclassfunction_fuzzer:fuzztest",
|
||||
"getallocationprofile_fuzzer:fuzztest",
|
||||
"getnativepointerfield_fuzzer:fuzztest",
|
||||
"getwordsarray_fuzzer:fuzztest",
|
||||
"int16arrayrefnew_fuzzer:fuzztest",
|
||||
@ -239,6 +240,8 @@ group("fuzztest") {
|
||||
"snapshotserializehugeobject_fuzzer:fuzztest",
|
||||
"snapshotserializerange_fuzzer:fuzztest",
|
||||
"startcpuprofilerforfile_fuzzer:fuzztest",
|
||||
"startsampling_fuzzer:fuzztest",
|
||||
"stopsampling_fuzzer:fuzztest",
|
||||
"stringrefnewfromutf8_fuzzer:fuzztest",
|
||||
"uint16arrayrefnew_fuzzer:fuzztest",
|
||||
"uint32arrayrefnew_fuzzer:fuzztest",
|
||||
|
44
test/fuzztest/getallocationprofile_fuzzer/BUILD.gn
Normal file
44
test/fuzztest/getallocationprofile_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################################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")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("GetAllocationProfileFuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file = "$js_root/test/fuzztest/getallocationprofile_fuzzer"
|
||||
|
||||
sources = [ "getallocationprofile_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "$js_root:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$js_root:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
|
||||
# hiviewdfx libraries
|
||||
external_deps = hiviewdfx_ext_deps
|
||||
deps += hiviewdfx_deps
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":GetAllocationProfileFuzzTest" ]
|
||||
}
|
14
test/fuzztest/getallocationprofile_fuzzer/corpus/init
Normal file
14
test/fuzztest/getallocationprofile_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "getallocationprofile_fuzzer.h"
|
||||
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
#include "ecmascript/napi/include/dfx_jsnapi.h"
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
void GetAllocationProfileFuzzerTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
int64_t key = 0;
|
||||
size_t maxByteLen = 8;
|
||||
if (size > maxByteLen) {
|
||||
size = maxByteLen;
|
||||
}
|
||||
if (memcpy_s(&key, maxByteLen, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
#ifndef ECMASCRIPT_SUPPORT_HEAPSAMPLING
|
||||
#define ECMASCRIPT_SUPPORT_HEAPSAMPLING
|
||||
DFXJSNApi::StartSampling(vm, key);
|
||||
DFXJSNApi::GetAllocationProfile(vm);
|
||||
#endif
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::GetAllocationProfileFuzzerTest(data, size);
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GETALLOCATIONPROFILE_FUZZER
|
||||
#define GETALLOCATIONPROFILE_FUZZER
|
||||
|
||||
#define FUZZ_PROJECT_NAME "getallocationprofile_fuzzer.h"
|
||||
|
||||
#endif
|
25
test/fuzztest/getallocationprofile_fuzzer/project.xml
Normal file
25
test/fuzztest/getallocationprofile_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<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>
|
44
test/fuzztest/startsampling_fuzzer/BUILD.gn
Normal file
44
test/fuzztest/startsampling_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################################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")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("StartSamplingFuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file = "$js_root/test/fuzztest/startsampling_fuzzer"
|
||||
|
||||
sources = [ "startsampling_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "$js_root:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$js_root:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
|
||||
# hiviewdfx libraries
|
||||
external_deps = hiviewdfx_ext_deps
|
||||
deps += hiviewdfx_deps
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":StartSamplingFuzzTest" ]
|
||||
}
|
14
test/fuzztest/startsampling_fuzzer/corpus/init
Normal file
14
test/fuzztest/startsampling_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
25
test/fuzztest/startsampling_fuzzer/project.xml
Normal file
25
test/fuzztest/startsampling_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<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>
|
57
test/fuzztest/startsampling_fuzzer/startsampling_fuzzer.cpp
Normal file
57
test/fuzztest/startsampling_fuzzer/startsampling_fuzzer.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "startsampling_fuzzer.h"
|
||||
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
#include "ecmascript/napi/include/dfx_jsnapi.h"
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
void StartSamplingFuzzerTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
int64_t key = 0;
|
||||
size_t maxByteLen = 8;
|
||||
if (size > maxByteLen) {
|
||||
size = maxByteLen;
|
||||
}
|
||||
if (memcpy_s(&key, maxByteLen, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
#ifndef ECMASCRIPT_SUPPORT_HEAPSAMPLING
|
||||
#define ECMASCRIPT_SUPPORT_HEAPSAMPLING
|
||||
DFXJSNApi::StartSampling(vm, key);
|
||||
#endif
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::StartSamplingFuzzerTest(data, size);
|
||||
return 0;
|
||||
}
|
21
test/fuzztest/startsampling_fuzzer/startsampling_fuzzer.h
Normal file
21
test/fuzztest/startsampling_fuzzer/startsampling_fuzzer.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef STARTSAMPLING_FUZZER_H
|
||||
#define STARTSAMPLING_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "startsampling_fuzzer.h"
|
||||
|
||||
#endif
|
44
test/fuzztest/stopsampling_fuzzer/BUILD.gn
Normal file
44
test/fuzztest/stopsampling_fuzzer/BUILD.gn
Normal file
@ -0,0 +1,44 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#####################################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")
|
||||
|
||||
####################################fuzztest##################################
|
||||
ohos_fuzztest("StopSamplingFuzzTest") {
|
||||
module_out_path = "arkcompiler/ets_runtime"
|
||||
|
||||
fuzz_config_file = "$js_root/test/fuzztest/stopsampling_fuzzer"
|
||||
|
||||
sources = [ "stopsampling_fuzzer.cpp" ]
|
||||
|
||||
configs = [ "$js_root:ecma_test_config" ]
|
||||
|
||||
deps = [
|
||||
"$js_root:libark_jsruntime",
|
||||
sdk_libc_secshared_dep,
|
||||
]
|
||||
|
||||
# hiviewdfx libraries
|
||||
external_deps = hiviewdfx_ext_deps
|
||||
deps += hiviewdfx_deps
|
||||
}
|
||||
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
deps += [ ":StopSamplingFuzzTest" ]
|
||||
}
|
14
test/fuzztest/stopsampling_fuzzer/corpus/init
Normal file
14
test/fuzztest/stopsampling_fuzzer/corpus/init
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FUZZ
|
25
test/fuzztest/stopsampling_fuzzer/project.xml
Normal file
25
test/fuzztest/stopsampling_fuzzer/project.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<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>
|
58
test/fuzztest/stopsampling_fuzzer/stopsampling_fuzzer.cpp
Normal file
58
test/fuzztest/stopsampling_fuzzer/stopsampling_fuzzer.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "stopsampling_fuzzer.h"
|
||||
|
||||
#include "ecmascript/base/string_helper.h"
|
||||
#include "ecmascript/napi/include/dfx_jsnapi.h"
|
||||
#include "ecmascript/napi/include/jsnapi.h"
|
||||
|
||||
using namespace panda;
|
||||
using namespace panda::ecmascript;
|
||||
|
||||
namespace OHOS {
|
||||
void StopSamplingFuzzerTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
RuntimeOption option;
|
||||
option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR);
|
||||
EcmaVM *vm = JSNApi::CreateJSVM(option);
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
int64_t key = 0;
|
||||
size_t maxByteLen = 8;
|
||||
if (size > maxByteLen) {
|
||||
size = maxByteLen;
|
||||
}
|
||||
if (memcpy_s(&key, maxByteLen, data, size) != EOK) {
|
||||
std::cout << "memcpy_s failed!";
|
||||
UNREACHABLE();
|
||||
}
|
||||
#ifndef ECMASCRIPT_SUPPORT_HEAPSAMPLING
|
||||
#define ECMASCRIPT_SUPPORT_HEAPSAMPLING
|
||||
DFXJSNApi::StartSampling(vm, key);
|
||||
DFXJSNApi::StopSampling(vm);
|
||||
#endif
|
||||
JSNApi::DestroyJSVM(vm);
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzer entry point.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
// Run your code on data.
|
||||
OHOS::StopSamplingFuzzerTest(data, size);
|
||||
return 0;
|
||||
}
|
21
test/fuzztest/stopsampling_fuzzer/stopsampling_fuzzer.h
Normal file
21
test/fuzztest/stopsampling_fuzzer/stopsampling_fuzzer.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef STOPSAMPLING_FUZZER_H
|
||||
#define STOPSAMPLING_FUZZER_H
|
||||
|
||||
#define FUZZ_PROJECT_NAME "stopsampling_fuzzer.h"
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user