gcc/libstdc++-v3/testsuite
Jonathan Wakely 5f070ba298 libstdc++: Add PRNG fallback to std::random_device
This makes std::random_device usable on VxWorks when running on older
x86 hardware. Since the r10-728 fix for PR libstdc++/85494 the library
will use the new code unconditionally on x86, but the cpuid checks for
RDSEED and RDRAND can fail at runtime, depending on the hardware where
the code is executing. If the OS does not provide /dev/urandom then this
means the std::random_device constructor always fails. In previous
releases if /dev/urandom is unavailable then std::mt19937 was used
unconditionally.

This patch adds a fallback for the case where the runtime cpuid checks
for x86 hardware instructions fail, and no /dev/urandom is available.
When this happens a std::linear_congruential_engine object will be used,
with a seed based on hashing the engine's address and the current time.
Distinct std::random_device objects will use different seeds, unless an
object is created and destroyed and a new object created at the same
memory location within the clock tick. This is not great, but is better
than always throwing from the constructor, and better than always using
std::mt19937 with the same seed (as GCC 9 and earlier do).

libstdc++-v3/ChangeLog:

	* src/c++11/random.cc (USE_LCG): Define when a pseudo-random
	fallback is needed.
	[USE_LCG] (bad_seed, construct_lcg_at, destroy_lcg_at, __lcg):
	New helper functions and callback.
	(random_device::_M_init): Add 'prng' and 'all' enumerators.
	Replace switch with fallthrough with a series of 'if' statements.
	[USE_LCG]: Construct an lcg_type engine and use __lcg when cpuid
	checks fail.
	(random_device::_M_init_pretr1) [USE_MT19937]: Accept "prng"
	token.
	(random_device::_M_getval): Check for callback unconditionally
	and always pass _M_file pointer.
	* testsuite/26_numerics/random/random_device/85494.cc: Remove
	effective-target check. Use new random_device_available helper.
	* testsuite/26_numerics/random/random_device/94087.cc: Likewise.
	* testsuite/26_numerics/random/random_device/cons/default-cow.cc:
	Remove effective-target check.
	* testsuite/26_numerics/random/random_device/cons/default.cc:
	Likewise.
	* testsuite/26_numerics/random/random_device/cons/token.cc: Use
	new random_device_available helper. Test "prng" token.
	* testsuite/util/testsuite_random.h (random_device_available):
	New helper function.
2021-03-26 19:12:12 +00:00
..
17_intro libstdc++, testsuite, Darwin : Adjust for names used in system headers. 2021-03-15 15:42:39 +00:00
18_support c++: Fix source_location inconsistency between calls from templates and non-templates [PR99672] 2021-03-25 21:35:11 +01:00
19_diagnostics libstdc++: Fix incorrect test for std::error_code comparisons 2021-02-03 15:49:36 +00:00
20_util libstdc++: Add std::is_scoped_enum for C++23 2021-03-19 20:10:56 +00:00
21_strings libstdc++: Fix and complete __gnu_debug::basic_string implementation 2021-03-25 21:56:14 +01:00
22_locale Update copyright years. 2021-01-04 10:26:59 +01:00
23_containers libstdc++: Add unordered containers heterogeneous lookup 2021-02-09 21:56:27 +01:00
24_iterators libstdc++: Add noexcept to std::begin etc as per LWG 2280 and 3537 2021-03-22 15:56:49 +00:00
25_algorithms Update copyright years. 2021-01-04 10:26:59 +01:00
26_numerics libstdc++: Add PRNG fallback to std::random_device 2021-03-26 19:12:12 +00:00
27_io libstdc++: Do not assume std::FILE is complete [PR 99270] 2021-02-25 15:35:58 +00:00
28_regex Update copyright years. 2021-01-04 10:26:59 +01:00
29_atomics Add options to link with libatomic in various tests. 2021-03-10 16:01:12 +00:00
30_threads libstdc++: Revert to old std::call_once implementation [PR 99341] 2021-03-16 12:25:28 +00:00
abi Update copyright years. 2021-01-04 10:26:59 +01:00
backward Update copyright years. 2021-01-04 10:26:59 +01:00
config Update copyright years. 2021-01-04 10:26:59 +01:00
data
decimal Update copyright years. 2021-01-04 10:26:59 +01:00
experimental libstdc++: Fix filesystem::rename on Windows [PR 98985] 2021-02-12 15:29:50 +00:00
ext libstdc++: Suppress more vstring testsuite warnings. [PR 98613] 2021-01-10 18:22:51 -05:00
lib Update copyright years. 2021-01-04 10:26:59 +01:00
libstdc++-abi Update copyright years. 2021-01-04 10:26:59 +01:00
libstdc++-dg libstdc++: Add std::experimental::simd from the Parallelism TS 2 2021-01-27 16:37:26 +00:00
libstdc++-prettyprinters Update copyright years. 2021-01-04 10:26:59 +01:00
libstdc++-xmethods Update copyright years. 2021-01-04 10:26:59 +01:00
performance Update copyright years. 2021-01-04 10:26:59 +01:00
special_functions Update copyright years. 2021-01-04 10:26:59 +01:00
std libstdc++: Improve test for views::reverse 2021-03-23 18:24:39 +00:00
tr1 Update copyright years. 2021-01-04 10:26:59 +01:00
tr2 Update copyright years. 2021-01-04 10:26:59 +01:00
util libstdc++: Add PRNG fallback to std::random_device 2021-03-26 19:12:12 +00:00
Makefile.am libstdc++: Work around test failures using -mno-tree-vrp 2021-02-03 15:49:30 +00:00
Makefile.in libstdc++: Work around test failures using -mno-tree-vrp 2021-02-03 15:49:30 +00:00