1 //===- llvm/unittest/Support/ParallelTest.cpp -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Parallel.h unit tests.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Support/Parallel.h"
16 #include "gtest/gtest.h"
20 uint32_t array[1024 * 1024];
24 TEST(Parallel, sort) {
25 std::mt19937 randEngine;
26 std::uniform_int_distribution<uint32_t> dist;
31 sort(parallel::par, std::begin(array), std::end(array));
32 ASSERT_TRUE(std::is_sorted(std::begin(array), std::end(array)));
35 TEST(Parallel, parallel_for) {
36 // We need to test the case with a TaskSize > 1. We are white-box testing
37 // here. The TaskSize is calculated as (End - Begin) / 1024 at the time of
40 std::fill(range, range + 2050, 1);
41 for_each_n(parallel::par, 0, 2049, [&range](size_t I) { ++range[I]; });
43 uint32_t expected[2049];
44 std::fill(expected, expected + 2049, 2);
45 ASSERT_TRUE(std::equal(range, range + 2049, expected));
46 // Check that we don't write past the end of the requested range.
47 ASSERT_EQ(range[2049], 1u);