summaryrefslogtreecommitdiffstats
path: root/auto-virtserial.c
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2009-11-27 21:57:12 +0530
committerAmit Shah <amit.shah@redhat.com>2009-12-22 12:36:01 +0530
commit8b78048cc1b56924fab7191fa3e259a09be14318 (patch)
treeb5749ab62e25ab3edc465140774ecc166afaa8f1 /auto-virtserial.c
parentb702d95f7f6d0febf9902bcec95f7cfc9d2202c4 (diff)
downloadtest-virtserial-8b78048cc1b56924fab7191fa3e259a09be14318.tar.gz
test-virtserial-8b78048cc1b56924fab7191fa3e259a09be14318.tar.xz
test-virtserial-8b78048cc1b56924fab7191fa3e259a09be14318.zip
auto-test: add support for guest->host file send
Send file from guest->host and compare csums Signed-off-by: Amit Shah <amit.shah@redhat.com>
Diffstat (limited to 'auto-virtserial.c')
-rw-r--r--auto-virtserial.c150
1 files changed, 139 insertions, 11 deletions
diff --git a/auto-virtserial.c b/auto-virtserial.c
index 5630611..f25cbbf 100644
--- a/auto-virtserial.c
+++ b/auto-virtserial.c
@@ -106,7 +106,8 @@ enum {
TEST_H_THROTTLE,
TEST_G_CACHING,
TEST_H_CACHING,
- TEST_FILE_SEND,
+ TEST_H_FILE_SEND,
+ TEST_G_FILE_SEND,
TEST_CONSOLE,
TEST_END
};
@@ -250,11 +251,20 @@ static int guest_set_port_nonblocking(int nr, int value)
return guest_cmd(&gpkt);
}
-static int guest_open_bigfile(int value)
+static int guest_open_host_bigfile(int value)
{
struct guest_packet gpkt;
- gpkt.key = KEY_OPEN_BIGFILE;
+ gpkt.key = KEY_OPEN_HOST_BIGFILE;
+ gpkt.value = value;
+ return guest_cmd(&gpkt);
+}
+
+static int guest_open_guest_bigfile(int value)
+{
+ struct guest_packet gpkt;
+
+ gpkt.key = KEY_OPEN_GUEST_BIGFILE;
gpkt.value = value;
return guest_cmd(&gpkt);
}
@@ -826,7 +836,7 @@ out:
return err;
}
-static int test_file_send(int nr)
+static int test_host_file_send(int nr)
{
char buf[BUF_LENGTH];
char csum[BUF_LENGTH];
@@ -837,7 +847,7 @@ static int test_file_send(int nr)
* Open guest, open host, send file, compute checksum on
* guest, compute checksum here, compare
*/
- fd = open(BIG_FILE, O_RDONLY);
+ fd = open(HOST_BIG_FILE, O_RDONLY);
err = result(__func__, true, "open", fd, -1, 0, OP_GT, false);
if (err)
return err;
@@ -845,14 +855,14 @@ static int test_file_send(int nr)
guest_open_port(nr);
host_connect_chardev(nr);
- ret = guest_open_bigfile(1);
+ ret = guest_open_host_bigfile(1);
err = result(__func__, true, "guest open", ret, -1, 0, OP_GT, false);
if (err)
goto out_close;
guest_set_length(nr, BUF_LENGTH);
- gpkt.key = KEY_BYTESTREAM;
+ gpkt.key = KEY_HOST_BYTESTREAM;
gpkt.value = nr;
guest_cmd_only(&gpkt);
/* The guest now is waiting for our data */
@@ -860,6 +870,7 @@ static int test_file_send(int nr)
while ((ret = read(fd, buf, BUF_LENGTH)))
write(chardevs[nr].sock, buf, ret);
+ close(fd);
/* guest will stop reading only if read() returns 0 */
host_close_chardev(nr);
@@ -879,12 +890,121 @@ static int test_file_send(int nr)
goto out_close;
host_connect_chardev(nr);
- gpkt.key = KEY_CSUM;
+ gpkt.key = KEY_HOST_CSUM;
+ gpkt.value = nr;
+ guest_cmd_only(&gpkt);
+
+ /* Compute checksum here while the guest does the same */
+ ret = system("sha1sum /tmp/amit/host-big-file > /tmp/amit/host-csumfile");
+ err = result(__func__, true, "csum1",
+ ret, -1, 0, OP_GT, false);
+ if (err)
+ goto out_close;
+
+ err = result(__func__, true, "csum2",
+ WIFEXITED(ret), true, 0, OP_EQ, false);
+ if (err)
+ goto out_close;
+
+ err = result(__func__, true, "csum3",
+ WEXITSTATUS(ret), 0, 0, OP_EQ, false);
+ if (err)
+ goto out_close;
+
+ csum_fd = open("/tmp/amit/host-csumfile", O_RDONLY);
+ err = result(__func__, true, "open csumfd",
+ csum_fd, -1, 0, OP_GT, false);
+ if (err)
+ goto out_close;
+
+ read(csum_fd, csum, BUF_LENGTH);
+ close(csum_fd);
+
+ get_guest_response(&gpkt);
+ err = result(__func__, true, "csum response",
+ gpkt.key, KEY_RESULT, 0, OP_EQ, false);
+ if (err)
+ goto out_close;
+
+ err = result(__func__, true, "guest csum",
+ gpkt.value, 0, 0, OP_GT, false);
+ if (err)
+ goto out_close;
+
+ /* Guest sent its computed checksum on the same port */
+ read(chardevs[nr].sock, buf, gpkt.value);
+ ret = strncmp(csum, buf, gpkt.value);
+ err = result(__func__, true, "csum", ret, 0, 0, OP_EQ, true);
+ if (err) {
+ debug("guest csum: %s\n", buf);
+ debug("host csum : %s\n", csum);
+ }
+
+out_close:
+ host_close_chardev(nr);
+ guest_close_port(nr);
+ return err;
+}
+
+static int test_guest_file_send(int nr)
+{
+ char buf[BUF_LENGTH];
+ char csum[BUF_LENGTH];
+ struct guest_packet gpkt;
+ int err, ret, fd, csum_fd;
+
+ /*
+ * Open guest, open host, recv file, compute checksum on
+ * guest, compute checksum here, compare
+ */
+ fd = open("/tmp/amit/guest-big-file", O_RDWR | O_CREAT);
+ err = result(__func__, true, "host open", fd, -1, 0, OP_GT, false);
+ if (err) {
+ return err;
+ }
+
+ guest_open_port(nr);
+ host_connect_chardev(nr);
+
+ ret = guest_open_guest_bigfile(1);
+ err = result(__func__, true, "guest open", ret, -1, 0, OP_GT, false);
+ if (err)
+ goto out_close;
+
+ guest_set_length(nr, BUF_LENGTH);
+
+ gpkt.key = KEY_GUEST_BYTESTREAM;
gpkt.value = nr;
guest_cmd_only(&gpkt);
+ /* The guest now is sending us data */
+
+ while ((ret = read(chardevs[nr].sock, buf, BUF_LENGTH))) {
+ write(fd, buf, ret);
+ if (ret > 0 && ret < BUF_LENGTH)
+ break;
+ }
+ err = result(__func__, true, "read/write", ret, -1, 0, OP_GT, false);
+ if (err)
+ goto out_close;
+
+ close(fd);
+ get_guest_response(&gpkt);
+ err = result(__func__, true, "bytestream response",
+ gpkt.key, KEY_RESULT, 0, OP_EQ, false);
+ if (err)
+ goto out_close;
+ err = result(__func__, true, "bytestream response",
+ gpkt.value, 0, 0, OP_EQ, false);
+ if (err)
+ goto out_close;
+
+ guest_open_port(nr);
+ gpkt.key = KEY_GUEST_CSUM;
+ gpkt.value = nr;
+ guest_cmd_only(&gpkt);
/* Compute checksum here while the guest does the same */
- ret = system("sha1sum /tmp/amit/big-file > /tmp/amit/csumfile");
+ ret = system("sha1sum /tmp/amit/guest-big-file > /tmp/amit/guest-csumfile");
err = result(__func__, true, "csum1",
ret, -1, 0, OP_GT, false);
if (err)
@@ -900,7 +1020,7 @@ static int test_file_send(int nr)
if (err)
goto out_close;
- csum_fd = open("/tmp/amit/csumfile", O_RDONLY);
+ csum_fd = open("/tmp/amit/guest-csumfile", O_RDONLY);
err = result(__func__, true, "open csumfd",
csum_fd, -1, 0, OP_GT, false);
if (err)
@@ -924,6 +1044,10 @@ static int test_file_send(int nr)
read(chardevs[nr].sock, buf, gpkt.value);
ret = strncmp(csum, buf, gpkt.value);
err = result(__func__, true, "csum", ret, 0, 0, OP_EQ, true);
+ if (err) {
+ debug("guest csum: %s\n", buf);
+ debug("host csum : %s\n", csum);
+ }
out_close:
host_close_chardev(nr);
@@ -1016,7 +1140,11 @@ static int start_tests(void)
run_test(test_host_caching, 3, TEST_H_CACHING);
/* Sends a big file across, compares sha1sums */
- run_test(test_file_send, 2, TEST_FILE_SEND);
+ run_test(test_host_file_send, 2, TEST_H_FILE_SEND);
+
+ /* Sends a big file across, compares sha1sums */
+ run_test(test_guest_file_send, 2, TEST_G_FILE_SEND);
+
}
/* The console test should work in any case. */
run_test(test_console, 0, TEST_CONSOLE);