From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 8DEA33990C18; Wed, 11 Aug 2021 22:52:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DEA33990C18 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r9-9670] libstdc++: Fix test that fails randomly [PR101866] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: f8ac77533951d79d4e6a65841aa30293b2f11fdd X-Git-Newrev: 326a020be21aeec77eab9a7247c0591c56745b37 Message-Id: <20210811225258.8DEA33990C18@sourceware.org> Date: Wed, 11 Aug 2021 22:52:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Aug 2021 22:52:58 -0000 https://gcc.gnu.org/g:326a020be21aeec77eab9a7247c0591c56745b37 commit r9-9670-g326a020be21aeec77eab9a7247c0591c56745b37 Author: Jonathan Wakely Date: Wed Aug 11 22:11:19 2021 +0100 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. (cherry picked from commit 93f1dbc7cdcc4b31ea4061efb4c2acf2d4f81eb8) Diff: --- libstdc++-v3/testsuite/experimental/random/randint.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/testsuite/experimental/random/randint.cc b/libstdc++-v3/testsuite/experimental/random/randint.cc index 2b7966901f4..67197d3db7a 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