1 //===- llvm/unittest/Support/ParallelTest.cpp -----------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Parallel.h unit tests.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/Parallel.h"
15 #include "gtest/gtest.h"
19 uint32_t array
[1024 * 1024];
23 // Tests below are hanging up on mingw. Investigating.
24 #if !defined(__MINGW32__)
26 TEST(Parallel
, sort
) {
27 std::mt19937 randEngine
;
28 std::uniform_int_distribution
<uint32_t> dist
;
33 sort(parallel::par
, std::begin(array
), std::end(array
));
34 ASSERT_TRUE(std::is_sorted(std::begin(array
), std::end(array
)));
37 TEST(Parallel
, parallel_for
) {
38 // We need to test the case with a TaskSize > 1. We are white-box testing
39 // here. The TaskSize is calculated as (End - Begin) / 1024 at the time of
42 std::fill(range
, range
+ 2050, 1);
43 for_each_n(parallel::par
, 0, 2049, [&range
](size_t I
) { ++range
[I
]; });
45 uint32_t expected
[2049];
46 std::fill(expected
, expected
+ 2049, 2);
47 ASSERT_TRUE(std::equal(range
, range
+ 2049, expected
));
48 // Check that we don't write past the end of the requested range.
49 ASSERT_EQ(range
[2049], 1u);