public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r10-9589] libstdc++: Make "nonexistent" paths less predictable in filesystem tests
Date: Mon, 29 Mar 2021 20:03:00 +0000 (GMT)	[thread overview]
Message-ID: <20210329200300.AA341385042D@sourceware.org> (raw)

https://gcc.gnu.org/g:86116175a37f9861a233fb0a53b6d904dcfa1833

commit r10-9589-g86116175a37f9861a233fb0a53b6d904dcfa1833
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Feb 12 15:13:02 2021 +0000

    libstdc++: Make "nonexistent" paths less predictable in filesystem tests
    
    The helper function for creating new paths doesn't work well on Windows,
    because the PID of a process started by Wine is very consistent and so
    the same path gets created each time.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/util/testsuite_fs.h (nonexistent_path): Add
            random number to the path.
    
    (cherry picked from commit 4179ec107943bea360b8aa75e29e2c5ad9f13e9e)

Diff:
---
 libstdc++-v3/testsuite/util/testsuite_fs.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/testsuite/util/testsuite_fs.h b/libstdc++-v3/testsuite/util/testsuite_fs.h
index 76d5e218924..69e5edc3cd4 100644
--- a/libstdc++-v3/testsuite/util/testsuite_fs.h
+++ b/libstdc++-v3/testsuite/util/testsuite_fs.h
@@ -34,8 +34,13 @@ namespace test_fs = std::experimental::filesystem;
 #include <fstream>
 #include <string>
 #include <cstdio>
-#include <stdlib.h>
-#include <unistd.h>
+
+#if defined(_GNU_SOURCE) || _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L
+#include <stdlib.h> // mkstemp
+#include <unistd.h> // unlink, close
+#else
+#include <random>   // std::random_device
+#endif
 
 namespace __gnu_test
 {
@@ -121,13 +126,13 @@ namespace __gnu_test
     if (file.length() > 64)
       file.resize(64);
     char buf[128];
-    static int counter;
+    static unsigned counter = std::random_device{}();
 #if _GLIBCXX_USE_C99_STDIO
     std::snprintf(buf, 128,
 #else
     std::sprintf(buf,
 #endif
-      "filesystem-test.%d.%lu-%s", counter++, (unsigned long) ::getpid(),
+      "filesystem-test.%u.%lu-%s", counter++, (unsigned long) ::getpid(),
       file.c_str());
     p = buf;
 #endif


                 reply	other threads:[~2021-03-29 20:03 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=20210329200300.AA341385042D@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@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).