diff options
author | Amit Shah <amit.shah@redhat.com> | 2010-08-25 19:00:53 +0530 |
---|---|---|
committer | Amit Shah <amit.shah@redhat.com> | 2010-08-26 09:43:22 +0530 |
commit | f50f751a4980447a465e5039272ae0b0d8708aed (patch) | |
tree | c77458b29b629c9596e2c9b5af05ce660d393f9e /auto-virtserial.c | |
parent | d99d351e8b683835b43060b562fd68163902d89a (diff) | |
download | test-virtserial-f50f751a4980447a465e5039272ae0b0d8708aed.tar.gz test-virtserial-f50f751a4980447a465e5039272ae0b0d8708aed.tar.xz test-virtserial-f50f751a4980447a465e5039272ae0b0d8708aed.zip |
auto-virtserial: Add guest SIGIO tests
The guest can receive the SIGIO signal on host connection and
disconnection events. This commit just adds a simple test for one
open/close event. A lot more are to be added, as explained in the
comments.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Diffstat (limited to 'auto-virtserial.c')
-rw-r--r-- | auto-virtserial.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/auto-virtserial.c b/auto-virtserial.c index 260825b..811bfd5 100644 --- a/auto-virtserial.c +++ b/auto-virtserial.c @@ -266,6 +266,15 @@ static int guest_join_read_thread(int nr) return guest_cmd(&gpkt); } +static int guest_get_sigio_poll_result(int nr) +{ + struct guest_packet gpkt; + + gpkt.key = KEY_GET_SIGIO_RESULT; + gpkt.value = nr; + return guest_cmd(&gpkt); +} + static void show_stats(void) { fprintf(stderr, "-----\n"); @@ -1205,6 +1214,48 @@ out: return err; } +/* + * The virtio_console guest kernel driver sends a SIGIO each time the + * host-side connection status is changed (connected, disconnected) to + * a process that has a virtserial port open. + * + * Tests: + * - open a port in the guest, connect host chardev. Should receive SIGIO. + * - open a port in host, then open in guest, disconnect host chardev. + * - write from the host to a guest port. Should receive SIGIO. + * - open multiple ports in guest, open corresponding host chardevs. + * - similar to above for host chardev disconnects + * - let the guest poll on some fd, then cause SIGIO. Make sure prev. poll + * works fine. + */ +static int test_sigio_handler(int nr) +{ + int ret, err; + + guest_open_port(nr); + /* Give time to the guest to schedule in and perform the open() */ + sleep(2); + + host_connect_chardev(nr); + + /* Give time to the guest to schedule in and to receive the signal */ + sleep(2); + + ret = guest_get_sigio_poll_result(nr); + err = result(__func__, true, "open", + ret, POLLOUT, POLLOUT, OP_EQ, true); + + host_close_chardev(nr); + sleep(2); + + ret = guest_get_sigio_poll_result(nr); + err = result(__func__, true, "close", + ret, POLLHUP, POLLHUP, OP_EQ, true); + + guest_close_port(nr); + return err; +} + enum { TEST_OPEN = 0, TEST_CLOSE, @@ -1224,6 +1275,7 @@ enum { TEST_G_FILE_SEND, TEST_CONSOLE, TEST_THREADED_READ_WRITE, + TEST_SIGIO_HANDLER, TEST_END }; @@ -1304,6 +1356,10 @@ static struct test_parameters { .test_function = test_threaded_read_write, .needs_guestok = true, }, + { + .test_function = test_sigio_handler, + .needs_guestok = true, + }, }; static void post_test_cleanup(int nr) @@ -1446,6 +1502,7 @@ static int start_tests(void) run_test(TEST_THREADED_READ_WRITE, 2); + run_test(TEST_SIGIO_HANDLER, 2); return 0; } |