From: Eric Fiselier Date: Wed, 11 Dec 2019 20:45:48 +0000 (-0500) Subject: [libc++] Add fuzzing tests for parts of . X-Git-Tag: llvmorg-11-init~2388 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=daacf57032450079b44b8a7f9b976700d3bc38f8;p=platform%2Fupstream%2Fllvm.git [libc++] Add fuzzing tests for parts of . This patch also re-names the existing fuzzing unit tests so they actually run. --- diff --git a/libcxx/fuzzing/RoutineNames.txt b/libcxx/fuzzing/RoutineNames.txt index 06ef70e..a853c87 100644 --- a/libcxx/fuzzing/RoutineNames.txt +++ b/libcxx/fuzzing/RoutineNames.txt @@ -18,3 +18,23 @@ regex_awk regex_grep regex_egrep search +uniform_int_distribution +uniform_real_distribution +bernoulli_distribution +poisson_distribution +geometric_distribution +binomial_distribution +negative_binomial_distribution +exponential_distribution +gamma_distribution +weibull_distribution +extreme_value_distribution +normal_distribution +lognormal_distribution +chi_squared_distribution +cauchy_distribution +fisher_f_distribution +student_t_distribution +discrete_distribution +piecewise_constant_distribution +piecewise_linear_distribution diff --git a/libcxx/fuzzing/fuzz_test_template.cpp b/libcxx/fuzzing/fuzz_test_template.cpp new file mode 100644 index 0000000..ba44eef --- /dev/null +++ b/libcxx/fuzzing/fuzz_test_template.cpp @@ -0,0 +1,22 @@ +//===------------------------- fuzz_test.cpp ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzing/fuzzing.h" +#ifdef NDEBUG +#undef NDEBUG +#endif +#include + +#ifndef TEST_FUNCTION +#error TEST_FUNCTION must be defined +#endif + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + int result = fuzzing::TEST_FUNCTION(data, size); + assert(result == 0); return 0; +} diff --git a/libcxx/fuzzing/fuzzing.cpp b/libcxx/fuzzing/fuzzing.cpp index 5c32f28..2849939 100644 --- a/libcxx/fuzzing/fuzzing.cpp +++ b/libcxx/fuzzing/fuzzing.cpp @@ -27,10 +27,16 @@ #include #include #include +#include #include +#include #include +#ifdef NDEBUG +#undef NDEBUG +#endif +#include // If we had C++14, we could use the four iterator version of is_permutation and equal namespace fuzzing { @@ -212,7 +218,7 @@ int partition_copy(const uint8_t *data, size_t size) auto iter = std::partition_copy(data, data + size, std::back_inserter(v1), std::back_inserter(v2), is_even()); - + ((void)iter); // The two vectors should add up to the original size if (v1.size() + v2.size() != size) return 1; @@ -614,4 +620,201 @@ static void set_helper (const uint8_t *data, size_t size, Vec &v1, Vec &v2) std::sort(v2.begin(), v2.end()); } +enum class ParamKind { + OneValue, + TwoValues, + PointerRange +}; + +template +std::vector GetValues(const uint8_t *data, size_t size) { + std::vector result; + while (size >= sizeof(IntT)) { + IntT tmp; + memcpy(&tmp, data, sizeof(IntT)); + size -= sizeof(IntT); + data += sizeof(IntT); + result.push_back(tmp); + } + return result; +} + +enum InitKind { + Default, + DoubleOnly, + VectorDouble, + VectorResultType +}; + +template +struct ParamTypeHelper { + using ParamT = typename Dist::param_type; + using ResultT = typename Dist::result_type; + static_assert(std::is_same::value, ""); + static ParamT Create(const uint8_t* data, size_t size, bool &OK) { + + if constexpr (std::is_constructible::value) + return CreateVectorResult(data, size, OK); + else if constexpr (std::is_constructible::value) + return CreateVectorDouble(data, size, OK); + else + return CreateDefault(data, size, OK); + } + + +static ParamT +CreateVectorResult(const uint8_t *data, size_t size, bool &OK) { + auto Input = GetValues(data, size); + OK = false; + if (Input.size() < 10) + return ParamT{}; + OK = true; + auto Beg = Input.begin(); + auto End = Input.end(); + auto Mid = Beg + ((End - Beg) / 2); + + assert(Mid - Beg <= (End - Mid)); + ParamT p(Beg, Mid, Mid); + return p; +} + + static ParamT + CreateVectorDouble(const uint8_t *data, size_t size, bool &OK) { + auto Input = GetValues(data, size); + + OK = true; + auto Beg = Input.begin(); + auto End = Input.end(); + + ParamT p(Beg, End); + return p; + } + + + static ParamT + CreateDefault(const uint8_t *data, size_t size, bool &OK) { + OK = false; + if (size < sizeof(ParamT)) + return ParamT{}; + OK = true; + ParamT input; + memcpy(&input, data, sizeof(ParamT)); + return input; + } + +}; + + + + +template +struct ParamTypeHelper> { + using Dist = std::poisson_distribution; + using ParamT = typename Dist::param_type; + using ResultT = typename Dist::result_type; + + static ParamT Create(const uint8_t *data, size_t size, bool& OK) { + OK = false; + auto vals = GetValues(data, size); + if (vals.empty() || std::isnan(vals[0]) || std::isnan(std::abs(vals[0])) || vals[0] < 0 ) + return ParamT{}; + OK = true; + //std::cerr << "Value: " << vals[0] << std::endl; + return ParamT{vals[0]}; + } +}; + + +template +struct ParamTypeHelper> { + using Dist = std::geometric_distribution; + using ParamT = typename Dist::param_type; + using ResultT = typename Dist::result_type; + + static ParamT Create(const uint8_t *data, size_t size, bool& OK) { + OK = false; + auto vals = GetValues(data, size); + if (vals.empty() || std::isnan(vals[0]) || vals[0] < 0 ) + return ParamT{}; + OK = true; + // std::cerr << "Value: " << vals[0] << std::endl; + return ParamT{vals[0]}; + } +}; + + +template +struct ParamTypeHelper> { + using Dist = std::lognormal_distribution; + using ParamT = typename Dist::param_type; + using ResultT = typename Dist::result_type; + + static ParamT Create(const uint8_t *data, size_t size, bool& OK) { + OK = false; + auto vals = GetValues(data, size); + if (vals.size() < 2 ) + return ParamT{}; + OK = true; + return ParamT{vals[0], vals[1]}; + } +}; + + +template <> +struct ParamTypeHelper { + using Dist = std::bernoulli_distribution; + using ParamT = typename Dist::param_type; + using ResultT = typename Dist::result_type; + + static ParamT Create(const uint8_t *data, size_t size, bool& OK) { + OK = false; + auto vals = GetValues(data, size); + if (vals.empty()) + return ParamT{}; + OK = true; + return ParamT{vals[0]}; + } +}; + +template +int random_distribution_helper(const uint8_t *data, size_t size) { + + std::mt19937 engine; + using ParamT = typename Distribution::param_type; + bool OK; + ParamT p = ParamTypeHelper::Create(data, size, OK); + if (!OK) + return 0; + Distribution d(p); + volatile auto res = d(engine); + if (std::isnan(res)) + return 1; + return 0; +} + +#define DEFINE_RANDOM_TEST(name, ...) \ +int name(const uint8_t *data, size_t size) { \ + return random_distribution_helper< std::name __VA_ARGS__ >(data, size); \ +} +DEFINE_RANDOM_TEST(uniform_int_distribution,) +DEFINE_RANDOM_TEST(uniform_real_distribution,) +DEFINE_RANDOM_TEST(bernoulli_distribution) +DEFINE_RANDOM_TEST(poisson_distribution,) +DEFINE_RANDOM_TEST(geometric_distribution,) +DEFINE_RANDOM_TEST(binomial_distribution, ) +DEFINE_RANDOM_TEST(negative_binomial_distribution, ) +DEFINE_RANDOM_TEST(exponential_distribution, ) +DEFINE_RANDOM_TEST(gamma_distribution, ) +DEFINE_RANDOM_TEST(weibull_distribution, ) +DEFINE_RANDOM_TEST(extreme_value_distribution, ) +DEFINE_RANDOM_TEST(normal_distribution, ) +DEFINE_RANDOM_TEST(lognormal_distribution, ) +DEFINE_RANDOM_TEST(chi_squared_distribution, ) +DEFINE_RANDOM_TEST(cauchy_distribution, ) +DEFINE_RANDOM_TEST(fisher_f_distribution, ) +DEFINE_RANDOM_TEST(student_t_distribution, ) +DEFINE_RANDOM_TEST(discrete_distribution, ) +DEFINE_RANDOM_TEST(piecewise_constant_distribution, ) +DEFINE_RANDOM_TEST(piecewise_linear_distribution, ) + } // namespace fuzzing diff --git a/libcxx/fuzzing/fuzzing.h b/libcxx/fuzzing/fuzzing.h index 64103e5..99a3aa1 100644 --- a/libcxx/fuzzing/fuzzing.h +++ b/libcxx/fuzzing/fuzzing.h @@ -56,6 +56,28 @@ namespace fuzzing { // int set_symmetric_difference (const uint8_t *data, size_t size); // int merge (const uint8_t *data, size_t size); +// Random numbers + int uniform_int_distribution(const uint8_t*, size_t); + int uniform_real_distribution(const uint8_t*, size_t); + int bernoulli_distribution(const uint8_t*, size_t); + int poisson_distribution(const uint8_t*, size_t); + int geometric_distribution(const uint8_t*, size_t); + int binomial_distribution(const uint8_t*, size_t); + int negative_binomial_distribution(const uint8_t*, size_t); + int exponential_distribution(const uint8_t*, size_t); + int gamma_distribution(const uint8_t*, size_t); + int weibull_distribution(const uint8_t*, size_t); + int extreme_value_distribution(const uint8_t*, size_t); + int normal_distribution(const uint8_t*, size_t); + int lognormal_distribution(const uint8_t*, size_t); + int chi_squared_distribution(const uint8_t*, size_t); + int cauchy_distribution(const uint8_t*, size_t); + int fisher_f_distribution(const uint8_t*, size_t); + int student_t_distribution(const uint8_t*, size_t); + int discrete_distribution(const uint8_t*, size_t); + int piecewise_constant_distribution(const uint8_t*, size_t); + int piecewise_linear_distribution(const uint8_t*, size_t); + } // namespace fuzzing #endif // _LIBCPP_FUZZING diff --git a/libcxx/test/libcxx/fuzzing/fuzzer_test.h b/libcxx/test/libcxx/fuzzing/fuzzer_test.h new file mode 100644 index 0000000..9b9a23f --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/fuzzer_test.h @@ -0,0 +1,46 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef TEST_LIBCXX_FUZZER_TEST_H +#define TEST_LIBCXX_FUZZER_TEST_H + +#include +#include + +#include "../../../fuzzing/fuzzing.h" +#include "../../../fuzzing/fuzzing.cpp" + +const char* TestCaseSetOne[] = {"", "s", "bac", + "bacasf" + "lkajseravea", + "adsfkajdsfjkas;lnc441324513,34535r34525234", + "b*c", + "ba?sf" + "lka*ea", + "adsf*kas;lnc441[0-9]1r34525234"}; + +using FuzzerFuncType = int(const uint8_t*, size_t); + +template +inline void RunFuzzingTest(FuzzerFuncType *to_test, const char* (&test_cases)[NumCases]) { + for (const char* TC : test_cases) { + const size_t size = std::strlen(TC); + const uint8_t* data = (const uint8_t*)TC; + int result = to_test(data, size); + assert(result == 0); + } +} + +#define FUZZER_TEST(FuncName) \ +int main() { \ + RunFuzzingTest(FuncName, TestCaseSetOne); \ +} \ +extern int require_semi + +#endif // TEST_LIBCXX_FUZZER_TEST_H diff --git a/libcxx/test/libcxx/fuzzing/geometric_distribution.pass.cpp b/libcxx/test/libcxx/fuzzing/geometric_distribution.pass.cpp new file mode 100644 index 0000000..acb07ef --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/geometric_distribution.pass.cpp @@ -0,0 +1,37 @@ +// -*- C++ -*- +//===------------------------ unique_copy.cpp -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include + +#include "fuzzer_test.h" + +template +int random_distribution_helper(const uint8_t *data, size_t size) { + std::mt19937 engine; + using ParamT = typename Distribution::param_type; + if (size < sizeof(double)) + return 0; + double Arg; + memcpy(&Arg, data, sizeof(double)); + ParamT p(Arg); + Distribution d(p); + for (int I=0; I < 1000; ++I) { + volatile auto res = d(engine); + ((void)res); + } + return 0; +} + +int FuzzRandom(const uint8_t *Data, size_t Size) { + return random_distribution_helper>(Data, Size); +} +FUZZER_TEST(FuzzRandom); + + diff --git a/libcxx/test/libcxx/fuzzing/nth_element.cpp b/libcxx/test/libcxx/fuzzing/nth_element.cpp deleted file mode 100644 index 482aeb6..0000000 --- a/libcxx/test/libcxx/fuzzing/nth_element.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===----------------------- nth_element.cpp ------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::nth_element(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/nth_element.pass.cpp b/libcxx/test/libcxx/fuzzing/nth_element.pass.cpp new file mode 100644 index 0000000..580c559 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/nth_element.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===----------------------- nth_element.cpp ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::nth_element); diff --git a/libcxx/test/libcxx/fuzzing/partial_sort.cpp b/libcxx/test/libcxx/fuzzing/partial_sort.cpp deleted file mode 100644 index 4f35766..0000000 --- a/libcxx/test/libcxx/fuzzing/partial_sort.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===-------------------------- partial_sort.cpp --------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::partial_sort(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/partial_sort.pass.cpp b/libcxx/test/libcxx/fuzzing/partial_sort.pass.cpp new file mode 100644 index 0000000..08fa1a3 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/partial_sort.pass.cpp @@ -0,0 +1,30 @@ +// -*- C++ -*- +//===-------------------------- partial_sort.cpp --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include +#include // for strlen + +#include "../fuzzing/fuzzing.h" +#include "../fuzzing/fuzzing.cpp" + +const char* test_cases[] = {"", "s", "bac", + "bacasf" + "lkajseravea", + "adsfkajdsfjkas;lnc441324513,34535r34525234"}; + +const size_t k_num_tests = sizeof(test_cases) / sizeof(test_cases[0]); + +int main(int, char**) { + for (size_t i = 0; i < k_num_tests; ++i) { + const size_t size = std::strlen(test_cases[i]); + const uint8_t* data = (const uint8_t*)test_cases[i]; + assert(0 == fuzzing::partial_sort(data, size)); + } + return 0; +} diff --git a/libcxx/test/libcxx/fuzzing/partial_sort_copy.cpp b/libcxx/test/libcxx/fuzzing/partial_sort_copy.cpp deleted file mode 100644 index b569f55..0000000 --- a/libcxx/test/libcxx/fuzzing/partial_sort_copy.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===----------------------- partial_sort_copy.cpp ------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::partial_sort_copy(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/partial_sort_copy.pass.cpp b/libcxx/test/libcxx/fuzzing/partial_sort_copy.pass.cpp new file mode 100644 index 0000000..42bc4ad --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/partial_sort_copy.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===----------------------- partial_sort_copy.cpp ------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::partial_sort_copy); diff --git a/libcxx/test/libcxx/fuzzing/partition.cpp b/libcxx/test/libcxx/fuzzing/partition.cpp deleted file mode 100644 index 0833e38..0000000 --- a/libcxx/test/libcxx/fuzzing/partition.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===--------------------------- partition.cpp ----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::partition(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/partition.pass.cpp b/libcxx/test/libcxx/fuzzing/partition.pass.cpp new file mode 100644 index 0000000..15bdcf4 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/partition.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===--------------------------- partition.cpp ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::partition); diff --git a/libcxx/test/libcxx/fuzzing/partition_copy.cpp b/libcxx/test/libcxx/fuzzing/partition_copy.cpp deleted file mode 100644 index f336a14..0000000 --- a/libcxx/test/libcxx/fuzzing/partition_copy.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===------------------------ partition_copy.cpp --------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::partition_copy(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/partition_copy.pass.cpp b/libcxx/test/libcxx/fuzzing/partition_copy.pass.cpp new file mode 100644 index 0000000..b026e7c --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/partition_copy.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===------------------------ partition_copy.cpp --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::partition_copy); diff --git a/libcxx/test/libcxx/fuzzing/regex_ECMAScript.cpp b/libcxx/test/libcxx/fuzzing/regex_ECMAScript.cpp deleted file mode 100644 index ca9a7da..0000000 --- a/libcxx/test/libcxx/fuzzing/regex_ECMAScript.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===--------------------- regex_ECMAScript.cpp ---------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "b*c", - "ba?sf" - "lka*ea", - "adsf*kas;lnc441[0-9]1r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::regex_ECMAScript(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/regex_ECMAScript.pass.cpp b/libcxx/test/libcxx/fuzzing/regex_ECMAScript.pass.cpp new file mode 100644 index 0000000..d0e1cf8 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/regex_ECMAScript.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===--------------------- regex_ECMAScript.cpp ---------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::regex_ECMAScript); diff --git a/libcxx/test/libcxx/fuzzing/regex_POSIX.cpp b/libcxx/test/libcxx/fuzzing/regex_POSIX.cpp deleted file mode 100644 index 69f40de..0000000 --- a/libcxx/test/libcxx/fuzzing/regex_POSIX.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===----------------------- regex_POSIX.cpp ------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "b*c", - "ba?sf" - "lka*ea", - "adsf*kas;lnc441[0-9]1r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::regex_POSIX(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/regex_POSIX.pass.cpp b/libcxx/test/libcxx/fuzzing/regex_POSIX.pass.cpp new file mode 100644 index 0000000..db1d760 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/regex_POSIX.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===----------------------- regex_POSIX.cpp ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::regex_POSIX); diff --git a/libcxx/test/libcxx/fuzzing/regex_awk.cpp b/libcxx/test/libcxx/fuzzing/regex_awk.cpp deleted file mode 100644 index ca9a7da..0000000 --- a/libcxx/test/libcxx/fuzzing/regex_awk.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===--------------------- regex_ECMAScript.cpp ---------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "b*c", - "ba?sf" - "lka*ea", - "adsf*kas;lnc441[0-9]1r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::regex_ECMAScript(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/regex_awk.pass.cpp b/libcxx/test/libcxx/fuzzing/regex_awk.pass.cpp new file mode 100644 index 0000000..d363059 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/regex_awk.pass.cpp @@ -0,0 +1,12 @@ +// -*- C++ -*- +//===------------------------- regex_awk.cpp ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::regex_awk); diff --git a/libcxx/test/libcxx/fuzzing/regex_egrep.cpp b/libcxx/test/libcxx/fuzzing/regex_egrep.cpp deleted file mode 100644 index f350f63..0000000 --- a/libcxx/test/libcxx/fuzzing/regex_egrep.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===------------------------ regex_egrep.cpp -----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "b*c", - "ba?sf" - "lka*ea", - "adsf*kas;lnc441[0-9]1r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::regex_egrep(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/regex_egrep.pass.cpp b/libcxx/test/libcxx/fuzzing/regex_egrep.pass.cpp new file mode 100644 index 0000000..840fd71 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/regex_egrep.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===------------------------ regex_egrep.cpp -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::regex_egrep); diff --git a/libcxx/test/libcxx/fuzzing/regex_extended.cpp b/libcxx/test/libcxx/fuzzing/regex_extended.cpp deleted file mode 100644 index ae55f5b..0000000 --- a/libcxx/test/libcxx/fuzzing/regex_extended.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===---------------------- regex_extended.cpp ----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "b*c", - "ba?sf" - "lka*ea", - "adsf*kas;lnc441[0-9]1r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::regex_extended(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/regex_extended.pass.cpp b/libcxx/test/libcxx/fuzzing/regex_extended.pass.cpp new file mode 100644 index 0000000..fe81d26 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/regex_extended.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===---------------------- regex_extended.cpp ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::regex_extended); diff --git a/libcxx/test/libcxx/fuzzing/regex_grep.cpp b/libcxx/test/libcxx/fuzzing/regex_grep.cpp deleted file mode 100644 index ac497b3..0000000 --- a/libcxx/test/libcxx/fuzzing/regex_grep.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -//===------------------------ regex_grep.cpp ------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "b*c", - "ba?sf" - "lka*ea", - "adsf*kas;lnc441[0-9]1r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::regex_grep(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/regex_grep.pass.cpp b/libcxx/test/libcxx/fuzzing/regex_grep.pass.cpp new file mode 100644 index 0000000..321c729 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/regex_grep.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===------------------------ regex_grep.cpp ------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::regex_grep); diff --git a/libcxx/test/libcxx/fuzzing/sort.cpp b/libcxx/test/libcxx/fuzzing/sort.cpp deleted file mode 100644 index 43b9064..0000000 --- a/libcxx/test/libcxx/fuzzing/sort.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===--------------------------- sort.cpp ---------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::sort(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/sort.pass.cpp b/libcxx/test/libcxx/fuzzing/sort.pass.cpp new file mode 100644 index 0000000..3de5fe4 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/sort.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===--------------------------- sort.cpp ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::sort); diff --git a/libcxx/test/libcxx/fuzzing/stable_partition.cpp b/libcxx/test/libcxx/fuzzing/stable_partition.cpp deleted file mode 100644 index b236190..0000000 --- a/libcxx/test/libcxx/fuzzing/stable_partition.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===--------------------- stable_partition.cpp ---------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::stable_partition(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/stable_partition.pass.cpp b/libcxx/test/libcxx/fuzzing/stable_partition.pass.cpp new file mode 100644 index 0000000..ed22a36 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/stable_partition.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===--------------------- stable_partition.cpp ---------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::stable_partition); diff --git a/libcxx/test/libcxx/fuzzing/stable_sort.cpp b/libcxx/test/libcxx/fuzzing/stable_sort.cpp deleted file mode 100644 index 1c8ac49..0000000 --- a/libcxx/test/libcxx/fuzzing/stable_sort.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===------------------------ stable_sort.cpp ----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::stable_sort(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/stable_sort.pass.cpp b/libcxx/test/libcxx/fuzzing/stable_sort.pass.cpp new file mode 100644 index 0000000..130e1ca --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/stable_sort.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===------------------------ stable_sort.cpp ----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::stable_sort); diff --git a/libcxx/test/libcxx/fuzzing/unique.cpp b/libcxx/test/libcxx/fuzzing/unique.cpp deleted file mode 100644 index cab512e..0000000 --- a/libcxx/test/libcxx/fuzzing/unique.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===--------------------------- unique.cpp -------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::unique(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/unique.pass.cpp b/libcxx/test/libcxx/fuzzing/unique.pass.cpp new file mode 100644 index 0000000..d30c966 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/unique.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===--------------------------- unique.cpp -------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::unique); diff --git a/libcxx/test/libcxx/fuzzing/unique_copy.cpp b/libcxx/test/libcxx/fuzzing/unique_copy.cpp deleted file mode 100644 index 311eb4c..0000000 --- a/libcxx/test/libcxx/fuzzing/unique_copy.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -*- C++ -*- -//===------------------------ unique_copy.cpp -----------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// XFAIL - -#include "fuzzing.h" -#include -#include // for strlen - -const char * test_cases[] = { - "", - "s", - "bac", - "bacasf" - "lkajseravea", - "adsfkajdsfjkas;lnc441324513,34535r34525234" - }; - -const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]); - - -int main(int, char**) -{ - for (size_t i = 0; i < k_num_tests; ++i) - { - const size_t size = std::strlen(test_cases[i]); - const uint8_t *data = (const uint8_t *) test_cases[i]; - assert(0 == fuzzing::unique_copy(data, size)); - } - return 0; -} diff --git a/libcxx/test/libcxx/fuzzing/unique_copy.pass.cpp b/libcxx/test/libcxx/fuzzing/unique_copy.pass.cpp new file mode 100644 index 0000000..78fed97 --- /dev/null +++ b/libcxx/test/libcxx/fuzzing/unique_copy.pass.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +//===------------------------ unique_copy.cpp -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "fuzzer_test.h" +FUZZER_TEST(fuzzing::unique_copy);