| From e15cec74f7e09c826497bdf46e06896a0d33560f Mon Sep 17 00:00:00 2001 |
| From: Dongjin Kim <dongjin_.kim@samsung.com> |
| Date: Sat, 24 Jul 2021 01:26:08 +0900 |
| Subject: [PATCH 3/5] [f2fs] Add the unordered readdir fs case in |
| TestDirectoryReaddirRmAll |
| |
| Change-Id: Idd521289e93b54097702945692df41da8727a5e4 |
| --- |
| 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 616328bd61f..b711904d8a0 100644 |
| --- a/src/storage/fs_test/directory.cc |
| +++ b/src/storage/fs_test/directory.cc |
| @@ -276,10 +276,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 do not need to be ordered by creation sequence. |
| + // 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 |
| |