[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / unittests / Support / ParallelTest.cpp
blob63c71522308b52d1d26cd31da295727aead5a587
1 //===- llvm/unittest/Support/ParallelTest.cpp -----------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Parallel.h unit tests.
11 ///
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/Parallel.h"
15 #include "gtest/gtest.h"
16 #include <array>
17 #include <random>
19 uint32_t array[1024 * 1024];
21 using namespace llvm;
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;
30 for (auto &i : array)
31 i = dist(randEngine);
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
40 // writing.
41 uint32_t range[2050];
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);
52 #endif