blob: 688a882b96e7b2bad1d44a1713e8e56c8a7e3d65 [file] [log] [blame]
From 139a165ac72ef8294f0945025d885b1044ca6eba Mon Sep 17 00:00:00 2001
From: Dongjin Kim <dongjin_.kim@samsung.com>
Date: Tue, 25 May 2021 20:54:50 +0900
Subject: [PATCH] [f2fs] Handle unordered readdir for f2fs in
TestDirectoryReaddirRmAll
For TestDirectoryReaddirRmAll of DirectoryTest,
since results of readdir are not ordered by creation sequence in f2fs,
check whether each readdir result is correct in an alternative way.
Now it checks whether each name is 5-digit and located inside expected range
Change-Id: I5f9e640157194337bacd6f25340a9facf72b2530
---
src/storage/fs_test/directory.cc | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/storage/fs_test/directory.cc b/src/storage/fs_test/directory.cc
index bf249c2e260..6b0f15ae828 100644
--- a/src/storage/fs_test/directory.cc
+++ b/src/storage/fs_test/directory.cc
@@ -278,10 +278,28 @@ TEST_P(DirectoryTest, TestDirectoryReaddirRmAll) {
// Ignore these entries
continue;
}
- char dirname[100];
- snprintf(dirname, 100, "%05lu", i++);
- ASSERT_EQ(strcmp(de->d_name, dirname), 0) << "Unexpected dirent";
- ASSERT_EQ(unlinkat(dirfd(dir), dirname, AT_REMOVEDIR), 0);
+
+ // Results of readdir are not ordered by creation sequence in f2fs.
+ // Therefore, check whether each name is 5-digit and located inside expected range
+ if (fs().GetTraits().name == std::string_view("f2fs")) {
+ ASSERT_EQ(strlen(de->d_name), 5UL);
+
+ size_t curname_num = static_cast<size_t>(atoi(de->d_name));
+ if (curname_num == 0) {
+ // If conversion by atoi() is failed, it returns 0.
+ // Therefore, check whether the result is converted from "00000"
+ ASSERT_EQ(strcmp(de->d_name, "00000"), 0);
+ }
+
+ ASSERT_GE(curname_num, 0UL);
+ ASSERT_LT(curname_num, kNumEntries);
+ ASSERT_EQ(unlinkat(dirfd(dir), de->d_name, AT_REMOVEDIR), 0);
+ } else {
+ char dirname[100];
+ snprintf(dirname, 100, "%05lu", i++);
+ ASSERT_EQ(strcmp(de->d_name, dirname), 0) << "Unexpected dirent";
+ ASSERT_EQ(unlinkat(dirfd(dir), dirname, AT_REMOVEDIR), 0);
+ }
num_seen++;
}
--
2.25.1