diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 267f1edcdfae2e6d8b8df966de2df9d9e0b11d11..f3942ad43a2c18b6e8da069089414492932b3fa4 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 0000000000000000000000000000000000000000..c609e06ecdcc0f3694ce15732fe6eff59bfdc8e5 --- /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 0000000000000000000000000000000000000000..1728b2973d601cf0b4208206fa857e897868b54f --- /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 0000000000000000000000000000000000000000..3d35b90ad43aaadaedb3752776f9653f071337d8 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..33b823bd6c525305c2ed47da16d86d75eead4333 --- /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 0000000000000000000000000000000000000000..1896d1b0f0cb72cfa2e0e52e2f5a6d4d63a45cc6 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..c7fc1a3cb50992520b02cb83b4ad99960216f7a3 --- /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 0000000000000000000000000000000000000000..fbe1e3c766621345a913942505ac61c8bdd773a7 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..23dc1c71291e8e32e581a6fe9dd75dcac8d68791 --- /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 0000000000000000000000000000000000000000..54ceadd0f6692a49c8ca2f30258cf06eecd9edd4 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..323a77e276b41a4228e14d46e9cc5e6b4289b7ee --- /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 0000000000000000000000000000000000000000..e05a1b6e4eeebf219971a08b1ac029e7433c3ec1 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..019dd38a6ff6d812fa29268f4e12b46492276afa --- /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 0000000000000000000000000000000000000000..44a5437dade705c34856986578d935e3e8c8c5e9 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..7afade9b815670d12d804940fe87dd6b24a044c8 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..a57895aa528934a7d466c937564f01f2f23ae5df --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..4d456e8a0b2733484637fd32ccb49a1594d44404 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..787aa5f924d6df7bace3164479dd80b2121294d9 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..08e9c7a8e4cfcb61cde1ab35eea1925251823527 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6725fe7e1196b69ff8aa146dd5da8874b439b420 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..f5273cde45915741f49939e71c137b59dfe0e250 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..f87096bd48d1fd5bae280b35761833ebd195f747 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..b49cc4ec975612550281af65a0ab84e9bfa0e776 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..d8fe0e50a1a4f832457e6c1aaf5a7bf73e8335e4 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..88cd1ae553c03a8da1a7984ef132fe3c97af68e6 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..a8ab055498fee0701279e2886b27c688685c06f2 --- /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 0000000000000000000000000000000000000000..6c3c462c567d1e257743a7ae1895dbab39bf4c0e --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..5fc1675b196d66a8f6245f3782390f3b4cba492a --- /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 0000000000000000000000000000000000000000..981da105b3d43a366245c67ef31f57c9d964a323 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..35600058767c532a9779a4e7e8e5d994064826bc --- /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 0000000000000000000000000000000000000000..93a7875aa1ce71935c0e73a53a2b0f85f59c0005 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..6697c5c93cfd69c7e3153c521d6d4101967109df --- /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 0000000000000000000000000000000000000000..64fd1c4c730ee26b660ae00fe612e8beee2168cc --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..7b3577480260d9e1a0aa306e18e5f4720197b3de --- /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 0000000000000000000000000000000000000000..c12a1bbbac63a949e00f7792df8b9955094b7952 --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..8dfcd24af3c36b43a7f9eb3653e30064f4624fbd --- /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 0000000000000000000000000000000000000000..6a8459e72d23f312664f5400822fa2b5eb247ecd --- /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 0000000000000000000000000000000000000000..6703f24fa867db64080597bc962d22e0cc927766 --- /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 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /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 0000000000000000000000000000000000000000..8e7c735f4da1260225d09647744d7c5733d17798 --- /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; +}