diff options
author | Justin DeMartino <jjdemartino@google.com> | 2020-09-21 13:23:58 -0700 |
---|---|---|
committer | Justin DeMartino <jjdemartino@google.com> | 2020-09-21 13:23:58 -0700 |
commit | 7e4fe6a28b718ab97c08811566238af2893ca65b (patch) | |
tree | 5413a5ec890b5a1ac4fbbe4548b5014e41a2591b /tests/pty_test.cpp | |
parent | dcdcb3fa15004669823a3a118189d9d72ff30852 (diff) | |
parent | ab08b955a34423d53b28a6210e7530e67241af4a (diff) |
Merge SP1A.200921.001
Change-Id: Id2ab019914bb555dadf52c46b8403c0d5fb3c20a
Diffstat (limited to 'tests/pty_test.cpp')
-rw-r--r-- | tests/pty_test.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/tests/pty_test.cpp b/tests/pty_test.cpp index 29f86f16a..d5d8994be 100644 --- a/tests/pty_test.cpp +++ b/tests/pty_test.cpp @@ -28,34 +28,34 @@ #include "utils.h" TEST(pty, openpty) { - int master, slave; + int pty, tty; char name[32]; struct winsize w = { 123, 456, 9999, 999 }; - ASSERT_EQ(0, openpty(&master, &slave, name, nullptr, &w)); - ASSERT_NE(-1, master); - ASSERT_NE(-1, slave); - ASSERT_NE(master, slave); + ASSERT_EQ(0, openpty(&pty, &tty, name, nullptr, &w)); + ASSERT_NE(-1, pty); + ASSERT_NE(-1, tty); + ASSERT_NE(pty, tty); char tty_name[32]; - ASSERT_EQ(0, ttyname_r(slave, tty_name, sizeof(tty_name))); + ASSERT_EQ(0, ttyname_r(tty, tty_name, sizeof(tty_name))); ASSERT_STREQ(tty_name, name); struct winsize w_actual; - ASSERT_EQ(0, ioctl(slave, TIOCGWINSZ, &w_actual)); + ASSERT_EQ(0, ioctl(tty, TIOCGWINSZ, &w_actual)); ASSERT_EQ(w_actual.ws_row, w.ws_row); ASSERT_EQ(w_actual.ws_col, w.ws_col); ASSERT_EQ(w_actual.ws_xpixel, w.ws_xpixel); ASSERT_EQ(w_actual.ws_ypixel, w.ws_ypixel); - close(master); - close(slave); + close(pty); + close(tty); } TEST(pty, forkpty) { pid_t sid = getsid(0); - int master; - pid_t pid = forkpty(&master, nullptr, nullptr, nullptr); + int pty; + pid_t pid = forkpty(&pty, nullptr, nullptr, nullptr); ASSERT_NE(-1, pid); if (pid == 0) { @@ -68,12 +68,12 @@ TEST(pty, forkpty) { AssertChildExited(pid, 0); - close(master); + close(pty); } struct PtyReader_28979140_Arg { int main_cpu_id; - int slave_fd; + int fd; uint32_t data_count; bool finished; std::atomic<bool> matched; @@ -90,7 +90,7 @@ static void PtyReader_28979140(PtyReader_28979140_Arg* arg) { while (counter <= arg->data_count) { char buf[4096]; // Use big buffer to read to hit the bug more easily. size_t to_read = std::min(sizeof(buf), (arg->data_count + 1 - counter) * sizeof(uint32_t)); - ASSERT_TRUE(android::base::ReadFully(arg->slave_fd, buf, to_read)); + ASSERT_TRUE(android::base::ReadFully(arg->fd, buf, to_read)); size_t num_of_value = to_read / sizeof(uint32_t); uint32_t* p = reinterpret_cast<uint32_t*>(buf); while (num_of_value-- > 0) { @@ -99,7 +99,7 @@ static void PtyReader_28979140(PtyReader_28979140_Arg* arg) { } } } - close(arg->slave_fd); + close(arg->fd); arg->finished = true; } @@ -114,16 +114,16 @@ TEST(pty, bug_28979140) { constexpr uint32_t TEST_DATA_COUNT = 2000000; // 1. Open raw pty. - int master; - int slave; - ASSERT_EQ(0, openpty(&master, &slave, nullptr, nullptr, nullptr)); + int pty; + int tty; + ASSERT_EQ(0, openpty(&pty, &tty, nullptr, nullptr, nullptr)); termios tattr; - ASSERT_EQ(0, tcgetattr(slave, &tattr)); + ASSERT_EQ(0, tcgetattr(tty, &tattr)); cfmakeraw(&tattr); - ASSERT_EQ(0, tcsetattr(slave, TCSADRAIN, &tattr)); + ASSERT_EQ(0, tcsetattr(tty, TCSADRAIN, &tattr)); - // 2. Make master thread and slave thread running on different cpus: - // master thread uses first available cpu, and slave thread uses other cpus. + // 2. Make two threads running on different cpus: + // pty thread uses first available cpu, and tty thread uses other cpus. PtyReader_28979140_Arg arg; arg.main_cpu_id = -1; for (int i = 0; i < CPU_SETSIZE; i++) { @@ -134,9 +134,9 @@ TEST(pty, bug_28979140) { } ASSERT_GE(arg.main_cpu_id, 0); - // 3. Create thread for slave reader. + // 3. Create thread for tty reader. pthread_t thread; - arg.slave_fd = slave; + arg.fd = tty; arg.data_count = TEST_DATA_COUNT; arg.matched = true; ASSERT_EQ(0, pthread_create(&thread, nullptr, @@ -147,7 +147,7 @@ TEST(pty, bug_28979140) { CPU_SET(arg.main_cpu_id, &cpus); ASSERT_EQ(0, sched_setaffinity(0, sizeof(cpu_set_t), &cpus)); - // 4. Send data to slave. + // 4. Send data to tty reader. // Send a bunch of data at a time, so it is easier to catch the bug that some data isn't seen // by the reader thread on another cpu. uint32_t counter_buf[100]; @@ -156,11 +156,11 @@ TEST(pty, bug_28979140) { for (size_t i = 0; i < sizeof(counter_buf) / sizeof(counter_buf[0]); ++i) { counter_buf[i] = counter++; } - ASSERT_TRUE(android::base::WriteFully(master, &counter_buf, sizeof(counter_buf))); + ASSERT_TRUE(android::base::WriteFully(pty, &counter_buf, sizeof(counter_buf))); ASSERT_TRUE(arg.matched) << "failed at count = " << counter; } ASSERT_EQ(0, pthread_join(thread, nullptr)); ASSERT_TRUE(arg.finished); ASSERT_TRUE(arg.matched); - close(master); + close(pty); } |