1 //===-- Unittests for mkdirat ---------------------------------------------===// 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 "src/sys/stat/mkdirat.h" 10 #include "src/unistd/rmdir.h" 11 #include "test/ErrnoSetterMatcher.h" 12 #include "utils/UnitTest/Test.h" 13 #include "utils/testutils/FDReader.h" 14 15 #include <errno.h> 16 #include <fcntl.h> 17 18 TEST(LlvmLibcMkdiratTest, CreateAndRemove) { 19 using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds; 20 constexpr const char *TEST_DIR = "testdata/mkdirat.testdir"; 21 ASSERT_THAT(__llvm_libc::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU), Succeeds(0)); 22 ASSERT_THAT(__llvm_libc::rmdir(TEST_DIR), Succeeds(0)); 23 } 24 25 TEST(LlvmLibcMkdiratTest, BadPath) { 26 using __llvm_libc::testing::ErrnoSetterMatcher::Fails; 27 ASSERT_THAT(__llvm_libc::mkdirat(AT_FDCWD, "non-existent-dir/test", S_IRWXU), 28 Fails(ENOENT)); 29 } 30