This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add experimental::sample and experimental::shuffle from N4531


On 29/06/18 10:45 +0100, Jonathan Wakely wrote:
On 29/06/18 09:39 +0200, Christophe Lyon wrote:
On Fri, 29 Jun 2018 at 09:21, Jonathan Wakely <jwakely@redhat.com> wrote:

On 29/06/18 08:55 +0200, Christophe Lyon wrote:
On Mon, 25 Jun 2018 at 18:23, Jonathan Wakely <jwakely@redhat.com> wrote:

The additions to <experimental/random> were added in 2015 but the new
algorithms in <experimental/algorithm> were not. This adds them.

        * include/experimental/algorithm (sample, shuffle): Add new overloads
        using per-thread random number engine.
        * testsuite/experimental/algorithm/sample.cc: Simpify and reduce
        dependencies by using __gnu_test::test_container.
        * testsuite/experimental/algorithm/sample-2.cc: New.
        * testsuite/experimental/algorithm/shuffle.cc: New.

Tested x86_64-linux, committed to trunk.

This would be safe to backport, but nobody has noticed the algos are
missing or complained, so it doesn't seem very important to backport.



Hi,

On bare-metal targets (aarch64 and arm + newlib), I've noticed that
the two new tests fail:
PASS: experimental/algorithm/shuffle.cc (test for excess errors)
spawn /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/utils/bin/qemu-wrapper.sh
./shuffle.exe
terminate called after throwing an instance of 'std::runtime_error'
 what():  random_device::random_device(const std::string&)

*** EXIT code 4242
FAIL: experimental/algorithm/shuffle.cc execution test

PASS: experimental/algorithm/sample-2.cc (test for excess errors)
spawn /aci-gcc-fsf/builds/gcc-fsf-gccsrc/obj-arm-none-eabi/gcc3/utils/bin/qemu-wrapper.sh
./sample-2.exe
terminate called after throwing an instance of 'std::runtime_error'
 what():  random_device::random_device(const std::string&)

*** EXIT code 4242
FAIL: experimental/algorithm/sample-2.cc execution test

Does this ring a bell?

Does the existing testsuite/experimental/random/randint.cc file fail
in the same way?


Yes it does.

And so do:
25_algorithms/make_heap/complexity.cc

This one also uses std::random_device.

23_containers/array/element_access/at_neg.cc

Hmm,

// Expected behavior is to either throw and have the uncaught
// exception end up in a terminate handler which eventually exits,
// or abort. (Depending on -fno-exceptions.)

So this is expected to XFAIL.

26_numerics/random/random_device/cons/default.cc

We should XFAIL the ones that use std::random_device, if we can
identify an effective target to describe them.

This adds a new "random_device" effective-target, so the tests are
disabled when the random_device isn't usable.

Tested powerpc64le-linux, committed to trunk. If this works for
Christophe's bare metal targets I'll backport it to gcc-8-branch too.


commit b32bcdc1dc7ff6d483a4a7223d78198b7522cbe4
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jul 4 15:44:45 2018 +0100

    Define "random_device" effective target
    
    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.

diff --git a/libstdc++-v3/testsuite/25_algorithms/make_heap/complexity.cc b/libstdc++-v3/testsuite/25_algorithms/make_heap/complexity.cc
index cca48f61e0a..069d2d0433d 100644
--- a/libstdc++-v3/testsuite/25_algorithms/make_heap/complexity.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/make_heap/complexity.cc
@@ -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>
diff --git a/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc
index 38210963f7e..5a34526a5f7 100644
--- a/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc
+++ b/libstdc++-v3/testsuite/26_numerics/random/random_device/cons/default.cc
@@ -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>
diff --git a/libstdc++-v3/testsuite/experimental/algorithm/sample-2.cc b/libstdc++-v3/testsuite/experimental/algorithm/sample-2.cc
index 541d17e08a0..ef3f7daa14c 100644
--- a/libstdc++-v3/testsuite/experimental/algorithm/sample-2.cc
+++ b/libstdc++-v3/testsuite/experimental/algorithm/sample-2.cc
@@ -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 }
 
diff --git a/libstdc++-v3/testsuite/experimental/algorithm/shuffle.cc b/libstdc++-v3/testsuite/experimental/algorithm/shuffle.cc
index ee06fbd996a..db958f600d4 100644
--- a/libstdc++-v3/testsuite/experimental/algorithm/shuffle.cc
+++ b/libstdc++-v3/testsuite/experimental/algorithm/shuffle.cc
@@ -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 }
 
diff --git a/libstdc++-v3/testsuite/experimental/random/randint.cc b/libstdc++-v3/testsuite/experimental/random/randint.cc
index e80bd858f29..90ba72ac2fc 100644
--- a/libstdc++-v3/testsuite/experimental/random/randint.cc
+++ b/libstdc++-v3/testsuite/experimental/random/randint.cc
@@ -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 }
 
diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index 7af3266f855..d8717e402df 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -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)] \

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]