Skip to content

Commit d5aa5e3

Browse files
authored
[libc] Update errno usage in integration tests. (#158147)
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.
1 parent 092de9b commit d5aa5e3

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

libc/test/IntegrationTest/test.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@
6868
////////////////////////////////////////////////////////////////////////////////
6969
// Errno checks.
7070

71-
#define ASSERT_ERRNO_EQ(VAL) ASSERT_EQ(VAL, static_cast<int>(libc_errno))
72-
#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(libc_errno))
73-
#define ASSERT_ERRNO_FAILURE() ASSERT_NE(0, static_cast<int>(libc_errno))
71+
#define ASSERT_ERRNO_EQ(VAL) ASSERT_EQ(VAL, static_cast<int>(errno))
72+
#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(errno))
73+
#define ASSERT_ERRNO_FAILURE() ASSERT_NE(0, static_cast<int>(errno))
7474

7575
// Integration tests are compiled with -ffreestanding which stops treating
7676
// the main function as a non-overloadable special function. Hence, we use a

libc/test/integration/src/pthread/pthread_create_test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
#include "src/__support/CPP/new.h"
3030
#include "src/__support/threads/thread.h"
3131

32-
#include "src/__support/libc_errno.h"
33-
3432
#include "test/IntegrationTest/test.h"
3533

34+
#include <errno.h>
3635
#include <linux/param.h> // For EXEC_PAGESIZE.
3736
#include <pthread.h>
3837

@@ -332,7 +331,7 @@ static void run_failure_tests() {
332331
}
333332

334333
TEST_MAIN() {
335-
libc_errno = 0;
334+
errno = 0;
336335
run_success_tests();
337336
run_failure_tests();
338337
return 0;

libc/test/integration/src/pthread/pthread_join_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include "src/pthread/pthread_create.h"
1010
#include "src/pthread/pthread_join.h"
1111

12-
#include "src/__support/libc_errno.h"
13-
1412
#include "test/IntegrationTest/test.h"
13+
14+
#include <errno.h>
1515
#include <pthread.h>
1616

1717
static void *simpleFunc(void *) { return nullptr; }
@@ -25,7 +25,7 @@ static void nullJoinTest() {
2525
}
2626

2727
TEST_MAIN() {
28-
libc_errno = 0;
28+
errno = 0;
2929
nullJoinTest();
3030
return 0;
3131
}

libc/test/integration/src/pthread/pthread_name_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "hdr/stdint_proxy.h" // uintptr_t
1010
#include "src/__support/CPP/string_view.h"
11-
#include "src/__support/libc_errno.h"
1211
#include "src/pthread/pthread_create.h"
1312
#include "src/pthread/pthread_getname_np.h"
1413
#include "src/pthread/pthread_join.h"
@@ -20,6 +19,7 @@
2019
#include "src/pthread/pthread_setname_np.h"
2120
#include "test/IntegrationTest/test.h"
2221

22+
#include <errno.h>
2323
#include <pthread.h>
2424

2525
using string_view = LIBC_NAMESPACE::cpp::string_view;

libc/test/integration/src/unistd/getcwd_test.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/__support/CPP/string_view.h"
10-
#include "src/__support/libc_errno.h"
1110
#include "src/stdlib/getenv.h"
1211
#include "src/unistd/getcwd.h"
1312

1413
#include "test/IntegrationTest/test.h"
1514

15+
#include <errno.h>
1616
#include <stdlib.h> // For malloc and free
1717

1818
using LIBC_NAMESPACE::cpp::string_view;
@@ -31,13 +31,12 @@ TEST_MAIN(int argc, char **argv, char **envp) {
3131
cwd = LIBC_NAMESPACE::getcwd(buffer, 0);
3232
ASSERT_TRUE(cwd == nullptr);
3333
ASSERT_ERRNO_EQ(EINVAL);
34-
libc_errno = 0;
3534

3635
// Insufficient size
36+
errno = 0;
3737
cwd = LIBC_NAMESPACE::getcwd(buffer, 2);
3838
ASSERT_TRUE(cwd == nullptr);
39-
int err = libc_errno;
40-
ASSERT_EQ(err, ERANGE);
39+
ASSERT_ERRNO_EQ(ERANGE);
4140

4241
return 0;
4342
}

libc/test/integration/startup/linux/tls_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "src/__support/libc_errno.h"
109
#include "src/sys/mman/mmap.h"
1110
#include "test/IntegrationTest/test.h"
1211

12+
#include <errno.h>
1313
#include <sys/mman.h>
1414

1515
constexpr int threadLocalDataSize = 101;

0 commit comments

Comments
 (0)