Skip to content

Commit e46974b

Browse files
committed
test cleanup
1 parent 924ed4c commit e46974b

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

libc/test/src/sys/ioctl/linux/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
add_custom_target(libc_sys_ioctl_unittests)
22

3+
add_subdirectory(testdata)
4+
35
add_libc_unittest(
46
ioctl_test
57
SUITE

libc/test/src/sys/ioctl/linux/ioctl_test.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,32 @@ TEST(LlvmLibcSysIoctlTest, TestFileFIONREAD) {
2323
constexpr const char TEST_MSG[] = "ioctl test";
2424
constexpr int TEST_MSG_SIZE = sizeof(TEST_MSG) - 1;
2525
constexpr const char *TEST_FILE = "testdata/ioctl.test";
26-
int test_file_fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
27-
ASSERT_GT(test_file_fd, 0);
26+
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
2827
ASSERT_ERRNO_SUCCESS();
28+
ASSERT_GT(fd, 0);
2929

3030
// FIONREAD reports the number of available bytes to read for the passed fd
3131
// This will report the full size of the file, as we haven't read anything yet
32-
int test_file_n = -1;
33-
int ret = LIBC_NAMESPACE::ioctl(test_file_fd, FIONREAD, &test_file_n);
34-
ASSERT_GT(ret, -1);
32+
int n = -1;
33+
int ret = LIBC_NAMESPACE::ioctl(fd, FIONREAD, &n);
3534
ASSERT_ERRNO_SUCCESS();
36-
ASSERT_EQ(test_file_n, TEST_MSG_SIZE);
35+
ASSERT_GT(ret, -1);
36+
ASSERT_EQ(n, TEST_MSG_SIZE);
3737

3838
// But if we read some bytes...
3939
constexpr int READ_COUNT = 5;
40-
char buffer[READ_COUNT];
41-
ASSERT_THAT(LIBC_NAMESPACE::read(test_file_fd, buffer, READ_COUNT),
40+
char read_buffer[READ_COUNT];
41+
ASSERT_THAT((int)LIBC_NAMESPACE::read(fd, read_buffer, READ_COUNT),
4242
Succeeds(READ_COUNT));
4343

4444
// ... n should have decreased by the number of bytes we've read
45-
int test_file_n_after_reading = -1;
46-
ret =
47-
LIBC_NAMESPACE::ioctl(test_file_fd, FIONREAD, &test_file_n_after_reading);
48-
ASSERT_GT(ret, -1);
45+
int n_after_reading = -1;
46+
ret = LIBC_NAMESPACE::ioctl(fd, FIONREAD, &n_after_reading);
4947
ASSERT_ERRNO_SUCCESS();
50-
ASSERT_EQ(test_file_n - READ_COUNT, test_file_n_after_reading);
48+
ASSERT_GT(ret, -1);
49+
ASSERT_EQ(n - READ_COUNT, n_after_reading);
5150

52-
ASSERT_THAT(LIBC_NAMESPACE::close(test_file_fd), Succeeds(0));
51+
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
5352
}
5453

5554
TEST(LlvmLibcSysIoctlTest, InvalidIoctlCommand) {

0 commit comments

Comments
 (0)