| Index: native_client_sdk/src/tests/nacl_io_test/tty_test.cc
|
| diff --git a/native_client_sdk/src/tests/nacl_io_test/tty_test.cc b/native_client_sdk/src/tests/nacl_io_test/tty_test.cc
|
| index d54fa96b38db3ee933663478218f88a3ef2a9d81..6a390e0572ba0965363fdf9c1fe46edf7cc95be8 100644
|
| --- a/native_client_sdk/src/tests/nacl_io_test/tty_test.cc
|
| +++ b/native_client_sdk/src/tests/nacl_io_test/tty_test.cc
|
| @@ -24,9 +24,17 @@ using namespace nacl_io;
|
|
|
| namespace {
|
|
|
| +static int ki_ioctl_wrapper(int fd, int request, ...) {
|
| + va_list ap;
|
| + va_start(ap, request);
|
| + int rtn = ki_ioctl(fd, request, ap);
|
| + va_end(ap);
|
| + return rtn;
|
| +}
|
| +
|
| class TtyNodeTest : public ::testing::Test {
|
| public:
|
| - TtyNodeTest() : fs_(&pepper_) {}
|
| + TtyNodeTest() : fs_(&ppapi_) {}
|
|
|
| void SetUp() {
|
| ASSERT_EQ(0, fs_.Access(Path("/tty"), R_OK | W_OK));
|
| @@ -36,7 +44,7 @@ class TtyNodeTest : public ::testing::Test {
|
| }
|
|
|
| protected:
|
| - FakePepperInterface pepper_;
|
| + FakePepperInterface ppapi_;
|
| DevFsForTesting fs_;
|
| ScopedNode dev_tty_;
|
| };
|
| @@ -45,15 +53,26 @@ class TtyTest : public ::testing::Test {
|
| public:
|
| void SetUp() {
|
| ASSERT_EQ(0, ki_push_state_for_testing());
|
| - ASSERT_EQ(0, ki_init(&kp_));
|
| + ASSERT_EQ(0, ki_init_interface(&kp_, &ppapi_));
|
| +
|
| + var_iface_ = ppapi_.GetVarInterface();
|
| }
|
|
|
| void TearDown() {
|
| ki_uninit();
|
| }
|
|
|
| + int TtyWrite(int fd, const char* string) {
|
| + PP_Var message_var = var_iface_->VarFromUtf8(string, strlen(string));
|
| + int result = ki_ioctl_wrapper(fd, NACL_IOC_HANDLEMESSAGE, &message_var);
|
| + var_iface_->Release(message_var);
|
| + return result;
|
| + }
|
| +
|
| protected:
|
| + FakePepperInterface ppapi_;
|
| KernelProxy kp_;
|
| + VarInterface* var_iface_;
|
| };
|
|
|
| TEST_F(TtyNodeTest, InvalidIoctl) {
|
| @@ -65,9 +84,8 @@ TEST_F(TtyNodeTest, TtyInput) {
|
| // Now let's try sending some data over.
|
| // First we create the message.
|
| std::string message("hello, how are you?\n");
|
| - struct tioc_nacl_input_string packaged_message;
|
| - packaged_message.length = message.size();
|
| - packaged_message.buffer = message.data();
|
| + VarInterface* var_iface = ppapi_.GetVarInterface();
|
| + PP_Var message_var = var_iface->VarFromUtf8(message.data(), message.size());
|
|
|
| // Now we make buffer we'll read into.
|
| // We fill the buffer and a backup buffer with arbitrary data
|
| @@ -80,7 +98,9 @@ TEST_F(TtyNodeTest, TtyInput) {
|
| memset(backup_buffer, 'a', 100);
|
|
|
| // Now we actually send the data
|
| - EXPECT_EQ(0, dev_tty_->Ioctl(TIOCNACLINPUT, &packaged_message));
|
| + EXPECT_EQ(0, dev_tty_->Ioctl(NACL_IOC_HANDLEMESSAGE, &message_var));
|
| +
|
| + var_iface->Release(message_var);
|
|
|
| // We read a small chunk first to ensure it doesn't give us
|
| // more than we ask for.
|
| @@ -137,21 +157,6 @@ TEST_F(TtyNodeTest, TtyOutput) {
|
| EXPECT_EQ(0, strncmp(user_data.output_buf, message, message_len));
|
| }
|
|
|
| -static int ki_ioctl_wrapper(int fd, int request, ...) {
|
| - va_list ap;
|
| - va_start(ap, request);
|
| - int rtn = ki_ioctl(fd, request, ap);
|
| - va_end(ap);
|
| - return rtn;
|
| -}
|
| -
|
| -static int TtyWrite(int fd, const char* string) {
|
| - struct tioc_nacl_input_string input;
|
| - input.buffer = string;
|
| - input.length = strlen(input.buffer);
|
| - return ki_ioctl_wrapper(fd, TIOCNACLINPUT, &input);
|
| -}
|
| -
|
| // Returns:
|
| // 0 -> Not readable
|
| // 1 -> Readable
|
| @@ -337,10 +342,12 @@ TEST_F(TtyTest, ResizeDuringSelect) {
|
| * Sleep for 50ms then send some input to the /dev/tty.
|
| */
|
| static void* input_thread_main(void* arg) {
|
| + TtyTest* thiz = static_cast<TtyTest*>(arg);
|
| +
|
| usleep(50 * 1000);
|
|
|
| int fd = ki_open("/dev/tty", O_RDONLY);
|
| - TtyWrite(fd, "test\n");
|
| + thiz->TtyWrite(fd, "test\n");
|
| return NULL;
|
| }
|
|
|
| @@ -357,7 +364,7 @@ TEST_F(TtyTest, InputDuringSelect) {
|
| FD_SET(tty_fd, &errorfds);
|
|
|
| pthread_t resize_thread;
|
| - pthread_create(&resize_thread, NULL, input_thread_main, NULL);
|
| + pthread_create(&resize_thread, NULL, input_thread_main, this);
|
|
|
| struct timeval timeout;
|
| timeout.tv_sec = 20;
|
| @@ -368,4 +375,5 @@ TEST_F(TtyTest, InputDuringSelect) {
|
|
|
| ASSERT_EQ(1, rtn);
|
| }
|
| -}
|
| +
|
| +} // namespace
|
|
|