aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Basic/VirtualFileSystemTest.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2018-09-14 12:47:38 +0000
committerSam McCall <sam.mccall@gmail.com>2018-09-14 12:47:38 +0000
commit0ae00567ba50f90cdcfc6216c4394fe7fdcf41b1 (patch)
treed1e04991c8cb2e99503b19fd771f7057ec2cc82a /clang/unittests/Basic/VirtualFileSystemTest.cpp
parent200cd748830a8d9e1ee0c1009b2c55ffb9e859c5 (diff)
downloadllvm-0ae00567ba50f90cdcfc6216c4394fe7fdcf41b1.zip
llvm-0ae00567ba50f90cdcfc6216c4394fe7fdcf41b1.tar.gz
llvm-0ae00567ba50f90cdcfc6216c4394fe7fdcf41b1.tar.bz2
[VFS] vfs::directory_iterator yields path and file type instead of full Status
Summary: Most callers I can find are using only `getName()`. Type is used by the recursive iterator. Now we don't have to call stat() on every listed file (on most platforms). Exceptions are e.g. Solaris where readdir() doesn't include type information. On those platforms we'll still stat() - see D51918. The result is significantly faster (stat() can be slow). My motivation: this may allow us to improve clang IO on large TUs with long include search paths. Caching readdir() results may allow us to skip many stat() and open() operations on nonexistent files. Reviewers: bkramer Subscribers: fedor.sergeev, cfe-commits Differential Revision: https://reviews.llvm.org/D51921 llvm-svn: 342232
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r--clang/unittests/Basic/VirtualFileSystemTest.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp
index 3d41db7..7f89d75 100644
--- a/clang/unittests/Basic/VirtualFileSystemTest.cpp
+++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp
@@ -104,7 +104,8 @@ public:
Path(_Path.str()) {
for ( ; I != FilesAndDirs.end(); ++I) {
if (isInPath(I->first)) {
- CurrentEntry = I->second;
+ CurrentEntry =
+ vfs::directory_entry(I->second.getName(), I->second.getType());
break;
}
}
@@ -113,12 +114,13 @@ public:
++I;
for ( ; I != FilesAndDirs.end(); ++I) {
if (isInPath(I->first)) {
- CurrentEntry = I->second;
+ CurrentEntry =
+ vfs::directory_entry(I->second.getName(), I->second.getType());
break;
}
}
if (I == FilesAndDirs.end())
- CurrentEntry = vfs::Status();
+ CurrentEntry = vfs::directory_entry();
return std::error_code();
}
};
@@ -398,11 +400,11 @@ TEST(VirtualFileSystemTest, BasicRealFSIteration) {
ASSERT_FALSE(EC);
ASSERT_NE(vfs::directory_iterator(), I);
// Check either a or c, since we can't rely on the iteration order.
- EXPECT_TRUE(I->getName().endswith("a") || I->getName().endswith("c"));
+ EXPECT_TRUE(I->path().endswith("a") || I->path().endswith("c"));
I.increment(EC);
ASSERT_FALSE(EC);
ASSERT_NE(vfs::directory_iterator(), I);
- EXPECT_TRUE(I->getName().endswith("a") || I->getName().endswith("c"));
+ EXPECT_TRUE(I->path().endswith("a") || I->path().endswith("c"));
I.increment(EC);
EXPECT_EQ(vfs::directory_iterator(), I);
}
@@ -438,7 +440,7 @@ TEST(VirtualFileSystemTest, BrokenSymlinkRealFSIteration) {
<< "EC message: " << EC2.message() << "\n";
}
ASSERT_FALSE(EC);
- EXPECT_TRUE(I->getName() == _b);
+ EXPECT_TRUE(I->path() == _b);
}
}
#endif
@@ -464,7 +466,7 @@ TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) {
std::vector<std::string> Contents;
for (auto E = vfs::recursive_directory_iterator(); !EC && I != E;
I.increment(EC)) {
- Contents.push_back(I->getName());
+ Contents.push_back(I->path());
}
// Check contents, which may be in any order
@@ -507,7 +509,7 @@ TEST(VirtualFileSystemTest, BrokenSymlinkRealFSRecursiveIteration) {
I != E; I.increment(EC)) {
auto EC2 = std::make_error_code(std::errc::no_such_file_or_directory);
if (EC == EC2) {
- VisitedBrokenSymlinks.push_back(I->getName());
+ VisitedBrokenSymlinks.push_back(I->path());
continue;
}
// For bot debugging.
@@ -523,7 +525,7 @@ TEST(VirtualFileSystemTest, BrokenSymlinkRealFSRecursiveIteration) {
<< "EC message: " << EC2.message() << "\n";
}
ASSERT_FALSE(EC);
- VisitedNonBrokenSymlinks.push_back(I->getName());
+ VisitedNonBrokenSymlinks.push_back(I->path());
}
// Check visited file names.
@@ -549,7 +551,7 @@ static void checkContents(DirIter I, ArrayRef<StringRef> ExpectedOut) {
// Do not rely on iteration order to check for contents, sort both
// content vectors before comparison.
for (DirIter E; !EC && I != E; I.increment(EC))
- InputToCheck.push_back(I->getName());
+ InputToCheck.push_back(I->path());
llvm::sort(InputToCheck.begin(), InputToCheck.end());
llvm::sort(Expected.begin(), Expected.end());
@@ -656,14 +658,14 @@ TEST(VirtualFileSystemTest, HiddenInIteration) {
O->pushOverlay(Upper);
std::error_code EC;
- Lower->addRegularFile("/onlyInLow", sys::fs::owner_read);
- Lower->addRegularFile("/hiddenByMid", sys::fs::owner_read);
- Lower->addRegularFile("/hiddenByUp", sys::fs::owner_read);
- Middle->addRegularFile("/onlyInMid", sys::fs::owner_write);
- Middle->addRegularFile("/hiddenByMid", sys::fs::owner_write);
- Middle->addRegularFile("/hiddenByUp", sys::fs::owner_write);
- Upper->addRegularFile("/onlyInUp", sys::fs::owner_all);
- Upper->addRegularFile("/hiddenByUp", sys::fs::owner_all);
+ Lower->addRegularFile("/onlyInLow");
+ Lower->addDirectory("/hiddenByMid");
+ Lower->addDirectory("/hiddenByUp");
+ Middle->addRegularFile("/onlyInMid");
+ Middle->addRegularFile("/hiddenByMid");
+ Middle->addDirectory("/hiddenByUp");
+ Upper->addRegularFile("/onlyInUp");
+ Upper->addRegularFile("/hiddenByUp");
checkContents(
O->dir_begin("/", EC),
{"/hiddenByUp", "/onlyInUp", "/hiddenByMid", "/onlyInMid", "/onlyInLow"});
@@ -673,19 +675,19 @@ TEST(VirtualFileSystemTest, HiddenInIteration) {
std::error_code EC;
vfs::directory_iterator I = O->dir_begin("/", EC), E;
for ( ; !EC && I != E; I.increment(EC))
- if (I->getName() == "/hiddenByUp")
+ if (I->path() == "/hiddenByUp")
break;
ASSERT_NE(E, I);
- EXPECT_EQ(sys::fs::owner_all, I->getPermissions());
+ EXPECT_EQ(sys::fs::file_type::regular_file, I->type());
}
{
std::error_code EC;
vfs::directory_iterator I = O->dir_begin("/", EC), E;
for ( ; !EC && I != E; I.increment(EC))
- if (I->getName() == "/hiddenByMid")
+ if (I->path() == "/hiddenByMid")
break;
ASSERT_NE(E, I);
- EXPECT_EQ(sys::fs::owner_write, I->getPermissions());
+ EXPECT_EQ(sys::fs::file_type::regular_file, I->type());
}
}
@@ -792,10 +794,10 @@ TEST_F(InMemoryFileSystemTest, DirectoryIteration) {
std::error_code EC;
vfs::directory_iterator I = FS.dir_begin("/", EC);
ASSERT_FALSE(EC);
- ASSERT_EQ("/a", I->getName());
+ ASSERT_EQ("/a", I->path());
I.increment(EC);
ASSERT_FALSE(EC);
- ASSERT_EQ("/b", I->getName());
+ ASSERT_EQ("/b", I->path());
I.increment(EC);
ASSERT_FALSE(EC);
ASSERT_EQ(vfs::directory_iterator(), I);
@@ -804,7 +806,7 @@ TEST_F(InMemoryFileSystemTest, DirectoryIteration) {
ASSERT_FALSE(EC);
// When on Windows, we end up with "/b\\c" as the name. Convert to Posix
// path for the sake of the comparison.
- ASSERT_EQ("/b/c", getPosixPath(I->getName()));
+ ASSERT_EQ("/b/c", getPosixPath(I->path()));
I.increment(EC);
ASSERT_FALSE(EC);
ASSERT_EQ(vfs::directory_iterator(), I);
@@ -967,7 +969,7 @@ TEST_F(InMemoryFileSystemTest, StatusName) {
clang::vfs::directory_iterator It = NormalizedFS.dir_begin("../b", EC);
// When on Windows, we end up with "../b\\c" as the name. Convert to Posix
// path for the sake of the comparison.
- ASSERT_EQ("../b/c", getPosixPath(It->getName()));
+ ASSERT_EQ("../b/c", getPosixPath(It->path()));
}
TEST_F(InMemoryFileSystemTest, AddHardLinkToFile) {
@@ -1067,7 +1069,7 @@ TEST_F(InMemoryFileSystemTest, RecursiveIterationWithHardLink) {
std::vector<std::string> Nodes;
for (auto E = vfs::recursive_directory_iterator(); !EC && I != E;
I.increment(EC)) {
- Nodes.push_back(getPosixPath(I->getName()));
+ Nodes.push_back(getPosixPath(I->path()));
}
EXPECT_THAT(Nodes, testing::UnorderedElementsAre("/a", "/a/b", "/c", "/c/d"));
}