Skip to content

Commit

Permalink
[linux] Do not hard-code fd numbers in epoll test
Browse files Browse the repository at this point in the history
In case file descriptor 3 and 4 are being used already, the executable
created by epoll.c exits with exit code 1, and prints the message -

	epoll_ctl<6>: Invalid argument

causing case-20-epoll.bash to FAIL.
  • Loading branch information
subnut committed Jan 28, 2023
1 parent 898fe0e commit 5ca335f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions dialects/linux/tests/case-20-epoll.bash
Expand Up @@ -8,8 +8,8 @@ if ! [ -x $TARGET ]; then
fi

$TARGET 2>> $report | {
read pid epfd
if [[ -z "$pid" || -z "$epfd" ]]; then
read pid epfd evfd0 evfd1
if [[ -z "$pid" || -z "$epfd" || -z "$evfd0" || -z "$evfd1" ]]; then
echo "unexpected output form target ( $TARGET )" >> $report
exit 1
fi
Expand All @@ -25,7 +25,7 @@ $TARGET 2>> $report | {
echo done
} >> $report
if $lsof -p $pid -a -d $epfd |
grep -q "epoll *[0-9]* *.* *${epfd}u *a_inode *[0-9]*,[0-9]* *[0-9]* *[0-9]* *\[eventpoll:5,6\]"; then
grep -q "epoll *[0-9]* *.* *${epfd}u *a_inode *[0-9]*,[0-9]* *[0-9]* *[0-9]* *\[eventpoll:${evfd0},${evfd1}\]"; then
kill $pid
exit 0
else
Expand Down
33 changes: 17 additions & 16 deletions dialects/linux/tests/epoll.c
Expand Up @@ -11,37 +11,38 @@ int main(int argc, char **argv) {
return 1;
}

struct epoll_event ev;
int fd[2];
if (pipe(fd) < 0)
if (fd < 0) {
perror("pipe");
return 1;
}
if (dup2(fd[0], 5) < 0) {
perror("dup2(fd[0], 5)");
int pipefd[2];
if (pipe(pipefd) < 0) {
perror("pipe");
return 1;
}
if (dup2(fd[1], 6) < 0) {
perror("dup2(fd[1], 6)");

int evfd[2];
if ((evfd[0] = dup(pipefd[0])) < 0) {
perror("dup(pipefd[0])");
return 1;
}
if ((evfd[1] = dup(pipefd[1])) < 0) {
perror("dup(pipefd[1])");
return 1;
}

struct epoll_event ev;
ev.events = EPOLLOUT;
ev.data.fd = 6;
ev.data.fd = evfd[1];
if (epoll_ctl(epfd, EPOLL_CTL_ADD, ev.data.fd, &ev) < 0) {
perror("epoll_ctl<6>");
perror("epoll_ctl<evfd[1]>");
return 1;
}

ev.events = EPOLLIN;
ev.data.fd = 5;
ev.data.fd = evfd[0];
if (epoll_ctl(epfd, EPOLL_CTL_ADD, ev.data.fd, &ev) < 0) {
perror("epoll_ctl<5>");
perror("epoll_ctl<evfd[0]>");
return 1;
}

printf("%d %d\n", getpid(), epfd);
printf("%d %d %d %d\n", getpid(), epfd, evfd[0], evfd[1]);
fflush(stdout);
pause();
return 0;
Expand Down

0 comments on commit 5ca335f

Please sign in to comment.