| Index: native_client_sdk/src/tests/nacl_io_test/mount_node_tty_test.cc
|
| diff --git a/native_client_sdk/src/tests/nacl_io_test/mount_node_tty_test.cc b/native_client_sdk/src/tests/nacl_io_test/mount_node_tty_test.cc
|
| index 9aa1ee74d60e9b6eb1d527e91863f71017aa6c1a..75b9ce8da294c964a7f798fea691904138e2aa54 100644
|
| --- a/native_client_sdk/src/tests/nacl_io_test/mount_node_tty_test.cc
|
| +++ b/native_client_sdk/src/tests/nacl_io_test/mount_node_tty_test.cc
|
| @@ -5,6 +5,7 @@
|
| #include <errno.h>
|
| #include <fcntl.h>
|
| #include <string.h>
|
| +#include <sys/ioctl.h>
|
| #include <sys/select.h>
|
| #include <sys/stat.h>
|
| #include <sys/time.h>
|
| @@ -58,7 +59,7 @@ TEST_F(TtyTest, TtyInput) {
|
| // Now let's try sending some data over.
|
| // First we create the message.
|
| std::string content("hello, how are you?\n");
|
| - std::string message = prefix.append(content);
|
| + std::string message = prefix + "input:" + content;
|
| struct tioc_nacl_input_string packaged_message;
|
| packaged_message.length = message.size();
|
| packaged_message.buffer = message.data();
|
| @@ -169,16 +170,16 @@ TEST_F(TtyTest, TtySelect) {
|
|
|
| // Send 4 bytes to TTY input
|
| struct tioc_nacl_input_string input;
|
| - input.buffer = "test";
|
| - input.length = 4;
|
| + input.buffer = "input:test";
|
| + input.length = strlen(input.buffer);
|
| char* ioctl_arg = reinterpret_cast<char*>(&input);
|
| ASSERT_EQ(0, ki_ioctl(tty_fd, TIOCNACLINPUT, ioctl_arg));
|
|
|
| // TTY should not be readable until newline in written
|
| ASSERT_EQ(IsReadable(tty_fd), 0);
|
|
|
| - input.buffer = "\n";
|
| - input.length = 1;
|
| + input.buffer = "input:\n";
|
| + input.length = strlen(input.buffer);
|
| ASSERT_EQ(0, ki_ioctl(tty_fd, TIOCNACLINPUT, ioctl_arg));
|
|
|
| // TTY should now be readable
|
| @@ -187,4 +188,46 @@ TEST_F(TtyTest, TtySelect) {
|
| ki_close(tty_fd);
|
| }
|
|
|
| +int g_recieved_signal = 0;
|
| +
|
| +void sighandler(int sig) {
|
| + g_recieved_signal = sig;
|
| +}
|
| +
|
| +TEST_F(TtyTest, WindowSize) {
|
| + // Get current window size
|
| + struct winsize old_winsize = { 0 };
|
| + ASSERT_EQ(0, dev_tty_->Ioctl(TIOCGWINSZ,
|
| + reinterpret_cast<char*>(&old_winsize)));
|
| +
|
| + // Install signal handler
|
| + sighandler_t new_handler = sighandler;
|
| + sighandler_t old_handler = ki_signal(SIGWINCH, new_handler);
|
| + ASSERT_NE(old_handler, SIG_ERR) << "signal return error: " << errno;
|
| +
|
| + // Set a new windows size
|
| + struct winsize winsize;
|
| + winsize.ws_col = 100;
|
| + winsize.ws_row = 200;
|
| + EXPECT_EQ(0, dev_tty_->Ioctl(TIOCSWINSZ,
|
| + reinterpret_cast<char*>(&winsize)));
|
| + EXPECT_EQ(g_recieved_signal, SIGWINCH);
|
| +
|
| + // Restore old signal handler
|
| + EXPECT_EQ(new_handler, ki_signal(SIGWINCH, old_handler));
|
| +
|
| + // Verify new window size can be queried correctly.
|
| + winsize.ws_col = 0;
|
| + winsize.ws_row = 0;
|
| + EXPECT_EQ(0, dev_tty_->Ioctl(TIOCGWINSZ,
|
| + reinterpret_cast<char*>(&winsize)));
|
| + EXPECT_EQ(winsize.ws_col, 100);
|
| + EXPECT_EQ(winsize.ws_row, 200);
|
| +
|
| + // Restore original windows size.
|
| + EXPECT_EQ(0, dev_tty_->Ioctl(TIOCSWINSZ,
|
| + reinterpret_cast<char*>(&old_winsize)));
|
| +
|
| +}
|
| +
|
| }
|
|
|