diff options
author | James Henderson <jh7370@my.bristol.ac.uk> | 2017-04-07 08:11:28 +0000 |
---|---|---|
committer | James Henderson <jh7370@my.bristol.ac.uk> | 2017-04-07 08:11:28 +0000 |
commit | 629f103ac3b479c5ff8905967de4fa2a91a434fd (patch) | |
tree | 0b8aa208dd96f1aaf8ac639f55a196eacb18c36b /lld/unittests | |
parent | abf6fefb18de0d8245b54184226d5b36e42b269b (diff) |
[Core] Fix parallel_for for Linux
r299635 exposed a latent bug in the Linux implementation of parallel_for, which
resulted in it calling the function outside of the range requested, resulting
later in a segmentation fault. This change fixes this issue and adds a unit test.
Diffstat (limited to 'lld/unittests')
-rw-r--r-- | lld/unittests/CoreTests/ParallelTest.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lld/unittests/CoreTests/ParallelTest.cpp b/lld/unittests/CoreTests/ParallelTest.cpp index c0282437e2e..f02db92c984 100644 --- a/lld/unittests/CoreTests/ParallelTest.cpp +++ b/lld/unittests/CoreTests/ParallelTest.cpp @@ -29,3 +29,18 @@ TEST(Parallel, sort) { lld::parallel_sort(std::begin(array), std::end(array)); ASSERT_TRUE(std::is_sorted(std::begin(array), std::end(array))); } + +TEST(Parallel, parallel_for) { + // We need to test the case with a TaskSize > 1. We are white-box testing + // here. The TaskSize is calculated as (End - Begin) / 1024 at the time of + // writing. + uint32_t range[2050]; + std::fill(range, range + 2050, 1); + lld::parallel_for(0, 2049, [&range](size_t I) { ++range[I]; }); + + uint32_t expected[2049]; + std::fill(expected, expected + 2049, 2); + ASSERT_TRUE(std::equal(range, range + 2049, expected)); + // Check that we don't write past the end of the requested range. + ASSERT_EQ(range[2049], 1); +} |