public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix test that fails randomly [PR101866]
Date: Wed, 11 Aug 2021 23:46:25 +0100	[thread overview]
Message-ID: <YRRTQWCJNcKym4v2@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 661 bytes --]

This test assumes that the same sequence of three values cannot occur,
which is incorect. It's unlikely, but not impossible.

Perform the check in a loop, so that in the unlikely event of an
identical sequence, we retry. If the library code is buggy it will keep
producing the same sequence and the test will time out. If the code is
working correctly then we will usually break out of the loop after one
iteration, or very rarely after two or three.

libstdc++-v3/ChangeLog:

	PR libstdc++/101866
	* testsuite/experimental/random/randint.cc: Loop and retry if
	reseed() produces the same sequence.

Tested x86_64-linux. Committed to trunk. I'll backport too.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2227 bytes --]

commit 93f1dbc7cdcc4b31ea4061efb4c2acf2d4f81eb8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Aug 11 22:11:19 2021

    libstdc++: Fix test that fails randomly [PR101866]
    
    This test assumes that the same sequence of three values cannot occur,
    which is incorect. It's unlikely, but not impossible.
    
    Perform the check in a loop, so that in the unlikely event of an
    identical sequence, we retry. If the library code is buggy it will keep
    producing the same sequence and the test will time out. If the code is
    working correctly then we will usually break out of the loop after one
    iteration, or very rarely after two or three.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/101866
            * testsuite/experimental/random/randint.cc: Loop and retry if
            reseed() produces the same sequence.

diff --git a/libstdc++-v3/testsuite/experimental/random/randint.cc b/libstdc++-v3/testsuite/experimental/random/randint.cc
index d6225eba1df..e05151e5ea0 100644
--- a/libstdc++-v3/testsuite/experimental/random/randint.cc
+++ b/libstdc++-v3/testsuite/experimental/random/randint.cc
@@ -34,7 +34,7 @@ test01()
   }
 
   std::experimental::reseed(99u);
-  const long n1[] = {
+  const int n1[] = {
     std::experimental::randint(0, 100),
     std::experimental::randint(0, 100),
     std::experimental::randint(0, 100),
@@ -42,7 +42,7 @@ test01()
     std::experimental::randint(0, 100)
   };
   std::experimental::reseed(99u);
-  const long n2[] = {
+  const int n2[] = {
     std::experimental::randint(0, 100),
     std::experimental::randint(0, 100),
     std::experimental::randint(0, 100),
@@ -52,13 +52,13 @@ test01()
   for (int i = 0; i < 5; ++i)
     VERIFY( n1[i] == n2[i] );
 
-  std::experimental::reseed();
-  const long n3[] = {
-    std::experimental::randint(0, 100),
-    std::experimental::randint(0, 100),
-    std::experimental::randint(0, 100)
-  };
-  VERIFY( !(n3[0] == n1[0] && n3[1] == n1[1] && n3[2] == n1[2]) );
+  do
+  {
+    std::experimental::reseed();
+  }
+  while (std::experimental::randint(0, 100) == n1[0]
+      && std::experimental::randint(0, 100) == n1[1]
+      && std::experimental::randint(0, 100) == n1[2]);
 }
 
 void

                 reply	other threads:[~2021-08-11 22:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YRRTQWCJNcKym4v2@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).