diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index e95c3307f024e86b4d38c3d69a2ba3c7da2b21a7..267f1edcdfae2e6d8b8df966de2df9d9e0b11d11 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -18,5 +18,6 @@ group("fuzztest") { deps += [ "accesstokenid:fuzztest", "hc_node:fuzztest", + "sched:fuzztest", ] } diff --git a/test/fuzztest/sched/BUILD.gn b/test/fuzztest/sched/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..04c5e262704a1fae3d5a43f9dffe2aae1ff39763 --- /dev/null +++ b/test/fuzztest/sched/BUILD.gn @@ -0,0 +1,27 @@ +# 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 += [ + "addthreadstortg_fuzzer:AddThreadsToRtgFuzzTest", + "addthreadtortg_fuzzer:AddThreadToRtgFuzzTest", + "beginframefreq_fuzzer:BeginFrameFreqFuzzTest", + "endframefreq_fuzzer:EndFrameFreqFuzzTest", + "endscene_fuzzer:EndSceneFuzzTest", + "searchrtgfortid_fuzzer:SearchRtgForTidFuzzTest", + "setmargin_fuzzer:SetMarginFuzzTest", + ] +} diff --git a/test/fuzztest/sched/addthreadstortg_fuzzer/BUILD.gn b/test/fuzztest/sched/addthreadstortg_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bec28e3abefa88ae2d5d51a6ddb344869d9f97ab --- /dev/null +++ b/test/fuzztest/sched/addthreadstortg_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/sched" + +ohos_fuzztest("AddThreadsToRtgFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/sched/addthreadstortg_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/rtg_interface.cpp", + "addthreadstortg_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AddThreadsToRtgFuzzTest" ] +} diff --git a/test/fuzztest/sched/addthreadstortg_fuzzer/addthreadstortg_fuzzer.cpp b/test/fuzztest/sched/addthreadstortg_fuzzer/addthreadstortg_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb8d7004d9c1c4ad2c3503937cac23ecc3498ef3 --- /dev/null +++ b/test/fuzztest/sched/addthreadstortg_fuzzer/addthreadstortg_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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 "rtg_interface.h" + +using namespace std; +using namespace OHOS::Kernel::Sched; +namespace OHOS { +bool AddThreadsToRtgFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + return ret; + } else { + uint8_t *countData = const_cast(data); + int tid = *(reinterpret_cast(countData)); + if (tid <= 0) { + return ret; + } + vector tids = {}; + tids.push_back(tid); + int grpId = 2; + ret = AddThreadsToRtg(tids, grpId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AddThreadsToRtgFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/sched/addthreadstortg_fuzzer/corpus/init b/test/fuzztest/sched/addthreadstortg_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/sched/addthreadstortg_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/sched/addthreadstortg_fuzzer/project.xml b/test/fuzztest/sched/addthreadstortg_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/sched/addthreadstortg_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/sched/addthreadtortg_fuzzer/BUILD.gn b/test/fuzztest/sched/addthreadtortg_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7b896d9a66a251f3f233d0c90b34affa4f7c7fb5 --- /dev/null +++ b/test/fuzztest/sched/addthreadtortg_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/sched" + +ohos_fuzztest("AddThreadToRtgFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/sched/addthreadtortg_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/rtg_interface.cpp", + "addthreadtortg_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AddThreadToRtgFuzzTest" ] +} diff --git a/test/fuzztest/sched/addthreadtortg_fuzzer/addthreadtortg_fuzzer.cpp b/test/fuzztest/sched/addthreadtortg_fuzzer/addthreadtortg_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..73b49ebc85dd2794a84a4f9d6b89a3628fd283a0 --- /dev/null +++ b/test/fuzztest/sched/addthreadtortg_fuzzer/addthreadtortg_fuzzer.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "rtg_interface.h" + +using namespace std; +using namespace OHOS::Kernel::Sched; +namespace OHOS { +bool AddThreadToRtgFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + return ret; + } else { + uint8_t *countData = const_cast(data); + int tid = *(reinterpret_cast(countData)); + if (tid <= 0) { + return ret; + } + int grpId = 2; + ret = AddThreadToRtg(tid, grpId); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AddThreadToRtgFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/sched/addthreadtortg_fuzzer/corpus/init b/test/fuzztest/sched/addthreadtortg_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/sched/addthreadtortg_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/sched/addthreadtortg_fuzzer/project.xml b/test/fuzztest/sched/addthreadtortg_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/sched/addthreadtortg_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/sched/beginframefreq_fuzzer/BUILD.gn b/test/fuzztest/sched/beginframefreq_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ff3f831fe57d4f533a0c341d270b079e54bb79d7 --- /dev/null +++ b/test/fuzztest/sched/beginframefreq_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/sched" + +ohos_fuzztest("BeginFrameFreqFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/sched/beginframefreq_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/rtg_interface.cpp", + "beginframefreq_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":BeginFrameFreqFuzzTest" ] +} diff --git a/test/fuzztest/sched/beginframefreq_fuzzer/beginframefreq_fuzzer.cpp b/test/fuzztest/sched/beginframefreq_fuzzer/beginframefreq_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..61e0bddcba8f19fb457263e0ca4db42e3aa2c0f3 --- /dev/null +++ b/test/fuzztest/sched/beginframefreq_fuzzer/beginframefreq_fuzzer.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "rtg_interface.h" + +using namespace std; +using namespace OHOS::Kernel::Sched; +namespace OHOS { +bool BeginFrameFreqFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + return ret; + } else { + uint8_t *countData = const_cast(data); + int margin = *(reinterpret_cast(countData)); + if (margin < MARGIN_LOWER_LIMIT_TIME || margin > MARGIN_UPPER_LIMIT_TIME) { + return ret; + } + int grpId = 2; + ret = BeginFrameFreq(grpId, margin); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::BeginFrameFreqFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/sched/beginframefreq_fuzzer/corpus/init b/test/fuzztest/sched/beginframefreq_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/sched/beginframefreq_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/sched/beginframefreq_fuzzer/project.xml b/test/fuzztest/sched/beginframefreq_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/sched/beginframefreq_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/sched/endframefreq_fuzzer/BUILD.gn b/test/fuzztest/sched/endframefreq_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ff5135ba15d566f3101938bef2078ba7a7b6b49d --- /dev/null +++ b/test/fuzztest/sched/endframefreq_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/sched" + +ohos_fuzztest("EndFrameFreqFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/sched/endframefreq_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/rtg_interface.cpp", + "endframefreq_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":EndFrameFreqFuzzTest" ] +} diff --git a/test/fuzztest/sched/endframefreq_fuzzer/corpus/init b/test/fuzztest/sched/endframefreq_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/sched/endframefreq_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/sched/endframefreq_fuzzer/endframefreq_fuzzer.cpp b/test/fuzztest/sched/endframefreq_fuzzer/endframefreq_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c05c9cd7af03e6d4423f7f1255d2fb539fac6d4 --- /dev/null +++ b/test/fuzztest/sched/endframefreq_fuzzer/endframefreq_fuzzer.cpp @@ -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. + */ + +#include +#include "rtg_interface.h" + +using namespace std; +using namespace OHOS::Kernel::Sched; +namespace OHOS { +bool EndFrameFreqFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + return ret; + } + int grpId = 2; + ret = EndFrameFreq(grpId); + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::EndFrameFreqFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/sched/endframefreq_fuzzer/project.xml b/test/fuzztest/sched/endframefreq_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/sched/endframefreq_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/sched/endscene_fuzzer/BUILD.gn b/test/fuzztest/sched/endscene_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..88a0198a0e162b9062d7dc067bf65f8f52d01e6c --- /dev/null +++ b/test/fuzztest/sched/endscene_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/sched" + +ohos_fuzztest("EndSceneFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/sched/endscene_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/rtg_interface.cpp", + "endscene_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":EndSceneFuzzTest" ] +} diff --git a/test/fuzztest/sched/endscene_fuzzer/corpus/init b/test/fuzztest/sched/endscene_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/sched/endscene_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/sched/endscene_fuzzer/endscene_fuzzer.cpp b/test/fuzztest/sched/endscene_fuzzer/endscene_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..859778e6247ca03c89f327589fed4293659fcb46 --- /dev/null +++ b/test/fuzztest/sched/endscene_fuzzer/endscene_fuzzer.cpp @@ -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. + */ + +#include +#include "rtg_interface.h" + +using namespace std; +using namespace OHOS::Kernel::Sched; +namespace OHOS { +bool EndSceneFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + return ret; + } + int grpId = 2; + ret = EndScene(grpId); + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::EndSceneFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/sched/endscene_fuzzer/project.xml b/test/fuzztest/sched/endscene_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/sched/endscene_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/sched/include/hilog/log.h b/test/fuzztest/sched/include/hilog/log.h new file mode 100644 index 0000000000000000000000000000000000000000..0530a318e0a960bc05d136df4f6d5f61369656bc --- /dev/null +++ b/test/fuzztest/sched/include/hilog/log.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HIVIEWDFX_HILOG_H +#define HIVIEWDFX_HILOG_H + +#include "hilog/log_c.h" +#include "hilog/log_cpp.h" + +#endif // HIVIEWDFX_HILOG_H \ No newline at end of file diff --git a/test/fuzztest/sched/include/hilog/log_c.h b/test/fuzztest/sched/include/hilog/log_c.h new file mode 100644 index 0000000000000000000000000000000000000000..38351387eefe11d2bd7c8ed383fda3af60632b49 --- /dev/null +++ b/test/fuzztest/sched/include/hilog/log_c.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef HIVIEWDFX_HILOG_C_H +#define HIVIEWDFX_HILOG_C_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef LOG_DOMAIN +#define LOG_DOMAIN 0 +#endif + +#ifndef LOG_TAG +#define LOG_TAG NULL +#endif + +typedef enum { + LOG_TYPE_MIN = 0, + LOG_INIT = 1, + LOG_CORE = 3, + LOG_TYPE_MAX +} LogType; + +typedef enum { + LOG_LEVEL_MIN = 0, + LOG_DEBUG = 3, + LOG_INFO = 4, + LOG_WARN = 5, + LOG_ERROR = 6, + LOG_FATAL = 7, + LOG_LEVEL_MAX, +} LogLevel; + +int HiLogPrint(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) + __attribute__((__format__(os_log, 5, 6))); + +#define HILOG_DEBUG(type, ...) ((void)HiLogPrint((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +#define HILOG_INFO(type, ...) ((void)HiLogPrint((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +#define HILOG_WARN(type, ...) ((void)HiLogPrint((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +#define HILOG_ERROR(type, ...) ((void)HiLogPrint((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +#define HILOG_FATAL(type, ...) ((void)HiLogPrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__)) + +bool HiLogIsLoggable(unsigned int domain, const char *tag, LogLevel level); + +#ifdef __cplusplus +} +#endif +#endif // HIVIEWDFX_HILOG_C_H diff --git a/test/fuzztest/sched/include/hilog/log_cpp.h b/test/fuzztest/sched/include/hilog/log_cpp.h new file mode 100644 index 0000000000000000000000000000000000000000..c25ece1fe7c054f09e78a423a6863eea06867bbb --- /dev/null +++ b/test/fuzztest/sched/include/hilog/log_cpp.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef HIVIEWDFX_HILOG_CPP_H +#define HIVIEWDFX_HILOG_CPP_H + +#include "hilog/log_c.h" + +#ifdef __cplusplus + +namespace OHOS { +namespace Kernel { +namespace Sched { +typedef struct HiLogLabel { + LogType type; + unsigned int domain; + const char *tag; +} HiLogLabel; + +class LogCpp { +public: + static int Debug(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); + static int Info(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); + static int Warn(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); + static int Error(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); + static int Fatal(const HiLogLabel &label, const char *fmt, ...) __attribute__((__format__(os_log, 2, 3))); +}; + +int LogCpp::Debug(const HiLogLabel &label, const char *fmt, ...) +{ + return 0; +} + +int LogCpp::Info(const HiLogLabel &label, const char *fmt, ...) +{ + return 0; +} + +int LogCpp::Warn(const HiLogLabel &label, const char *fmt, ...) +{ + std::cout << label.tag << ": " << fmt << std::endl; + return 0; +} + +int LogCpp::Error(const HiLogLabel &label, const char *fmt, ...) +{ + std::cout << label.tag << ": " << fmt << std::endl; + return 0; +} + +int LogCpp::Fatal(const HiLogLabel &label, const char *fmt, ...) +{ + std::cout << label.tag << ": " << fmt << std::endl; + return 0; +} +} // namespace Sched +} // namespace Kernel +} // namespace OHOS +#endif // __cplusplus +#endif // HIVIEWDFX_HILOG_CPP_H diff --git a/test/fuzztest/sched/include/rme_log_domain.h b/test/fuzztest/sched/include/rme_log_domain.h new file mode 100644 index 0000000000000000000000000000000000000000..cda2fc411b17809bf780594f4f32b7dad53c08ae --- /dev/null +++ b/test/fuzztest/sched/include/rme_log_domain.h @@ -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. + */ + +#ifndef RME_LOG_DOMAIN_H +#define RME_LOG_DOMAIN_H + +#include +#include "hilog/log.h" + +namespace OHOS { +namespace Kernel { +namespace Sched { +constexpr uint32_t COMMON = 0xD006600; +constexpr uint32_t RME_SERVICE = 0xD006601; +constexpr uint32_t RME_TEST = 0xD006602; +constexpr uint32_t RME_INTELLISENSE = 0xD006604; + +#define RME_LOGF(...) (void)LogCpp::Fatal(RME_LOG_LABEL, ##__VA_ARGS__) +#define RME_LOGE(...) (void)LogCpp::Error(RME_LOG_LABEL, ##__VA_ARGS__) +#define RME_LOGW(...) (void)LogCpp::Warn(RME_LOG_LABEL, ##__VA_ARGS__) +#define RME_LOGI(...) (void)LogCpp::Info(RME_LOG_LABEL, ##__VA_ARGS__) +#define RME_LOGD(...) (void)LogCpp::Debug(RME_LOG_LABEL, ##__VA_ARGS__) +} // namespace Sched +} // namespace Kernel +} // namespace OHOS +#endif // RME_LOG_DOMAIN_H diff --git a/test/fuzztest/sched/include/rtg_interface.h b/test/fuzztest/sched/include/rtg_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..8377f9749ec2f4d5b8e8fab89aa9bf39582abe58 --- /dev/null +++ b/test/fuzztest/sched/include/rtg_interface.h @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_FRAME_AWARE_SCHED_COMMON_INCLUDE_RTG_INTERFACE_H +#define OHOS_FRAME_AWARE_SCHED_COMMON_INCLUDE_RTG_INTERFACE_H + +#include +#include + +namespace OHOS { +namespace Kernel { +namespace Sched { +using namespace std; + +constexpr size_t MAX_LENGTH = 100; +constexpr size_t MAX_STR_LEN = 100; + +constexpr int MARGIN_UPPER_LIMIT_TIME = 32000; +constexpr int MARGIN_LOWER_LIMIT_TIME = -32000; + +const char RTG_SCHED_IPC_MAGIC = 0xAB; + +#define CMD_ID_SET_RTG \ + _IOWR(RTG_SCHED_IPC_MAGIC, SET_RTG, struct rtg_str_data) +#define CMD_ID_BEGIN_FRAME_FREQ \ + _IOWR(RTG_SCHED_IPC_MAGIC, BEGIN_FRAME_FREQ, struct proc_state_data) +#define CMD_ID_END_FRAME_FREQ \ + _IOWR(RTG_SCHED_IPC_MAGIC, END_FRAME_FREQ, struct proc_state_data) +#define CMD_ID_END_SCENE \ + _IOWR(RTG_SCHED_IPC_MAGIC, END_SCENE, struct proc_state_data) +#define CMD_ID_SET_MARGIN \ + _IOWR(RTG_SCHED_IPC_MAGIC, SET_MARGIN, struct proc_state_data) +#define CMD_ID_SEARCH_RTG \ + _IOWR(RTG_SCHED_IPC_MAGIC, SEARCH_RTG, struct proc_state_data) + +#define MAX_TID_NUM 5 +#define MAX_SUBPROCESS_NUM 8 +#define MULTI_FRAME_NUM 5 + +enum rtg_type : int { + VIP = 0, + TOP_TASK_KEY, + NORMAL_TASK, + RTG_TYPE_MAX, +}; + +struct rtg_enable_data { + int enable; + int len; + char *data; +}; + +struct rtg_str_data { + int type; + int len; + char *data; +}; + +struct proc_state_data { + int grp_id; + int state_param; +}; + +enum grp_ctrl_cmd { + CMD_CREATE_RTG_GRP, + CMD_ADD_RTG_THREAD, + CMD_REMOVE_RTG_THREAD, + CMD_CLEAR_RTG_GRP, + CMD_DESTROY_RTG_GRP, +}; + +struct rtg_grp_data { + int rtg_cmd; + int grp_id; + int prio_type; + int rt_cnt; + int tid_num; + int tids[MAX_TID_NUM]; +}; + +struct rtg_info { + int rtg_num; + int rtgs[MULTI_FRAME_NUM]; +}; + +enum rtg_sched_cmdid { + SET_ENABLE = 1, + SET_RTG, + SET_CONFIG, + SET_RTG_ATTR, + BEGIN_FRAME_FREQ = 5, + END_FRAME_FREQ, + END_SCENE, + SET_MIN_UTIL, + SET_MARGIN, + LIST_RTG, + LIST_RTG_THREAD, + SEARCH_RTG, + GET_ENABLE, + RTG_CTRL_MAX_NR, +}; + +extern "C" { + int AddThreadToRtg(int tid, int grpId, int prioType = 0); + int AddThreadsToRtg(vector tids, int grpId, int prioType = 0); + int BeginFrameFreq(int grpId, int stateParam); + int EndFrameFreq(int grpId); + int EndScene(int grpId); + int SetMargin(int grpId, int stateParam); + int SearchRtgForTid(int stateParam); +} +} // namespace Sched +} // namespace Kernel +} // namespace OHOS +#endif // OHOS_FRAME_AWARE_SCHED_COMMON_INCLUDE_RTG_INTERFACE_H \ No newline at end of file diff --git a/test/fuzztest/sched/searchrtgfortid_fuzzer/BUILD.gn b/test/fuzztest/sched/searchrtgfortid_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8a1352e274921fd7ab46d5ca56b41f3a7d258d44 --- /dev/null +++ b/test/fuzztest/sched/searchrtgfortid_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/sched" + +ohos_fuzztest("SearchRtgForTidFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "//kernel/linux/build/test/fuzztest/sched/searchrtgfortid_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/rtg_interface.cpp", + "searchrtgfortid_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SearchRtgForTidFuzzTest" ] +} diff --git a/test/fuzztest/sched/searchrtgfortid_fuzzer/corpus/init b/test/fuzztest/sched/searchrtgfortid_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/sched/searchrtgfortid_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/sched/searchrtgfortid_fuzzer/project.xml b/test/fuzztest/sched/searchrtgfortid_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/sched/searchrtgfortid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/sched/searchrtgfortid_fuzzer/searchrtgfortid_fuzzer.cpp b/test/fuzztest/sched/searchrtgfortid_fuzzer/searchrtgfortid_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3289a332bfd9c86e213d9c75b4a24bfa57c29771 --- /dev/null +++ b/test/fuzztest/sched/searchrtgfortid_fuzzer/searchrtgfortid_fuzzer.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "rtg_interface.h" + +using namespace std; +using namespace OHOS::Kernel::Sched; +namespace OHOS { +bool SearchRtgForTidFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + return ret; + } else { + uint8_t *countData = const_cast(data); + int tid = *(reinterpret_cast(countData)); + if (tid <= 0) { + return ret; + } + ret = SearchRtgForTid(tid); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SearchRtgForTidFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/sched/setmargin_fuzzer/BUILD.gn b/test/fuzztest/sched/setmargin_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7ef3aac57148263a2d3fc19fb3075864dc418c10 --- /dev/null +++ b/test/fuzztest/sched/setmargin_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/features.gni") +import("//build/test.gni") + +module_output_path = "linuxkerneltest/sched" + +ohos_fuzztest("SetMarginFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/sched/setmargin_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/rtg_interface.cpp", + "setmargin_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetMarginFuzzTest" ] +} diff --git a/test/fuzztest/sched/setmargin_fuzzer/corpus/init b/test/fuzztest/sched/setmargin_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/sched/setmargin_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/sched/setmargin_fuzzer/project.xml b/test/fuzztest/sched/setmargin_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/sched/setmargin_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/sched/setmargin_fuzzer/setmargin_fuzzer.cpp b/test/fuzztest/sched/setmargin_fuzzer/setmargin_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c8d43e45528e4eab2742a016b8e6750283d9b202 --- /dev/null +++ b/test/fuzztest/sched/setmargin_fuzzer/setmargin_fuzzer.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "rtg_interface.h" + +using namespace std; +using namespace OHOS::Kernel::Sched; +namespace OHOS { +bool SetMarginFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + return ret; + } else { + uint8_t *countData = const_cast(data); + int margin = *(reinterpret_cast(countData)); + if (margin < MARGIN_LOWER_LIMIT_TIME || margin > MARGIN_UPPER_LIMIT_TIME) { + return ret; + } + int grpId = 2; + ret = SetMargin(grpId, margin); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetMarginFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/sched/src/rtg_interface.cpp b/test/fuzztest/sched/src/rtg_interface.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f32c472e9f043ab0b15689e683f0d3a8c68fd66 --- /dev/null +++ b/test/fuzztest/sched/src/rtg_interface.cpp @@ -0,0 +1,184 @@ +/* + * 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 "rtg_interface.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rme_log_domain.h" +using namespace OHOS::Kernel::Sched; +namespace OHOS { +namespace Kernel { +namespace Sched { +static constexpr HiLogLabel RME_LOG_LABEL = {LOG_CORE, RME_INTELLISENSE, "rtg_interface"}; + +int BasicOpenRtgNode() +{ + char fileName[] = "/dev/sched_rtg_ctrl"; + int fd = open(fileName, O_RDWR); + if (fd < 0) { + RME_LOGE("Open fail, errno = %d (%s), dev = %s", errno, strerror(errno), fileName); + } + return fd; +} + +int AddThreadToRtg(int tid, int grpId, int prioType) +{ + struct rtg_grp_data grp_data = {0}; + int ret = 0; + int fd = BasicOpenRtgNode(); + if (fd < 0) { + RME_LOGE("open node failed."); + return fd; + } + grp_data.tid_num = 1; + grp_data.tids[0] = tid; + grp_data.grp_id = grpId; + grp_data.rtg_cmd = CMD_ADD_RTG_THREAD; + grp_data.prio_type = prioType; + ret = ioctl(fd, CMD_ID_SET_RTG, &grp_data); + close(fd); + return ret; +} + +int AddThreadsToRtg(vector tids, int grpId, int prioType) +{ + struct rtg_grp_data grp_data = {0}; + int ret = 0; + int fd = BasicOpenRtgNode(); + if (fd < 0) { + return fd; + } + int num = tids.size(); + if (num > MAX_TID_NUM) { + return -1; + } + grp_data.tid_num = num; + grp_data.grp_id = grpId; + grp_data.rtg_cmd = CMD_ADD_RTG_THREAD; + grp_data.prio_type = prioType; + for (int i = 0; i < num; i++) { + if (tids[i] < 0) { + return -1; + } + grp_data.tids[i] = tids[i]; + } + + ret = ioctl(fd, CMD_ID_SET_RTG, &grp_data); + close(fd); + return ret; +}; + +int BeginFrameFreq(int grpId, int stateParam) +{ + int ret = 0; + struct proc_state_data state_data; + state_data.grp_id = grpId; + state_data.state_param = stateParam; + + int fd = BasicOpenRtgNode(); + if (fd < 0) { + return fd; + } + ret = ioctl(fd, CMD_ID_BEGIN_FRAME_FREQ, &state_data); + close(fd); + return ret; +} + +int EndFrameFreq(int grpId) +{ + int ret = 0; + struct proc_state_data state_data; + state_data.grp_id = grpId; + state_data.state_param = 0; + + int fd = BasicOpenRtgNode(); + if (fd < 0) { + return fd; + } + ret = ioctl(fd, CMD_ID_END_FRAME_FREQ, &state_data); + close(fd); + return ret; +} + +int EndScene(int grpId) +{ + int ret = 0; + struct proc_state_data state_data; + state_data.grp_id = grpId; + + int fd = BasicOpenRtgNode(); + if (fd < 0) { + return fd; + } + ret = ioctl(fd, CMD_ID_END_SCENE, &state_data); + if (ret < 0) { + RME_LOGE("set EndScene failed, errno = %d (%s)", errno, strerror(errno)); + } else { + RME_LOGI("set EndScene success, get ret %d.", ret); + } + close(fd); + + return ret; +} + +int SetMargin(int grpId, int stateParam) +{ + int ret = 0; + struct proc_state_data state_data; + state_data.grp_id = grpId; + state_data.state_param = stateParam; + + int fd = BasicOpenRtgNode(); + if (fd < 0) { + return fd; + } + ret = ioctl(fd, CMD_ID_SET_MARGIN, &state_data); + close(fd); + return ret; +} + +int SearchRtgForTid(int tid) +{ + int ret = 0; + struct proc_state_data search_data = {0}; + int fd = BasicOpenRtgNode(); + if (fd < 0) { + return fd; + } + if (tid <= 0) { + RME_LOGI("Search tid err: invalid tid."); + return -1; + } + search_data.state_param = tid; + ret = ioctl(fd, CMD_ID_SEARCH_RTG, &search_data); + if (ret < 0) { + RME_LOGE("Search tid fail, errno = %d (%s)", errno, strerror(errno)); + } else { + RME_LOGI("Search tid %d success with rtg_grp %d", tid, ret); + } + close(fd); + return ret; +} +} // namespace Sched +} // namespace Kernel +} // namespace OHOS diff --git a/test/moduletest/runtest/bin/enhancedswap_t/testcases/bin/enhancedswap04.sh b/test/moduletest/runtest/bin/enhancedswap_t/testcases/bin/enhancedswap04.sh index b207bfa7296092632dacbc6118624f5c692564e5..408200863013473ad3430b60aa76af60340da779 100644 --- a/test/moduletest/runtest/bin/enhancedswap_t/testcases/bin/enhancedswap04.sh +++ b/test/moduletest/runtest/bin/enhancedswap_t/testcases/bin/enhancedswap04.sh @@ -36,7 +36,7 @@ do_test() local ret=0 local memcg_100_stat=/dev/memcg/100/memory.stat local memcg_stat=/dev/memcg/memory.stat - local avail_buffers=/dev/memcg/memory.avail_buffers + avail_buffers=/dev/memcg/memory.avail_buffers local zswapd_s=/dev/memcg/memory.zswapd_pressure_show tst_res TINFO "Start anon to zram test" @@ -48,6 +48,12 @@ do_test() # get buffer_size buffer_size=$(cat $zswapd_s | grep 'buffer_size' | awk -F ':' '{print$2}') + # get init avail_buffers values + avail_buffers_def=$(cat $avail_buffers | awk '$1=="avail_buffers:"{print $2}') + min_avail_buffers_def=$(cat $avail_buffers | awk '$1=="min_avail_buffers:"{print $2}') + high_avail_buffers_def=$(cat $avail_buffers | awk '$1=="high_avail_buffers:"{print $2}') + free_swap_threshold_def=$(cat $avail_buffers | awk '$1=="free_swap_threshold:"{print $2}') + # set avail_buffers > buffer_size to swap out to zram echo 0 $(( $buffer_size + 50 )) $(( $buffer_size + 100 )) 0 > $avail_buffers @@ -77,7 +83,8 @@ do_test() do_clean() { - + # set avail_buffers_def > buffer_size + echo $avail_buffers_def $min_avail_buffers_def $high_avail_buffers_def $free_swap_threshold_def > $avail_buffers } do_setup