From 9c8d0e2c979d0f005f8675481e772cabf46e9989 Mon Sep 17 00:00:00 2001 From: zhujie81 Date: Wed, 2 Nov 2022 17:06:52 +0800 Subject: [PATCH] Add tooling fuzzer test files complate cover to testcases https://gitee.com/openharmony/arkcompiler_toolchain/issues/I5Y56P Signed-off-by: zhujie81 --- test/fuzztest/BUILD.gn | 2 + test/fuzztest/agent/BUILD.gn | 19 ++++++ test/fuzztest/agent/heapprofiler/BUILD.gn | 33 ++++++++++ .../BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ ...pprofileraddinspectedheapobject_fuzzer.cpp | 62 ++++++++++++++++++ ...eapprofileraddinspectedheapobject_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ .../heapprofilercollectgarbage_fuzzer.cpp | 62 ++++++++++++++++++ .../heapprofilercollectgarbage_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../heapprofilerdisable_fuzzer/BUILD.gn | 43 ++++++++++++ .../heapprofilerdisable_fuzzer/corpus/init | 14 ++++ .../heapprofilerdisable_fuzzer.cpp | 62 ++++++++++++++++++ .../heapprofilerdisable_fuzzer.h | 21 ++++++ .../heapprofilerdisable_fuzzer/project.xml | 25 +++++++ .../heapprofilerdispatch_fuzzer/BUILD.gn | 43 ++++++++++++ .../heapprofilerdispatch_fuzzer/corpus/init | 14 ++++ .../heapprofilerdispatch_fuzzer.cpp | 62 ++++++++++++++++++ .../heapprofilerdispatch_fuzzer.h | 21 ++++++ .../heapprofilerdispatch_fuzzer/project.xml | 25 +++++++ .../heapprofilerenable_fuzzer/BUILD.gn | 43 ++++++++++++ .../heapprofilerenable_fuzzer/corpus/init | 14 ++++ .../heapprofilerenable_fuzzer.cpp | 62 ++++++++++++++++++ .../heapprofilerenable_fuzzer.h | 21 ++++++ .../heapprofilerenable_fuzzer/project.xml | 25 +++++++ .../BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ .../heapprofilergetheapobjectid_fuzzer.cpp | 62 ++++++++++++++++++ .../heapprofilergetheapobjectid_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ ...profilergetobjectbyheapobjectid_fuzzer.cpp | 62 ++++++++++++++++++ ...approfilergetobjectbyheapobjectid_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ .../heapprofilergetsamplingprofile_fuzzer.cpp | 62 ++++++++++++++++++ .../heapprofilergetsamplingprofile_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../heapprofilerstartsampling_fuzzer/BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ .../heapprofilerstartsampling_fuzzer.cpp | 62 ++++++++++++++++++ .../heapprofilerstartsampling_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ ...rofilerstarttrackingheapobjects_fuzzer.cpp | 61 +++++++++++++++++ ...pprofilerstarttrackingheapobjects_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../heapprofilerstopsampling_fuzzer/BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ .../heapprofilerstopsampling_fuzzer.cpp | 62 ++++++++++++++++++ .../heapprofilerstopsampling_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ ...profilerstoptrackingheapobjects_fuzzer.cpp | 60 +++++++++++++++++ ...approfilerstoptrackingheapobjects_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 43 ++++++++++++ .../corpus/init | 14 ++++ .../heapprofilertakeheapsnapshot_fuzzer.cpp | 60 +++++++++++++++++ .../heapprofilertakeheapsnapshot_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ test/fuzztest/backend/BUILD.gn | 25 +++++++ .../backend/backendbreakpoint_fuzzer/BUILD.gn | 44 +++++++++++++ .../backendbreakpoint_fuzzer.cpp | 65 +++++++++++++++++++ .../backendbreakpoint_fuzzer.h | 21 ++++++ .../backendbreakpoint_fuzzer/corpus/init | 14 ++++ .../backendbreakpoint_fuzzer/project.xml | 25 +++++++ .../backend/backendexception_fuzzer/BUILD.gn | 44 +++++++++++++ .../backendexception_fuzzer.cpp | 65 +++++++++++++++++++ .../backendexception_fuzzer.h | 21 ++++++ .../backendexception_fuzzer/corpus/init | 14 ++++ .../backendexception_fuzzer/project.xml | 25 +++++++ .../backend/backendloadmodule_fuzzer/BUILD.gn | 44 +++++++++++++ .../backendloadmodule_fuzzer.cpp | 65 +++++++++++++++++++ .../backendloadmodule_fuzzer.h | 21 ++++++ .../backendloadmodule_fuzzer/corpus/init | 14 ++++ .../backendloadmodule_fuzzer/project.xml | 25 +++++++ .../backendnativecalling_fuzzer/BUILD.gn | 43 ++++++++++++ .../backendnativecalling_fuzzer.cpp | 65 +++++++++++++++++++ .../backendnativecalling_fuzzer.h | 21 ++++++ .../backendnativecalling_fuzzer/corpus/init | 14 ++++ .../backendnativecalling_fuzzer/project.xml | 25 +++++++ .../backendpendingjobentry_fuzzer/BUILD.gn | 43 ++++++++++++ .../backendpendingjobentry_fuzzer.cpp | 65 +++++++++++++++++++ .../backendpendingjobentry_fuzzer.h | 21 ++++++ .../backendpendingjobentry_fuzzer/corpus/init | 14 ++++ .../backendpendingjobentry_fuzzer/project.xml | 25 +++++++ .../backend/backendsinglestep_fuzzer/BUILD.gn | 44 +++++++++++++ .../backendsinglestep_fuzzer.cpp | 65 +++++++++++++++++++ .../backendsinglestep_fuzzer.h | 21 ++++++ .../backendsinglestep_fuzzer/corpus/init | 14 ++++ .../backendsinglestep_fuzzer/project.xml | 25 +++++++ .../dispatchprotocolmessage_fuzzer/BUILD.gn | 2 +- .../initializedebugger_fuzzer/BUILD.gn | 5 +- test/resource/tooling/ohos_test.xml | 45 +++++++++++++ 102 files changed, 3281 insertions(+), 2 deletions(-) create mode 100644 test/fuzztest/agent/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/heapprofileraddinspectedheapobject_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/heapprofileraddinspectedheapobject_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofileraddinspectedheapobject_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/heapprofilercollectgarbage_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/heapprofilercollectgarbage_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilercollectgarbage_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/heapprofilerdisable_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/heapprofilerdisable_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdisable_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/heapprofilerdispatch_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/heapprofilerdispatch_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerdispatch_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/heapprofilerenable_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/heapprofilerenable_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerenable_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/heapprofilergetheapobjectid_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/heapprofilergetheapobjectid_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetheapobjectid_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/heapprofilergetobjectbyheapobjectid_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/heapprofilergetobjectbyheapobjectid_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetobjectbyheapobjectid_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/heapprofilergetsamplingprofile_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/heapprofilergetsamplingprofile_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilergetsamplingprofile_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/heapprofilerstartsampling_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/heapprofilerstartsampling_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstartsampling_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/heapprofilerstarttrackingheapobjects_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/heapprofilerstarttrackingheapobjects_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstarttrackingheapobjects_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/heapprofilerstopsampling_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/heapprofilerstopsampling_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstopsampling_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/heapprofilerstoptrackingheapobjects_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/heapprofilerstoptrackingheapobjects_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilerstoptrackingheapobjects_fuzzer/project.xml create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/BUILD.gn create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/corpus/init create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/heapprofilertakeheapsnapshot_fuzzer.cpp create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/heapprofilertakeheapsnapshot_fuzzer.h create mode 100644 test/fuzztest/agent/heapprofiler/heapprofilertakeheapsnapshot_fuzzer/project.xml create mode 100644 test/fuzztest/backend/BUILD.gn create mode 100644 test/fuzztest/backend/backendbreakpoint_fuzzer/BUILD.gn create mode 100644 test/fuzztest/backend/backendbreakpoint_fuzzer/backendbreakpoint_fuzzer.cpp create mode 100644 test/fuzztest/backend/backendbreakpoint_fuzzer/backendbreakpoint_fuzzer.h create mode 100644 test/fuzztest/backend/backendbreakpoint_fuzzer/corpus/init create mode 100644 test/fuzztest/backend/backendbreakpoint_fuzzer/project.xml create mode 100644 test/fuzztest/backend/backendexception_fuzzer/BUILD.gn create mode 100644 test/fuzztest/backend/backendexception_fuzzer/backendexception_fuzzer.cpp create mode 100644 test/fuzztest/backend/backendexception_fuzzer/backendexception_fuzzer.h create mode 100644 test/fuzztest/backend/backendexception_fuzzer/corpus/init create mode 100644 test/fuzztest/backend/backendexception_fuzzer/project.xml create mode 100644 test/fuzztest/backend/backendloadmodule_fuzzer/BUILD.gn create mode 100644 test/fuzztest/backend/backendloadmodule_fuzzer/backendloadmodule_fuzzer.cpp create mode 100644 test/fuzztest/backend/backendloadmodule_fuzzer/backendloadmodule_fuzzer.h create mode 100644 test/fuzztest/backend/backendloadmodule_fuzzer/corpus/init create mode 100644 test/fuzztest/backend/backendloadmodule_fuzzer/project.xml create mode 100644 test/fuzztest/backend/backendnativecalling_fuzzer/BUILD.gn create mode 100644 test/fuzztest/backend/backendnativecalling_fuzzer/backendnativecalling_fuzzer.cpp create mode 100644 test/fuzztest/backend/backendnativecalling_fuzzer/backendnativecalling_fuzzer.h create mode 100644 test/fuzztest/backend/backendnativecalling_fuzzer/corpus/init create mode 100644 test/fuzztest/backend/backendnativecalling_fuzzer/project.xml create mode 100644 test/fuzztest/backend/backendpendingjobentry_fuzzer/BUILD.gn create mode 100644 test/fuzztest/backend/backendpendingjobentry_fuzzer/backendpendingjobentry_fuzzer.cpp create mode 100644 test/fuzztest/backend/backendpendingjobentry_fuzzer/backendpendingjobentry_fuzzer.h create mode 100644 test/fuzztest/backend/backendpendingjobentry_fuzzer/corpus/init create mode 100644 test/fuzztest/backend/backendpendingjobentry_fuzzer/project.xml create mode 100644 test/fuzztest/backend/backendsinglestep_fuzzer/BUILD.gn create mode 100644 test/fuzztest/backend/backendsinglestep_fuzzer/backendsinglestep_fuzzer.cpp create mode 100644 test/fuzztest/backend/backendsinglestep_fuzzer/backendsinglestep_fuzzer.h create mode 100644 test/fuzztest/backend/backendsinglestep_fuzzer/corpus/init create mode 100644 test/fuzztest/backend/backendsinglestep_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 0746cd73..eff7f600 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 00000000..6fe2f226 --- /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 00000000..1eb373cb --- /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 00000000..d237d4c2 --- /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 00000000..b9a20c8e --- /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 00000000..2c789996 --- /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 00000000..4a56bcc5 --- /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 00000000..6e8ad2cf --- /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 00000000..d1cee2d5 --- /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 00000000..b9a20c8e --- /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 00000000..dc0ff0ab --- /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 00000000..9754e8c6 --- /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 00000000..6e8ad2cf --- /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 00000000..e4c62337 --- /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 00000000..b9a20c8e --- /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 00000000..27d9d1aa --- /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 00000000..9b3d11fb --- /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 00000000..6e8ad2cf --- /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 00000000..e2a34239 --- /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 00000000..b9a20c8e --- /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 00000000..756f9742 --- /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 00000000..d4b93ceb --- /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 00000000..6e8ad2cf --- /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 00000000..e5d29c37 --- /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 00000000..b9a20c8e --- /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 00000000..4269a138 --- /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 00000000..9b3d11fb --- /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 00000000..6e8ad2cf --- /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 00000000..da8c1199 --- /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 00000000..b9a20c8e --- /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 00000000..7371d4b7 --- /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 00000000..9b3d11fb --- /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 00000000..6e8ad2cf --- /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 00000000..78642c1e --- /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 00000000..b9a20c8e --- /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 00000000..7974fb93 --- /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 00000000..9b3d11fb --- /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 00000000..6e8ad2cf --- /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 00000000..13f2c273 --- /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 00000000..b9a20c8e --- /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 00000000..abdbce23 --- /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 00000000..67c5fa5c --- /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 00000000..6e8ad2cf --- /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 00000000..4eedb87c --- /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 00000000..b9a20c8e --- /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 00000000..8e381ed5 --- /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 00000000..580dd828 --- /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 00000000..6e8ad2cf --- /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 00000000..4359c992 --- /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 00000000..b9a20c8e --- /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 00000000..8e5a3f7e --- /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 00000000..9b3d11fb --- /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 00000000..6e8ad2cf --- /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 00000000..33e093e9 --- /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 00000000..b9a20c8e --- /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 00000000..bd8c0dcf --- /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 00000000..a61b6a6e --- /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 00000000..6e8ad2cf --- /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 00000000..d27c874d --- /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 00000000..b9a20c8e --- /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 00000000..bbc26ce9 --- /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 00000000..8d4e0c08 --- /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 00000000..6e8ad2cf --- /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 00000000..c5c7f98e --- /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 00000000..b9a20c8e --- /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 00000000..98f86bab --- /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 00000000..eae11e95 --- /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 00000000..6e8ad2cf --- /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 00000000..1fbdf150 --- /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 00000000..3e1c6717 --- /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 00000000..6ff2e1b4 --- /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 00000000..d4b93ceb --- /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 00000000..b9a20c8e --- /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 00000000..6e8ad2cf --- /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 00000000..e1f2f77f --- /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 00000000..49835a58 --- /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 00000000..053160a2 --- /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 00000000..b9a20c8e --- /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 00000000..6e8ad2cf --- /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 00000000..75c4a4e7 --- /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 00000000..5bc72832 --- /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 00000000..9a57c64d --- /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 00000000..b9a20c8e --- /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 00000000..6e8ad2cf --- /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 00000000..702769cc --- /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 00000000..90690fb1 --- /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 00000000..2e98f255 --- /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 00000000..b9a20c8e --- /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 00000000..6e8ad2cf --- /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 00000000..2ce400d3 --- /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 00000000..425faa50 --- /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 00000000..ff0db60e --- /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 00000000..b9a20c8e --- /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 00000000..6e8ad2cf --- /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 00000000..4e2cea9b --- /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 00000000..bcbc49e5 --- /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 00000000..bbab87f1 --- /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 00000000..b9a20c8e --- /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 00000000..6e8ad2cf --- /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 a1a6254e..ea946d96 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 cfde7f60..37fef3a1 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 5a3cdfc9..d3dde0e8 100755 --- a/test/resource/tooling/ohos_test.xml +++ b/test/resource/tooling/ohos_test.xml @@ -35,4 +35,49 @@