diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 0746cd736e26c1040c0f6fd03d8ee52054e14ec4..eff7f600537ec6a700a44fd92a6d7f8fc6c508d4 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -16,6 +16,8 @@ group("fuzztest") { deps = [] deps += [ + "agent:fuzztest", + "backend:fuzztest", "dispatchprotocolmessage_fuzzer:fuzztest", "initializedebugger_fuzzer:fuzztest", ] diff --git a/test/fuzztest/agent/BUILD.gn b/test/fuzztest/agent/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6fe2f226bef9233af04ed68e927fc97716675adc --- /dev/null +++ b/test/fuzztest/agent/BUILD.gn @@ -0,0 +1,19 @@ +# 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 = [] + + deps += [ "heapprofiler:fuzztest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/BUILD.gn b/test/fuzztest/agent/heapprofiler/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1eb373cb0dbc194d7c912ee362136e4ba0850726 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/BUILD.gn @@ -0,0 +1,33 @@ +# 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 = [] + + deps += [ + "heapprofileraddinspectedheapobject_fuzzer:fuzztest", + "heapprofilercollectgarbage_fuzzer:fuzztest", + "heapprofilerdisable_fuzzer:fuzztest", + "heapprofilerdispatch_fuzzer:fuzztest", + "heapprofilerenable_fuzzer:fuzztest", + "heapprofilergetheapobjectid_fuzzer:fuzztest", + "heapprofilergetobjectbyheapobjectid_fuzzer:fuzztest", + "heapprofilergetsamplingprofile_fuzzer:fuzztest", + "heapprofilerstartsampling_fuzzer:fuzztest", + "heapprofilerstarttrackingheapobjects_fuzzer:fuzztest", + "heapprofilerstopsampling_fuzzer:fuzztest", + "heapprofilerstoptrackingheapobjects_fuzzer:fuzztest", + "heapprofilertakeheapsnapshot_fuzzer:fuzztest", + ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d237d4c24302b16aa3e69da25a84a6995a9f0075 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerAddInspectedHeapObjectFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer" + + sources = [ "heapprofileraddinspectedheapobject_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerAddInspectedHeapObjectFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/heapprofileraddinspectedheapobject_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/heapprofileraddinspectedheapobject_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c789996b283ca50822967be18bf1a3580be1506 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/heapprofileraddinspectedheapobject_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofileraddinspectedheapobject_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerAddInspectedHeapObjectFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->AddInspectedHeapObject(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerAddInspectedHeapObjectFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/heapprofileraddinspectedheapobject_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/heapprofileraddinspectedheapobject_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4a56bcc5fa0dcc648d640c5ee3b036fff9838d42 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/heapprofileraddinspectedheapobject_fuzzer.h @@ -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 HEAPPROFILERADDINSPECTEDHEAPOBJECT_FUZZER_H +#define HEAPPROFILERADDINSPECTEDHEAPOBJECT_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofileraddinspectedheapobject_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d1cee2d59779fc50f0f5528518e59adcce9c5abe --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerCollectgarbageFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer" + + sources = [ "heapprofilercollectgarbage_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerCollectgarbageFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/heapprofilercollectgarbage_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/heapprofilercollectgarbage_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc0ff0ab43eb4f023a7eb7754608f6f03ab929b9 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/heapprofilercollectgarbage_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilercollectgarbage_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerCollectgarbageFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->CollectGarbage(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerCollectgarbageFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/heapprofilercollectgarbage_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/heapprofilercollectgarbage_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9754e8c6f5597d2d3ad91258fd228f3d5cea4dc9 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/heapprofilercollectgarbage_fuzzer.h @@ -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 HEAPPROFILERCOLLECTGARBAGE_FUZZER_H +#define HEAPPROFILERCOLLECTGARBAGE_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilercollectgarbage_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e4c623371a51aa2ebb5b03779db8c6bf422f3c8d --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerDisableFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer" + + sources = [ "heapprofilerdisable_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerDisableFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/heapprofilerdisable_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/heapprofilerdisable_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27d9d1aadf06620030fedb5109902dcf3a923d96 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/heapprofilerdisable_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilerdisable_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerDisableFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->Disable(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerDisableFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/heapprofilerdisable_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/heapprofilerdisable_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9b3d11fb472fe35d5cd3119488b6324ef30f4b16 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/heapprofilerdisable_fuzzer.h @@ -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 HEAPPROFILERENABLE_FUZZER_H +#define HEAPPROFILERENABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilerenable_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e2a342398b4d9a5056ce48cb28504fdd91844d8e --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerDispatchFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer" + + sources = [ "heapprofilerdispatch_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerDispatchFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/heapprofilerdispatch_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/heapprofilerdispatch_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..756f9742c7719210de779d3c896a81fbd933655f --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/heapprofilerdispatch_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilerdispatch_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerDispatchFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->Dispatch(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerDispatchFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/heapprofilerdispatch_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/heapprofilerdispatch_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..d4b93ceb95f88bc48b5130e47f3ca4c54ac9f735 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/heapprofilerdispatch_fuzzer.h @@ -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 BACKENDBREAKPOINT_FUZZER_H +#define BACKENDBREAKPOINT_FUZZER_H + +#define FUZZ_PROJECT_NAME "backendbreakpoint_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e5d29c370eaf3ea27fe7699b7d1df5f372132884 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerEnableFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer" + + sources = [ "heapprofilerenable_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerEnableFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/heapprofilerenable_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/heapprofilerenable_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4269a1385fb757e94ef1ff4e7d20b7759f78eddd --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/heapprofilerenable_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilerenable_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerEnableFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->Enable(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerEnableFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/heapprofilerenable_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/heapprofilerenable_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9b3d11fb472fe35d5cd3119488b6324ef30f4b16 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/heapprofilerenable_fuzzer.h @@ -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 HEAPPROFILERENABLE_FUZZER_H +#define HEAPPROFILERENABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilerenable_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..da8c1199c403b09fbaed7ad00c524b131e769e3d --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerGetheapObjectIdFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer" + + sources = [ "heapprofilergetheapobjectid_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerGetheapObjectIdFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/heapprofilergetheapobjectid_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/heapprofilergetheapobjectid_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7371d4b74df65250f6ee316bc20f8c08dca320e1 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/heapprofilergetheapobjectid_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilergetheapobjectid_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerGetheapObjectIdFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->GetHeapObjectId(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerGetheapObjectIdFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/heapprofilergetheapobjectid_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/heapprofilergetheapobjectid_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9b3d11fb472fe35d5cd3119488b6324ef30f4b16 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/heapprofilergetheapobjectid_fuzzer.h @@ -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 HEAPPROFILERENABLE_FUZZER_H +#define HEAPPROFILERENABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilerenable_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..78642c1eabde3adc1809699f56a2277c449869be --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerGetObjectByHeapObjectIdFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer" + + sources = [ "heapprofilergetobjectbyheapobjectid_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerGetObjectByHeapObjectIdFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/heapprofilergetobjectbyheapobjectid_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/heapprofilergetobjectbyheapobjectid_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7974fb93f09c78b4851399e66a80adb54986995f --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/heapprofilergetobjectbyheapobjectid_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilergetobjectbyheapobjectid_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerGetObjectByHeapObjectIdFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->GetObjectByHeapObjectId(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerGetObjectByHeapObjectIdFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/heapprofilergetobjectbyheapobjectid_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/heapprofilergetobjectbyheapobjectid_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9b3d11fb472fe35d5cd3119488b6324ef30f4b16 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/heapprofilergetobjectbyheapobjectid_fuzzer.h @@ -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 HEAPPROFILERENABLE_FUZZER_H +#define HEAPPROFILERENABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilerenable_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..13f2c273b00d2c0f177b90f82a0a5a47cc95e033 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerGetSamplingProfileFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer" + + sources = [ "heapprofilergetsamplingprofile_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerGetSamplingProfileFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/heapprofilergetsamplingprofile_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/heapprofilergetsamplingprofile_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..abdbce238e7ea1be244bdd92b21e51f4574c99f4 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/heapprofilergetsamplingprofile_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilergetsamplingprofile_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerGetSamplingProfileFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->GetSamplingProfile(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerGetSamplingProfileFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/heapprofilergetsamplingprofile_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/heapprofilergetsamplingprofile_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..67c5fa5c03192f354e4f9da4bde77c4051b9ebcc --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/heapprofilergetsamplingprofile_fuzzer.h @@ -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 HEAPPROFILERGETSAMPLINGPROFILE_FUZZER_H +#define HEAPPROFILERGETSAMPLINGPROFILE_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilergetsamplingprofile_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4eedb87c89ab7131ebcef3983408dc45be24fc3d --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerStartSamplingFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer" + + sources = [ "heapprofilerstartsampling_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerStartSamplingFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/heapprofilerstartsampling_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/heapprofilerstartsampling_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8e381ed5bfae4f5598b864945fa77694e08aae19 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/heapprofilerstartsampling_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilerstartsampling_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerStartSamplingFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->StartSampling(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerStartSamplingFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/heapprofilerstartsampling_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/heapprofilerstartsampling_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..580dd828006518bafbf3f8cca920a7b3b15a0ca5 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/heapprofilerstartsampling_fuzzer.h @@ -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 HEAPPROFILERSTARTSAMPLING_FUZZER_H +#define HEAPPROFILERSTARTSAMPLING_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilerstartsampling_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4359c9923f6aeade10951891f124959671874ab4 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerStartTrackingHeapObjectsFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer" + + sources = [ "heapprofilerstarttrackingheapobjects_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerStartTrackingHeapObjectsFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/heapprofilerstarttrackingheapobjects_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/heapprofilerstarttrackingheapobjects_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8e5a3f7e2b5a5aa617b6383aad3e20aeb6c07ff0 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/heapprofilerstarttrackingheapobjects_fuzzer.cpp @@ -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 "heapprofilerstarttrackingheapobjects_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerStartTrackingHeapObjectsFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(vm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->StartTrackingHeapObjects(*req); + dispatcherImpl->StopTrackingHeapObjects(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerStartTrackingHeapObjectsFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/heapprofilerstarttrackingheapobjects_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/heapprofilerstarttrackingheapobjects_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9b3d11fb472fe35d5cd3119488b6324ef30f4b16 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/heapprofilerstarttrackingheapobjects_fuzzer.h @@ -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 HEAPPROFILERENABLE_FUZZER_H +#define HEAPPROFILERENABLE_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilerenable_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..33e093e980505941b135ae64d2f6e480443f35c7 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerStopSamplingFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer" + + sources = [ "heapprofilerstopsampling_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerStopSamplingFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/heapprofilerstopsampling_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/heapprofilerstopsampling_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd8c0dcfaeef18966316c0e912f0fce1cb3a97ec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/heapprofilerstopsampling_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "heapprofilerstopsampling_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerStopSamplingFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + using EcmaVMS = panda::ecmascript::EcmaVM; + EcmaVMS *ecmaVm {nullptr}; + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(ecmaVm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->StopSampling(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerStopSamplingFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/heapprofilerstopsampling_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/heapprofilerstopsampling_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a61b6a6eb523c90a2ef471c94d74000d7cd294b0 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/heapprofilerstopsampling_fuzzer.h @@ -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 HEAPPROFILERSTOPSAMPLING_FUZZER_H +#define HEAPPROFILERSTOPSAMPLING_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilerstopsampling_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d27c874dcf4b136c4f461d38a188e08d627e7a85 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerStopTrackingHeapObjectsFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer" + + sources = [ "heapprofilerstoptrackingheapobjects_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerStopTrackingHeapObjectsFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/heapprofilerstoptrackingheapobjects_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/heapprofilerstoptrackingheapobjects_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbc26ce92544f4df546898d0447848aae80e1041 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/heapprofilerstoptrackingheapobjects_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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 "heapprofilerstoptrackingheapobjects_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerStopTrackingHeapObjectsFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(vm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->StopTrackingHeapObjects(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerStopTrackingHeapObjectsFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/heapprofilerstoptrackingheapobjects_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/heapprofilerstoptrackingheapobjects_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8d4e0c0824f6b0a9583163ae1bf700f6315de453 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/heapprofilerstoptrackingheapobjects_fuzzer.h @@ -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 HEAPPROFILERSTOPTRACKINGHEAPOBJECTS_FUZZER_H +#define HEAPPROFILERSTOPTRACKINGHEAPOBJECTS_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilerstoptrackingheapobjects_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/BUILD.gn b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c5c7f98edf54c8ed76997569959b16fc48448402 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("HeapprofilerTakeHeapSnapshotFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer" + + sources = [ "heapprofilertakeheapsnapshot_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":HeapprofilerTakeHeapSnapshotFuzzTest" ] +} diff --git a/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/corpus/init b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/heapprofilertakeheapsnapshot_fuzzer.cpp b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/heapprofilertakeheapsnapshot_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..98f86bab40879cad7bffba33196b962febc27e75 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/heapprofilertakeheapsnapshot_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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 "heapprofilertakeheapsnapshot_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/heapprofiler_impl.h" +#include "tooling/dispatcher.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void HeapprofilerTakeHeapSnapshotFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int index = 0; + if (size <= 0) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&index, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + std::string str(data, data + size); + auto req = std::make_unique(str); + auto heapProfiler = std::make_unique(vm, nullptr); + auto dispatcherImpl = + std::make_unique(nullptr, std::move(heapProfiler)); + dispatcherImpl->TakeHeapSnapshot(*req); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::HeapprofilerTakeHeapSnapshotFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/heapprofilertakeheapsnapshot_fuzzer.h b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/heapprofilertakeheapsnapshot_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..eae11e9591dd1b27abbebf2ca6677866aa8ed284 --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/heapprofilertakeheapsnapshot_fuzzer.h @@ -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 HEAPPROFILERTAKEHEAPSNAPSHOT_FUZZER_H +#define HEAPPROFILERTAKEHEAPSNAPSHOT_FUZZER_H + +#define FUZZ_PROJECT_NAME "heapprofilertakeheapsnapshot_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/project.xml b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/backend/BUILD.gn b/test/fuzztest/backend/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1fbdf150640c3d32e5364a17e1e0199d87cbb8b3 --- /dev/null +++ b/test/fuzztest/backend/BUILD.gn @@ -0,0 +1,25 @@ +# 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 = [] + + deps += [ + "backendbreakpoint_fuzzer:fuzztest", + "backendexception_fuzzer:fuzztest", + "backendloadmodule_fuzzer:fuzztest", + "backendnativecalling_fuzzer:fuzztest", + "backendpendingjobentry_fuzzer:fuzztest", + ] +} diff --git a/test/fuzztest/backend/backendbreakpoint_fuzzer/BUILD.gn b/test/fuzztest/backend/backendbreakpoint_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3e1c67174081c3313ccb60704e89e946b0f43c58 --- /dev/null +++ b/test/fuzztest/backend/backendbreakpoint_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("BackendBreakpointFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = + "//arkcompiler/toolchain/test/fuzztest/backend/backendbreakpoint_fuzzer" + + sources = [ "backendbreakpoint_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":BackendBreakpointFuzzTest" ] +} diff --git a/test/fuzztest/backend/backendbreakpoint_fuzzer/backendbreakpoint_fuzzer.cpp b/test/fuzztest/backend/backendbreakpoint_fuzzer/backendbreakpoint_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6ff2e1b49cab7799b188e781f849d36b90b9cc90 --- /dev/null +++ b/test/fuzztest/backend/backendbreakpoint_fuzzer/backendbreakpoint_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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 "backendbreakpoint_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/debugger_impl.h" +#include "tooling/backend/js_pt_hooks.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void BackendBreakpointFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int32_t input; + if (size <= 1) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&input, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + const int32_t MaxMenory = 1073741824; + if (input > MaxMenory) { + input = MaxMenory; + } + using JSPtLocation = tooling::JSPtLocation; + EntityId methodId(input); + uint32_t bytecodeOffset = 0; + auto debugger = std::make_unique(vm, nullptr, nullptr); + std::unique_ptr jspthooks = std::make_unique(debugger.get()); + JSPtLocation ptLocation1(nullptr, methodId, bytecodeOffset); + jspthooks->Breakpoint(ptLocation1); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::BackendBreakpointFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/backend/backendbreakpoint_fuzzer/backendbreakpoint_fuzzer.h b/test/fuzztest/backend/backendbreakpoint_fuzzer/backendbreakpoint_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..d4b93ceb95f88bc48b5130e47f3ca4c54ac9f735 --- /dev/null +++ b/test/fuzztest/backend/backendbreakpoint_fuzzer/backendbreakpoint_fuzzer.h @@ -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 BACKENDBREAKPOINT_FUZZER_H +#define BACKENDBREAKPOINT_FUZZER_H + +#define FUZZ_PROJECT_NAME "backendbreakpoint_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/backend/backendbreakpoint_fuzzer/corpus/init b/test/fuzztest/backend/backendbreakpoint_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/backend/backendbreakpoint_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/backend/backendbreakpoint_fuzzer/project.xml b/test/fuzztest/backend/backendbreakpoint_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/backend/backendbreakpoint_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/backend/backendexception_fuzzer/BUILD.gn b/test/fuzztest/backend/backendexception_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e1f2f77f831c552a1b671be7bcb69e0965a8a83e --- /dev/null +++ b/test/fuzztest/backend/backendexception_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("BackendExceptionFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = + "//arkcompiler/toolchain/test/fuzztest/backend/backendexception_fuzzer" + + sources = [ "backendexception_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":BackendExceptionFuzzTest" ] +} diff --git a/test/fuzztest/backend/backendexception_fuzzer/backendexception_fuzzer.cpp b/test/fuzztest/backend/backendexception_fuzzer/backendexception_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49835a58c2b7256b3537e675803013a9bf22e884 --- /dev/null +++ b/test/fuzztest/backend/backendexception_fuzzer/backendexception_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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 "backendexception_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/debugger_impl.h" +#include "tooling/backend/js_pt_hooks.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void BackendExceptionFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int32_t input; + if (size <= 1) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&input, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + const int32_t MaxMenory = 1073741824; + if (input > MaxMenory) { + input = MaxMenory; + } + using JSPtLocation = tooling::JSPtLocation; + EntityId methodId(input); + uint32_t bytecodeOffset = 0; + auto debugger = std::make_unique(vm, nullptr, nullptr); + std::unique_ptr jspthooks = std::make_unique(debugger.get()); + JSPtLocation ptLocation1(nullptr, methodId, bytecodeOffset); + jspthooks->Exception(ptLocation1); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::BackendExceptionFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/backend/backendexception_fuzzer/backendexception_fuzzer.h b/test/fuzztest/backend/backendexception_fuzzer/backendexception_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..053160a2d0a3320c4b1cc9f2d8a4c093447edf51 --- /dev/null +++ b/test/fuzztest/backend/backendexception_fuzzer/backendexception_fuzzer.h @@ -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 BACKENDEXCEPTION_FUZZER_H +#define BACKENDEXCEPTION_FUZZER_H + +#define FUZZ_PROJECT_NAME "backendexception_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/backend/backendexception_fuzzer/corpus/init b/test/fuzztest/backend/backendexception_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/backend/backendexception_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/backend/backendexception_fuzzer/project.xml b/test/fuzztest/backend/backendexception_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/backend/backendexception_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/backend/backendloadmodule_fuzzer/BUILD.gn b/test/fuzztest/backend/backendloadmodule_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..75c4a4e791396dff1bafbbcb5cea76677e09ab89 --- /dev/null +++ b/test/fuzztest/backend/backendloadmodule_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("BackendLoadModuleFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = + "//arkcompiler/toolchain/test/fuzztest/backend/backendloadmodule_fuzzer" + + sources = [ "backendloadmodule_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":BackendLoadModuleFuzzTest" ] +} diff --git a/test/fuzztest/backend/backendloadmodule_fuzzer/backendloadmodule_fuzzer.cpp b/test/fuzztest/backend/backendloadmodule_fuzzer/backendloadmodule_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5bc728326dd58c330645d01fce1e14986eba9644 --- /dev/null +++ b/test/fuzztest/backend/backendloadmodule_fuzzer/backendloadmodule_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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 "backendloadmodule_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/debugger_impl.h" +#include "tooling/backend/js_pt_hooks.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void BackendLoadModuleFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int32_t input; + if (size <= 1) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&input, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + const int32_t MaxMenory = 1073741824; + if (input > MaxMenory) { + input = MaxMenory; + } + using JSPtLocation = tooling::JSPtLocation; + EntityId methodId(input); + uint32_t bytecodeOffset = 0; + auto debugger = std::make_unique(vm, nullptr, nullptr); + std::unique_ptr jspthooks = std::make_unique(debugger.get()); + JSPtLocation ptLocation1(nullptr, methodId, bytecodeOffset); + jspthooks->LoadModule("pandafile/test.abc", "func_main_0"); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::BackendLoadModuleFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/backend/backendloadmodule_fuzzer/backendloadmodule_fuzzer.h b/test/fuzztest/backend/backendloadmodule_fuzzer/backendloadmodule_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..9a57c64d28e356b620b8364eaea610f6ab3713dd --- /dev/null +++ b/test/fuzztest/backend/backendloadmodule_fuzzer/backendloadmodule_fuzzer.h @@ -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 BACKENDLOADMODULE_FUZZER_H +#define BACKENDLOADMODULE_FUZZER_H + +#define FUZZ_PROJECT_NAME "backendloadmodule_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/backend/backendloadmodule_fuzzer/corpus/init b/test/fuzztest/backend/backendloadmodule_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/backend/backendloadmodule_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/backend/backendloadmodule_fuzzer/project.xml b/test/fuzztest/backend/backendloadmodule_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/backend/backendloadmodule_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/backend/backendnativecalling_fuzzer/BUILD.gn b/test/fuzztest/backend/backendnativecalling_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..702769cc8ac52781b182c0e442ab44d6efa7ad7d --- /dev/null +++ b/test/fuzztest/backend/backendnativecalling_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("BackendNativeCallingFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/backend/backendnativecalling_fuzzer" + + sources = [ "backendnativecalling_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":BackendNativeCallingFuzzTest" ] +} diff --git a/test/fuzztest/backend/backendnativecalling_fuzzer/backendnativecalling_fuzzer.cpp b/test/fuzztest/backend/backendnativecalling_fuzzer/backendnativecalling_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..90690fb11057ac736d9d1eef72d93da3551b04fb --- /dev/null +++ b/test/fuzztest/backend/backendnativecalling_fuzzer/backendnativecalling_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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 "backendnativecalling_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/debugger_impl.h" +#include "tooling/backend/js_pt_hooks.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void BackendNativeCallingFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int32_t input; + if (size <= 1) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&input, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + const int32_t MaxMenory = 1073741824; + if (input > MaxMenory) { + input = MaxMenory; + } + using JSPtLocation = tooling::JSPtLocation; + EntityId methodId(input); + uint32_t bytecodeOffset = 0; + auto debugger = std::make_unique(vm, nullptr, nullptr); + std::unique_ptr jspthooks = std::make_unique(debugger.get()); + JSPtLocation ptLocation1(nullptr, methodId, bytecodeOffset); + jspthooks->NativeCalling(nullptr); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::BackendNativeCallingFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/backend/backendnativecalling_fuzzer/backendnativecalling_fuzzer.h b/test/fuzztest/backend/backendnativecalling_fuzzer/backendnativecalling_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2e98f2555fbbeb5211552a8a59e8a3a9ab9fb57d --- /dev/null +++ b/test/fuzztest/backend/backendnativecalling_fuzzer/backendnativecalling_fuzzer.h @@ -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 BACKENDNATIVECALLING_FUZZER_H +#define BACKENDNATIVECALLING_FUZZER_H + +#define FUZZ_PROJECT_NAME "backendnativecalling_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/backend/backendnativecalling_fuzzer/corpus/init b/test/fuzztest/backend/backendnativecalling_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/backend/backendnativecalling_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/backend/backendnativecalling_fuzzer/project.xml b/test/fuzztest/backend/backendnativecalling_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/backend/backendnativecalling_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/backend/backendpendingjobentry_fuzzer/BUILD.gn b/test/fuzztest/backend/backendpendingjobentry_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2ce400d3843ed807a3c8045dff81a97e1e188192 --- /dev/null +++ b/test/fuzztest/backend/backendpendingjobentry_fuzzer/BUILD.gn @@ -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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("BackendPendingJobEntryFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/backend/backendpendingjobentry_fuzzer" + + sources = [ "backendpendingjobentry_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":BackendPendingJobEntryFuzzTest" ] +} diff --git a/test/fuzztest/backend/backendpendingjobentry_fuzzer/backendpendingjobentry_fuzzer.cpp b/test/fuzztest/backend/backendpendingjobentry_fuzzer/backendpendingjobentry_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..425faa5088e4e21a963e9aa07eb21b8f6278b6b9 --- /dev/null +++ b/test/fuzztest/backend/backendpendingjobentry_fuzzer/backendpendingjobentry_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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 "backendpendingjobentry_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/debugger_impl.h" +#include "tooling/backend/js_pt_hooks.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void BackendPendingJobEntryFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int32_t input; + if (size <= 1) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&input, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + const int32_t MaxMenory = 1073741824; + if (input > MaxMenory) { + input = MaxMenory; + } + using JSPtLocation = tooling::JSPtLocation; + EntityId methodId(input); + uint32_t bytecodeOffset = 0; + auto debugger = std::make_unique(vm, nullptr, nullptr); + std::unique_ptr jspthooks = std::make_unique(debugger.get()); + JSPtLocation ptLocation1(nullptr, methodId, bytecodeOffset); + jspthooks->PendingJobEntry(); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::BackendPendingJobEntryFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/backend/backendpendingjobentry_fuzzer/backendpendingjobentry_fuzzer.h b/test/fuzztest/backend/backendpendingjobentry_fuzzer/backendpendingjobentry_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ff0db60e69a1dbac39048e2e6f3b6e6781f6f94c --- /dev/null +++ b/test/fuzztest/backend/backendpendingjobentry_fuzzer/backendpendingjobentry_fuzzer.h @@ -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 BACKENDPENDINGJOBENTRY_FUZZER_H +#define BACKENDPENDINGJOBENTRY_FUZZER_H + +#define FUZZ_PROJECT_NAME "backendpendingjobentry_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/backend/backendpendingjobentry_fuzzer/corpus/init b/test/fuzztest/backend/backendpendingjobentry_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/backend/backendpendingjobentry_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/backend/backendpendingjobentry_fuzzer/project.xml b/test/fuzztest/backend/backendpendingjobentry_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/backend/backendpendingjobentry_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/backend/backendsinglestep_fuzzer/BUILD.gn b/test/fuzztest/backend/backendsinglestep_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4e2cea9b355913948fc6e3540f0c511af2bf3219 --- /dev/null +++ b/test/fuzztest/backend/backendsinglestep_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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/toolchain/test/test_helper.gni") +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +####################################fuzztest################################## +ohos_fuzztest("BackendSingleStepFuzzTest") { + module_out_path = "arkcompiler/toolchain" + + fuzz_config_file = + "//arkcompiler/toolchain/test/fuzztest/backend/backendsinglestep_fuzzer" + + sources = [ "backendsinglestep_fuzzer.cpp" ] + + configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] + + deps = [ + "//arkcompiler/ets_runtime:libark_jsruntime_test", + "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + sdk_libc_secshared_dep, + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":BackendSingleStepFuzzTest" ] +} diff --git a/test/fuzztest/backend/backendsinglestep_fuzzer/backendsinglestep_fuzzer.cpp b/test/fuzztest/backend/backendsinglestep_fuzzer/backendsinglestep_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bcbc49e54737aeefac2763269fc29862de68c56b --- /dev/null +++ b/test/fuzztest/backend/backendsinglestep_fuzzer/backendsinglestep_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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 "backendsinglestep_fuzzer.h" +#include "ecmascript/napi/include/jsnapi.h" +#include "agent/debugger_impl.h" +#include "tooling/backend/js_pt_hooks.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::tooling; + +#define MAXBYTELEN sizeof(int32_t) + +namespace OHOS { + void BackendSingleStepFuzzTest(const uint8_t* data, size_t size) + { + RuntimeOption option; + option.SetLogLevel(RuntimeOption::LOG_LEVEL::ERROR); + auto vm = JSNApi::CreateJSVM(option); + int32_t input; + if (size <= 1) { + return; + } + if (size > MAXBYTELEN) { + size = MAXBYTELEN; + } + if (memcpy_s(&input, MAXBYTELEN, data, size) != 0) { + std::cout << "memcpy_s failed!"; + UNREACHABLE(); + } + const int32_t MaxMenory = 1073741824; + if (input > MaxMenory) { + input = MaxMenory; + } + using JSPtLocation = tooling::JSPtLocation; + EntityId methodId(input); + uint32_t bytecodeOffset = 0; + auto debugger = std::make_unique(vm, nullptr, nullptr); + std::unique_ptr jspthooks = std::make_unique(debugger.get()); + JSPtLocation ptLocation1(nullptr, methodId, bytecodeOffset); + jspthooks->SingleStep(ptLocation1); + JSNApi::DestroyJSVM(vm); + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::BackendSingleStepFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/backend/backendsinglestep_fuzzer/backendsinglestep_fuzzer.h b/test/fuzztest/backend/backendsinglestep_fuzzer/backendsinglestep_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..bbab87f12095e84ba06035d268e7ea943701ee93 --- /dev/null +++ b/test/fuzztest/backend/backendsinglestep_fuzzer/backendsinglestep_fuzzer.h @@ -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 BACKENDSINGLESTEP_FUZZER_H +#define BACKENDSINGLESTEP_FUZZER_H + +#define FUZZ_PROJECT_NAME "backendsinglestep_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/backend/backendsinglestep_fuzzer/corpus/init b/test/fuzztest/backend/backendsinglestep_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..b9a20c8eb6a74b442cec3b244a433adbfa9414a2 --- /dev/null +++ b/test/fuzztest/backend/backendsinglestep_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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 \ No newline at end of file diff --git a/test/fuzztest/backend/backendsinglestep_fuzzer/project.xml b/test/fuzztest/backend/backendsinglestep_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/backend/backendsinglestep_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/dispatchprotocolmessage_fuzzer/BUILD.gn b/test/fuzztest/dispatchprotocolmessage_fuzzer/BUILD.gn index a1a6254e8f4caba17e7474f438c340720e71df00..ea946d9681f74098d067d2e443e062ff3f04b842 100644 --- a/test/fuzztest/dispatchprotocolmessage_fuzzer/BUILD.gn +++ b/test/fuzztest/dispatchprotocolmessage_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("DispatchProtocolMessageFuzzTest") { configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] deps = [ - "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/ets_runtime:libark_jsruntime_test", "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", sdk_libc_secshared_dep, diff --git a/test/fuzztest/initializedebugger_fuzzer/BUILD.gn b/test/fuzztest/initializedebugger_fuzzer/BUILD.gn index cfde7f605c40dbf091696740bb7d5bb62095ef49..37fef3a1766aa6326852949d042c4c134b479e65 100644 --- a/test/fuzztest/initializedebugger_fuzzer/BUILD.gn +++ b/test/fuzztest/initializedebugger_fuzzer/BUILD.gn @@ -25,12 +25,15 @@ ohos_fuzztest("InitializeDebuggerFuzzTest") { fuzz_config_file = "//arkcompiler/toolchain/test/fuzztest/initializedebugger_fuzzer" + resource_config_file = + "//arkcompiler/toolchain/test/resource/tooling/ohos_test.xml" + sources = [ "initializedebugger_fuzzer.cpp" ] configs = [ "//arkcompiler/toolchain:toolchain_test_config" ] deps = [ - "//arkcompiler/ets_runtime:libark_jsruntime", + "//arkcompiler/ets_runtime:libark_jsruntime_test", "//arkcompiler/toolchain/tooling:libark_ecma_debugger_set", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", sdk_libc_secshared_dep, diff --git a/test/resource/tooling/ohos_test.xml b/test/resource/tooling/ohos_test.xml index 5a3cdfc9a13baa28328969603d32a5772cb527aa..d3dde0e816128ee6f0779fb818548ec46fb55501 100755 --- a/test/resource/tooling/ohos_test.xml +++ b/test/resource/tooling/ohos_test.xml @@ -35,4 +35,49 @@