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/accesstokenid/BUILD.gn b/test/fuzztest/accesstokenid/BUILD.gn index aa82ac29138f2ed60a1239d1232a9eaa9bc69169..a637feb54660c7322d939c0afbed7500ed8be72e 100644 --- a/test/fuzztest/accesstokenid/BUILD.gn +++ b/test/fuzztest/accesstokenid/BUILD.gn @@ -16,13 +16,23 @@ group("fuzztest") { deps = [] deps += [ + "accessftokenidgrptest_fuzzer:AccessfTokenidGrpTestFuzzTest", + "accessftokenidgrptestother_fuzzer:AccessfTokenidGrpTestOtherFuzzTest", + "accessftokenidthreadtest_fuzzer:AccessfTokenidThreadTestFuzzTest", + "accesstokenidgrptest_fuzzer:AccessTokenidGrpTestFuzzTest", + "accesstokenidgrptestother_fuzzer:AccessTokenidGrpTestOtherFuzzTest", + "accesstokenidthreadtest_fuzzer:AccessTokenidThreadTestFuzzTest", "getftokenidcmdcorrect_fuzzer:GetfTokenidCmdCorrectFuzzTest", "getftokenidcmderror_fuzzer:GetfTokenidCmdErrorFuzzTest", + "getftokenidnullptr_fuzzer:GetfTokenidNullptrFuzzTest", "gettokenidcmdcorrect_fuzzer:GetTokenidCmdCorrectFuzzTest", "gettokenidcmderror_fuzzer:GetTokenidCmdErrorFuzzTest", + "gettokenidnullptr_fuzzer:GetTokenidNullptrFuzzTest", "setftokenidcmdcorrect_fuzzer:SetfTokenidCmdCorrectFuzzTest", "setftokenidcmderror_fuzzer:SetfTokenidCmdErrorFuzzTest", + "setftokenidnullptr_fuzzer:SetfTokenidNullptrFuzzTest", "settokenidcmdcorrect_fuzzer:SetTokenidCmdCorrectFuzzTest", "settokenidcmderror_fuzzer:SetTokenidCmdErrorFuzzTest", + "settokenidnullptr_fuzzer:SetTokenidNullptrFuzzTest", ] } diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..25f6b34d81c1927d31763313f2c85b67c23ff139 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_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/accesstokenid" + +ohos_fuzztest("AccessfTokenidGrpTestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "accessftokenidgrptest_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessfTokenidGrpTestFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c535b276f673a73131c438ea23a555b3ad9c7101 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/accessftokenidgrptest_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool AccessfTokenidGrpTestFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + uint8_t *data_ftoken = const_cast(data); + ret = AccessfTokenidGrpTest(data_ftoken); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessfTokenidGrpTestFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_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/accesstokenid/accessftokenidgrptest_fuzzer/project.xml b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d902d27f417973e42fb0de63fcbba0f6935de5db --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_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/accesstokenid" + +ohos_fuzztest("AccessfTokenidGrpTestOtherFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "accessftokenidgrptestother_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessfTokenidGrpTestOtherFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..399d77f49cbe2bf363a29dcd0d263dca7a206537 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/accessftokenidgrptestother_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool AccessfTokenidGrpTestOtherFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + uint8_t *data_ftoken = const_cast(data); + ret = AccessfTokenidGrpTestOther(data_ftoken); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessfTokenidGrpTestOtherFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_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/accesstokenid/accessftokenidgrptestother_fuzzer/project.xml b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidgrptestother_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3bdbd2bbb40092340d484da3c7d6a22b3fc20c11 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_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/accesstokenid" + +ohos_fuzztest("AccessfTokenidThreadTestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "accessftokenidthreadtest_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessfTokenidThreadTestFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..42129808f82758415c5ffa9c8ea2598935b30ae3 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/accessftokenidthreadtest_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool AccessfTokenidThreadTestFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + uint8_t *data_ftoken = const_cast(data); + ret = AccessfTokenidThreadTest(data_ftoken); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessfTokenidThreadTestFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_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/accesstokenid/accessftokenidthreadtest_fuzzer/project.xml b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/accessftokenidthreadtest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c83fa86a5714f101f41e5d274c2723a8f6430592 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_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/accesstokenid" + +ohos_fuzztest("AccessTokenidGrpTestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "accesstokenidgrptest_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessTokenidGrpTestFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..af5b63685345d7d0c4710b08fef1619c9126aa1c --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/accesstokenidgrptest_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool AccessTokenidGrpTestFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + uint8_t *data_token = const_cast(data); + ret = AccessTokenidGrpTest(data_token); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessTokenidGrpTestFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_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/accesstokenid/accesstokenidgrptest_fuzzer/project.xml b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a7ffa34d55318a36c3a22d83f1843a6adc381059 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_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/accesstokenid" + +ohos_fuzztest("AccessTokenidGrpTestOtherFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "accesstokenidgrptestother_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessTokenidGrpTestOtherFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a4e57da17d3d51a68e837588583f6a8787f7a158 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/accesstokenidgrptestother_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool AccessTokenidGrpTestOtherFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + uint8_t *data_token = const_cast(data); + ret = AccessTokenidGrpTestOther(data_token); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessTokenidGrpTestOtherFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_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/accesstokenid/accesstokenidgrptestother_fuzzer/project.xml b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidgrptestother_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b643bcff5bbeb32309fe4657dd27eb5eefcebdd3 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_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/accesstokenid" + +ohos_fuzztest("AccessTokenidThreadTestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-pthread", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "accesstokenidthreadtest_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":AccessTokenidThreadTestFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5215747069b19cdb0e76324df45db7f2572a293e --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/accesstokenidthreadtest_fuzzer.cpp @@ -0,0 +1,39 @@ +/* + * 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 "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool AccessTokenidThreadTestFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if ((data == nullptr) || (size < sizeof(unsigned long long))) { + return ret; + } else { + uint8_t *data_token = const_cast(data); + ret = AccessTokenidThreadTest(data_token); + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::AccessTokenidThreadTestFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/corpus/init b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_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/accesstokenid/accesstokenidthreadtest_fuzzer/project.xml b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/accesstokenidthreadtest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn index b9bbbf22c880cb2b72ef7e490e5380e5e796e505..dd833e2068a3286420d1f26f7a8c8193b5325c0f 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("GetfTokenidCmdCorrectFuzzTest") { ] sources = [ - "../src/accesstokenidcmdcorrect.cpp", + "../src/accessftokenidcommon.cpp", "getftokenidcmdcorrect_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp index fd0d5d7b609767cabf34c9b2d4266dcaa0d54173..1173bb9352a3a98c6b0d14b8ae7b24f1bcc6d030 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmdcorrect_fuzzer/getftokenidcmdcorrect_fuzzer.cpp @@ -14,11 +14,10 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "getftokenidcmdcorrect_fuzzer.h" +#include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn index fda5dce486cc0c21abc02b81afdbdad768e527db..66b1aab8178c3de7ab0ef03e7bc287ac00a9f719 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("GetfTokenidCmdErrorFuzzTest") { ] sources = [ - "../src/accesstokenidcmderror.cpp", + "../src/accessftokenidcommon.cpp", "getftokenidcmderror_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp index 235306a085b1123fbfde99e4bcbfea5d653f3b0c..0ffb6a996379b9cdb5d2c4dadd386f5e6ac5449d 100644 --- a/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/getftokenidcmderror_fuzzer/getftokenidcmderror_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include -#include "accesstokenidcmderror.h" -#include "getftokenidcmderror_fuzzer.h" +#define CMDERROR +#include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a7aa7278a55657d3651f13da66e2c3ac16bae9a8 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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/accesstokenid" + +ohos_fuzztest("GetfTokenidNullptrFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "getftokenidnullptr_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetfTokenidNullptrFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/corpus/init b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_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/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c098598c96f64f3811bc60a111979a9425b9ac6b --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/getftokenidnullptr_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * 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. + reinterpret_cast + static_cast + */ + +#include +#include "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool GetfTokenidNullptrFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = GetfTokenid(&tokenId); + } else { + return ret; + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetfTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/project.xml b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/getftokenidnullptr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn index 51af0fd3a886087149b502f87a218194b80eccb0..1e8be2f58612f95347dedcdccd6db8728efa9334 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("GetTokenidCmdCorrectFuzzTest") { ] sources = [ - "../src/accesstokenidcmdcorrect.cpp", + "../src/accesstokenidcommon.cpp", "gettokenidcmdcorrect_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp index 9bee2a94697f33c9c9c3380b302cbbb48fc5a8f3..40762c219ab01753b52fd948f3be228ac15151a3 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmdcorrect_fuzzer/gettokenidcmdcorrect_fuzzer.cpp @@ -16,11 +16,10 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "gettokenidcmdcorrect_fuzzer.h" +#include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn index 2131812419bbe780acfa9e41024a4bf6c2485506..d72acf87f2d142b5f0198ec16a2cc1715a00b99a 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("GetTokenidCmdErrorFuzzTest") { ] sources = [ - "../src/accesstokenidcmderror.cpp", + "../src/accesstokenidcommon.cpp", "gettokenidcmderror_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp index 02242b6aa06d41e3785affcf69a78dc351c980e7..46d305e8b425f7fea67f3e039097e1eee3b68ace 100644 --- a/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/gettokenidcmderror_fuzzer/gettokenidcmderror_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include -#include "accesstokenidcmderror.h" -#include "gettokenidcmderror_fuzzer.h" +#define CMDERROR +#include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool GetTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..912b3bc126c31f0da32383ffca5d4431e69c985b --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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/accesstokenid" + +ohos_fuzztest("GetTokenidNullptrFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "gettokenidnullptr_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":GetTokenidNullptrFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/corpus/init b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_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/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5be434efe3e662e364592d7f6f59f41af052354d --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/gettokenidnullptr_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * 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. + reinterpret_cast + static_cast + */ + +#include +#include "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool GetTokenidNullptrFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = GetTokenid(&tokenId); + } else { + return ret; + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::GetTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/project.xml b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/gettokenidnullptr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h similarity index 40% rename from test/fuzztest/accesstokenid/include/accesstokenidcmderror.h rename to test/fuzztest/accesstokenid/include/accessftokenidcommon.h index 0ce6f092984504ed5787955048c7658e31fa2cec..e0c3903814f6e5c8f8ac84ac8bca07d9c2629a5d 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmderror.h +++ b/test/fuzztest/accesstokenid/include/accessftokenidcommon.h @@ -12,33 +12,59 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H -#define TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H + +#ifndef ACCESSFTOKENIDCOMMON_H +#define ACCESSFTOKENIDCOMMON_H + +#define FUZZ_PROJECT_NAME "accessftokenidcommon" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { - constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; - constexpr unsigned int GET_TOKEN_ID = 0; - constexpr unsigned int SET_TOKEN_ID = 0; - constexpr unsigned int GET_FTOKEN_ID = 0; - constexpr unsigned int SET_FTOKEN_ID = 0; - -#define ACCESS_TOKENID_GET_TOKENID \ - _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) -#define ACCESS_TOKENID_SET_TOKENID \ - _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) +#define ACCESS_TOKEN_ID_IOCTL_BASE 'A' + +#ifdef CMDERROR +constexpr unsigned int GET_FTOKEN_ID = 0; +constexpr unsigned int SET_FTOKEN_ID = 0; +#else +constexpr unsigned int GET_FTOKEN_ID = 3; +constexpr unsigned int SET_FTOKEN_ID = 4; +#endif + #define ACCESS_TOKENID_GET_FTOKENID \ _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_FTOKEN_ID, unsigned long long) #define ACCESS_TOKENID_SET_FTOKENID \ _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_FTOKEN_ID, unsigned long long) - int GetTokenid(unsigned long long *token); - int SetTokenid(unsigned long long *token); - int GetfTokenid(unsigned long long *ftoken); - int SetfTokenid(unsigned long long *ftoken); +#define LIST_NUM_1 1 +#define LIST_NUM_2 2 +#define TEST_VALUE 123 +#define CHILDREN_NUM 3 +#define WAIT_FOR_SHELL_OP_TIME 1 +#define FATHER_WAIT_TIME (WAIT_FOR_SHELL_OP_TIME * (CHILDREN_NUM + 1)) + +#define ACCESS_TOKEN_UID 3020 +#define ACCESS_TOKEN_GRPID 3020 + +#define ACCESS_TOKEN_OTHER_UID 1234 +#define ACCESS_TOKEN_OTHER_GRPID 1234 + +#define INVAL_TOKEN 0xffffffffffffffff + +int GetfTokenid(unsigned long long *ftoken); +int SetfTokenid(unsigned long long *ftoken); + +void SetUidAndGrp(); +void SetUidAndGrpOther(); +void GetCurfToken(unsigned long long *ftoken); +void SetRandfTokenAndCheck(unsigned long long *data_ftoken); +void fTokenTest(unsigned long long *data_ftoken); +void ThreadTest(unsigned long long *data_ftoken); +int AccessfTokenidThreadTest(uint8_t *data_ftoken); +int AccessfTokenidGrpTest(uint8_t *data_ftoken); +int AccessfTokenidGrpTestOther(uint8_t *data_ftoken); } // namespace AccessToken -} // namespace Security +} // namespace Kernel } // namespace OHOS -#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDERROR_FUZZER_H +#endif // ACCESSTOKENIDCOMMON_H diff --git a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h similarity index 41% rename from test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h rename to test/fuzztest/accesstokenid/include/accesstokenidcommon.h index d626a76af4567a79525a1cd148d858c74092baf9..febe47573e273447a4db1992012e962dc20b96d3 100644 --- a/test/fuzztest/accesstokenid/include/accesstokenidcmdcorrect.h +++ b/test/fuzztest/accesstokenid/include/accesstokenidcommon.h @@ -12,33 +12,59 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef TEST_FUZZTEST_ACCESSTOKENIDCMDCORRECT_FUZZER_H -#define TEST_FUZZTEST_ACCESSTOKENIDCMDCORRECT_FUZZER_H + +#ifndef ACCESSTOKENIDCOMMON_H +#define ACCESSTOKENIDCOMMON_H + +#define FUZZ_PROJECT_NAME "accesstokenidcommon" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { - constexpr unsigned char ACCESS_TOKEN_ID_IOCTL_BASE = 'A'; - constexpr unsigned int GET_TOKEN_ID = 1; - constexpr unsigned int SET_TOKEN_ID = 2; - constexpr unsigned int GET_FTOKEN_ID = 3; - constexpr unsigned int SET_FTOKEN_ID = 4; +#define ACCESS_TOKEN_ID_IOCTL_BASE 'A' + +#ifdef CMDERROR +constexpr unsigned int GET_TOKEN_ID = 0; +constexpr unsigned int SET_TOKEN_ID = 0; +#else +constexpr unsigned int GET_TOKEN_ID = 1; +constexpr unsigned int SET_TOKEN_ID = 2; +#endif #define ACCESS_TOKENID_GET_TOKENID \ _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_TOKEN_ID, unsigned long long) #define ACCESS_TOKENID_SET_TOKENID \ _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_TOKEN_ID, unsigned long long) -#define ACCESS_TOKENID_GET_FTOKENID \ - _IOR(ACCESS_TOKEN_ID_IOCTL_BASE, GET_FTOKEN_ID, unsigned long long) -#define ACCESS_TOKENID_SET_FTOKENID \ - _IOW(ACCESS_TOKEN_ID_IOCTL_BASE, SET_FTOKEN_ID, unsigned long long) - - int GetTokenid(unsigned long long *token); - int SetTokenid(unsigned long long *token); - int GetfTokenid(unsigned long long *ftoken); - int SetfTokenid(unsigned long long *ftoken); + +#define LIST_NUM_1 1 +#define LIST_NUM_2 2 +#define TEST_VALUE 123 +#define CHILDREN_NUM 3 +#define WAIT_FOR_SHELL_OP_TIME 1 +#define FATHER_WAIT_TIME (WAIT_FOR_SHELL_OP_TIME * (CHILDREN_NUM + 1)) + +#define ACCESS_TOKEN_UID 3020 +#define ACCESS_TOKEN_GRPID 3020 + +#define ACCESS_TOKEN_OTHER_UID 1234 +#define ACCESS_TOKEN_OTHER_GRPID 1234 + +#define INVAL_TOKEN 0xffffffffffffffff + +int GetTokenid(unsigned long long *token); +int SetTokenid(unsigned long long *token); + +void SetUidAndGrp(); +void SetUidAndGrpOther(); +void GetCurToken(unsigned long long *token); +void SetRandTokenAndCheck(unsigned long long *data_token); +void TokenTest(unsigned long long *data_token); +void ThreadTest(unsigned long long *data_token); +int AccessTokenidThreadTest(uint8_t *data_token); +int AccessTokenidGrpTest(uint8_t *data_token); +int AccessTokenidGrpTestOther(uint8_t *data_token); } // namespace AccessToken -} // namespace Security +} // namespace Kernel } // namespace OHOS -#endif // TEST_FUZZTEST_ACCESSTOKENIDCMDCORRECT_FUZZER_H +#endif // ACCESSTOKENIDCOMMON_H diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn index 916f7dd7a8c75732815a022a7a65d794ce809426..bdabf6fa9cc37a6801b48d146972d4d2d402a90e 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("SetfTokenidCmdCorrectFuzzTest") { ] sources = [ - "../src/accesstokenidcmdcorrect.cpp", + "../src/accessftokenidcommon.cpp", "setftokenidcmdcorrect_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp index 4fea69011c050efa51f4c8b5bb3d96396cf50859..000316cb94c492fd14bd3f28d4ad6a4eec791df3 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmdcorrect_fuzzer/setftokenidcmdcorrect_fuzzer.cpp @@ -14,11 +14,10 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "setftokenidcmdcorrect_fuzzer.h" +#include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetfTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn index f15c87ef9755482871769502570e3823c707e8ef..00fb0ffc6e165a7435d002b6b42a249fbe6b2e60 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("SetfTokenidCmdErrorFuzzTest") { ] sources = [ - "../src/accesstokenidcmderror.cpp", + "../src/accessftokenidcommon.cpp", "setftokenidcmderror_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp index cce1d22623781e0a171fb18052e0b7f29d18d69c..9a2f08595bfa7f7e3631adc2caf37411d3e41e60 100644 --- a/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/setftokenidcmderror_fuzzer/setftokenidcmderror_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include -#include "accesstokenidcmderror.h" -#include "setftokenidcmderror_fuzzer.h" +#define CMDERROR +#include "accessftokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetfTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0847e822561b035a429bf7825a397478c8662c93 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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/accesstokenid" + +ohos_fuzztest("SetfTokenidNullptrFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accessftokenidcommon.cpp", + "setftokenidnullptr_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetfTokenidNullptrFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/corpus/init b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_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/accesstokenid/setftokenidnullptr_fuzzer/project.xml b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f79706f091622994daa87c5cb3c927df2ae88a9c --- /dev/null +++ b/test/fuzztest/accesstokenid/setftokenidnullptr_fuzzer/setftokenidnullptr_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * 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. + reinterpret_cast + static_cast + */ + +#include +#include "accessftokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool SetfTokenidNullptrFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = SetfTokenid(&tokenId); + } else { + return ret; + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetfTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn index f44747352a2f0d60041814d3b1a3ad5e41d58f92..0def8993e6dbb8ec81dd88b2fab223649facc454 100644 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/BUILD.gn @@ -29,7 +29,7 @@ ohos_fuzztest("SetTokenidCmdCorrectFuzzTest") { "-fno-omit-frame-pointer", ] sources = [ - "../src/accesstokenidcmdcorrect.cpp", + "../src/accesstokenidcommon.cpp", "settokenidcmdcorrect_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp index 602c55f41a692f0e5188f152e60f70e044739ee8..7183f678a1f862899d99c7c5ac411217b6267fc1 100644 --- a/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmdcorrect_fuzzer/settokenidcmdcorrect_fuzzer.cpp @@ -16,11 +16,10 @@ */ #include -#include "accesstokenidcmdcorrect.h" -#include "settokenidcmdcorrect_fuzzer.h" +#include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetTokenidCmdCorrectFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn index 126f61fb147caa7a4f9be4efa8cd46870c12e897..037811e6c3e406eada1d9cbc06b647dc490c0fcf 100644 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/BUILD.gn @@ -30,7 +30,7 @@ ohos_fuzztest("SetTokenidCmdErrorFuzzTest") { ] sources = [ - "../src/accesstokenidcmderror.cpp", + "../src/accesstokenidcommon.cpp", "settokenidcmderror_fuzzer.cpp", ] } diff --git a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp index fcb9cfa51ea012ca568ee8db2d1dae282256c81f..37851e069437b857a1c7dbf629b6adab8e8f5002 100644 --- a/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp +++ b/test/fuzztest/accesstokenid/settokenidcmderror_fuzzer/settokenidcmderror_fuzzer.cpp @@ -14,11 +14,11 @@ */ #include -#include "accesstokenidcmderror.h" -#include "settokenidcmderror_fuzzer.h" +#define CMDERROR +#include "accesstokenidcommon.h" using namespace std; -using namespace OHOS::Security::AccessToken; +using namespace OHOS::Kernel::AccessToken; namespace OHOS { bool SetTokenidCmdErrorFuzzTest(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/BUILD.gn b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3b78e95cd07fb79f8c5e3084f7ebcb60030eac67 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/BUILD.gn @@ -0,0 +1,42 @@ +# 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/accesstokenid" + +ohos_fuzztest("SetTokenidNullptrFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "//kernel/linux/build/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer" + + include_dirs = [ "../include" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "../src/accesstokenidcommon.cpp", + "settokenidnullptr_fuzzer.cpp", + ] +} + +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":SetTokenidNullptrFuzzTest" ] +} diff --git a/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/corpus/init b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..58ee85e5da3dcf11bcb8e41f5bd5312014a16989 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidnullptr_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/accesstokenid/settokenidnullptr_fuzzer/project.xml b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..715454c97a7f05d5db7c2afaf7e9c978afb70878 --- /dev/null +++ b/test/fuzztest/accesstokenid/settokenidnullptr_fuzzer/settokenidnullptr_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * 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. + reinterpret_cast + static_cast + */ + +#include +#include "accesstokenidcommon.h" + +using namespace std; +using namespace OHOS::Kernel::AccessToken; +namespace OHOS { +bool SetTokenidNullptrFuzzTest(const uint8_t *data, size_t size) +{ + bool ret = false; + if (data == nullptr) { + unsigned long long tokenId = *(reinterpret_cast(data)); + ret = SetTokenid(&tokenId); + } else { + return ret; + } + return ret; +} +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::SetTokenidNullptrFuzzTest(data, size); + return 0; +} diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp similarity index 34% rename from test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp rename to test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp index f840f90b96b9df575b94f0cccfcfe6637c5962b1..6fa504faad6fa345b43a814d1989b6f63c258a94 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmderror.cpp +++ b/test/fuzztest/accesstokenid/src/accessftokenidcommon.cpp @@ -15,33 +15,29 @@ #include #include -#include -#include #include -#include -#include -#include #include +#include #include -#include +#include #include #include -#include -#include "accesstokenidcmderror.h" +#include +#include "accessftokenidcommon.h" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { const char *DEVACCESSTOKENID = "/dev/access_token_id"; -int GetTokenid(unsigned long long *token) +int GetfTokenid(unsigned long long *ftoken) { int fd = open(DEVACCESSTOKENID, O_RDWR); if (fd < 0) { return -1; } - int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); + int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); if (ret) { close(fd); return -1; @@ -51,14 +47,14 @@ int GetTokenid(unsigned long long *token) return 0; } -int SetTokenid(unsigned long long *token) +int SetfTokenid(unsigned long long *ftoken) { int fd = open(DEVACCESSTOKENID, O_RDWR); if (fd < 0) { return -1; } - int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, token); + int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); if (ret) { close(fd); return -1; @@ -68,39 +64,132 @@ int SetTokenid(unsigned long long *token) return 0; } -int GetfTokenid(unsigned long long *ftoken) +void SetUidAndGrp() { - int fd = open(DEVACCESSTOKENID, O_RDWR); - if (fd < 0) { - return -1; + int ret = 0; + size_t groupListSize = LIST_NUM_2; + gid_t groupList[LIST_NUM_2] = {ACCESS_TOKEN_GRPID, TEST_VALUE}; + + ret = setgroups(groupListSize, groupList); + if (ret != 0) { + return; } - int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); - if (ret) { - close(fd); - return -1; + ret = setuid(ACCESS_TOKEN_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); } - close(fd); - return 0; + return; } -int SetfTokenid(unsigned long long *ftoken) +void SetUidAndGrpOther() { - int fd = open(DEVACCESSTOKENID, O_RDWR); - if (fd < 0) { - return -1; + int ret = 0; + size_t groupListSize = LIST_NUM_1; + gid_t groupList[LIST_NUM_1] = {ACCESS_TOKEN_OTHER_GRPID}; + + ret = setgroups(groupListSize, groupList); + if (ret != 0) { + return; } - int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); - if (ret) { - close(fd); - return -1; + ret = setuid(ACCESS_TOKEN_OTHER_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \r\n", ret); } - close(fd); + return; +} + +void SetRandfTokenAndCheck(unsigned long long *data_ftoken) +{ + pid_t pid = getpid(); + pid_t tid = syscall(__NR_gettid); + unsigned long long ftoken = INVAL_TOKEN; + unsigned long long ftokenSet = *data_ftoken; + + SetfTokenid(&ftokenSet); + GetfTokenid(&ftoken); + + if (ftoken != ftokenSet) { + printf("pid:%d tid:%d ftoken test failed, ftoken:%llu ftokenSet:%llu\n", + pid, tid, ftoken, ftokenSet); + } else { + printf("pid:%d tid:%d ftoken test succeed, ftoken:%llu ftokenSet:%llu\n", + pid, tid, ftoken, ftokenSet); + } + + sleep(WAIT_FOR_SHELL_OP_TIME); + + GetfTokenid(&ftoken); + if (ftoken != ftokenSet) { + printf("pid:%d tid:%d ftoken test failed, ftoken:%llu ftokenSet:%llu\n", + pid, tid, ftoken, ftokenSet); + } else { + printf("pid:%d tid:%d ftoken test succeed, ftoken:%llu ftokenSet:%llu\n", + pid, tid, ftoken, ftokenSet); + } + return; +} + +void *fTokenTest(void *data_ftoken) +{ + SetRandfTokenAndCheck(static_cast(data_ftoken)); + return nullptr; +} + +void ThreadTest(void *data_ftoken) +{ + pthread_t id_1; + pthread_t id_2; + pthread_t id_3; + int ret = 0; + + ret = pthread_create(&id_1, nullptr, fTokenTest, data_ftoken); + if (ret != 0) { + return; + } + + ret = pthread_create(&id_2, nullptr, fTokenTest, data_ftoken); + if (ret != 0) { + return; + } + + ret = pthread_create(&id_3, nullptr, fTokenTest, data_ftoken); + if (ret != 0) { + return; + } + + pthread_join(id_1, nullptr); + pthread_join(id_2, nullptr); + pthread_join(id_3, nullptr); + + return; +} + +int AccessfTokenidThreadTest(uint8_t *data_ftoken) +{ + fTokenTest(static_cast(data_ftoken)); + ThreadTest(static_cast(data_ftoken)); + return 0; +} + +int AccessfTokenidGrpTest(uint8_t *data_ftoken) +{ + SetUidAndGrp(); + fTokenTest(static_cast(data_ftoken)); + ThreadTest(static_cast(data_ftoken)); + return 0; +} + +int AccessfTokenidGrpTestOther(uint8_t *data_ftoken) +{ + SetUidAndGrpOther(); + fTokenTest(static_cast(data_ftoken)); + ThreadTest(static_cast(data_ftoken)); return 0; } } // namespace AccessToken -} // namespace Security +} // namespace Kernel } // namespace OHOS diff --git a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp similarity index 34% rename from test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp rename to test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp index 808820ac3fef21cb612aee2807e1199a3833cea8..1be96bd699a01d96b74c69a88b62d2a35a13e323 100644 --- a/test/fuzztest/accesstokenid/src/accesstokenidcmdcorrect.cpp +++ b/test/fuzztest/accesstokenid/src/accesstokenidcommon.cpp @@ -15,22 +15,18 @@ #include #include -#include -#include #include -#include -#include -#include #include +#include #include -#include +#include #include #include -#include -#include "accesstokenidcmdcorrect.h" +#include +#include "accesstokenidcommon.h" namespace OHOS { -namespace Security { +namespace Kernel { namespace AccessToken { const char *DEVACCESSTOKENID = "/dev/access_token_id"; @@ -40,13 +36,11 @@ int GetTokenid(unsigned long long *token) if (fd < 0) { return -1; } - int ret = ioctl(fd, ACCESS_TOKENID_GET_TOKENID, token); if (ret) { close(fd); return -1; } - close(fd); return 0; } @@ -57,50 +51,142 @@ int SetTokenid(unsigned long long *token) if (fd < 0) { return -1; } - int ret = ioctl(fd, ACCESS_TOKENID_SET_TOKENID, token); if (ret) { close(fd); return -1; } - close(fd); return 0; } -int GetfTokenid(unsigned long long *ftoken) +void SetUidAndGrp() { - int fd = open(DEVACCESSTOKENID, O_RDWR); - if (fd < 0) { - return -1; + int ret = 0; + size_t groupListSize = LIST_NUM_2; + gid_t groupList[LIST_NUM_2] = {ACCESS_TOKEN_GRPID, TEST_VALUE}; + + ret = setgroups(groupListSize, groupList); + if (ret != 0) { + return; } - int ret = ioctl(fd, ACCESS_TOKENID_GET_FTOKENID, ftoken); - if (ret) { - close(fd); - return -1; + ret = setuid(ACCESS_TOKEN_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); } - close(fd); - return 0; + return; } -int SetfTokenid(unsigned long long *ftoken) +void SetUidAndGrpOther() { - int fd = open(DEVACCESSTOKENID, O_RDWR); - if (fd < 0) { - return -1; + int ret = 0; + size_t groupListSize = LIST_NUM_1; + gid_t groupList[LIST_NUM_1] = {ACCESS_TOKEN_OTHER_GRPID}; + + ret = setgroups(groupListSize, groupList); + if (ret != 0) { + return; } - int ret = ioctl(fd, ACCESS_TOKENID_SET_FTOKENID, ftoken); - if (ret) { - close(fd); - return -1; + ret = setuid(ACCESS_TOKEN_OTHER_UID); + if (ret != 0) { + printf("SetUidAndGrp setuid error %d \n", ret); } - close(fd); + return; +} + +void SetRandTokenAndCheck(unsigned long long *data_token) +{ + pid_t pid = getpid(); + pid_t tid = syscall(__NR_gettid); + unsigned long long token = INVAL_TOKEN; + unsigned long long tokenSet = *data_token; + + SetTokenid(&tokenSet); + GetTokenid(&token); + + if (token != tokenSet) { + printf("pid:%d tid:%d token test failed, token:%llu tokenSet:%llu\n", + pid, tid, token, tokenSet); + } else { + printf("pid:%d tid:%d token test succeed, token:%llu tokenSet:%llu\n", + pid, tid, token, tokenSet); + } + + sleep(WAIT_FOR_SHELL_OP_TIME); + + GetTokenid(&token); + if (token != tokenSet) { + printf("pid:%d tid:%d token test failed, token:%llu tokenSet:%llu\n", + pid, tid, token, tokenSet); + } else { + printf("pid:%d tid:%d token test succeed, token:%llu tokenSet:%llu\n", + pid, tid, token, tokenSet); + } + return; +} + +void *TokenTest(void *data_token) +{ + SetRandTokenAndCheck(static_cast(data_token)); + + return nullptr; +} + +void ThreadTest(void *data_token) +{ + pthread_t id_1; + pthread_t id_2; + pthread_t id_3; + int ret = 0; + + ret = pthread_create(&id_1, nullptr, TokenTest, data_token); + if (ret != 0) { + return; + } + + ret = pthread_create(&id_2, nullptr, TokenTest, data_token); + if (ret != 0) { + return; + } + + ret = pthread_create(&id_3, nullptr, TokenTest, data_token); + if (ret != 0) { + return; + } + + pthread_join(id_1, nullptr); + pthread_join(id_2, nullptr); + pthread_join(id_3, nullptr); + + return; +} + +int AccessTokenidThreadTest(uint8_t *data_token) +{ + TokenTest(static_cast(data_token)); + ThreadTest(static_cast(data_token)); + return 0; +} + +int AccessTokenidGrpTest(uint8_t *data_token) +{ + SetUidAndGrp(); + TokenTest(static_cast(data_token)); + ThreadTest(static_cast(data_token)); + return 0; +} + +int AccessTokenidGrpTestOther(uint8_t *data_token) +{ + SetUidAndGrpOther(); + TokenTest(static_cast(data_token)); + ThreadTest(static_cast(data_token)); return 0; } } // namespace AccessToken -} // namespace Security +} // namespace Kernel } // namespace OHOS 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 b/test/fuzztest/sched/include/hilog new file mode 120000 index 0000000000000000000000000000000000000000..428b913a13f54b0a02df4d27d0ffb54ddc892122 --- /dev/null +++ b/test/fuzztest/sched/include/hilog @@ -0,0 +1 @@ +../../../../../../../foundation/multimedia/image_standard/mock/native/include/hilog/ \ No newline at end of file diff --git a/test/fuzztest/sched/include/rme_log_domain.h b/test/fuzztest/sched/include/rme_log_domain.h new file mode 120000 index 0000000000000000000000000000000000000000..d9397ef9ffad8847298262d4eb9047abe9d26b2c --- /dev/null +++ b/test/fuzztest/sched/include/rme_log_domain.h @@ -0,0 +1 @@ +../../../../../../../foundation/resourceschedule/frame_aware_sched/common/include/rme_log_domain.h \ No newline at end of file diff --git a/test/fuzztest/sched/include/rtg_interface.h b/test/fuzztest/sched/include/rtg_interface.h new file mode 120000 index 0000000000000000000000000000000000000000..a16db793c3ae5a46d9d749820ffdf052e0219c73 --- /dev/null +++ b/test/fuzztest/sched/include/rtg_interface.h @@ -0,0 +1 @@ +../../../../../../../foundation/resourceschedule/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 120000 index 0000000000000000000000000000000000000000..9cf01c31daa8d6934efa90026a01d236381c2025 --- /dev/null +++ b/test/fuzztest/sched/src/rtg_interface.cpp @@ -0,0 +1 @@ +../../../../../../../foundation/resourceschedule/frame_aware_sched/interfaces/innerkits/frameintf/rtg_interface.cpp \ No newline at end of file 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