kernel: add fifo polling test from #7859
This commit is contained in:
parent
17f88a29db
commit
12b5c184b2
@ -11,6 +11,8 @@ SimpleTest fibo_load_image : fibo_load_image.cpp ;
|
||||
SimpleTest fibo_fork : fibo_fork.cpp ;
|
||||
SimpleTest fibo_exec : fibo_exec.cpp ;
|
||||
|
||||
SimpleTest fifo_poll_test : fifo_poll_test.cpp ;
|
||||
|
||||
SimpleTest live_query :
|
||||
live_query.cpp
|
||||
: be
|
||||
|
32
src/tests/system/kernel/fifo_poll_test.cpp
Normal file
32
src/tests/system/kernel/fifo_poll_test.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <poll.h>
|
||||
|
||||
int main() {
|
||||
FILE* f = popen("/bin/bash -c 'for i in 1 2 3; do { echo $i; sleep 1; }; done'", "r");
|
||||
printf("f=%p\n", f);
|
||||
int fd = fileno(f);
|
||||
printf("fd=%d\n", fd);
|
||||
|
||||
struct pollfd pfd;
|
||||
pfd.fd = fd;
|
||||
pfd.events = POLLIN | POLLRDBAND;
|
||||
|
||||
char buffer[80];
|
||||
|
||||
while (1) {
|
||||
int rv = poll(&pfd, 1, 500);
|
||||
printf("rv=%d\n", rv);
|
||||
if (rv == 0)
|
||||
continue;
|
||||
if (rv < 0)
|
||||
break;
|
||||
printf("events=%08x revents=%08x\n", pfd.events, pfd.revents);
|
||||
if ((pfd.events & pfd.revents) == 0)
|
||||
break;
|
||||
|
||||
fgets(buffer, 79, f);
|
||||
printf("output: %s", buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user