Check if select handles error returns and errno correctly
| 214 | |
| 215 | // Check if select handles error returns and errno correctly |
| 216 | void test_errors() { |
| 217 | printf("test_errors\n"); |
| 218 | struct timeval tv = {0, 0}; |
| 219 | fd_set readfds; |
| 220 | |
| 221 | // Negative nfds should fail with EINVAL |
| 222 | FD_ZERO(&readfds); |
| 223 | errno = 0; |
| 224 | assert(select(-1, &readfds, NULL, NULL, &tv) == -1); |
| 225 | assert(errno == EINVAL); |
| 226 | |
| 227 | // Closed / invalid fd should fail with EBADF |
| 228 | int pipe_fds[2]; |
| 229 | assert(pipe(pipe_fds) == 0); |
| 230 | close(pipe_fds[0]); // close read end |
| 231 | FD_ZERO(&readfds); |
| 232 | FD_SET(pipe_fds[0], &readfds); |
| 233 | errno = 0; |
| 234 | assert(select(pipe_fds[0] + 1, &readfds, NULL, NULL, &tv) == -1); |
| 235 | assert(errno == EBADF); |
| 236 | close(pipe_fds[1]); |
| 237 | } |
| 238 | |
| 239 | int main() { |
| 240 | test_select_in_threads(); |