public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-patches@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH 1/2] Unpick cygpath TESTSUITE
Date: Sun,  2 May 2021 16:25:35 +0100	[thread overview]
Message-ID: <20210502152537.32312-2-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20210502152537.32312-1-jon.turney@dronecode.org.uk>

Rather than having testsuite.h do various things, depending on defines,
just have it do one thing, and then explicitly redirect to test stubs in
path.cc when building test.
---
 winsup/utils/path.cc      | 31 +++++++++++++------------------
 winsup/utils/path.h       | 10 ++++++++--
 winsup/utils/testsuite.cc | 31 ++++++++++++++++---------------
 winsup/utils/testsuite.h  | 34 +++++++++++-----------------------
 4 files changed, 48 insertions(+), 58 deletions(-)

diff --git a/winsup/utils/path.cc b/winsup/utils/path.cc
index 29344be02..0d41a45d8 100644
--- a/winsup/utils/path.cc
+++ b/winsup/utils/path.cc
@@ -25,7 +25,6 @@ details. */
 #include "../cygwin/include/sys/mount.h"
 #define _NOMNTENT_MACROS
 #include "../cygwin/include/mntent.h"
-#include "testsuite.h"
 #ifdef FSTAB_ONLY
 #include <sys/cygwin.h>
 #endif
@@ -255,14 +254,8 @@ readlink (HANDLE fh, char *path, size_t maxlen)
 }
 #endif /* !FSTAB_ONLY */
 
-#ifndef TESTSUITE
 mnt_t mount_table[255];
 int max_mount_entry;
-#else
-#  define TESTSUITE_MOUNT_TABLE
-#  include "testsuite.h"
-#  undef TESTSUITE_MOUNT_TABLE
-#endif
 
 inline void
 unconvert_slashes (char* name)
@@ -271,9 +264,6 @@ unconvert_slashes (char* name)
     *name++ = '\\';
 }
 
-/* These functions aren't called when defined(TESTSUITE) which results
-   in a compiler warning.  */
-#ifndef TESTSUITE
 inline char *
 skip_ws (char *in)
 {
@@ -555,11 +545,8 @@ from_fstab (bool user, PWCHAR path, PWCHAR path_end)
   CloseHandle (h);
 }
 #endif /* !FSTAB_ONLY */
-#endif /* !TESTSUITE */
 
 #ifndef FSTAB_ONLY
-
-#ifndef TESTSUITE
 static int
 mnt_sort (const void *a, const void *b)
 {
@@ -653,7 +640,11 @@ read_mounts ()
   from_fstab (true, path, path_end);
   qsort (mount_table, max_mount_entry, sizeof (mnt_t), mnt_sort);
 }
-#endif /* !defined(TESTSUITE) */
+
+#ifdef TESTSUITE
+#define read_mounts testsuite_read_mounts
+#endif
+
 
 /* Return non-zero if PATH1 is a prefix of PATH2.
    Both are assumed to be of the same path style and / vs \ usage.
@@ -757,6 +748,11 @@ concat (const char *s, ...)
   return vconcat (s, v);
 }
 
+#ifdef TESTSUITE
+#undef GetCurrentDirectory
+#define GetCurrentDirectory testsuite_getcwd
+#endif
+
 /* This is a helper function for when vcygpath is passed what appears
    to be a relative POSIX path.  We take a Win32 CWD (either as specified
    in 'cwd' or as retrieved with GetCurrentDirectory() if 'cwd' is NULL)
@@ -822,10 +818,9 @@ vcygpath (const char *cwd, const char *s, va_list v)
   size_t max_len = 0;
   mnt_t *m, *match = NULL;
 
-#ifndef TESTSUITE
   if (!max_mount_entry)
     read_mounts ();
-#endif
+
   char *path;
   if (s[0] == '.' && isslash (s[1]))
     s += 2;
@@ -912,10 +907,10 @@ extern "C" FILE *
 setmntent (const char *, const char *)
 {
   m = mount_table;
-#ifndef TESTSUITE
+
   if (!max_mount_entry)
     read_mounts ();
-#endif
+
   return NULL;
 }
 
diff --git a/winsup/utils/path.h b/winsup/utils/path.h
index a1840a003..c64f6ebfb 100644
--- a/winsup/utils/path.h
+++ b/winsup/utils/path.h
@@ -6,6 +6,9 @@ This software is a copyrighted work licensed under the terms of the
 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
 details. */
 
+#ifndef _PATH_H_
+#define _PATH_H_
+
 struct mnt_t
 {
   char *native;
@@ -22,11 +25,14 @@ int get_word (HANDLE, int);
 int get_dword (HANDLE, int);
 bool from_fstab_line (mnt_t *m, char *line, bool user);
 
-#ifndef TESTSUITE
 extern mnt_t mount_table[255];
 extern int max_mount_entry;
-#endif
 
 #ifndef SYMLINK_MAX
 #define SYMLINK_MAX 4095  /* PATH_MAX - 1 */
 #endif
+
+DWORD testsuite_getcwd (DWORD nBufferLength, LPSTR lpBuffer);
+void testsuite_read_mounts (void);
+
+#endif
diff --git a/winsup/utils/testsuite.cc b/winsup/utils/testsuite.cc
index 23ed8e0d8..ef9f14fa7 100644
--- a/winsup/utils/testsuite.cc
+++ b/winsup/utils/testsuite.cc
@@ -15,22 +15,9 @@ details. */
 #include <unistd.h>
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
-#ifndef TESTSUITE
-#define TESTSUITE
-#endif
+#include "path.h"
 #include "testsuite.h"
 
-typedef struct
-  {
-    const char *cwd;    /* in win32 form, as if by GetCurrentDirectory */
-    const char *posix;  /* input */
-    const char *win32;  /* expected output */
-  } test_t;
-
-#define TESTSUITE_TESTS
-#include "testsuite.h"
-#undef TESTSUITE_TESTS
-
 static int curtest;
 
 /* A replacement for the w32api GetCurrentDirectory() that returns
@@ -55,7 +42,21 @@ testsuite_getcwd (DWORD nBufferLength, LPSTR lpBuffer)
   return len;
 }
 
-extern char *cygpath (const char *s, ...);
+/*
+  A replacement for read_mounts that installs the test mount table
+ */
+void
+testsuite_read_mounts (void)
+{
+  int i;
+  for (i = 0; test_mount_table[i].posix; i++)
+    {
+      mount_table[i] = test_mount_table[i];
+    }
+  max_mount_entry = i;
+}
+
+WCHAR cygwin_dll_path[32768];
 
 int
 main (int argc, char **argv)
diff --git a/winsup/utils/testsuite.h b/winsup/utils/testsuite.h
index 0dd631539..c3d9ad60d 100644
--- a/winsup/utils/testsuite.h
+++ b/winsup/utils/testsuite.h
@@ -6,6 +6,10 @@ This software is a copyrighted work licensed under the terms of the
 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
 details. */
 
+#include "path.h"
+#include "../cygwin/include/cygwin/bits.h"
+#include "../cygwin/include/sys/mount.h"
+
 /* This file implements a test harness for the MinGW implementation of
    POSIX path translation in utils/path.cc.  This code is used by strace
    and cygcheck which cannot depend on the Cygwin DLL.  The tests below
@@ -13,9 +17,6 @@ details. */
    absolute paths from POSIX form to Win32 form based on the contents of
    a mount table.  */
 
-/* Including this file should be a no-op if TESTSUITE is not defined.  */
-#ifdef TESTSUITE
-
 /* These definitions are common to both the testsuite mount table
    as well as the testsuite definitions themselves, so define them
    here so that they are only defined in one location.  */
@@ -26,9 +27,7 @@ details. */
    This is used in place of actually reading the host mount
    table from the registry for the duration of the testsuite.  This
    table should match the battery of tests below.  */
-
-#if defined(TESTSUITE_MOUNT_TABLE)
-static mnt_t mount_table[] = {
+static mnt_t test_mount_table[] = {
 /* native                 posix               flags */
  { (char*)TESTSUITE_ROOT,        (char*)"/",                MOUNT_SYSTEM},
  { (char*)"O:\\other",           (char*)"/otherdir",        MOUNT_SYSTEM},
@@ -39,12 +38,16 @@ static mnt_t mount_table[] = {
  { NULL,                  (char*)NULL,               0}
 };
 
+typedef struct
+  {
+    const char *cwd;    /* in win32 form, as if by GetCurrentDirectory */
+    const char *posix;  /* input */
+    const char *win32;  /* expected output */
+  } test_t;
 
 /* Define the main set of tests.  This is defined here instead of in
    testsuite.cc so that all test harness data is in one place and not
    spread over several files.  */
-
-#elif defined(TESTSUITE_TESTS)
 #define NO_CWD "N/A"
 static test_t testsuite_tests[] = {
  { NO_CWD,                     "/file.ext",              TESTSUITE_ROOT"\\file.ext" },
@@ -112,18 +115,3 @@ static test_t testsuite_tests[] = {
  { NO_CWD,                     "//server/share/foo/bar", "\\\\server\\share\\foo\\bar" },
  { NO_CWD,                     NULL,                     NULL }
 };
-
-#else
-
-/* Redirect calls to GetCurrentDirectory() to the testsuite instead.  */
-#ifdef GetCurrentDirectory
-#undef GetCurrentDirectory
-#endif
-#define GetCurrentDirectory testsuite_getcwd
-
-DWORD testsuite_getcwd (DWORD, LPSTR);
-
-#endif
-
-#endif /* TESTSUITE */
-
-- 
2.31.1


  reply	other threads:[~2021-05-02 15:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-02 15:25 [PATCH 0/2] Improve automake object file location for utils/mingw/ Jon Turney
2021-05-02 15:25 ` Jon Turney [this message]
2021-05-02 15:25 ` [PATCH 2/2] Move source files used in utils/mingw/ into that subdirectory Jon Turney
2021-05-03 10:48   ` Corinna Vinschen
2021-05-04 18:34     ` Jon Turney
2021-05-06  8:43       ` Corinna Vinschen
2021-05-09 15:16         ` Jon Turney
2021-05-10  7:51           ` Corinna Vinschen
2021-05-09 15:09 ` [PATCH 3/2] Get rid of relative include paths in strace.cc Jon Turney
2021-05-10  8:09   ` Corinna Vinschen

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=20210502152537.32312-2-jon.turney@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-patches@cygwin.com \
    /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).