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
This commit is contained in:
Jonathan Wakely 2019-05-29 23:00:57 +01:00 committed by Jonathan Wakely
parent 3cb929a32a
commit ea16f6acb0
2 changed files with 64 additions and 8 deletions

View File

@ -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

View File

@ -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();
}