[libc-commits] [libc] [libc] Make fstatvfs test less flakey (PR #115949)

via libc-commits libc-commits at lists.llvm.org
Tue Nov 12 14:20:40 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

<details>
<summary>Changes</summary>

Apparently I forgot to fix the filename for the fstatvfs test so that
it's different from the statvfs test, oops. This patch fixes that and
also deletes the folder if it already exists.


---
Full diff: https://github.com/llvm/llvm-project/pull/115949.diff


2 Files Affected:

- (modified) libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp (+5-1) 
- (modified) libc/test/src/sys/statvfs/linux/statvfs_test.cpp (+4) 


``````````diff
diff --git a/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp b/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp
index 9daac13321cd43..f4d71e906e2ad8 100644
--- a/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp
+++ b/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp
@@ -33,9 +33,13 @@ TEST(LlvmLibcSysFStatvfsTest, FStatvfsBasic) {
 TEST(LlvmLibcSysFStatvfsTest, FStatvfsInvalidPath) {
   struct statvfs buf;
 
-  constexpr const char *FILENAME = "statvfs.testdir";
+  constexpr const char *FILENAME = "fstatvfs.testdir";
   auto TEST_DIR = libc_make_test_file_path(FILENAME);
 
+  // Always delete the folder so that we start in a consistent state.
+  LIBC_NAMESPACE::rmdir(TEST_DIR);
+  LIBC_NAMESPACE::libc_errno = 0; // Reset errno
+
   ASSERT_THAT(LIBC_NAMESPACE::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU),
               Succeeds(0));
 
diff --git a/libc/test/src/sys/statvfs/linux/statvfs_test.cpp b/libc/test/src/sys/statvfs/linux/statvfs_test.cpp
index 68448e0530af84..32f8120e17b42e 100644
--- a/libc/test/src/sys/statvfs/linux/statvfs_test.cpp
+++ b/libc/test/src/sys/statvfs/linux/statvfs_test.cpp
@@ -33,6 +33,10 @@ TEST(LlvmLibcSysStatvfsTest, StatvfsInvalidPath) {
   constexpr const char *FILENAME = "statvfs.testdir";
   auto TEST_DIR = libc_make_test_file_path(FILENAME);
 
+  // Always delete the folder so that we start in a consistent state.
+  LIBC_NAMESPACE::rmdir(TEST_DIR);
+  LIBC_NAMESPACE::libc_errno = 0; // Reset errno
+
   ASSERT_THAT(LIBC_NAMESPACE::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU),
               Succeeds(0));
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/115949


More information about the libc-commits mailing list