From 9ce70bf450003d332c258930ba4cbb57e4816815 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Wed, 28 Apr 2021 14:54:47 +0100 Subject: [PATCH] Unpick cygpath TESTSUITE 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 #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 #define WIN32_LEAN_AND_MEAN #include -#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 */ -