[libc-commits] [libc] [libc] fix unit tests (PR #75361)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Wed Dec 13 09:29:15 PST 2023
https://github.com/nickdesaulniers updated https://github.com/llvm/llvm-project/pull/75361
>From bd9b1a1bad3c2e4d1e6a47e7108371a1ecf616dd Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Wed, 13 Dec 2023 09:18:51 -0800
Subject: [PATCH 1/5] [libc] fix unit tests
Fixes #75261
---
libc/test/src/fcntl/creat_test.cpp | 2 ++
libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp | 1 +
2 files changed, 3 insertions(+)
diff --git a/libc/test/src/fcntl/creat_test.cpp b/libc/test/src/fcntl/creat_test.cpp
index ca926b30e62faf..ef30d8862c45f2 100644
--- a/libc/test/src/fcntl/creat_test.cpp
+++ b/libc/test/src/fcntl/creat_test.cpp
@@ -13,6 +13,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcCreatTest, CreatAndOpen) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/creat.test";
diff --git a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
index 7e6bb0aaca9251..0870deeeb5d801 100644
--- a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
+++ b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
@@ -17,6 +17,7 @@
#include "test/UnitTest/Test.h"
#include <sys/resource.h>
+#include <sys/stat.h>
TEST(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
>From 48ba5ccf7ad3248fa91d794bb43e1b830242c8f7 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Wed, 13 Dec 2023 09:22:23 -0800
Subject: [PATCH 2/5] fix another test
---
libc/test/src/unistd/symlink_test.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libc/test/src/unistd/symlink_test.cpp b/libc/test/src/unistd/symlink_test.cpp
index 84d963b7a207ce..b25cfa4f857699 100644
--- a/libc/test/src/unistd/symlink_test.cpp
+++ b/libc/test/src/unistd/symlink_test.cpp
@@ -14,6 +14,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcSymlinkTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_BASE = "symlink.test";
>From 0efed5486b4e18b542e3a298c163caa257d5beca Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Wed, 13 Dec 2023 09:23:21 -0800
Subject: [PATCH 3/5] another fix
---
libc/test/src/unistd/syscall_test.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/test/src/unistd/syscall_test.cpp b/libc/test/src/unistd/syscall_test.cpp
index 211b27c3188c4d..7a354e1cb567fd 100644
--- a/libc/test/src/unistd/syscall_test.cpp
+++ b/libc/test/src/unistd/syscall_test.cpp
@@ -12,6 +12,7 @@
#include "test/UnitTest/Test.h"
#include <fcntl.h>
+#include <sys/stat.h> // For S_* flags.
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h>
>From be8b278a695068d802728a19098a4039d94b036f Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Wed, 13 Dec 2023 09:28:41 -0800
Subject: [PATCH 4/5] fix rest
---
libc/test/src/unistd/access_test.cpp | 1 +
libc/test/src/unistd/dup2_test.cpp | 2 ++
libc/test/src/unistd/dup3_test.cpp | 2 ++
libc/test/src/unistd/dup_test.cpp | 2 ++
libc/test/src/unistd/ftruncate_test.cpp | 2 ++
libc/test/src/unistd/isatty_test.cpp | 2 ++
libc/test/src/unistd/link_test.cpp | 2 ++
libc/test/src/unistd/linkat_test.cpp | 2 ++
libc/test/src/unistd/pread_pwrite_test.cpp | 2 ++
libc/test/src/unistd/read_write_test.cpp | 2 ++
libc/test/src/unistd/symlinkat_test.cpp | 2 ++
libc/test/src/unistd/truncate_test.cpp | 2 ++
libc/test/src/unistd/unlink_test.cpp | 2 ++
libc/test/src/unistd/unlinkat_test.cpp | 2 ++
14 files changed, 27 insertions(+)
diff --git a/libc/test/src/unistd/access_test.cpp b/libc/test/src/unistd/access_test.cpp
index ed1fe96f4f4a16..7d4b3be443fed4 100644
--- a/libc/test/src/unistd/access_test.cpp
+++ b/libc/test/src/unistd/access_test.cpp
@@ -14,6 +14,7 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
#include <unistd.h>
TEST(LlvmLibcAccessTest, CreateAndTest) {
diff --git a/libc/test/src/unistd/dup2_test.cpp b/libc/test/src/unistd/dup2_test.cpp
index ff870db0334c93..d46c4b919ce72c 100644
--- a/libc/test/src/unistd/dup2_test.cpp
+++ b/libc/test/src/unistd/dup2_test.cpp
@@ -16,6 +16,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
constexpr int DUPFD = 0xD0;
libc_errno = 0;
diff --git a/libc/test/src/unistd/dup3_test.cpp b/libc/test/src/unistd/dup3_test.cpp
index 279cfbfea1b144..d2d544d5d9a12f 100644
--- a/libc/test/src/unistd/dup3_test.cpp
+++ b/libc/test/src/unistd/dup3_test.cpp
@@ -16,6 +16,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
// The tests here are exactly the same as those of dup2. We only test the
// plumbing of the dup3 syscall and not the dup3 functionality itself as it is
// a simple syscall wrapper. Testing dup3 functionality is beyond the scope of
diff --git a/libc/test/src/unistd/dup_test.cpp b/libc/test/src/unistd/dup_test.cpp
index 38c439125db3d7..856b004fbe65d5 100644
--- a/libc/test/src/unistd/dup_test.cpp
+++ b/libc/test/src/unistd/dup_test.cpp
@@ -16,6 +16,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
diff --git a/libc/test/src/unistd/ftruncate_test.cpp b/libc/test/src/unistd/ftruncate_test.cpp
index ae743b385e220d..fc68348e32ec66 100644
--- a/libc/test/src/unistd/ftruncate_test.cpp
+++ b/libc/test/src/unistd/ftruncate_test.cpp
@@ -17,6 +17,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
namespace cpp = LIBC_NAMESPACE::cpp;
TEST(LlvmLibcFtruncateTest, CreateAndTruncate) {
diff --git a/libc/test/src/unistd/isatty_test.cpp b/libc/test/src/unistd/isatty_test.cpp
index fce4a3e5f5062a..7bf8dd708bfa6f 100644
--- a/libc/test/src/unistd/isatty_test.cpp
+++ b/libc/test/src/unistd/isatty_test.cpp
@@ -13,6 +13,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
diff --git a/libc/test/src/unistd/link_test.cpp b/libc/test/src/unistd/link_test.cpp
index b1b9383cb62ee0..2d5aa7588b08b9 100644
--- a/libc/test/src/unistd/link_test.cpp
+++ b/libc/test/src/unistd/link_test.cpp
@@ -14,6 +14,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcLinkTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/link.test";
diff --git a/libc/test/src/unistd/linkat_test.cpp b/libc/test/src/unistd/linkat_test.cpp
index 2ef41cd4e75f6a..d1ffe37d63b48c 100644
--- a/libc/test/src/unistd/linkat_test.cpp
+++ b/libc/test/src/unistd/linkat_test.cpp
@@ -14,6 +14,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcLinkatTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
diff --git a/libc/test/src/unistd/pread_pwrite_test.cpp b/libc/test/src/unistd/pread_pwrite_test.cpp
index 6819f559424f3e..f90d1341c20108 100644
--- a/libc/test/src/unistd/pread_pwrite_test.cpp
+++ b/libc/test/src/unistd/pread_pwrite_test.cpp
@@ -17,6 +17,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) {
// The strategy here is that we first create a file and write to it. Next,
// we open that file again and write at an offset. Finally, we open the
diff --git a/libc/test/src/unistd/read_write_test.cpp b/libc/test/src/unistd/read_write_test.cpp
index 20b51bb8082b12..3007d4c3871157 100644
--- a/libc/test/src/unistd/read_write_test.cpp
+++ b/libc/test/src/unistd/read_write_test.cpp
@@ -15,6 +15,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcUniStd, WriteAndReadBackTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "__unistd_read_write.test";
diff --git a/libc/test/src/unistd/symlinkat_test.cpp b/libc/test/src/unistd/symlinkat_test.cpp
index b0308787f2052a..8aba2daee8cf38 100644
--- a/libc/test/src/unistd/symlinkat_test.cpp
+++ b/libc/test/src/unistd/symlinkat_test.cpp
@@ -14,6 +14,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcSymlinkatTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
diff --git a/libc/test/src/unistd/truncate_test.cpp b/libc/test/src/unistd/truncate_test.cpp
index 15940321e5ad45..6d8a3b8e53f728 100644
--- a/libc/test/src/unistd/truncate_test.cpp
+++ b/libc/test/src/unistd/truncate_test.cpp
@@ -17,6 +17,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
namespace cpp = LIBC_NAMESPACE::cpp;
TEST(LlvmLibcTruncateTest, CreateAndTruncate) {
diff --git a/libc/test/src/unistd/unlink_test.cpp b/libc/test/src/unistd/unlink_test.cpp
index 8a64f88ee6f26d..77f65b5ecc6a1a 100644
--- a/libc/test/src/unistd/unlink_test.cpp
+++ b/libc/test/src/unistd/unlink_test.cpp
@@ -13,6 +13,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcUnlinkTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/unlink.test";
diff --git a/libc/test/src/unistd/unlinkat_test.cpp b/libc/test/src/unistd/unlinkat_test.cpp
index 5953085bf12b66..22a20bc6ad07bc 100644
--- a/libc/test/src/unistd/unlinkat_test.cpp
+++ b/libc/test/src/unistd/unlinkat_test.cpp
@@ -14,6 +14,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include <sys/stat.h>
+
TEST(LlvmLibcUnlinkatTest, CreateAndDeleteTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
>From 6ce1b59ad8544488dd20383258d63fc51b3c63ba Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Wed, 13 Dec 2023 09:28:59 -0800
Subject: [PATCH 5/5] reformat
---
libc/test/src/unistd/syscall_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/unistd/syscall_test.cpp b/libc/test/src/unistd/syscall_test.cpp
index 7a354e1cb567fd..6a5ca47f8d494a 100644
--- a/libc/test/src/unistd/syscall_test.cpp
+++ b/libc/test/src/unistd/syscall_test.cpp
@@ -12,7 +12,7 @@
#include "test/UnitTest/Test.h"
#include <fcntl.h>
-#include <sys/stat.h> // For S_* flags.
+#include <sys/stat.h> // For S_* flags.
#include <sys/syscall.h> // For syscall numbers.
#include <unistd.h>
More information about the libc-commits
mailing list