Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <sys/ioctl.h> | 10 #include <sys/ioctl.h> |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 EXPECT_EQ(0, FD_ISSET(fds[0], &rd_set)); | 305 EXPECT_EQ(0, FD_ISSET(fds[0], &rd_set)); |
| 306 EXPECT_EQ(0, FD_ISSET(fds[1], &rd_set)); | 306 EXPECT_EQ(0, FD_ISSET(fds[1], &rd_set)); |
| 307 // TODO(noelallen) fix poll based on open mode | 307 // TODO(noelallen) fix poll based on open mode |
| 308 // EXPECT_EQ(0, FD_ISSET(fds[0], &wr_set)); | 308 // EXPECT_EQ(0, FD_ISSET(fds[0], &wr_set)); |
| 309 // Bug 291018 | 309 // Bug 291018 |
| 310 EXPECT_NE(0, FD_ISSET(fds[1], &wr_set)); | 310 EXPECT_NE(0, FD_ISSET(fds[1], &wr_set)); |
| 311 EXPECT_EQ(0, FD_ISSET(fds[0], &ex_set)); | 311 EXPECT_EQ(0, FD_ISSET(fds[0], &ex_set)); |
| 312 EXPECT_EQ(0, FD_ISSET(fds[1], &ex_set)); | 312 EXPECT_EQ(0, FD_ISSET(fds[1], &ex_set)); |
| 313 } | 313 } |
| 314 | 314 |
| 315 /** | |
| 316 * Test that calling select() only writes the initial parts of the fs_sets | |
| 317 * passed in. | |
| 318 * 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
| |
| 319 * which was causing curruption in ssh which always allocates the fs_sets to be | |
|
binji
2014/04/09 21:26:22
sp: corruption
| |
| 320 * hold 'nfds' worth of descriptors. | |
| 321 */ | |
| 322 TEST_F(SelectPollTest, SelectPartialFdset) { | |
| 323 int fds[2]; | |
| 324 | |
| 325 // Both FDs for regular files should be read/write but not exception. | |
| 326 fds[0] = kp->open("/test.txt", O_CREAT | O_WRONLY); | |
| 327 fds[1] = kp->open("/test.txt", O_RDONLY); | |
| 328 ASSERT_GT(fds[0], -1); | |
| 329 ASSERT_GT(fds[1], -1); | |
| 330 ASSERT_LT(fds[1], 8); | |
| 331 SetFDs(fds, 2); | |
| 332 | |
| 333 // Fill in all the remaining bytes in the fd_sets a contant value | |
| 334 static const char guard_value = 0xab; | |
| 335 for (int i = 1; i < sizeof(fd_set); i++) { | |
| 336 ((char*)&rd_set)[i] = guard_value; | |
| 337 ((char*)&wr_set)[i] = guard_value; | |
| 338 ((char*)&ex_set)[i] = guard_value; | |
| 339 } | |
| 340 | |
| 341 ASSERT_EQ(4, kp->select(fds[1] + 1, &rd_set, &wr_set, &ex_set, &tv)); | |
| 342 | |
| 343 // Verify guard values were not touched. | |
| 344 for (int i = 1; i < sizeof(fd_set); i++) { | |
| 345 ASSERT_EQ(guard_value, ((char*)&rd_set)[i]); | |
| 346 ASSERT_EQ(guard_value, ((char*)&wr_set)[i]); | |
| 347 ASSERT_EQ(guard_value, ((char*)&ex_set)[i]); | |
| 348 } | |
| 349 } | |
| OLD | NEW |