X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Fregression%2Fkernel%2Fselect_poll_epoll.c;h=08e7fce0d898df547da42e371dc694f90bea4141;hp=e0e92fd381c8980499059aea44c77525b2922fd2;hb=8b3b99e2870d53c97f9ec9a976ed91f43da5f02b;hpb=d542c0aefc94e5c5805e6158b03c9e82e53b5fd1 diff --git a/tests/regression/kernel/select_poll_epoll.c b/tests/regression/kernel/select_poll_epoll.c index e0e92fd38..08e7fce0d 100644 --- a/tests/regression/kernel/select_poll_epoll.c +++ b/tests/regression/kernel/select_poll_epoll.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #define BUF_SIZE 256 #define NB_FD 1 @@ -437,30 +437,36 @@ void ppoll_fds_ulong_max(void) } /* - * Select is limited to 1024 FDs, should output a pselect event - * with 0 FDs. + * Pass an invalid file descriptor to pselect6(). The syscall should return + * -EBADF. The recorded event should contain a "ret = -EBADF (-9)". */ -void pselect_fd_too_big(void) +void pselect_invalid_fd(void) { fd_set rfds; int ret; - int fd2; + int fd; char buf[BUF_SIZE]; /* - * Test if nfds > 1024. - * Make sure ulimit is set correctly (ulimit -n 2048). + * Open a file, close it and use the closed FD in the pselect6 call. */ - fd2 = dup2(wait_fd, 2047); - if (fd2 != 2047) { - perror("dup2"); - return; + + fd = open("/dev/null", O_RDONLY); + if (fd == -1) { + perror("open"); + goto error; } - FD_ZERO(&rfds); - FD_SET(fd2, &rfds); - ret = syscall(SYS_pselect6, fd2 + 1, &rfds, NULL, NULL, NULL, NULL); + ret = close(fd); + if (ret == -1) { + perror("close"); + goto error; + } + + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + ret = syscall(SYS_pselect6, fd + 1, &rfds, NULL, NULL, NULL, NULL); if (ret == -1) { perror("# pselect()"); } else if (ret) { @@ -472,7 +478,8 @@ void pselect_fd_too_big(void) } else { printf("# [pselect] timeout\n"); } - +error: + return; } /* @@ -655,7 +662,11 @@ void stress_ppoll(int *fds, int value) do_ppoll(fds, ufds); } stop_thread = 1; - pthread_join(writer, NULL); + ret = pthread_join(writer, NULL); + if (ret) { + fprintf(stderr, "[error] pthread_join\n"); + goto end; + } end: return; } @@ -719,17 +730,15 @@ void epoll_pwait_concurrent_munmap(void) int ret, epollfd, i, fds[MAX_FDS]; char buf[BUF_SIZE]; struct epoll_event *epoll_event; - void *addr = NULL; pthread_t writer; - epollfd = epoll_create(MAX_FDS); if (epollfd < 0) { perror("[eppoll] create"); goto end; } - epoll_event = mmap(addr, MAX_FDS * sizeof(struct epoll_event), + epoll_event = mmap(NULL, MAX_FDS * sizeof(struct epoll_event), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (epoll_event == MAP_FAILED) { @@ -755,7 +764,7 @@ void epoll_pwait_concurrent_munmap(void) (void *) epoll_event); if (ret != 0) { fprintf(stderr, "[error] pthread_create\n"); - goto end; + goto end_unmap; } ret = epoll_pwait(epollfd, epoll_event, 1, 1, NULL); @@ -773,8 +782,11 @@ void epoll_pwait_concurrent_munmap(void) } stop_thread = 1; - pthread_join(writer, NULL); - + ret = pthread_join(writer, NULL); + if (ret) { + fprintf(stderr, "[error] pthread_join\n"); + goto end_unmap; + } end_unmap: for (i = 0; i < MAX_FDS; i++) { ret = close(fds[i]); @@ -783,7 +795,7 @@ end_unmap: } } - ret = munmap(addr, MAX_FDS * sizeof(struct epoll_event)); + ret = munmap(epoll_event, MAX_FDS * sizeof(struct epoll_event)); if (ret != 0) { perror("munmap"); } @@ -808,14 +820,14 @@ void print_list(void) "and epoll, waiting for input\n"); fprintf(stderr, "\t2: Timeout cases (1ms) for select, pselect6, poll, " "ppoll and epoll\n"); - fprintf(stderr, "\t3: pselect with a FD > 1023\n"); + fprintf(stderr, "\t3: pselect with an invalid fd\n"); fprintf(stderr, "\t4: ppoll with %d FDs\n", MAX_FDS); fprintf(stderr, "\t5: ppoll buffer overflow, should segfault, waits " "for input\n"); - fprintf(stderr, "\t6: pselect with invalid pointer, waits for " + fprintf(stderr, "\t6: pselect with an invalid pointer, waits for " "input\n"); fprintf(stderr, "\t7: ppoll with ulong_max fds, waits for input\n"); - fprintf(stderr, "\t8: epoll_pwait with invalid pointer, waits for " + fprintf(stderr, "\t8: epoll_pwait with an invalid pointer, waits for " "input\n"); fprintf(stderr, "\t9: epoll_pwait with maxevents set to INT_MAX, " "waits for input\n"); @@ -888,7 +900,7 @@ int main(int argc, const char **argv) run_working_cases(); break; case 3: - pselect_fd_too_big(); + pselect_invalid_fd(); break; case 4: test_ppoll_big();