diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-05-29 23:00:57 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-05-29 23:00:57 +0100 |
commit | ea16f6acb0f0bf5d8f97ebd75e1400826fc39f7f (patch) | |
tree | 0aaf23428ce47f8d825538fcff60e120ebe45fe5 | |
parent | 3cb929a32af3986ad95ca511ea84d0863c29ce57 (diff) | |
download | gcc-ea16f6acb0f0bf5d8f97ebd75e1400826fc39f7f.zip gcc-ea16f6acb0f0bf5d8f97ebd75e1400826fc39f7f.tar.gz gcc-ea16f6acb0f0bf5d8f97ebd75e1400826fc39f7f.tar.bz2 |
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
-rw-r--r-- | libstdc++-v3/ChangeLog | 4 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/26_numerics/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 2005182..4543aea 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,9 @@ 2019-05-29 Jonathan Wakely <jwakely@redhat.com> + 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 c1f3963..cf5e81e 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 // <http://www.gnu.org/licenses/>. -// 26.4.6 class random_device [rand.device] -// 26.4.6 [3] +// C++11 26.5.6 class random_device [rand.device] #include <random> +#include <stdexcept> #include <testsuite_hooks.h> 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<std::random_device::result_type>::min() ); VERIFY( x.max() == std::numeric_limits<std::random_device::result_type>::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(); } |