Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/test/src/dirent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ add_libc_unittest(
libc.src.dirent.opendir
libc.src.dirent.readdir
libc.src.errno.errno
libc.test.UnitTest.ErrnoCheckingTest
)

13 changes: 5 additions & 8 deletions libc/test/src/dirent/dirent_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
//===----------------------------------------------------------------------===//

#include "src/__support/CPP/string_view.h"
#include "src/__support/libc_errno.h"
#include "src/dirent/closedir.h"
#include "src/dirent/dirfd.h"
#include "src/dirent/opendir.h"
#include "src/dirent/readdir.h"

#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"

#include <dirent.h>

using LlvmLibcDirentTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
using string_view = LIBC_NAMESPACE::cpp::string_view;

TEST(LlvmLibcDirentTest, SimpleOpenAndRead) {
TEST_F(LlvmLibcDirentTest, SimpleOpenAndRead) {
::DIR *dir = LIBC_NAMESPACE::opendir("testdata");
ASSERT_TRUE(dir != nullptr);
// The file descriptors 0, 1 and 2 are reserved for standard streams.
Expand Down Expand Up @@ -54,18 +55,14 @@ TEST(LlvmLibcDirentTest, SimpleOpenAndRead) {
ASSERT_EQ(LIBC_NAMESPACE::closedir(dir), 0);
}

TEST(LlvmLibcDirentTest, OpenNonExistentDir) {
libc_errno = 0;
TEST_F(LlvmLibcDirentTest, OpenNonExistentDir) {
::DIR *dir = LIBC_NAMESPACE::opendir("___xyz123__.non_existent__");
ASSERT_TRUE(dir == nullptr);
ASSERT_ERRNO_EQ(ENOENT);
libc_errno = 0;
}

TEST(LlvmLibcDirentTest, OpenFile) {
libc_errno = 0;
TEST_F(LlvmLibcDirentTest, OpenFile) {
::DIR *dir = LIBC_NAMESPACE::opendir("testdata/file1.txt");
ASSERT_TRUE(dir == nullptr);
ASSERT_ERRNO_EQ(ENOTDIR);
libc_errno = 0;
}
3 changes: 3 additions & 0 deletions libc/test/src/fcntl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_libc_unittest(
libc.src.fcntl.creat
libc.src.fcntl.open
libc.src.unistd.close
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)

Expand All @@ -32,6 +33,7 @@ add_libc_unittest(
libc.src.unistd.getpid
libc.hdr.types.struct_flock
libc.hdr.fcntl_macros
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)

Expand All @@ -48,5 +50,6 @@ add_libc_unittest(
libc.src.fcntl.openat
libc.src.unistd.close
libc.src.unistd.read
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
6 changes: 4 additions & 2 deletions libc/test/src/fcntl/creat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/libc_errno.h"
#include "src/fcntl/creat.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"

#include <sys/stat.h>

TEST(LlvmLibcCreatTest, CreatAndOpen) {
using LlvmLibcCreatTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcCreatTest, CreatAndOpen) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/creat.test";
int fd = LIBC_NAMESPACE::creat(TEST_FILE, S_IRWXU);
Expand Down
19 changes: 10 additions & 9 deletions libc/test/src/fcntl/fcntl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@
#include "hdr/fcntl_macros.h"
#include "hdr/stdio_macros.h"
#include "hdr/types/struct_flock.h"
#include "src/__support/libc_errno.h"
#include "src/fcntl/fcntl.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/getpid.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"

#include <sys/stat.h> // For S_IRWXU

TEST(LlvmLibcFcntlTest, FcntlDupfd) {
using LlvmLibcFcntlTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcFcntlTest, FcntlDupfd) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_dup.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
Expand All @@ -41,7 +43,7 @@ TEST(LlvmLibcFcntlTest, FcntlDupfd) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd3), Succeeds(0));
}

TEST(LlvmLibcFcntlTest, FcntlGetFl) {
TEST_F(LlvmLibcFcntlTest, FcntlGetFl) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getfl.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
Expand All @@ -57,7 +59,7 @@ TEST(LlvmLibcFcntlTest, FcntlGetFl) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}

TEST(LlvmLibcFcntlTest, FcntlSetFl) {
TEST_F(LlvmLibcFcntlTest, FcntlSetFl) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_setfl.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
Expand Down Expand Up @@ -92,7 +94,7 @@ TEST(LlvmLibcFcntlTest, FcntlSetFl) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}

TEST(LlvmLibcFcntlTest, FcntlGetLkRead) {
TEST_F(LlvmLibcFcntlTest, FcntlGetLkRead) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkread.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
Expand Down Expand Up @@ -124,7 +126,7 @@ TEST(LlvmLibcFcntlTest, FcntlGetLkRead) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}

TEST(LlvmLibcFcntlTest, FcntlGetLkWrite) {
TEST_F(LlvmLibcFcntlTest, FcntlGetLkWrite) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkwrite.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
Expand Down Expand Up @@ -155,7 +157,7 @@ TEST(LlvmLibcFcntlTest, FcntlGetLkWrite) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}

TEST(LlvmLibcFcntlTest, UseAfterClose) {
TEST_F(LlvmLibcFcntlTest, UseAfterClose) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_use_after_close.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
Expand All @@ -165,8 +167,7 @@ TEST(LlvmLibcFcntlTest, UseAfterClose) {
ASSERT_ERRNO_EQ(EBADF);
}

TEST(LlvmLibcFcntlTest, SetGetOwnerTest) {
libc_errno = 0;
TEST_F(LlvmLibcFcntlTest, SetGetOwnerTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
pid_t pid = LIBC_NAMESPACE::getpid();
ASSERT_GT(pid, -1);
Expand Down
8 changes: 5 additions & 3 deletions libc/test/src/fcntl/openat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/fcntl/openat.h"
#include "src/unistd/close.h"
#include "src/unistd/read.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"

#include "hdr/fcntl_macros.h"

TEST(LlvmLibcUniStd, OpenAndReadTest) {
using LlvmLibcOpenAtTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcOpenAtTest, OpenAndReadTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "openat.test";
Expand All @@ -36,7 +38,7 @@ TEST(LlvmLibcUniStd, OpenAndReadTest) {
ASSERT_THAT(LIBC_NAMESPACE::close(dir_fd), Succeeds(0));
}

TEST(LlvmLibcUniStd, FailTest) {
TEST_F(LlvmLibcOpenAtTest, FailTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
EXPECT_THAT(LIBC_NAMESPACE::openat(AT_FDCWD, "openat.test", O_RDONLY),
Fails(ENOENT));
Expand Down
6 changes: 6 additions & 0 deletions libc/test/src/sched/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_libc_unittest(
libc.src.errno.errno
libc.src.sched.sched_getaffinity
libc.src.sched.sched_setaffinity
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)

Expand All @@ -26,6 +27,7 @@ add_libc_unittest(
DEPENDS
libc.src.errno.errno
libc.src.sched.sched_yield
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand All @@ -39,6 +41,7 @@ add_libc_unittest(
libc.src.errno.errno
libc.src.sched.sched_get_priority_min
libc.src.sched.sched_get_priority_max
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand Down Expand Up @@ -70,6 +73,7 @@ add_libc_unittest(
libc.src.sched.sched_get_priority_min
libc.src.sched.sched_get_priority_max
libc.src.unistd.getuid
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand All @@ -87,6 +91,7 @@ add_libc_unittest(
libc.src.sched.sched_get_priority_min
libc.src.sched.sched_rr_get_interval
libc.src.unistd.getuid
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand All @@ -104,5 +109,6 @@ add_libc_unittest(
libc.src.errno.errno
libc.src.sched.sched_getaffinity
libc.src.sched.__sched_getcpucount
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
13 changes: 5 additions & 8 deletions libc/test/src/sched/affinity_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
//===----------------------------------------------------------------------===//

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/libc_errno.h"
#include "src/sched/sched_getaffinity.h"
#include "src/sched/sched_setaffinity.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"

#include "hdr/types/cpu_set_t.h"
#include "hdr/types/pid_t.h"
#include <sys/syscall.h>

TEST(LlvmLibcSchedAffinityTest, SmokeTest) {
using LlvmLibcSchedAffinityTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcSchedAffinityTest, SmokeTest) {
cpu_set_t mask;
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
ASSERT_GT(tid, pid_t(0));
Expand All @@ -29,19 +30,15 @@ TEST(LlvmLibcSchedAffinityTest, SmokeTest) {
Succeeds(0));
}

TEST(LlvmLibcSchedAffinityTest, BadMask) {
TEST_F(LlvmLibcSchedAffinityTest, BadMask) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);

libc_errno = 0;
ASSERT_THAT(
LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), nullptr),
Fails(EFAULT));

libc_errno = 0;
ASSERT_THAT(
LIBC_NAMESPACE::sched_setaffinity(tid, sizeof(cpu_set_t), nullptr),
Fails(EFAULT));

libc_errno = 0;
}
7 changes: 4 additions & 3 deletions libc/test/src/sched/cpu_count_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
//===----------------------------------------------------------------------===//

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/libc_errno.h"
#include "src/sched/sched_getaffinity.h"
#include "src/sched/sched_getcpucount.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"

#include "hdr/sched_macros.h"
#include "hdr/types/cpu_set_t.h"
#include "hdr/types/pid_t.h"

TEST(LlvmLibcSchedCpuCountTest, SmokeTest) {
using LlvmLibcSchedCpuCountTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcSchedCpuCountTest, SmokeTest) {
cpu_set_t mask;
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
ASSERT_GT(tid, pid_t(0));
Expand Down
10 changes: 5 additions & 5 deletions libc/test/src/sched/get_priority_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/libc_errno.h"
#include "src/sched/sched_get_priority_max.h"
#include "src/sched/sched_get_priority_min.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"

#include "hdr/sched_macros.h"

TEST(LlvmLibcSchedGetPriorityTest, HandleBadPolicyTest) {
using LlvmLibcSchedGetPriorityTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcSchedGetPriorityTest, HandleBadPolicyTest) {

// Test arbitrary values for which there is no policy.
{
Expand Down Expand Up @@ -57,9 +59,7 @@ TEST(LlvmLibcSchedGetPriorityTest, HandleBadPolicyTest) {
}
}

TEST(LlvmLibcSchedGetPriorityTest, SmokeTest) {
libc_errno = 0;

TEST_F(LlvmLibcSchedGetPriorityTest, SmokeTest) {
// We Test:
// SCHED_OTHER, SCHED_FIFO, SCHED_RR
// Linux specific test could also include:
Expand Down
1 change: 0 additions & 1 deletion libc/test/src/sched/getcpu_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//

#include "src/__support/OSUtil/syscall.h"
#include "src/__support/libc_errno.h"
#include "src/sched/getcpu.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
Expand Down
Loading
Loading