From ea16f6acb0f0bf5d8f97ebd75e1400826fc39f7f Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 29 May 2019 23:00:57 +0100 Subject: [PATCH] PR libstdc++/85494 fix failing test This test now fails on mingw-w64 because it's no longer always true that the mt19937 engine is used when _GLIBCXX_USE_DEV_RANDOM is not defined. Add tests for all the known tokens to ensure that at least one is accepted. * testsuite/26_numerics/random/random_device/cons/token.cc: Fix test that fails on mingw-w64. From-SVN: r271756 --- libstdc++-v3/ChangeLog | 4 ++ .../random/random_device/cons/token.cc | 68 ++++++++++++++++--- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2005182e926..4543aea7f37 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,9 @@ 2019-05-29 Jonathan Wakely + PR libstdc++/85494 + * testsuite/26_numerics/random/random_device/cons/token.cc: Fix test + that fails on mingw-w64. + PR libstdc++/88881 * src/c++17/fs_ops.cc [_GLIBCXX_FILESYSTEM_IS_WINDOWS] (status(const path&, error_code&)): Use parent_path() to remove diff --git a/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc index c1f3963e57d..cf5e81edd7b 100644 --- a/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc +++ b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/token.cc @@ -20,27 +20,79 @@ // with this library; see the file COPYING3. If not see // . -// 26.4.6 class random_device [rand.device] -// 26.4.6 [3] +// C++11 26.5.6 class random_device [rand.device] #include +#include #include void test01() { -#ifdef _GLIBCXX_USE_DEV_RANDOM - std::random_device x("/dev/random"); -#else - std::random_device x("0"); -#endif + std::random_device x("default"); VERIFY( x.min() == std::numeric_limits::min() ); VERIFY( x.max() == std::numeric_limits::max() ); + +} + +void +test02() +{ +#ifdef _GLIBCXX_USE_DEV_RANDOM + std::random_device x1("/dev/urandom"); + std::random_device x2("/dev/random"); +#endif +} + +void +test03() +{ + // At least one of these tokens should be valid. + const std::string tokens[] = { + "rdseed", "rdrand", "rand_s", "/dev/urandom", "/dev/random", "mt19337" + }; + int count = 0; + for (const std::string& token : tokens) + { + try + { + std::random_device x(token); + ++count; + } + catch (const std::runtime_error&) + { + } + } + VERIFY( count != 0 ); +} + +void +test04() +{ + bool can_use_mt19937 = true; + try + { + std::random_device x("mt19937"); + } + catch (const std::runtime_error&) + { + can_use_mt19937 = false; + } + + // If "mt19337" is a valid token then numeric seeds should be too. + if (can_use_mt19937) + { + std::random_device x1("0"); + std::random_device x2("1234"); + std::random_device x3("0xc0fefe"); + } } int main() { test01(); - return 0; + test02(); + test03(); + test04(); } -- 2.30.2