From c11350e5c84e3fcced84374ad6bfcd5d858f98da Mon Sep 17 00:00:00 2001 From: 13359001024 Date: Thu, 30 Jun 2022 14:38:18 +0800 Subject: [PATCH] add memory dufuzz testcases. Signed-off-by: 13359001024 --- test/fuzztest/BUILD.gn | 1 + test/fuzztest/memory/BUILD.gn | 38 ++++++++++++ .../BUILD.gn | 36 ++++++++++++ .../anonrefaultsnapshotmininterval_fuzzer.cpp | 58 +++++++++++++++++++ .../corpus/init | 13 +++++ .../project.xml | 25 ++++++++ test/fuzztest/memory/appscore_fuzzer/BUILD.gn | 36 ++++++++++++ .../appscore_fuzzer/appscore_fuzzer.cpp | 58 +++++++++++++++++++ .../memory/appscore_fuzzer/corpus/init | 13 +++++ .../memory/appscore_fuzzer/project.xml | 25 ++++++++ .../areaanonrefaultthreshold_fuzzer/BUILD.gn | 36 ++++++++++++ .../areaanonrefaultthreshold_fuzzer.cpp | 58 +++++++++++++++++++ .../corpus/init | 13 +++++ .../project.xml | 25 ++++++++ .../memory/availbuffers_fuzzer/BUILD.gn | 37 ++++++++++++ .../availbuffers_fuzzer.cpp | 58 +++++++++++++++++++ .../memory/availbuffers_fuzzer/corpus/init | 13 +++++ .../memory/availbuffers_fuzzer/project.xml | 25 ++++++++ .../memory/bufferratioparams_fuzzer/BUILD.gn | 37 ++++++++++++ .../bufferratioparams_fuzzer.cpp | 58 +++++++++++++++++++ .../bufferratioparams_fuzzer/corpus/init | 13 +++++ .../bufferratioparams_fuzzer/project.xml | 25 ++++++++ .../memory/compressratio_fuzzer/BUILD.gn | 37 ++++++++++++ .../compressratio_fuzzer.cpp | 58 +++++++++++++++++++ .../memory/compressratio_fuzzer/corpus/init | 13 +++++ .../memory/compressratio_fuzzer/project.xml | 25 ++++++++ .../emptyroundcheckthreshold_fuzzer/BUILD.gn | 36 ++++++++++++ .../corpus/init | 13 +++++ .../emptyroundcheckthreshold_fuzzer.cpp | 58 +++++++++++++++++++ .../project.xml | 25 ++++++++ .../emptyroundskipinterval_fuzzer/BUILD.gn | 37 ++++++++++++ .../emptyroundskipinterval_fuzzer/corpus/init | 13 +++++ .../emptyroundskipinterval_fuzzer.cpp | 58 +++++++++++++++++++ .../emptyroundskipinterval_fuzzer/project.xml | 25 ++++++++ .../memory/forceshrinkanon_fuzzer/BUILD.gn | 37 ++++++++++++ .../memory/forceshrinkanon_fuzzer/corpus/init | 13 +++++ .../forceshrinkanon_fuzzer.cpp | 50 ++++++++++++++++ .../memory/forceshrinkanon_fuzzer/project.xml | 25 ++++++++ .../memory/maxskipinterval_fuzzer/BUILD.gn | 37 ++++++++++++ .../memory/maxskipinterval_fuzzer/corpus/init | 13 +++++ .../maxskipinterval_fuzzer.cpp | 58 +++++++++++++++++++ .../memory/maxskipinterval_fuzzer/project.xml | 25 ++++++++ test/fuzztest/memory/name_fuzzer/BUILD.gn | 36 ++++++++++++ test/fuzztest/memory/name_fuzzer/corpus/init | 13 +++++ .../memory/name_fuzzer/name_fuzzer.cpp | 58 +++++++++++++++++++ test/fuzztest/memory/name_fuzzer/project.xml | 25 ++++++++ .../memory/ubufs2zramratio_fuzzer/BUILD.gn | 37 ++++++++++++ .../memory/ubufs2zramratio_fuzzer/corpus/init | 13 +++++ .../memory/ubufs2zramratio_fuzzer/project.xml | 25 ++++++++ .../ubufs2zramratio_fuzzer.cpp | 58 +++++++++++++++++++ .../zramcriticalthreshold_fuzzer/BUILD.gn | 37 ++++++++++++ .../zramcriticalthreshold_fuzzer/corpus/init | 13 +++++ .../zramcriticalthreshold_fuzzer/project.xml | 25 ++++++++ .../zramcriticalthreshold_fuzzer.cpp | 58 +++++++++++++++++++ .../memory/zramwmratio_fuzzer/BUILD.gn | 37 ++++++++++++ .../memory/zramwmratio_fuzzer/corpus/init | 13 +++++ .../memory/zramwmratio_fuzzer/project.xml | 25 ++++++++ .../zramwmratio_fuzzer/zramwmratio_fuzzer.cpp | 58 +++++++++++++++++++ .../zswapdmaxreclaimsize_fuzzer/BUILD.gn | 37 ++++++++++++ .../zswapdmaxreclaimsize_fuzzer/corpus/init | 13 +++++ .../zswapdmaxreclaimsize_fuzzer/project.xml | 25 ++++++++ .../zswapdmaxreclaimsize_fuzzer.cpp | 58 +++++++++++++++++++ .../memory/zswapdmemcgsparam_fuzzer/BUILD.gn | 37 ++++++++++++ .../zswapdmemcgsparam_fuzzer/corpus/init | 13 +++++ .../zswapdmemcgsparam_fuzzer/project.xml | 25 ++++++++ .../zswapdmemcgsparam_fuzzer.cpp | 58 +++++++++++++++++++ .../memory/zswapdpressureshow_fuzzer/BUILD.gn | 37 ++++++++++++ .../zswapdpressureshow_fuzzer/corpus/init | 13 +++++ .../zswapdpressureshow_fuzzer/project.xml | 25 ++++++++ .../zswapdpressureshow_fuzzer.cpp | 58 +++++++++++++++++++ .../zswapdsinglememcgparam_fuzzer/BUILD.gn | 37 ++++++++++++ .../zswapdsinglememcgparam_fuzzer/corpus/init | 13 +++++ .../zswapdsinglememcgparam_fuzzer/project.xml | 25 ++++++++ .../zswapdsinglememcgparam_fuzzer.cpp | 58 +++++++++++++++++++ 74 files changed, 2420 insertions(+) create mode 100644 test/fuzztest/memory/BUILD.gn create mode 100644 test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/anonrefaultsnapshotmininterval_fuzzer.cpp create mode 100644 test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/project.xml create mode 100644 test/fuzztest/memory/appscore_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/appscore_fuzzer/appscore_fuzzer.cpp create mode 100644 test/fuzztest/memory/appscore_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/appscore_fuzzer/project.xml create mode 100644 test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/areaanonrefaultthreshold_fuzzer.cpp create mode 100644 test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/project.xml create mode 100644 test/fuzztest/memory/availbuffers_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/availbuffers_fuzzer/availbuffers_fuzzer.cpp create mode 100644 test/fuzztest/memory/availbuffers_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/availbuffers_fuzzer/project.xml create mode 100644 test/fuzztest/memory/bufferratioparams_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/bufferratioparams_fuzzer/bufferratioparams_fuzzer.cpp create mode 100644 test/fuzztest/memory/bufferratioparams_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/bufferratioparams_fuzzer/project.xml create mode 100644 test/fuzztest/memory/compressratio_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/compressratio_fuzzer/compressratio_fuzzer.cpp create mode 100644 test/fuzztest/memory/compressratio_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/compressratio_fuzzer/project.xml create mode 100644 test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/emptyroundcheckthreshold_fuzzer.cpp create mode 100644 test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/project.xml create mode 100644 test/fuzztest/memory/emptyroundskipinterval_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/emptyroundskipinterval_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/emptyroundskipinterval_fuzzer/emptyroundskipinterval_fuzzer.cpp create mode 100644 test/fuzztest/memory/emptyroundskipinterval_fuzzer/project.xml create mode 100644 test/fuzztest/memory/forceshrinkanon_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/forceshrinkanon_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/forceshrinkanon_fuzzer/forceshrinkanon_fuzzer.cpp create mode 100644 test/fuzztest/memory/forceshrinkanon_fuzzer/project.xml create mode 100644 test/fuzztest/memory/maxskipinterval_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/maxskipinterval_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/maxskipinterval_fuzzer/maxskipinterval_fuzzer.cpp create mode 100644 test/fuzztest/memory/maxskipinterval_fuzzer/project.xml create mode 100644 test/fuzztest/memory/name_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/name_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/name_fuzzer/name_fuzzer.cpp create mode 100644 test/fuzztest/memory/name_fuzzer/project.xml create mode 100644 test/fuzztest/memory/ubufs2zramratio_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/ubufs2zramratio_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/ubufs2zramratio_fuzzer/project.xml create mode 100644 test/fuzztest/memory/ubufs2zramratio_fuzzer/ubufs2zramratio_fuzzer.cpp create mode 100644 test/fuzztest/memory/zramcriticalthreshold_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/zramcriticalthreshold_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/zramcriticalthreshold_fuzzer/project.xml create mode 100644 test/fuzztest/memory/zramcriticalthreshold_fuzzer/zramcriticalthreshold_fuzzer.cpp create mode 100644 test/fuzztest/memory/zramwmratio_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/zramwmratio_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/zramwmratio_fuzzer/project.xml create mode 100644 test/fuzztest/memory/zramwmratio_fuzzer/zramwmratio_fuzzer.cpp create mode 100644 test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/project.xml create mode 100644 test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/zswapdmaxreclaimsize_fuzzer.cpp create mode 100644 test/fuzztest/memory/zswapdmemcgsparam_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/zswapdmemcgsparam_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/zswapdmemcgsparam_fuzzer/project.xml create mode 100644 test/fuzztest/memory/zswapdmemcgsparam_fuzzer/zswapdmemcgsparam_fuzzer.cpp create mode 100644 test/fuzztest/memory/zswapdpressureshow_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/zswapdpressureshow_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/zswapdpressureshow_fuzzer/project.xml create mode 100644 test/fuzztest/memory/zswapdpressureshow_fuzzer/zswapdpressureshow_fuzzer.cpp create mode 100644 test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/BUILD.gn create mode 100644 test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/corpus/init create mode 100644 test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/project.xml create mode 100644 test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/zswapdsinglememcgparam_fuzzer.cpp diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 267f1ed..f3942ad 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,6 +18,7 @@ group("fuzztest") { deps += [ "accesstokenid:fuzztest", "hc_node:fuzztest", + "memory:fuzztest", "sched:fuzztest", ] } diff --git a/test/fuzztest/memory/BUILD.gn b/test/fuzztest/memory/BUILD.gn new file mode 100644 index 0000000..c609e06 --- /dev/null +++ b/test/fuzztest/memory/BUILD.gn @@ -0,0 +1,38 @@ +# 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 += [ + "anonrefaultsnapshotmininterval_fuzzer:AnonRefaultSnapshotMinIntervalFuzzTest", + "appscore_fuzzer:AppScoreFuzzTest", + "areaanonrefaultthreshold_fuzzer:AreaAnonRefaultThresholdFuzzTest", + "availbuffers_fuzzer:AvailBuffersFuzzTest", + "bufferratioparams_fuzzer:BufferRatioParamsFuzzTest", + "compressratio_fuzzer:CompressRatioFuzzTest", + "emptyroundcheckthreshold_fuzzer:EmptyRoundCheckThresholdFuzzTest", + "emptyroundskipinterval_fuzzer:EmptyRoundSkipIntervalFuzzTest", + "forceshrinkanon_fuzzer:ForceShrinkAnonFuzzTest", + "maxskipinterval_fuzzer:MaxSkipIntervalFuzzTest", + "name_fuzzer:NameFuzzTest", + "ubufs2zramratio_fuzzer:UbUfs2zramRatioFuzzTest", + "zramcriticalthreshold_fuzzer:ZramCriticalThresholdFuzzTest", + "zramwmratio_fuzzer:ZramWmRatioFuzzTest", + "zswapdmaxreclaimsize_fuzzer:ZswapdMaxReclaimSizeFuzzTest", + "zswapdmemcgsparam_fuzzer:ZswapdMemcgsparamFuzzTest", + "zswapdpressureshow_fuzzer:ZswapdPressureShowFuzzTest", + "zswapdsinglememcgparam_fuzzer:ZswapdSingleMemcgParamFuzzTest", + ] +} diff --git a/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/BUILD.gn b/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/BUILD.gn new file mode 100644 index 0000000..1728b29 --- /dev/null +++ b/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("AnonRefaultSnapshotMinIntervalFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "anonrefaultsnapshotmininterval_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AnonRefaultSnapshotMinIntervalFuzzTest" ] +} diff --git a/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/anonrefaultsnapshotmininterval_fuzzer.cpp b/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/anonrefaultsnapshotmininterval_fuzzer.cpp new file mode 100644 index 0000000..3d35b90 --- /dev/null +++ b/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/anonrefaultsnapshotmininterval_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *ANON_REFAULT_SNAPSHOT_MIN_INTERVAL = "/dev/memcg/memory.anon_refault_snapshot_min_interval"; + +namespace OHOS { +bool AnonRefaultSnapshotMinIntervalFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(ANON_REFAULT_SNAPSHOT_MIN_INTERVAL, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", ANON_REFAULT_SNAPSHOT_MIN_INTERVAL); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AnonRefaultSnapshotMinIntervalFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/corpus/init b/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/project.xml b/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/anonrefaultsnapshotmininterval_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/appscore_fuzzer/BUILD.gn b/test/fuzztest/memory/appscore_fuzzer/BUILD.gn new file mode 100644 index 0000000..33b823b --- /dev/null +++ b/test/fuzztest/memory/appscore_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("AppScoreFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/appscore_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "appscore_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AppScoreFuzzTest" ] +} diff --git a/test/fuzztest/memory/appscore_fuzzer/appscore_fuzzer.cpp b/test/fuzztest/memory/appscore_fuzzer/appscore_fuzzer.cpp new file mode 100644 index 0000000..1896d1b --- /dev/null +++ b/test/fuzztest/memory/appscore_fuzzer/appscore_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *APP_SCORE = "/dev/memcg/memory.app_score"; + +namespace OHOS { +bool AppScoreFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(APP_SCORE, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", APP_SCORE); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AppScoreFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/appscore_fuzzer/corpus/init b/test/fuzztest/memory/appscore_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/appscore_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/appscore_fuzzer/project.xml b/test/fuzztest/memory/appscore_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/appscore_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/BUILD.gn b/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/BUILD.gn new file mode 100644 index 0000000..c7fc1a3 --- /dev/null +++ b/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("AreaAnonRefaultThresholdFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "areaanonrefaultthreshold_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AreaAnonRefaultThresholdFuzzTest" ] +} diff --git a/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/areaanonrefaultthreshold_fuzzer.cpp b/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/areaanonrefaultthreshold_fuzzer.cpp new file mode 100644 index 0000000..fbe1e3c --- /dev/null +++ b/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/areaanonrefaultthreshold_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *AREA_ANON_REFAULT_THRESHOLD = "/dev/memcg/memory.area_anon_refault_threshold"; + +namespace OHOS { +bool AreaAnonRefaultThresholdFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(AREA_ANON_REFAULT_THRESHOLD, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", AREA_ANON_REFAULT_THRESHOLD); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AreaAnonRefaultThresholdFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/corpus/init b/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/project.xml b/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/areaanonrefaultthreshold_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/availbuffers_fuzzer/BUILD.gn b/test/fuzztest/memory/availbuffers_fuzzer/BUILD.gn new file mode 100644 index 0000000..23dc1c7 --- /dev/null +++ b/test/fuzztest/memory/availbuffers_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("AvailBuffersFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/availbuffers_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "availbuffers_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AvailBuffersFuzzTest" ] +} diff --git a/test/fuzztest/memory/availbuffers_fuzzer/availbuffers_fuzzer.cpp b/test/fuzztest/memory/availbuffers_fuzzer/availbuffers_fuzzer.cpp new file mode 100644 index 0000000..54ceadd --- /dev/null +++ b/test/fuzztest/memory/availbuffers_fuzzer/availbuffers_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *AVAIL_BUFFERS = "/dev/memcg/memory.avail_buffers"; + +namespace OHOS { +bool AvailBuffersFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(AVAIL_BUFFERS, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", AVAIL_BUFFERS); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AvailBuffersFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/availbuffers_fuzzer/corpus/init b/test/fuzztest/memory/availbuffers_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/availbuffers_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/availbuffers_fuzzer/project.xml b/test/fuzztest/memory/availbuffers_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/availbuffers_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/bufferratioparams_fuzzer/BUILD.gn b/test/fuzztest/memory/bufferratioparams_fuzzer/BUILD.gn new file mode 100644 index 0000000..323a77e --- /dev/null +++ b/test/fuzztest/memory/bufferratioparams_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("BufferRatioParamsFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/bufferratioparams_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bufferratioparams_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":BufferRatioParamsFuzzTest" ] +} diff --git a/test/fuzztest/memory/bufferratioparams_fuzzer/bufferratioparams_fuzzer.cpp b/test/fuzztest/memory/bufferratioparams_fuzzer/bufferratioparams_fuzzer.cpp new file mode 100644 index 0000000..e05a1b6 --- /dev/null +++ b/test/fuzztest/memory/bufferratioparams_fuzzer/bufferratioparams_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *BUFFER_RATIO_PARAMS = "/dev/memcg/memory.buffer_ratio_params"; + +namespace OHOS { +bool BufferRatioParamsFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(BUFFER_RATIO_PARAMS, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", BUFFER_RATIO_PARAMS); + close(fd); + return false; + } + + ret = write(fd, data, sizeof(uint8_t)); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::BufferRatioParamsFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/bufferratioparams_fuzzer/corpus/init b/test/fuzztest/memory/bufferratioparams_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/bufferratioparams_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/bufferratioparams_fuzzer/project.xml b/test/fuzztest/memory/bufferratioparams_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/bufferratioparams_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/compressratio_fuzzer/BUILD.gn b/test/fuzztest/memory/compressratio_fuzzer/BUILD.gn new file mode 100644 index 0000000..019dd38 --- /dev/null +++ b/test/fuzztest/memory/compressratio_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("CompressRatioFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/compressratio_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "compressratio_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":CompressRatioFuzzTest" ] +} diff --git a/test/fuzztest/memory/compressratio_fuzzer/compressratio_fuzzer.cpp b/test/fuzztest/memory/compressratio_fuzzer/compressratio_fuzzer.cpp new file mode 100644 index 0000000..44a5437 --- /dev/null +++ b/test/fuzztest/memory/compressratio_fuzzer/compressratio_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *COMPRESS_RATIO = "/dev/memcg/memory.compress_ratio"; + +namespace OHOS { +bool CompressRatioFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(COMPRESS_RATIO, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", COMPRESS_RATIO); + close(fd); + return false; + } + + ret = write(fd, data, sizeof(uint8_t)); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::CompressRatioFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/compressratio_fuzzer/corpus/init b/test/fuzztest/memory/compressratio_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/compressratio_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/compressratio_fuzzer/project.xml b/test/fuzztest/memory/compressratio_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/compressratio_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/BUILD.gn b/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/BUILD.gn new file mode 100644 index 0000000..7afade9 --- /dev/null +++ b/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("EmptyRoundCheckThresholdFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "emptyroundcheckthreshold_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":EmptyRoundCheckThresholdFuzzTest" ] +} diff --git a/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/corpus/init b/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/emptyroundcheckthreshold_fuzzer.cpp b/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/emptyroundcheckthreshold_fuzzer.cpp new file mode 100644 index 0000000..a57895a --- /dev/null +++ b/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/emptyroundcheckthreshold_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *EMPTY_ROUND_CHECK_THRESHOLD = "/dev/memcg/memory.empty_round_check_threshold"; + +namespace OHOS { +bool EmptyRoundCheckThresholdFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(EMPTY_ROUND_CHECK_THRESHOLD, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", EMPTY_ROUND_CHECK_THRESHOLD); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::EmptyRoundCheckThresholdFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/project.xml b/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/emptyroundcheckthreshold_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/emptyroundskipinterval_fuzzer/BUILD.gn b/test/fuzztest/memory/emptyroundskipinterval_fuzzer/BUILD.gn new file mode 100644 index 0000000..4d456e8 --- /dev/null +++ b/test/fuzztest/memory/emptyroundskipinterval_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("EmptyRoundSkipIntervalFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/emptyroundskipinterval_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "emptyroundskipinterval_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":EmptyRoundSkipIntervalFuzzTest" ] +} diff --git a/test/fuzztest/memory/emptyroundskipinterval_fuzzer/corpus/init b/test/fuzztest/memory/emptyroundskipinterval_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/emptyroundskipinterval_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/emptyroundskipinterval_fuzzer/emptyroundskipinterval_fuzzer.cpp b/test/fuzztest/memory/emptyroundskipinterval_fuzzer/emptyroundskipinterval_fuzzer.cpp new file mode 100644 index 0000000..787aa5f --- /dev/null +++ b/test/fuzztest/memory/emptyroundskipinterval_fuzzer/emptyroundskipinterval_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *EMPTY_ROUND_SKIP_INTERVAL = "/dev/memcg/memory.empty_round_skip_interval"; + +namespace OHOS { +bool EmptyRoundSkipIntervalFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(EMPTY_ROUND_SKIP_INTERVAL, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", EMPTY_ROUND_SKIP_INTERVAL); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::EmptyRoundSkipIntervalFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/emptyroundskipinterval_fuzzer/project.xml b/test/fuzztest/memory/emptyroundskipinterval_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/emptyroundskipinterval_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/forceshrinkanon_fuzzer/BUILD.gn b/test/fuzztest/memory/forceshrinkanon_fuzzer/BUILD.gn new file mode 100644 index 0000000..08e9c7a --- /dev/null +++ b/test/fuzztest/memory/forceshrinkanon_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("ForceShrinkAnonFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/forceshrinkanon_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "forceshrinkanon_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ForceShrinkAnonFuzzTest" ] +} diff --git a/test/fuzztest/memory/forceshrinkanon_fuzzer/corpus/init b/test/fuzztest/memory/forceshrinkanon_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/forceshrinkanon_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/forceshrinkanon_fuzzer/forceshrinkanon_fuzzer.cpp b/test/fuzztest/memory/forceshrinkanon_fuzzer/forceshrinkanon_fuzzer.cpp new file mode 100644 index 0000000..6725fe7 --- /dev/null +++ b/test/fuzztest/memory/forceshrinkanon_fuzzer/forceshrinkanon_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *FORCE_SHRINK_ANON = "/dev/memcg/memory.force_shrink_anon"; + +namespace OHOS { +bool ForceShrinkAnonFuzzer(const uint8_t *data, size_t size) +{ + int fd = open(FORCE_SHRINK_ANON, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = write(fd, data, size); + if (ret < 0) { + printf("%s write fail\n", FORCE_SHRINK_ANON); + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ForceShrinkAnonFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/forceshrinkanon_fuzzer/project.xml b/test/fuzztest/memory/forceshrinkanon_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/forceshrinkanon_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/maxskipinterval_fuzzer/BUILD.gn b/test/fuzztest/memory/maxskipinterval_fuzzer/BUILD.gn new file mode 100644 index 0000000..f5273cd --- /dev/null +++ b/test/fuzztest/memory/maxskipinterval_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("MaxSkipIntervalFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/maxskipinterval_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "maxskipinterval_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":MaxSkipIntervalFuzzTest" ] +} diff --git a/test/fuzztest/memory/maxskipinterval_fuzzer/corpus/init b/test/fuzztest/memory/maxskipinterval_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/maxskipinterval_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/maxskipinterval_fuzzer/maxskipinterval_fuzzer.cpp b/test/fuzztest/memory/maxskipinterval_fuzzer/maxskipinterval_fuzzer.cpp new file mode 100644 index 0000000..f87096b --- /dev/null +++ b/test/fuzztest/memory/maxskipinterval_fuzzer/maxskipinterval_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *MAX_SKIP_INTERVAL = "/dev/memcg/memory.max_skip_interval"; + +namespace OHOS { +bool MaxSkipIntervalFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(MAX_SKIP_INTERVAL, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", MAX_SKIP_INTERVAL); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::MaxSkipIntervalFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/maxskipinterval_fuzzer/project.xml b/test/fuzztest/memory/maxskipinterval_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/maxskipinterval_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/name_fuzzer/BUILD.gn b/test/fuzztest/memory/name_fuzzer/BUILD.gn new file mode 100644 index 0000000..b49cc4e --- /dev/null +++ b/test/fuzztest/memory/name_fuzzer/BUILD.gn @@ -0,0 +1,36 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("NameFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/memory/name_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "name_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":NameFuzzTest" ] +} diff --git a/test/fuzztest/memory/name_fuzzer/corpus/init b/test/fuzztest/memory/name_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/name_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/name_fuzzer/name_fuzzer.cpp b/test/fuzztest/memory/name_fuzzer/name_fuzzer.cpp new file mode 100644 index 0000000..d8fe0e5 --- /dev/null +++ b/test/fuzztest/memory/name_fuzzer/name_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *NAME = "/dev/memcg/memory.name"; + +namespace OHOS { +bool NameFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(NAME, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", NAME); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::NameFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/name_fuzzer/project.xml b/test/fuzztest/memory/name_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/name_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/ubufs2zramratio_fuzzer/BUILD.gn b/test/fuzztest/memory/ubufs2zramratio_fuzzer/BUILD.gn new file mode 100644 index 0000000..88cd1ae --- /dev/null +++ b/test/fuzztest/memory/ubufs2zramratio_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("UbUfs2zramRatioFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/ubufs2zramratio_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ubufs2zramratio_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":UbUfs2zramRatioFuzzTest" ] +} diff --git a/test/fuzztest/memory/ubufs2zramratio_fuzzer/corpus/init b/test/fuzztest/memory/ubufs2zramratio_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/ubufs2zramratio_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/ubufs2zramratio_fuzzer/project.xml b/test/fuzztest/memory/ubufs2zramratio_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/ubufs2zramratio_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/ubufs2zramratio_fuzzer/ubufs2zramratio_fuzzer.cpp b/test/fuzztest/memory/ubufs2zramratio_fuzzer/ubufs2zramratio_fuzzer.cpp new file mode 100644 index 0000000..a8ab055 --- /dev/null +++ b/test/fuzztest/memory/ubufs2zramratio_fuzzer/ubufs2zramratio_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *UB_UFS2ZRAM_RATIO = "/dev/memcg/memory.ub_ufs2zram_ratio"; + +namespace OHOS { +bool UbUfs2zramRatioFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(UB_UFS2ZRAM_RATIO, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", UB_UFS2ZRAM_RATIO); + close(fd); + return false; + } + + ret = write(fd, data, sizeof(uint8_t)); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UbUfs2zramRatioFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/zramcriticalthreshold_fuzzer/BUILD.gn b/test/fuzztest/memory/zramcriticalthreshold_fuzzer/BUILD.gn new file mode 100644 index 0000000..6c3c462 --- /dev/null +++ b/test/fuzztest/memory/zramcriticalthreshold_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("ZramCriticalThresholdFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/zramcriticalthreshold_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "zramcriticalthreshold_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ZramCriticalThresholdFuzzTest" ] +} diff --git a/test/fuzztest/memory/zramcriticalthreshold_fuzzer/corpus/init b/test/fuzztest/memory/zramcriticalthreshold_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/zramcriticalthreshold_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/zramcriticalthreshold_fuzzer/project.xml b/test/fuzztest/memory/zramcriticalthreshold_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/zramcriticalthreshold_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/zramcriticalthreshold_fuzzer/zramcriticalthreshold_fuzzer.cpp b/test/fuzztest/memory/zramcriticalthreshold_fuzzer/zramcriticalthreshold_fuzzer.cpp new file mode 100644 index 0000000..5fc1675 --- /dev/null +++ b/test/fuzztest/memory/zramcriticalthreshold_fuzzer/zramcriticalthreshold_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *ZRAM_CRITICAL_THRESHOLD = "/dev/memcg/memory.zram_critical_threshold"; + +namespace OHOS { +bool ZramCriticalThresholdFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(ZRAM_CRITICAL_THRESHOLD, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", ZRAM_CRITICAL_THRESHOLD); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ZramCriticalThresholdFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/zramwmratio_fuzzer/BUILD.gn b/test/fuzztest/memory/zramwmratio_fuzzer/BUILD.gn new file mode 100644 index 0000000..981da10 --- /dev/null +++ b/test/fuzztest/memory/zramwmratio_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("ZramWmRatioFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/zramwmratio_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "zramwmratio_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ZramWmRatioFuzzTest" ] +} diff --git a/test/fuzztest/memory/zramwmratio_fuzzer/corpus/init b/test/fuzztest/memory/zramwmratio_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/zramwmratio_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/zramwmratio_fuzzer/project.xml b/test/fuzztest/memory/zramwmratio_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/zramwmratio_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/zramwmratio_fuzzer/zramwmratio_fuzzer.cpp b/test/fuzztest/memory/zramwmratio_fuzzer/zramwmratio_fuzzer.cpp new file mode 100644 index 0000000..3560005 --- /dev/null +++ b/test/fuzztest/memory/zramwmratio_fuzzer/zramwmratio_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *ZRAM_WR_RATIO = "/dev/memcg/memory.zram_wm_ratio"; + +namespace OHOS { +bool ZramWmRatioFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(ZRAM_WR_RATIO, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", ZRAM_WR_RATIO); + close(fd); + return false; + } + + ret = write(fd, data, sizeof(uint8_t)); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ZramWmRatioFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/BUILD.gn b/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/BUILD.gn new file mode 100644 index 0000000..93a7875 --- /dev/null +++ b/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("ZswapdMaxReclaimSizeFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "zswapdmaxreclaimsize_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ZswapdMaxReclaimSizeFuzzTest" ] +} diff --git a/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/corpus/init b/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/project.xml b/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/zswapdmaxreclaimsize_fuzzer.cpp b/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/zswapdmaxreclaimsize_fuzzer.cpp new file mode 100644 index 0000000..6697c5c --- /dev/null +++ b/test/fuzztest/memory/zswapdmaxreclaimsize_fuzzer/zswapdmaxreclaimsize_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *ZSWAPD_MAX_RECLAIM_SIZE = "/dev/memcg/memory.zswapd_max_reclaim_size"; + +namespace OHOS { +bool ZswapdMaxReclaimSizeFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(ZSWAPD_MAX_RECLAIM_SIZE, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", ZSWAPD_MAX_RECLAIM_SIZE); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ZswapdMaxReclaimSizeFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/BUILD.gn b/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/BUILD.gn new file mode 100644 index 0000000..64fd1c4 --- /dev/null +++ b/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("ZswapdMemcgsparamFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/zswapdmemcgsparam_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "zswapdmemcgsparam_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ZswapdMemcgsparamFuzzTest" ] +} diff --git a/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/corpus/init b/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/project.xml b/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/zswapdmemcgsparam_fuzzer.cpp b/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/zswapdmemcgsparam_fuzzer.cpp new file mode 100644 index 0000000..7b35774 --- /dev/null +++ b/test/fuzztest/memory/zswapdmemcgsparam_fuzzer/zswapdmemcgsparam_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *ZSWAPD_MEMCGS_PARAM = "/dev/memcg/memory.zswapd_memcgs_param"; + +namespace OHOS { +bool ZswapdMemcgsParamFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(ZSWAPD_MEMCGS_PARAM, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", ZSWAPD_MEMCGS_PARAM); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ZswapdMemcgsParamFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/zswapdpressureshow_fuzzer/BUILD.gn b/test/fuzztest/memory/zswapdpressureshow_fuzzer/BUILD.gn new file mode 100644 index 0000000..c12a1bb --- /dev/null +++ b/test/fuzztest/memory/zswapdpressureshow_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("ZswapdPressureShowFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/zswapdpressureshow_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "zswapdpressureshow_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ZswapdPressureShowFuzzTest" ] +} diff --git a/test/fuzztest/memory/zswapdpressureshow_fuzzer/corpus/init b/test/fuzztest/memory/zswapdpressureshow_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/zswapdpressureshow_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/zswapdpressureshow_fuzzer/project.xml b/test/fuzztest/memory/zswapdpressureshow_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/zswapdpressureshow_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/zswapdpressureshow_fuzzer/zswapdpressureshow_fuzzer.cpp b/test/fuzztest/memory/zswapdpressureshow_fuzzer/zswapdpressureshow_fuzzer.cpp new file mode 100644 index 0000000..8dfcd24 --- /dev/null +++ b/test/fuzztest/memory/zswapdpressureshow_fuzzer/zswapdpressureshow_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *ZSWAPD_PRESSURE_SHOW = "/dev/memcg/memory.zswapd_pressure_show"; + +namespace OHOS { +bool ZswapdPressureShowFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(ZSWAPD_PRESSURE_SHOW, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", ZSWAPD_PRESSURE_SHOW); + close(fd); + return false; + } + + ret = write(fd, data, sizeof(uint8_t)); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ZswapdPressureShowFuzzer(data, size); + return 0; +} diff --git a/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/BUILD.gn b/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/BUILD.gn new file mode 100644 index 0000000..6a8459e --- /dev/null +++ b/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/BUILD.gn @@ -0,0 +1,37 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/memory" + +ohos_fuzztest("ZswapdSingleMemcgParamFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "zswapdsinglememcgparam_fuzzer.cpp" ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":ZswapdSingleMemcgParamFuzzTest" ] +} diff --git a/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/corpus/init b/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/corpus/init new file mode 100644 index 0000000..6703f24 --- /dev/null +++ b/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/project.xml b/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/project.xml new file mode 100644 index 0000000..6e8ad2c --- /dev/null +++ b/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/zswapdsinglememcgparam_fuzzer.cpp b/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/zswapdsinglememcgparam_fuzzer.cpp new file mode 100644 index 0000000..8e7c735 --- /dev/null +++ b/test/fuzztest/memory/zswapdsinglememcgparam_fuzzer/zswapdsinglememcgparam_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +const char *ZSWAPD_SINGLE_MEMCG_PARAM = "/dev/memcg/memory.zswapd_single_memcg_param"; + +namespace OHOS { +bool ZswapdSingleMemcgParamFuzzer(const uint8_t *data, size_t size) +{ + uint32_t value = 0; + + int fd = open(ZSWAPD_SINGLE_MEMCG_PARAM, O_RDWR); + if (fd < 0) { + return false; + } + + int ret = read(fd, &value, sizeof(value)); + if (ret < 0) { + printf("%s read fail\n", ZSWAPD_SINGLE_MEMCG_PARAM); + close(fd); + return false; + } + + ret = write(fd, data, size); + if (ret < 0) { + close(fd); + return false; + } + + close(fd); + return true; +} +} // namespace OHOS + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::ZswapdSingleMemcgParamFuzzer(data, size); + return 0; +} -- Gitee