diff options
author | Elliott Hughes <enh@google.com> | 2014-07-25 17:24:00 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-07-29 10:48:34 -0700 |
commit | 2ea0a58e01c1ed6db1da9dd0314ee053f5a32026 (patch) | |
tree | 63ff9d142049e6a1b1fec9945f4d21a1626550f5 /tests | |
parent | a09fe118b1a5eb876ddaa2620965c4a8fb8b007c (diff) | |
download | bionic-2ea0a58e01c1ed6db1da9dd0314ee053f5a32026.zip bionic-2ea0a58e01c1ed6db1da9dd0314ee053f5a32026.tar.gz bionic-2ea0a58e01c1ed6db1da9dd0314ee053f5a32026.tar.bz2 |
Fix linkage of grantpt(3).
Also clean up the implementation of all the pty functions, add tests,
and fix the stub implementations of ttyname(3) and ttyname_r(3).
Bug: https://code.google.com/p/android/issues/detail?id=58888
(cherry picked from commit 4916706cfe590eb06c9b5bd4bd402ce056034d51)
Change-Id: I5cb7a1c17b156456e4c4818e65f256eb8d045424
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdlib_test.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp index 6d29421..553f018 100644 --- a/tests/stdlib_test.cpp +++ b/tests/stdlib_test.cpp @@ -262,3 +262,102 @@ TEST(unistd, _Exit) { ASSERT_TRUE(WIFEXITED(status)); ASSERT_EQ(99, WEXITSTATUS(status)); } + +TEST(stdlib, pty_smoke) { + // getpt returns a pty with O_RDWR|O_NOCTTY. + int fd = getpt(); + ASSERT_NE(-1, fd); + + // grantpt is a no-op. + ASSERT_EQ(0, grantpt(fd)); + + // ptsname_r should start "/dev/pts/". + char name_r[128]; + ASSERT_EQ(0, ptsname_r(fd, name_r, sizeof(name_r))); + name_r[9] = 0; + ASSERT_STREQ("/dev/pts/", name_r); + + close(fd); +} + +TEST(stdlib, posix_openpt) { + int fd = posix_openpt(O_RDWR|O_NOCTTY|O_CLOEXEC); + ASSERT_NE(-1, fd); + close(fd); +} + +TEST(stdlib, ptsname_r_ENOTTY) { + errno = 0; + char buf[128]; + ASSERT_EQ(ENOTTY, ptsname_r(STDOUT_FILENO, buf, sizeof(buf))); + ASSERT_EQ(ENOTTY, errno); +} + +TEST(stdlib, ptsname_r_EINVAL) { + int fd = getpt(); + ASSERT_NE(-1, fd); + errno = 0; + char* buf = NULL; + ASSERT_EQ(EINVAL, ptsname_r(fd, buf, 128)); + ASSERT_EQ(EINVAL, errno); + close(fd); +} + +TEST(stdlib, ptsname_r_ERANGE) { + int fd = getpt(); + ASSERT_NE(-1, fd); + errno = 0; + char buf[1]; + ASSERT_EQ(ERANGE, ptsname_r(fd, buf, sizeof(buf))); + ASSERT_EQ(ERANGE, errno); + close(fd); +} + +TEST(stdlib, ttyname_r) { + int fd = getpt(); + ASSERT_NE(-1, fd); + + // ttyname_r returns "/dev/ptmx" for a pty. + char name_r[128]; + ASSERT_EQ(0, ttyname_r(fd, name_r, sizeof(name_r))); + ASSERT_STREQ("/dev/ptmx", name_r); + + close(fd); +} + +TEST(stdlib, ttyname_r_ENOTTY) { + int fd = open("/dev/null", O_WRONLY); + errno = 0; + char buf[128]; + ASSERT_EQ(ENOTTY, ttyname_r(fd, buf, sizeof(buf))); + ASSERT_EQ(ENOTTY, errno); + close(fd); +} + +TEST(stdlib, ttyname_r_EINVAL) { + int fd = getpt(); + ASSERT_NE(-1, fd); + errno = 0; + char* buf = NULL; + ASSERT_EQ(EINVAL, ttyname_r(fd, buf, 128)); + ASSERT_EQ(EINVAL, errno); + close(fd); +} + +TEST(stdlib, ttyname_r_ERANGE) { + int fd = getpt(); + ASSERT_NE(-1, fd); + errno = 0; + char buf[1]; + ASSERT_EQ(ERANGE, ttyname_r(fd, buf, sizeof(buf))); + ASSERT_EQ(ERANGE, errno); + close(fd); +} + +TEST(stdlib, unlockpt_ENOTTY) { + int fd = open("/dev/null", O_WRONLY); + errno = 0; + ASSERT_EQ(-1, unlockpt(fd)); + ASSERT_EQ(ENOTTY, errno); + close(fd); +} |