1 //===-- Interactive unittests for select ----------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/errno/libc_errno.h"
10 #include "src/sys/select/select.h"
11 #include "src/unistd/read.h"
12 #include "test/UnitTest/Test.h"
14 #include <sys/select.h>
17 // This test is not be run automatically as part of the libc testsuite.
18 // Instead, one has to run it manually and press a key on the keyboard
19 // to make the test succeed.
20 TEST(LlvmLibcSelectTest
, ReadStdinAfterSelect
) {
21 LIBC_NAMESPACE::libc_errno
= 0;
22 constexpr int STDIN_FD
= 0;
25 FD_SET(STDIN_FD
, &set
);
31 }; // Wait for an hour.
33 // Zero timeout means we don't wait for input. So, select should return
36 LIBC_NAMESPACE::select(STDIN_FD
+ 1, &set
, nullptr, nullptr, &zero
);
37 // The set should indicate that stdin is NOT ready for reading.
38 ASSERT_EQ(0, FD_ISSET(STDIN_FD
, &set
));
40 FD_SET(STDIN_FD
, &set
);
41 // Wait for an hour and give the user a chance to hit a key.
42 count
= LIBC_NAMESPACE::select(STDIN_FD
+ 1, &set
, nullptr, nullptr, &hr
);
44 // The set should indicate that stdin is ready for reading.
45 ASSERT_EQ(1, FD_ISSET(STDIN_FD
, &set
));
47 // Verify that atleast one character can be read.
49 ASSERT_EQ(LIBC_NAMESPACE::read(STDIN_FD
, &c
, 1), ssize_t(1));