From 857359b72f8886b6e90db3b596d04f08559d2b51 Mon Sep 17 00:00:00 2001
From: Thomas Rodgers <trodgers@redhat.com>
Date: Mon, 3 Jul 2023 15:04:45 -0700
Subject: [PATCH] libstdc++: Split up pstl/set.cc testcase
This testcase is causing some timeout issues. This patch splits the
testcase up by individual set algorithm.
libstdc++-v3:/ChangeLog:
* testsuite/25_algorithms/pstl/alg_sorting/set.cc: Delete
file.
* testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc:
New file.
* testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc:
Likewise.
* testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc:
Likewise.
* testsuite/25_algorithms/pstl/alg_sorting/set_union.cc:
Likewise.
* testsuite/25_algorithms/pstl/alg_sorting/set_util.h:
Likewise.
---
.../25_algorithms/pstl/alg_sorting/set.cc | 289 ------------------
.../pstl/alg_sorting/set_difference.cc | 90 ++++++
.../pstl/alg_sorting/set_intersection.cc | 91 ++++++
.../alg_sorting/set_symmetric_difference.cc | 92 ++++++
.../pstl/alg_sorting/set_union.cc | 90 ++++++
.../25_algorithms/pstl/alg_sorting/set_util.h | 72 +++++
6 files changed, 435 insertions(+), 289 deletions(-)
delete mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set.cc
create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_difference.cc
create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_intersection.cc
create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_symmetric_difference.cc
create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_union.cc
create mode 100644 libstdc++-v3/testsuite/25_algorithms/pstl/alg_sorting/set_util.h
deleted file mode 100644
@@ -1,289 +0,0 @@
-// -*- C++ -*-
-// { dg-options "-ltbb" }
-// { dg-do run { target c++17 } }
-// { dg-timeout-factor 3 }
-// { dg-require-effective-target tbb_backend }
-
-//===-- set.pass.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 "pstl/pstl_test_config.h"
-
-#ifdef PSTL_STANDALONE_TESTS
-
-#include <cmath>
-#include <chrono>
-
-#include "pstl/execution"
-#include "pstl/algorithm"
-#else
-#include <execution>
-#include <algorithm>
-#endif // PSTL_STANDALONE_TESTS
-
-#include "pstl/test_utils.h"
-
-using namespace TestUtils;
-
-template <typename T>
-struct Num
-{
- T val;
-
- Num() : val{} {}
- Num(const T& v) : val(v) {}
-
- //for "includes" checks
- template <typename T1>
- bool
- operator<(const Num<T1>& v1) const
- {
- return val < v1.val;
- }
-
- //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them
- template <typename T1>
- operator Num<T1>() const
- {
- return Num<T1>((T1)val);
- }
-
- friend bool
- operator==(const Num& v1, const Num& v2)
- {
- return v1.val == v2.val;
- }
-};
-
-template <typename Type>
-struct test_set_union
-{
- template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
- typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
- operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
- Compare comp)
- {
- using T1 = typename std::iterator_traits<InputIterator1>::value_type;
-
- auto n1 = std::distance(first1, last1);
- auto n2 = std::distance(first2, last2);
- auto n = n1 + n2;
- Sequence<T1> expect(n);
- Sequence<T1> out(n);
-
- auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp);
- auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp);
-
- EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union");
- EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect");
- }
-
- template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
- typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
- operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
- {
- }
-};
-
-template <typename Type>
-struct test_set_intersection
-{
- template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
- typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
- operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
- Compare comp)
- {
- using T1 = typename std::iterator_traits<InputIterator1>::value_type;
-
- auto n1 = std::distance(first1, last1);
- auto n2 = std::distance(first2, last2);
- auto n = n1 + n2;
- Sequence<T1> expect(n);
- Sequence<T1> out(n);
-
- auto expect_res = std::set_intersection(first1, last1, first2, last2, expect.begin(), comp);
- auto res = std::set_intersection(exec, first1, last1, first2, last2, out.begin(), comp);
-
- EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_intersection");
- EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_intersection effect");
- }
-
- template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
- typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
- operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
- {
- }
-};
-
-template <typename Type>
-struct test_set_difference
-{
- template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
- typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
- operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
- Compare comp)
- {
- using T1 = typename std::iterator_traits<InputIterator1>::value_type;
-
- auto n1 = std::distance(first1, last1);
- auto n2 = std::distance(first2, last2);
- auto n = n1 + n2;
- Sequence<T1> expect(n);
- Sequence<T1> out(n);
-
- auto expect_res = std::set_difference(first1, last1, first2, last2, expect.begin(), comp);
- auto res = std::set_difference(exec, first1, last1, first2, last2, out.begin(), comp);
-
- EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_difference");
- EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_difference effect");
- }
-
- template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
- typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
- operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
- {
- }
-};
-
-template <typename Type>
-struct test_set_symmetric_difference
-{
- template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
- typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
- operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
- Compare comp)
- {
- using T1 = typename std::iterator_traits<InputIterator1>::value_type;
-
- auto n1 = std::distance(first1, last1);
- auto n2 = std::distance(first2, last2);
- auto n = n1 + n2;
- Sequence<T1> expect(n);
- Sequence<T1> out(n);
-
- auto expect_res = std::set_symmetric_difference(first1, last1, first2, last2, expect.begin(), comp);
- auto res = std::set_symmetric_difference(exec, first1, last1, first2, last2, out.begin(), comp);
-
- EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_symmetric_difference");
- EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res),
- "wrong set_symmetric_difference effect");
- }
-
- template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
- typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
- operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
- {
- }
-};
-
-template <typename T1, typename T2, typename Compare>
-void
-test_set(Compare compare)
-{
-
- const std::size_t n_max = 100000;
-
- // The rand()%(2*n+1) encourages generation of some duplicates.
- std::srand(4200);
-
- for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n))
- {
- for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m))
- {
- //prepare the input ranges
- Sequence<T1> in1(n, [](std::size_t k) { return rand() % (2 * k + 1); });
- Sequence<T2> in2(m, [m](std::size_t k) { return (m % 2) * rand() + rand() % (k + 1); });
-
- std::sort(in1.begin(), in1.end(), compare);
- std::sort(in2.begin(), in2.end(), compare);
-
- invoke_on_all_policies(test_set_union<T1>(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(),
- compare);
-
- invoke_on_all_policies(test_set_intersection<T1>(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(),
- compare);
-
- invoke_on_all_policies(test_set_difference<T1>(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(),
- compare);
-
- invoke_on_all_policies(test_set_symmetric_difference<T1>(), in1.begin(), in1.end(), in2.cbegin(),
- in2.cend(), compare);
- }
- }
-}
-
-template <typename T>
-struct test_non_const_set_difference
-{
- template <typename Policy, typename InputIterator, typename OutputInterator>
- void
- operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
- {
- set_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>()));
- }
-};
-
-template <typename T>
-struct test_non_const_set_intersection
-{
- template <typename Policy, typename InputIterator, typename OutputInterator>
- void
- operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
- {
- set_intersection(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>()));
- }
-};
-
-template <typename T>
-struct test_non_const_set_symmetric_difference
-{
- template <typename Policy, typename InputIterator, typename OutputInterator>
- void
- operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
- {
- set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter,
- non_const(std::less<T>()));
- }
-};
-
-template <typename T>
-struct test_non_const_set_union
-{
- template <typename Policy, typename InputIterator, typename OutputInterator>
- void
- operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
- {
- set_union(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>()));
- }
-};
-
-int
-main()
-{
-
- test_set<float64_t, float64_t>(std::less<>());
- test_set<Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; });
-
- test_set<MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool {
- return val1.value() < val2.value();
- });
- EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls");
- EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls");
-
- test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_difference<int32_t>>());
-
- test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_intersection<int32_t>>());
-
- test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_symmetric_difference<int32_t>>());
-
- test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_union<int32_t>>());
-
- std::cout << done() << std::endl;
-
- return 0;
-}
new file mode 100644
@@ -0,0 +1,90 @@
+// -*- C++ -*-
+// { dg-options "-ltbb" }
+// { dg-do run { target c++17 } }
+// { dg-timeout-factor 3 }
+// { dg-require-effective-target tbb_backend }
+
+//===-- set.pass.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 "pstl/pstl_test_config.h"
+
+#ifdef PSTL_STANDALONE_TESTS
+
+#include <cmath>
+#include <chrono>
+
+#include "pstl/execution"
+#include "pstl/algorithm"
+#else
+#include <execution>
+#include <algorithm>
+#endif // PSTL_STANDALONE_TESTS
+
+#include "pstl/test_utils.h"
+
+#include "set_util.h"
+
+using namespace TestUtils;
+
+template <typename Type>
+struct test_set_difference
+{
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
+ Compare comp)
+ {
+ using T1 = typename std::iterator_traits<InputIterator1>::value_type;
+
+ auto n1 = std::distance(first1, last1);
+ auto n2 = std::distance(first2, last2);
+ auto n = n1 + n2;
+ Sequence<T1> expect(n);
+ Sequence<T1> out(n);
+
+ auto expect_res = std::set_difference(first1, last1, first2, last2, expect.begin(), comp);
+ auto res = std::set_difference(exec, first1, last1, first2, last2, out.begin(), comp);
+
+ EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_difference");
+ EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_difference effect");
+ }
+
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
+ {
+ }
+};
+
+template <typename T>
+struct test_non_const_set_difference
+{
+ template <typename Policy, typename InputIterator, typename OutputInterator>
+ void
+ operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
+ {
+ set_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>()));
+ }
+};
+
+int
+main()
+{
+ test_set_op<test_set_difference<float64_t>, float64_t, float64_t>(std::less<>());
+ test_set_op<test_set_difference<Num<int64_t>>, Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; });
+ test_set_op<test_set_difference<MemoryChecker>, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool {
+ return val1.value() < val2.value();
+ });
+ EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls");
+ EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls");
+
+ test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_difference<int32_t>>());
+
+ std::cout << done() << std::endl;
+}
new file mode 100644
@@ -0,0 +1,91 @@
+// -*- C++ -*-
+// { dg-options "-ltbb" }
+// { dg-do run { target c++17 } }
+// { dg-timeout-factor 3 }
+// { dg-require-effective-target tbb_backend }
+
+//===-- set.pass.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 "pstl/pstl_test_config.h"
+
+#ifdef PSTL_STANDALONE_TESTS
+
+#include <cmath>
+#include <chrono>
+
+#include "pstl/execution"
+#include "pstl/algorithm"
+#else
+#include <execution>
+#include <algorithm>
+#endif // PSTL_STANDALONE_TESTS
+
+#include "pstl/test_utils.h"
+
+#include "set_util.h"
+
+using namespace TestUtils;
+
+template <typename Type>
+struct test_set_intersection
+{
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
+ Compare comp)
+ {
+ using T1 = typename std::iterator_traits<InputIterator1>::value_type;
+
+ auto n1 = std::distance(first1, last1);
+ auto n2 = std::distance(first2, last2);
+ auto n = n1 + n2;
+ Sequence<T1> expect(n);
+ Sequence<T1> out(n);
+
+ auto expect_res = std::set_intersection(first1, last1, first2, last2, expect.begin(), comp);
+ auto res = std::set_intersection(exec, first1, last1, first2, last2, out.begin(), comp);
+
+ EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_intersection");
+ EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_intersection effect");
+ }
+
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
+ {
+ }
+};
+
+template <typename T>
+struct test_non_const_set_intersection
+{
+ template <typename Policy, typename InputIterator, typename OutputInterator>
+ void
+ operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
+ {
+ set_intersection(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>()));
+ }
+};
+
+int
+main()
+{
+ test_set_op<test_set_intersection<float64_t>, float64_t, float64_t>(std::less<>());
+ test_set_op<test_set_intersection<Num<int64_t>>, Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; });
+
+ test_set_op<test_set_intersection<MemoryChecker>, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool {
+ return val1.value() < val2.value();
+ });
+ EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls");
+ EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls");
+
+ std::cout << done() << std::endl;
+
+ test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_intersection<int32_t>>());
+}
new file mode 100644
@@ -0,0 +1,92 @@
+// -*- C++ -*-
+// { dg-options "-ltbb" }
+// { dg-do run { target c++17 } }
+// { dg-timeout-factor 3 }
+// { dg-require-effective-target tbb_backend }
+
+//===-- set.pass.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 "pstl/pstl_test_config.h"
+
+#ifdef PSTL_STANDALONE_TESTS
+
+#include <cmath>
+#include <chrono>
+
+#include "pstl/execution"
+#include "pstl/algorithm"
+#else
+#include <execution>
+#include <algorithm>
+#endif // PSTL_STANDALONE_TESTS
+
+#include "pstl/test_utils.h"
+
+#include "set_util.h"
+
+using namespace TestUtils;
+
+template <typename Type>
+struct test_set_symmetric_difference
+{
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
+ Compare comp)
+ {
+ using T1 = typename std::iterator_traits<InputIterator1>::value_type;
+
+ auto n1 = std::distance(first1, last1);
+ auto n2 = std::distance(first2, last2);
+ auto n = n1 + n2;
+ Sequence<T1> expect(n);
+ Sequence<T1> out(n);
+
+ auto expect_res = std::set_symmetric_difference(first1, last1, first2, last2, expect.begin(), comp);
+ auto res = std::set_symmetric_difference(exec, first1, last1, first2, last2, out.begin(), comp);
+
+ EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_symmetric_difference");
+ EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res),
+ "wrong set_symmetric_difference effect");
+ }
+
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
+ {
+ }
+};
+
+template <typename T>
+struct test_non_const_set_symmetric_difference
+{
+ template <typename Policy, typename InputIterator, typename OutputInterator>
+ void
+ operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
+ {
+ set_symmetric_difference(exec, input_iter, input_iter, input_iter, input_iter, out_iter,
+ non_const(std::less<T>()));
+ }
+};
+
+int
+main()
+{
+ test_set_op<test_set_symmetric_difference<float64_t>, float64_t, float64_t>(std::less<>());
+ test_set_op<test_set_symmetric_difference<Num<int64_t>>, Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; });
+ test_set_op<test_set_symmetric_difference<MemoryChecker>, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool {
+ return val1.value() < val2.value();
+ });
+ EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls");
+ EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls");
+
+ test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_symmetric_difference<int32_t>>());
+
+ std::cout << done() << std::endl;
+}
new file mode 100644
@@ -0,0 +1,90 @@
+// -*- C++ -*-
+// { dg-options "-ltbb" }
+// { dg-do run { target c++17 } }
+// { dg-timeout-factor 3 }
+// { dg-require-effective-target tbb_backend }
+
+//===-- set.pass.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 "pstl/pstl_test_config.h"
+
+#ifdef PSTL_STANDALONE_TESTS
+
+#include <cmath>
+#include <chrono>
+
+#include "pstl/execution"
+#include "pstl/algorithm"
+#else
+#include <execution>
+#include <algorithm>
+#endif // PSTL_STANDALONE_TESTS
+
+#include "pstl/test_utils.h"
+
+#include "set_util.h"
+
+using namespace TestUtils;
+
+template <typename Type>
+struct test_set_union
+{
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<!TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
+ Compare comp)
+ {
+ using T1 = typename std::iterator_traits<InputIterator1>::value_type;
+
+ auto n1 = std::distance(first1, last1);
+ auto n2 = std::distance(first2, last2);
+ auto n = n1 + n2;
+ Sequence<T1> expect(n);
+ Sequence<T1> out(n);
+
+ auto expect_res = std::set_union(first1, last1, first2, last2, expect.begin(), comp);
+ auto res = std::set_union(exec, first1, last1, first2, last2, out.begin(), comp);
+
+ EXPECT_TRUE(expect_res - expect.begin() == res - out.begin(), "wrong result for set_union");
+ EXPECT_EQ_N(expect.begin(), out.begin(), std::distance(out.begin(), res), "wrong set_union effect");
+ }
+
+ template <typename Policy, typename InputIterator1, typename InputIterator2, typename Compare>
+ typename std::enable_if<TestUtils::isReverse<InputIterator1>::value, void>::type
+ operator()(Policy&&, InputIterator1, InputIterator1, InputIterator2, InputIterator2, Compare)
+ {
+ }
+};
+
+template <typename T>
+struct test_non_const_set_union
+{
+ template <typename Policy, typename InputIterator, typename OutputInterator>
+ void
+ operator()(Policy&& exec, InputIterator input_iter, OutputInterator out_iter)
+ {
+ set_union(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>()));
+ }
+};
+
+int
+main()
+{
+ test_set_op<test_set_union<float64_t>, float64_t, float64_t>(std::less<>());
+ test_set_op<test_set_union<Num<int64_t>>, Num<int64_t>, Num<int32_t>>([](const Num<int64_t>& x, const Num<int32_t>& y) { return x < y; });
+ test_set_op<test_set_union<MemoryChecker>, MemoryChecker, MemoryChecker>([](const MemoryChecker& val1, const MemoryChecker& val2) -> bool {
+ return val1.value() < val2.value();
+ });
+ EXPECT_FALSE(MemoryChecker::alive_objects() < 0, "wrong effect from set algorithms: number of ctors calls < num of dtors calls");
+ EXPECT_FALSE(MemoryChecker::alive_objects() > 0, "wrong effect from set algorithms: number of ctors calls > num of dtors calls");
+
+ test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const_set_union<int32_t>>());
+
+ std::cout << done() << std::endl;
+}
new file mode 100644
@@ -0,0 +1,72 @@
+// -*- C++ -*-
+
+//===-- set.pass.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
+//
+//===----------------------------------------------------------------------===//
+#ifndef __PSTL_TEST_SET_UTIL_H
+#define __PSTL_TEST_SET_UTIL_H
+
+namespace TestUtils
+{
+ template <typename T>
+ struct Num
+ {
+ T val;
+
+ Num() : val{} {}
+ Num(const T& v) : val(v) {}
+
+ //for "includes" checks
+ template <typename T1>
+ bool
+ operator<(const Num<T1>& v1) const
+ {
+ return val < v1.val;
+ }
+
+ //The types Type1 and Type2 must be such that an object of type InputIt can be dereferenced and then implicitly converted to both of them
+ template <typename T1>
+ operator Num<T1>() const
+ {
+ return Num<T1>((T1)val);
+ }
+
+ friend bool
+ operator==(const Num& v1, const Num& v2)
+ {
+ return v1.val == v2.val;
+ }
+ };
+
+ template <typename Operation,
+ typename T1, typename T2, typename Compare>
+ void
+ test_set_op(Compare compare)
+ {
+ const std::size_t n_max = 100000;
+
+ // The rand()%(2*n+1) encourages generation of some duplicates.
+ std::srand(4200);
+
+ for (std::size_t n = 0; n < n_max; n = n <= 16 ? n + 1 : size_t(3.1415 * n))
+ {
+ for (std::size_t m = 0; m < n_max; m = m <= 16 ? m + 1 : size_t(2.71828 * m))
+ {
+ //prepare the input ranges
+ Sequence<T1> in1(n, [](std::size_t k) { return rand() % (2 * k + 1); });
+ Sequence<T2> in2(m, [m](std::size_t k) { return (m % 2) * rand() + rand() % (k + 1); });
+
+ std::sort(in1.begin(), in1.end(), compare);
+ std::sort(in2.begin(), in2.end(), compare);
+
+ invoke_on_all_policies(Operation(), in1.begin(), in1.end(), in2.cbegin(), in2.cend(),
+ compare);
+ }
+ }
+ }
+} // namespace TestUtils
+#endif // __PSTL_TEST_SET_UTIL_H
--
2.40.1