[libc-commits] [libc] [libc] Update errno usage in integration tests. (PR #158147)
via libc-commits
libc-commits at lists.llvm.org
Thu Sep 11 13:16:58 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Alexey Samsonov (vonosmas)
<details>
<summary>Changes</summary>
Instead of using libc_errno directly, include <errno.h> and use regular "errno" in the code. (to verify that errno-as-an-interface works properly).
This is the recipe prescribed in the libc/src/__support/libc_errno.h header - let's actually follow it in the integration tests.
---
Full diff: https://github.com/llvm/llvm-project/pull/158147.diff
6 Files Affected:
- (modified) libc/test/IntegrationTest/test.h (+3-3)
- (modified) libc/test/integration/src/pthread/pthread_create_test.cpp (+2-3)
- (modified) libc/test/integration/src/pthread/pthread_join_test.cpp (+3-3)
- (modified) libc/test/integration/src/pthread/pthread_name_test.cpp (+1-1)
- (modified) libc/test/integration/src/unistd/getcwd_test.cpp (+3-4)
- (modified) libc/test/integration/startup/linux/tls_test.cpp (+1-1)
``````````diff
diff --git a/libc/test/IntegrationTest/test.h b/libc/test/IntegrationTest/test.h
index 24c007d2e12e6..4a03f7aa6318b 100644
--- a/libc/test/IntegrationTest/test.h
+++ b/libc/test/IntegrationTest/test.h
@@ -68,9 +68,9 @@
////////////////////////////////////////////////////////////////////////////////
// Errno checks.
-#define ASSERT_ERRNO_EQ(VAL) ASSERT_EQ(VAL, static_cast<int>(libc_errno))
-#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(libc_errno))
-#define ASSERT_ERRNO_FAILURE() ASSERT_NE(0, static_cast<int>(libc_errno))
+#define ASSERT_ERRNO_EQ(VAL) ASSERT_EQ(VAL, static_cast<int>(errno))
+#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(errno))
+#define ASSERT_ERRNO_FAILURE() ASSERT_NE(0, static_cast<int>(errno))
// Integration tests are compiled with -ffreestanding which stops treating
// the main function as a non-overloadable special function. Hence, we use a
diff --git a/libc/test/integration/src/pthread/pthread_create_test.cpp b/libc/test/integration/src/pthread/pthread_create_test.cpp
index aecbad6514aaa..abd348e707c09 100644
--- a/libc/test/integration/src/pthread/pthread_create_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_create_test.cpp
@@ -29,10 +29,9 @@
#include "src/__support/CPP/new.h"
#include "src/__support/threads/thread.h"
-#include "src/__support/libc_errno.h"
-
#include "test/IntegrationTest/test.h"
+#include <errno.h>
#include <linux/param.h> // For EXEC_PAGESIZE.
#include <pthread.h>
@@ -332,7 +331,7 @@ static void run_failure_tests() {
}
TEST_MAIN() {
- libc_errno = 0;
+ errno = 0;
run_success_tests();
run_failure_tests();
return 0;
diff --git a/libc/test/integration/src/pthread/pthread_join_test.cpp b/libc/test/integration/src/pthread/pthread_join_test.cpp
index 5d0bcd8e23658..6dea99de1a64f 100644
--- a/libc/test/integration/src/pthread/pthread_join_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_join_test.cpp
@@ -9,9 +9,9 @@
#include "src/pthread/pthread_create.h"
#include "src/pthread/pthread_join.h"
-#include "src/__support/libc_errno.h"
-
#include "test/IntegrationTest/test.h"
+
+#include <errno.h>
#include <pthread.h>
static void *simpleFunc(void *) { return nullptr; }
@@ -25,7 +25,7 @@ static void nullJoinTest() {
}
TEST_MAIN() {
- libc_errno = 0;
+ errno = 0;
nullJoinTest();
return 0;
}
diff --git a/libc/test/integration/src/pthread/pthread_name_test.cpp b/libc/test/integration/src/pthread/pthread_name_test.cpp
index 343a22356593a..d2a5ffc544ec9 100644
--- a/libc/test/integration/src/pthread/pthread_name_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_name_test.cpp
@@ -8,7 +8,6 @@
#include "hdr/stdint_proxy.h" // uintptr_t
#include "src/__support/CPP/string_view.h"
-#include "src/__support/libc_errno.h"
#include "src/pthread/pthread_create.h"
#include "src/pthread/pthread_getname_np.h"
#include "src/pthread/pthread_join.h"
@@ -20,6 +19,7 @@
#include "src/pthread/pthread_setname_np.h"
#include "test/IntegrationTest/test.h"
+#include <errno.h>
#include <pthread.h>
using string_view = LIBC_NAMESPACE::cpp::string_view;
diff --git a/libc/test/integration/src/unistd/getcwd_test.cpp b/libc/test/integration/src/unistd/getcwd_test.cpp
index 1b321b01e9315..7b87a8f0ed41c 100644
--- a/libc/test/integration/src/unistd/getcwd_test.cpp
+++ b/libc/test/integration/src/unistd/getcwd_test.cpp
@@ -7,12 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/__support/CPP/string_view.h"
-#include "src/__support/libc_errno.h"
#include "src/stdlib/getenv.h"
#include "src/unistd/getcwd.h"
#include "test/IntegrationTest/test.h"
+#include <errno.h>
#include <stdlib.h> // For malloc and free
using LIBC_NAMESPACE::cpp::string_view;
@@ -31,13 +31,12 @@ TEST_MAIN(int argc, char **argv, char **envp) {
cwd = LIBC_NAMESPACE::getcwd(buffer, 0);
ASSERT_TRUE(cwd == nullptr);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
// Insufficient size
+ errno = 0;
cwd = LIBC_NAMESPACE::getcwd(buffer, 2);
ASSERT_TRUE(cwd == nullptr);
- int err = libc_errno;
- ASSERT_EQ(err, ERANGE);
+ ASSERT_ERRNO_EQ(ERANGE);
return 0;
}
diff --git a/libc/test/integration/startup/linux/tls_test.cpp b/libc/test/integration/startup/linux/tls_test.cpp
index de3bd06c39cf6..688a94bdeb6fb 100644
--- a/libc/test/integration/startup/linux/tls_test.cpp
+++ b/libc/test/integration/startup/linux/tls_test.cpp
@@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/sys/mman/mmap.h"
#include "test/IntegrationTest/test.h"
+#include <errno.h>
#include <sys/mman.h>
constexpr int threadLocalDataSize = 101;
``````````
</details>
https://github.com/llvm/llvm-project/pull/158147
More information about the libc-commits
mailing list