1 //===- llvm/unittest/Support/ParallelTest.cpp -----------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// Parallel.h unit tests. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #include "llvm/Support/Parallel.h" 16 #include "gtest/gtest.h" 17 #include <array> 18 #include <random> 19 20 uint32_t array[1024 * 1024]; 21 22 using namespace llvm; 23 24 // Tests below are hanging up on mingw. Investigating. 25 #if !defined(__MINGW32__) 26 27 TEST(Parallel, sort) { 28 std::mt19937 randEngine; 29 std::uniform_int_distribution<uint32_t> dist; 30 31 for (auto &i : array) 32 i = dist(randEngine); 33 34 sort(parallel::par, std::begin(array), std::end(array)); 35 ASSERT_TRUE(std::is_sorted(std::begin(array), std::end(array))); 36 } 37 38 TEST(Parallel, parallel_for) { 39 // We need to test the case with a TaskSize > 1. We are white-box testing 40 // here. The TaskSize is calculated as (End - Begin) / 1024 at the time of 41 // writing. 42 uint32_t range[2050]; 43 std::fill(range, range + 2050, 1); 44 for_each_n(parallel::par, 0, 2049, [&range](size_t I) { ++range[I]; }); 45 46 uint32_t expected[2049]; 47 std::fill(expected, expected + 2049, 2); 48 ASSERT_TRUE(std::equal(range, range + 2049, expected)); 49 // Check that we don't write past the end of the requested range. 50 ASSERT_EQ(range[2049], 1u); 51 } 52 53 #endif 54