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..837d3151f308b96edc89c2ca7f2c17b4f4678b75 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,37 @@ 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_)); |
+ |
+ buffer_iface_ = ppapi_.GetVarArrayBufferInterface(); |
+ var_iface_ = ppapi_.GetVarInterface(); |
} |
void TearDown() { |
ki_uninit(); |
} |
+ int TtyWrite(int fd, const char* string) { |
+ size_t len = strlen(string); |
+ PP_Var message_var = buffer_iface_->Create(strlen(string)); |
+ |
+ char* data = static_cast<char*>(buffer_iface_->Map(message_var)); |
+ EXPECT_NE((char*)NULL, data); |
+ |
+ memcpy(data, string, len); |
+ buffer_iface_->Unmap(message_var); |
+ |
+ int result = ki_ioctl_wrapper(fd, NACL_IOC_HANDLEMESSAGE, &message_var); |
+ |
+ var_iface_->Release(message_var); |
+ return result; |
+ } |
+ |
protected: |
+ FakePepperInterface ppapi_; |
KernelProxy kp_; |
+ VarArrayBufferInterface* buffer_iface_; |
+ VarInterface* var_iface_; |
}; |
TEST_F(TtyNodeTest, InvalidIoctl) { |
@@ -65,9 +95,15 @@ 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(); |
+ VarArrayBufferInterface* buffer_iface = ppapi_.GetVarArrayBufferInterface(); |
+ VarInterface* var_iface = ppapi_.GetVarInterface(); |
+ PP_Var message_var = buffer_iface->Create(message.size()); |
+ |
+ char* data = static_cast<char*>(buffer_iface->Map(message_var)); |
+ ASSERT_NE((char*)NULL, data); |
+ |
+ memcpy(data, message.data(), message.size()); |
+ buffer_iface->Unmap(message_var); |
// Now we make buffer we'll read into. |
// We fill the buffer and a backup buffer with arbitrary data |
@@ -80,7 +116,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 +175,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 |
@@ -176,6 +199,9 @@ static int IsReadable(int fd) { |
return 1; // readable |
} |
+TEST_F(TtyTest, Empty) { |
+} |
Sam Clegg
2014/06/17 22:29:29
?
binji
2014/06/17 22:55:23
Done.
|
+ |
TEST_F(TtyTest, TtySelect) { |
struct timeval timeout; |
fd_set readfds; |
@@ -337,10 +363,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 +385,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 +396,5 @@ TEST_F(TtyTest, InputDuringSelect) { |
ASSERT_EQ(1, rtn); |
} |
-} |
+ |
+} // namespace |