Skip to content

Commit 46f6e62

Browse files
authored
[LLVM][Support] Fix tests on Cygwin (#151417)
Cygwin returns -1 for `getconf(_SC_ARG_MAX)`, which makes `llvm::sys::commandLineFitsWithinSystemLimits` always return true, so skip the `ArgumentLimit` test in that case. Skip the `ArgumentLimitWindows` and `ResponseFileWindows` tests on Cygwin also as it doesn't suffer from the Windows limits either. Cygwin requires the same `dllexport` annotation as Win32 in the `DynamicLibrary` test, so add its preprocessor check to PipSqueak.h. Cygwin's `getcwd` function does not fail with `ENOENT` if the current working directory is unlinked. According to POSIX issue 8, this is not required. Skip the `PhysicalFileSystemWorkingDirFailure` test on Cygwin as it relies on this behavior.
1 parent 4c80193 commit 46f6e62

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

llvm/unittests/Support/CommandLineTest.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include <fstream>
2929
#include <stdlib.h>
3030
#include <string>
31+
#if HAVE_UNISTD_H
32+
#include <unistd.h>
33+
#endif
3134

3235
using namespace llvm;
3336
using llvm::unittest::TempDir;
@@ -834,14 +837,23 @@ TEST(CommandLineTest, DefaultOptions) {
834837
}
835838

836839
TEST(CommandLineTest, ArgumentLimit) {
837-
std::string args(32 * 4096, 'a');
838-
EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
840+
#if HAVE_UNISTD_H && defined(_SC_ARG_MAX)
841+
if (sysconf(_SC_ARG_MAX) != -1) {
842+
#endif
843+
std::string args(32 * 4096, 'a');
844+
EXPECT_FALSE(
845+
llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
846+
#if HAVE_UNISTD_H && defined(_SC_ARG_MAX)
847+
}
848+
#endif
839849
std::string args2(256, 'a');
840850
EXPECT_TRUE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args2.data()));
841851
}
842852

843853
TEST(CommandLineTest, ArgumentLimitWindows) {
844-
if (!Triple(sys::getProcessTriple()).isOSWindows())
854+
Triple processTriple(sys::getProcessTriple());
855+
if (!processTriple.isOSWindows() ||
856+
processTriple.isWindowsCygwinEnvironment())
845857
GTEST_SKIP();
846858
// We use 32000 as a limit for command line length. Program name ('cl'),
847859
// separating spaces and termination null character occupy 5 symbols.
@@ -854,7 +866,9 @@ TEST(CommandLineTest, ArgumentLimitWindows) {
854866
}
855867

856868
TEST(CommandLineTest, ResponseFileWindows) {
857-
if (!Triple(sys::getProcessTriple()).isOSWindows())
869+
Triple processTriple(sys::getProcessTriple());
870+
if (!processTriple.isOSWindows() ||
871+
processTriple.isWindowsCygwinEnvironment())
858872
GTEST_SKIP();
859873

860874
StackOption<std::string, cl::list<std::string>> InputFilenames(

llvm/unittests/Support/DynamicLibrary/PipSqueak.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <vector>
2323
#endif
2424

25-
#ifdef _WIN32
25+
#if defined(_WIN32) || defined(__CYGWIN__)
2626
#define PIPSQUEAK_EXPORT __declspec(dllexport)
2727
#elif defined(__MVS__)
2828
#define PIPSQUEAK_EXPORT __attribute__((__visibility__("default")))

llvm/unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,10 @@ TEST(VirtualFileSystemTest, PhysicalFileSystemWorkingDirFailure) {
553553
// Some platforms (e.g. Solaris) disallow removal of the working directory.
554554
GTEST_SKIP() << "test requires deletion of working directory";
555555

556+
#ifdef __CYGWIN__
557+
GTEST_SKIP() << "Cygwin getcwd succeeds with unlinked working directory";
558+
#endif
559+
556560
// Verify that we still get two separate working directories.
557561
auto FS1 = vfs::createPhysicalFileSystem();
558562
auto FS2 = vfs::createPhysicalFileSystem();

0 commit comments

Comments
 (0)