Define "random_device" effective target
authorJonathan Wakely <jwakely@redhat.com>
Wed, 4 Jul 2018 16:56:21 +0000 (17:56 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 4 Jul 2018 16:56:21 +0000 (17:56 +0100)
Currently only matches targets where _GLIBCXX_USE_RANDOM_TR1 is defined,
which means /dev/random and /dev/urandom are usable.

* testsuite/25_algorithms/make_heap/complexity.cc: Require effective
target for std::random_device.
* testsuite/26_numerics/random/random_device/cons/default.cc:
Likewise.
* testsuite/experimental/algorithm/sample-2.cc: Likewise.
* testsuite/experimental/algorithm/shuffle.cc: Likewise.
* testsuite/experimental/random/randint.cc: Likewise.
* testsuite/lib/libstdc++.exp
(check_effective_target_random_device): New proc.

From-SVN: r262415

libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/25_algorithms/make_heap/complexity.cc
libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc
libstdc++-v3/testsuite/experimental/algorithm/sample-2.cc
libstdc++-v3/testsuite/experimental/algorithm/shuffle.cc
libstdc++-v3/testsuite/experimental/random/randint.cc
libstdc++-v3/testsuite/lib/libstdc++.exp

index b1747e82cb8559f625b2c4b606148c128d32969b..24acd68751b63a6f85bbece789ab1b55efd88879 100644 (file)
@@ -1,3 +1,15 @@
+2018-07-04  Jonathan Wakely  <jwakely@redhat.com>
+
+       * testsuite/25_algorithms/make_heap/complexity.cc: Require effective
+       target for std::random_device.
+       * testsuite/26_numerics/random/random_device/cons/default.cc:
+       Likewise.
+       * testsuite/experimental/algorithm/sample-2.cc: Likewise.
+       * testsuite/experimental/algorithm/shuffle.cc: Likewise.
+       * testsuite/experimental/random/randint.cc: Likewise.
+       * testsuite/lib/libstdc++.exp
+       (check_effective_target_random_device): New proc.
+
 2018-07-04  Jonathan Wakely  <jwakely@redhat.com>
            Jakub Jelinek  <jakub@redhat.com>
 
index cca48f61e0a1c445ba0e4adcb2f0da0e256db80c..069d2d0433d1d9e56012c4f85ed0eec50012680b 100644 (file)
@@ -16,6 +16,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++11 } }
+// { dg-require-effective-target random_device }
 
 #include <random>
 #include <vector>
index 38210963f7ebb8109a5c4a598d103bc8fe3e1a0d..5a34526a5f75904a9d995d8aa5501ca25cb1816c 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++11 } }
+// { dg-require-effective-target random_device }
 // { dg-require-cstdint "" }
 //
 // 2008-11-24  Edward M. Smith-Rowland <3dw4rd@verizon.net>
index 541d17e08a0a1b26e49937197e2058622cc9c9ae..ef3f7daa14ca75aceac3fab2ffe168d6866479c1 100644 (file)
@@ -16,6 +16,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++14 } }
+// { dg-require-effective-target random_device }
 // { dg-require-effective-target tls_runtime }
 // { dg-add-options tls }
 
index ee06fbd996a8962212b77eb2d4601160447ddf8b..db958f600d4bd2b7f7beb3dbbcdb05b3e5c96e35 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++14 } }
+// { dg-require-effective-target random_device }
 // { dg-require-effective-target tls_runtime }
 // { dg-add-options tls }
 
index e80bd858f2995bb10b6dbdddf4e09acc8de1011b..90ba72ac2fc54742f06a68fa2c077ac1f23caeba 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do run { target c++14 } }
+// { dg-require-effective-target random_device }
 // { dg-require-effective-target tls_runtime }
 // { dg-add-options tls }
 
index 7af3266f855216bdce73bf4832519bdb8dc91e50..d8717e402df9ad0b7fe775f633fa6f438d5b31b0 100644 (file)
@@ -2061,6 +2061,34 @@ proc check_effective_target_cxx11-abi { } {
     return 0
 }
 
+# Return 1 if std::random_device should be usable using the current flags, 0 otherwise.
+proc check_effective_target_random_device { } {
+    global cxxflags
+
+    # Set up and preprocess a C++ test program that depends
+    # on std::random_device being usable.
+    set src random_device[pid].cc
+
+    set f [open $src "w"]
+    puts $f "#include <bits/c++config.h>"
+    puts $f "#if ! _GLIBCXX_USE_RANDOM_TR1"
+    puts $f "#  error No working std::random_device available"
+    puts $f "#endif"
+    close $f
+
+    set lines [v3_target_compile $src /dev/null preprocess ""]
+    file delete $src
+
+    if [string match "" $lines] {
+       # No error message, preprocessing succeeded.
+       verbose "check_v3_random_device: `1'" 2
+       return 1
+    }
+
+    verbose "check_v3_random_device: `0'" 2
+    return 0
+}
+
 set additional_prunes ""
 
 if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \