diff options
author | Amit Shah <amit.shah@redhat.com> | 2010-08-26 09:36:29 +0530 |
---|---|---|
committer | Amit Shah <amit.shah@redhat.com> | 2010-08-26 09:43:58 +0530 |
commit | 6978ab579482e055bd679893491f74392b84e6ed (patch) | |
tree | 266b9b73b103b0e5215bca9e7896c5d94e6463df | |
parent | 875796bff9d5d1aea84648b1b634a6f374ad0c7f (diff) | |
download | test-virtserial-6978ab579482e055bd679893491f74392b84e6ed.tar.gz test-virtserial-6978ab579482e055bd679893491f74392b84e6ed.tar.xz test-virtserial-6978ab579482e055bd679893491f74392b84e6ed.zip |
auto-test: Add a key to specify poll events to poll for
We always invoked a guest poll with POLLIN|POLLOUT events. There's a
case where custom events might be necessary -- the sigio handler test,
for example. Add a new key to set the poll events.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r-- | auto-virtserial-guest.c | 13 | ||||
-rw-r--r-- | auto-virtserial.c | 25 | ||||
-rw-r--r-- | virtserial.h | 1 |
3 files changed, 31 insertions, 8 deletions
diff --git a/auto-virtserial-guest.c b/auto-virtserial-guest.c index 7e16282..10daeb5 100644 --- a/auto-virtserial-guest.c +++ b/auto-virtserial-guest.c @@ -40,6 +40,8 @@ /* The fd to work with for read / write requests. Set by the open message */ static int g_fd; +/* The events to poll for */ +static int g_poll_events; /* The fd to stuff in bytes for a big file receive command */ static int g_bigfile_fd; /* The length to read / write. Set by the length message. Unset at close */ @@ -179,13 +181,18 @@ static int open_port(int nr) return fd; } +static int set_poll_events(int events) +{ + return g_poll_events = events; +} + static int poll_port(int timeout) { struct pollfd pollfds[1]; int ret; pollfds[0].fd = g_fd; - pollfds[0].events = POLLIN | POLLOUT; + pollfds[0].events = g_poll_events ? : POLLIN | POLLOUT; ret = safepoll(pollfds, 1, timeout); if (ret <= 0) return ret; @@ -654,6 +661,10 @@ back_to_open: ret = write_port(gpkt.value); send_report(cfd, ret); break; + case KEY_POLL_EVENTS: + ret = set_poll_events(gpkt.value); + send_report(cfd, ret); + break; case KEY_POLL: ret = poll_port(gpkt.value); send_report(cfd, ret); diff --git a/auto-virtserial.c b/auto-virtserial.c index e0a61f6..ccd35e9 100644 --- a/auto-virtserial.c +++ b/auto-virtserial.c @@ -212,10 +212,21 @@ static int guest_write(int nr, int len) return guest_cmd(&gpkt); } -static int guest_poll(int nr, int timeout) +static int guest_set_poll_events(int nr, int events) { struct guest_packet gpkt; + gpkt.key = KEY_POLL_EVENTS; + gpkt.value = events; + return guest_cmd(&gpkt); +} + +static int guest_poll(int nr, int events, int timeout) +{ + struct guest_packet gpkt; + + guest_set_poll_events(nr, events); + gpkt.key = KEY_POLL; gpkt.value = timeout; return guest_cmd(&gpkt); @@ -574,7 +585,7 @@ static int test_nonblocking_write(int nr) * i is 128. */ for (i = 0; i < 200 && !test_done; i++) { - ret = guest_poll(nr, 0); + ret = guest_poll(nr, 0, 0); if (i && ret == 0) { /* vq full. Nonblocking IO and poll for that works. */ @@ -608,7 +619,7 @@ static int test_poll(int nr) int err, ret; guest_open_port(nr); - ret = guest_poll(nr, 0); + ret = guest_poll(nr, 0, 0); err = result(__func__, true, "POLLHUP", ret, POLLHUP, 0, OP_EQ, true); if (err) goto out; @@ -622,7 +633,7 @@ static int test_poll(int nr) host_connect_chardev(nr); /* Give the guest a chance to be scheduled in and react */ sleep(2); - ret = guest_poll(nr, 0); + ret = guest_poll(nr, 0, 0); err = result(__func__, true, "POLLOUT", ret, POLLOUT, 0, OP_EQ, true); if (err) goto out_close; @@ -630,7 +641,7 @@ static int test_poll(int nr) write(chardevs[nr].sock, &ret, sizeof(ret)); /* Give the guest a chance to be scheduled in and react */ sleep(2); - ret = guest_poll(nr, 0); + ret = guest_poll(nr, 0, 0); err = result(__func__, true, "POLLIN", ret, POLLIN|POLLOUT, 0, OP_EQ, true); @@ -750,7 +761,7 @@ static int test_guest_caching(int nr) /* Make sure the data made its way to the port in the guest */ sleep(2); - ret = guest_poll(nr, 10000); + ret = guest_poll(nr, 0, 10000); err = result(__func__, chardevs[nr].caching, "guest poll", ret, POLLIN|POLLOUT, POLLIN|POLLOUT, OP_EQ, false); @@ -1426,7 +1437,7 @@ static void post_test_cleanup(int nr) ret = guest_open_port(nr); if (ret < 0) goto skip_guest; - while ((ret = guest_poll(nr, 0))) { + while ((ret = guest_poll(nr, 0, 0))) { if ((ret > 0) && (ret & POLLIN)) guest_read(nr, BUF_LENGTH); else diff --git a/virtserial.h b/virtserial.h index 45857ad..4617414 100644 --- a/virtserial.h +++ b/virtserial.h @@ -19,6 +19,7 @@ #define KEY_CREATE_READ_THREAD 19 #define KEY_JOIN_READ_THREAD 20 #define KEY_GET_SIGIO_RESULT 21 +#define KEY_POLL_EVENTS 22 #define HOST_BIG_FILE "/tmp/amit/host-big-file" #define GUEST_BIG_FILE "/tmp/amit/guest-big-file" |