summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/ModuleTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/IR/ModuleTest.cpp')
-rw-r--r--llvm/unittests/IR/ModuleTest.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ModuleTest.cpp b/llvm/unittests/IR/ModuleTest.cpp
index c5f0bcb08f3..043ea04a0c1 100644
--- a/llvm/unittests/IR/ModuleTest.cpp
+++ b/llvm/unittests/IR/ModuleTest.cpp
@@ -9,8 +9,11 @@
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Module.h"
+#include "llvm/Support/RandomNumberGenerator.h"
#include "gtest/gtest.h"
+#include <random>
+
using namespace llvm;
namespace {
@@ -45,4 +48,28 @@ TEST(ModuleTest, sortGlobalsByName) {
}
}
+TEST(ModuleTest, randomNumberGenerator) {
+ LLVMContext Context;
+ static char ID;
+ struct DummyPass : ModulePass {
+ DummyPass() : ModulePass(ID) {}
+ bool runOnModule(Module &) { return true; }
+ } DP;
+
+ Module M("R", Context);
+
+ std::uniform_int_distribution<int> dist;
+ constexpr std::size_t NBCheck = 10;
+
+ std::array<int, NBCheck> RandomStreams[2];
+ for (auto &RandomStream : RandomStreams) {
+ std::unique_ptr<RandomNumberGenerator> RNG{M.createRNG(&DP)};
+ std::generate(RandomStream.begin(), RandomStream.end(),
+ [&]() { return dist(*RNG); });
+ }
+
+ EXPECT_TRUE(std::equal(RandomStreams[0].begin(), RandomStreams[0].end(),
+ RandomStreams[1].begin()));
+}
+
} // end namespace
OpenPOWER on IntegriCloud