1 | //===-- Unittests for statvfs ---------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "hdr/fcntl_macros.h" |
10 | #include "src/__support/libc_errno.h" |
11 | #include "src/__support/macros/config.h" |
12 | #include "src/sys/stat/mkdirat.h" |
13 | #include "src/sys/statvfs/statvfs.h" |
14 | #include "src/unistd/rmdir.h" |
15 | #include "test/UnitTest/ErrnoCheckingTest.h" |
16 | #include "test/UnitTest/ErrnoSetterMatcher.h" |
17 | #include "test/UnitTest/Test.h" |
18 | |
19 | using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; |
20 | using LlvmLibcSysStatvfsTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; |
21 | |
22 | TEST_F(LlvmLibcSysStatvfsTest, StatvfsBasic) { |
23 | struct statvfs buf; |
24 | // The root of the file directory must always exist |
25 | ASSERT_THAT(LIBC_NAMESPACE::statvfs("/" , &buf), Succeeds()); |
26 | } |
27 | |
28 | TEST_F(LlvmLibcSysStatvfsTest, StatvfsInvalidPath) { |
29 | struct statvfs buf; |
30 | |
31 | ASSERT_THAT(LIBC_NAMESPACE::statvfs("" , &buf), Fails(ENOENT)); |
32 | |
33 | // create the file, assert it exists, then delete it and assert it doesn't |
34 | // exist anymore. |
35 | constexpr const char *FILENAME = "statvfs.testdir" ; |
36 | auto TEST_DIR = libc_make_test_file_path(FILENAME); |
37 | |
38 | // Always delete the folder so that we start in a consistent state. |
39 | LIBC_NAMESPACE::rmdir(TEST_DIR); |
40 | libc_errno = 0; // Reset errno |
41 | |
42 | ASSERT_THAT(LIBC_NAMESPACE::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU), |
43 | Succeeds(0)); |
44 | |
45 | ASSERT_THAT(LIBC_NAMESPACE::statvfs(TEST_DIR, &buf), Succeeds()); |
46 | |
47 | ASSERT_THAT(LIBC_NAMESPACE::rmdir(TEST_DIR), Succeeds(0)); |
48 | |
49 | ASSERT_THAT(LIBC_NAMESPACE::statvfs(TEST_DIR, &buf), Fails(ENOENT)); |
50 | } |
51 | |