summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2010-03-26 12:17:49 +0530
committerAmit Shah <amit.shah@redhat.com>2010-04-06 20:01:35 +0530
commitc2ce8ad58da33c731c18f1a198e49b99e7aa5870 (patch)
tree3097aadede41e3c23d87b41655bf5e9a532d0ed6
parent7798bff7fa23ea2218a1480fecbcdd981fed4039 (diff)
downloadtest-virtserial-c2ce8ad58da33c731c18f1a198e49b99e7aa5870.tar.gz
test-virtserial-c2ce8ad58da33c731c18f1a198e49b99e7aa5870.tar.xz
test-virtserial-c2ce8ad58da33c731c18f1a198e49b99e7aa5870.zip
auto-test: Non-blocking write test
This new test puts a port in non-blocking mode in the guest and keeps sending data till the host can't accept any more. In this case, the vq is filled and the guest gets -EAGAIN on write. poll() should not return POLLOUT. Signed-off-by: Amit Shah <amit.shah@redhat.com>
-rw-r--r--auto-virtserial.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/auto-virtserial.c b/auto-virtserial.c
index e3f2a81..5777583 100644
--- a/auto-virtserial.c
+++ b/auto-virtserial.c
@@ -501,6 +501,64 @@ out:
return err;
}
+static int test_blocking_write(int nr)
+{
+ return 0;
+}
+
+static int test_nonblocking_write(int nr)
+{
+ unsigned int i;
+ int err, ret;
+ bool test_done;
+
+ ret = guest_open_port(nr);
+ err = result(__func__, true, "guest open", ret, -1, -1, OP_GT, false);
+ if (err)
+ return err;
+
+ ret = guest_set_port_nonblocking(nr, true);
+ err = result(__func__, true, "blocking", ret, 0, 0, OP_EQ, false);
+ if (err)
+ goto out;
+
+ host_connect_chardev(nr);
+
+ test_done = false;
+ /*
+ * We currently have 128 buffers in a virtqueue --
+ * hw/virtio-serial-bus.c, so this while loop should stop when
+ * i is 128.
+ */
+ for (i = 0; i < 200 && !test_done; i++) {
+ ret = guest_poll(nr, 0);
+ if (i && ret == 0) {
+ /* vq full. Nonblocking IO and poll for that works. */
+
+ test_done = true;
+
+ /* Now try writing to the guest. That should fail too */
+ }
+ err = result(__func__, test_done, "guest poll", ret,
+ 0, POLLOUT, OP_EQ, false);
+ if (err)
+ goto out;
+
+ ret = guest_write(nr, BUF_LENGTH);
+ err = result(__func__, test_done, "guest write",
+ ret, -EAGAIN, BUF_LENGTH, OP_EQ, false);
+ if (err)
+ goto out;
+ }
+
+out:
+ ret = guest_set_port_nonblocking(nr, false);
+ err = result(__func__, true, "blocking", ret, 0, 0, OP_EQ, true);
+ host_close_chardev(nr);
+ guest_close_port(nr);
+ return err;
+}
+
static int test_poll(int nr)
{
int err, ret;
@@ -1042,6 +1100,8 @@ enum {
TEST_READ_WO_HOST,
TEST_BLOCKING_READ,
TEST_NOBLOCK_READ,
+ TEST_BLOCKING_WRITE,
+ TEST_NONBLOCK_WRITE,
TEST_POLL,
TEST_G_THROTTLE,
TEST_H_THROTTLE,
@@ -1087,6 +1147,14 @@ static struct test_parameters {
.needs_guestok = true,
},
{
+ .test_function = test_blocking_write,
+ .needs_guestok = true,
+ },
+ {
+ .test_function = test_nonblocking_write,
+ .needs_guestok = true,
+ },
+ {
.test_function = test_poll,
.needs_guestok = true,
},
@@ -1182,6 +1250,9 @@ static int start_tests(void)
run_test(TEST_BLOCKING_READ, 2);
run_test(TEST_NOBLOCK_READ, 2);
+ run_test(TEST_BLOCKING_WRITE, 2);
+ run_test(TEST_NONBLOCK_WRITE, 2);
+
run_test(TEST_POLL, 2);
#if 0