summaryrefslogtreecommitdiffstats
path: root/auto-virtserial.c
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2009-10-23 17:05:47 +0530
committerAmit Shah <amit.shah@redhat.com>2009-10-24 14:27:35 +0530
commited66b2d7d901b96ed53987d27d78118c3824bc0f (patch)
treeee5c3e9456d4fdf3b7394ef9a2be5bab37316ea8 /auto-virtserial.c
parent0d93141ebaabb041fc590ce7cc7f409df3162af7 (diff)
downloadtest-virtserial-ed66b2d7d901b96ed53987d27d78118c3824bc0f.tar.gz
test-virtserial-ed66b2d7d901b96ed53987d27d78118c3824bc0f.tar.xz
test-virtserial-ed66b2d7d901b96ed53987d27d78118c3824bc0f.zip
auto-test: support for transferring a big file and comparing sha1sums
There are a lot of values hardcoded; they should become configurable someplace. Signed-off-by: Amit Shah <amit.shah@redhat.com>
Diffstat (limited to 'auto-virtserial.c')
-rw-r--r--auto-virtserial.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/auto-virtserial.c b/auto-virtserial.c
index 5c3cc9e..f2db046 100644
--- a/auto-virtserial.c
+++ b/auto-virtserial.c
@@ -37,6 +37,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
+#include <sys/wait.h>
#include "virtserial.h"
#define DEBUG 1
@@ -224,6 +225,15 @@ static int guest_set_port_nonblocking(int nr, int value)
return guest_cmd(&gpkt);
}
+static int guest_open_bigfile(int value)
+{
+ struct guest_packet gpkt;
+
+ gpkt.key = KEY_OPEN_BIGFILE;
+ gpkt.value = value;
+ return guest_cmd(&gpkt);
+}
+
static void show_stats(void)
{
fprintf(stderr, "-----\n");
@@ -776,6 +786,125 @@ out:
return ret;
}
+static int test_file_send(int nr)
+{
+ char buf[BUF_LENGTH];
+ char csum[BUF_LENGTH];
+ struct pollfd pollfds[1];
+ struct guest_packet gpkt;
+ int ret, fd, csum_fd;
+
+ /*
+ * Open guest, open host, send file, compute checksum on
+ * guest, compute checksum here, compare
+ */
+ fd = open(BIG_FILE, O_RDONLY);
+ if (fd < 0) {
+ fail(__func__, "open");
+ debug("%s: open: ret = %d\n", __func__, -errno);
+ ret = -errno;
+ goto out;
+ }
+ guest_open_port(nr);
+ host_connect_chardev(nr);
+
+ ret = guest_open_bigfile(1);
+ if (ret < 0) {
+ fail(__func__, "open bigfile");
+ debug("%s: open_bigfile: ret = %d\n", __func__, ret);
+ goto out_clean;
+ }
+ guest_set_length(nr, BUF_LENGTH);
+
+ gpkt.key = KEY_BYTESTREAM;
+ gpkt.value = nr;
+ guest_cmd_only(&gpkt);
+ /* The guest now is waiting for our data */
+
+ while ((ret = read(fd, buf, BUF_LENGTH)))
+ ret = write(chardevs[nr].sock, buf, ret);
+
+ /* guest will stop reading only if read() returns 0 */
+ host_close_chardev(nr);
+
+ if (ret < 0) {
+ fail(__func__, "read/write");
+ debug("%s: read/write: ret = %d\n", __func__, -errno);
+ fd = -errno;
+ goto out_clean;
+ }
+ get_guest_response(&gpkt);
+ if (gpkt.key != KEY_RESULT || gpkt.value != 0) {
+ fail(__func__, "guest response");
+ debug("%s: guest responded with %d(%d)\n",
+ __func__, gpkt.key, gpkt.value);
+ goto out_clean;
+ }
+ host_connect_chardev(nr);
+ gpkt.key = KEY_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");
+ if (ret == -1) {
+ fail(__func__, "csum");
+ ret = -errno;
+ goto out_clean;
+ }
+ if (WIFEXITED(ret) != true) {
+ fail(__func__, "csum2");
+ ret = -1;
+ goto out_clean;
+ }
+ if (WEXITSTATUS(ret) != 0) {
+ fail(__func__, "csum3");
+ ret = -WEXITSTATUS(ret);
+ goto out_clean;
+ }
+ csum_fd = open("/tmp/amit/csumfile", O_RDONLY);
+ if (!csum_fd) {
+ return -errno;
+ }
+ ret = read(csum_fd, csum, BUF_LENGTH);
+ close(csum_fd);
+
+ get_guest_response(&gpkt);
+ if (gpkt.key != KEY_RESULT || gpkt.value < 0) {
+ fail(__func__, "guest csum");
+ debug("%s: guest responded with %d(%d)\n",
+ __func__, gpkt.key, gpkt.value);
+ goto out_clean;
+ }
+ /* Guest sent its computed checksum on the same port */
+ read(chardevs[nr].sock, buf, gpkt.value);
+ if (!strncmp(csum, buf, gpkt.value)) {
+ pass(__func__, "csum");
+ } else {
+ fail(__func__, "csum");
+ debug("%s: guest csum: %s, host csum: %s\n",
+ __func__, buf, csum);
+ }
+out_clean:
+ /*
+ * If read/write above fails, we would have an outstanding
+ * guest response to look after.
+ */
+ pollfds[0].fd = chardevs[nr].sock;
+ pollfds[0].events = POLLIN;
+ while (poll(pollfds, 1, 0) > 0)
+ read(chardevs[1].sock, buf, BUF_LENGTH);
+
+ while(guest_poll(nr, 0) & POLLIN)
+ guest_read(nr, BUF_LENGTH);
+
+ while (poll(pollfds, 1, 0) > 0)
+ read(chardevs[nr].sock, buf, BUF_LENGTH);
+
+ guest_close_port(nr);
+out:
+ return ret;
+}
+
static int start_tests(void)
{
if (guest_ok) {
@@ -814,6 +943,9 @@ static int start_tests(void)
test_host_caching(2);
/* Caching is not enabled on this port */
test_host_caching(3);
+
+ /* Sends a big file across, compares sha1sums */
+ test_file_send(3);
}
/* The console test should work in any case. */
test_console(0);