Skip to content

Commit 4769122

Browse files
authored
[libc][test] split exit tests into two separate tests (#169820)
_Exit(3) is a fairly simple syscall wrapper whereas exit(3) calls atexit-registered functions + whole lot of stuff that require support for sync primitives. Splitting the tests allows testing the former easily (especially for new port projects) --------- Signed-off-by: Shreeyash Pandey <[email protected]>
1 parent d989ff9 commit 4769122

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

libc/test/UnitTest/ExecuteFunctionUnix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, int timeout_ms) {
5757
}
5858
::close(pipe_fds[1]);
5959

60-
struct pollfd poll_fd{pipe_fds[0], POLLIN, 0};
60+
pollfd poll_fd{pipe_fds[0], POLLIN, 0};
6161
// No events requested so this call will only return after the timeout or if
6262
// the pipes peer was closed, signaling the process exited.
6363
if (::poll(&poll_fd, 1, timeout_ms) == -1) {

libc/test/src/stdlib/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,19 @@ if(LLVM_LIBC_FULL_BUILD)
448448
libc-stdlib-tests
449449
SRCS
450450
_Exit_test.cpp
451+
DEPENDS
452+
libc.src.__support.OSUtil.osutil
453+
libc.src.stdlib._Exit
454+
)
455+
456+
add_libc_test(
457+
exit_test
458+
# The EXPECT_EXITS test is only availible for unit tests.
459+
UNIT_TEST_ONLY
460+
SUITE
461+
libc-stdlib-tests
462+
SRCS
463+
exit_test.cpp
451464
DEPENDS
452465
libc.src.stdlib._Exit
453466
libc.src.stdlib.exit

libc/test/src/stdlib/_Exit_test.cpp

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

99
#include "src/stdlib/_Exit.h"
10-
#include "src/stdlib/exit.h"
1110
#include "test/UnitTest/Test.h"
1211

1312
TEST(LlvmLibcStdlib, _Exit) {
1413
EXPECT_EXITS([] { LIBC_NAMESPACE::_Exit(1); }, 1);
1514
EXPECT_EXITS([] { LIBC_NAMESPACE::_Exit(65); }, 65);
16-
17-
EXPECT_EXITS([] { LIBC_NAMESPACE::exit(1); }, 1);
18-
EXPECT_EXITS([] { LIBC_NAMESPACE::exit(65); }, 65);
1915
}

libc/test/src/stdlib/exit_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===-- Unittests for exit -----------------------------------------------===//
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/stdlib/exit.h"
10+
#include "test/UnitTest/Test.h"
11+
12+
TEST(LlvmLibcStdlib, exit) {
13+
EXPECT_EXITS([] { LIBC_NAMESPACE::exit(1); }, 1);
14+
EXPECT_EXITS([] { LIBC_NAMESPACE::exit(65); }, 65);
15+
}

0 commit comments

Comments
 (0)