Chromium Code Reviews| Index: native_client_sdk/src/tests/nacl_io_test/event_test.cc |
| diff --git a/native_client_sdk/src/tests/nacl_io_test/event_test.cc b/native_client_sdk/src/tests/nacl_io_test/event_test.cc |
| index 76f535961971ed566791b57452a5f4b7e7165873..962203a5fbbf01b3bb39fb18f13081e9f748f752 100644 |
| --- a/native_client_sdk/src/tests/nacl_io_test/event_test.cc |
| +++ b/native_client_sdk/src/tests/nacl_io_test/event_test.cc |
| @@ -312,3 +312,38 @@ TEST_F(SelectPollTest, SelectMemPipe) { |
| EXPECT_EQ(0, FD_ISSET(fds[1], &ex_set)); |
| } |
| +/** |
| + * Test that calling select() only writes the initial parts of the fs_sets |
| + * passed in. |
| + * We had an issue when select() was calling FD_ZERO() on the incoming fs_sets |
|
binji
2014/04/09 21:26:22
sp: fd_sets
|
| + * which was causing curruption in ssh which always allocates the fs_sets to be |
|
binji
2014/04/09 21:26:22
sp: corruption
|
| + * hold 'nfds' worth of descriptors. |
| + */ |
| +TEST_F(SelectPollTest, SelectPartialFdset) { |
| + int fds[2]; |
| + |
| + // Both FDs for regular files should be read/write but not exception. |
| + fds[0] = kp->open("/test.txt", O_CREAT | O_WRONLY); |
| + fds[1] = kp->open("/test.txt", O_RDONLY); |
| + ASSERT_GT(fds[0], -1); |
| + ASSERT_GT(fds[1], -1); |
| + ASSERT_LT(fds[1], 8); |
| + SetFDs(fds, 2); |
| + |
| + // Fill in all the remaining bytes in the fd_sets a contant value |
| + static const char guard_value = 0xab; |
| + for (int i = 1; i < sizeof(fd_set); i++) { |
| + ((char*)&rd_set)[i] = guard_value; |
| + ((char*)&wr_set)[i] = guard_value; |
| + ((char*)&ex_set)[i] = guard_value; |
| + } |
| + |
| + ASSERT_EQ(4, kp->select(fds[1] + 1, &rd_set, &wr_set, &ex_set, &tv)); |
| + |
| + // Verify guard values were not touched. |
| + for (int i = 1; i < sizeof(fd_set); i++) { |
| + ASSERT_EQ(guard_value, ((char*)&rd_set)[i]); |
| + ASSERT_EQ(guard_value, ((char*)&wr_set)[i]); |
| + ASSERT_EQ(guard_value, ((char*)&ex_set)[i]); |
| + } |
| +} |