diff options
author | Amit Shah <amit.shah@redhat.com> | 2009-11-27 21:57:12 +0530 |
---|---|---|
committer | Amit Shah <amit.shah@redhat.com> | 2009-12-22 12:36:01 +0530 |
commit | 8b78048cc1b56924fab7191fa3e259a09be14318 (patch) | |
tree | b5749ab62e25ab3edc465140774ecc166afaa8f1 /auto-virtserial-guest.c | |
parent | b702d95f7f6d0febf9902bcec95f7cfc9d2202c4 (diff) | |
download | test-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-guest.c')
-rw-r--r-- | auto-virtserial-guest.c | 96 |
1 files changed, 84 insertions, 12 deletions
diff --git a/auto-virtserial-guest.c b/auto-virtserial-guest.c index 29ddac3..ce64ebc 100644 --- a/auto-virtserial-guest.c +++ b/auto-virtserial-guest.c @@ -168,15 +168,15 @@ static int spawn_console(int val) return 0; } -static int open_bigfile(int val) +static int open_host_bigfile(int val) { - g_bigfile_fd = open(BIG_FILE, O_RDWR | O_CREAT); + g_bigfile_fd = open(HOST_BIG_FILE, O_RDWR | O_CREAT); if (g_bigfile_fd < 0) return -errno; return 0; } -static int save_bytestream(int val) +static int recv_bytestream(int val) { int ret; char *buf; @@ -195,14 +195,14 @@ static int save_bytestream(int val) return ret; } -static int send_csum(int nr) +static int send_host_csum(int nr) { char *buf; int ret, csum_fd; buf = malloc(g_length); - ret = system("sha1sum /tmp/amit/big-file > /tmp/amit/csumfile"); + ret = system("sha1sum /tmp/amit/host-big-file > /tmp/amit/host-csumfile"); if (ret == -1) return -errno; if (WIFEXITED(ret) != true) @@ -210,7 +210,67 @@ static int send_csum(int nr) if (WEXITSTATUS(ret) != 0) return -WEXITSTATUS(ret); - csum_fd = open("/tmp/amit/csumfile", O_RDONLY); + csum_fd = open("/tmp/amit/host-csumfile", O_RDONLY); + if (!csum_fd) { + return -errno; + } + ret = read(csum_fd, buf, g_length); + close(csum_fd); + + ret = write(g_fd, buf, ret); + if (ret < 0) + ret = -errno; + free(buf); + return ret; +} + +static int open_guest_bigfile(int val) +{ + g_bigfile_fd = open(GUEST_BIG_FILE, O_RDONLY); + if (g_bigfile_fd < 0) + return -errno; + return 0; +} + +static int send_bytestream(int val) +{ + int ret; + char *buf; + + buf = malloc(g_length); + if (!buf) + return -ENOMEM; + + while((ret = read(g_bigfile_fd, buf, g_length)) > 0) { + + ret = write(g_fd, buf, ret); + if (ret < 0) + break; + } + free(buf); + close(g_bigfile_fd); + close(g_fd); + if (ret < 0) + ret = -errno; + return ret; +} + +static int send_guest_csum(int nr) +{ + char *buf; + int ret, csum_fd; + + buf = malloc(g_length); + + ret = system("sha1sum /tmp/amit/guest-big-file > /tmp/amit/guest-csumfile"); + if (ret == -1) + return -errno; + if (WIFEXITED(ret) != true) + return -1; + if (WEXITSTATUS(ret) != 0) + return -WEXITSTATUS(ret); + + csum_fd = open("/tmp/amit/guest-csumfile", O_RDONLY); if (!csum_fd) { return -errno; } @@ -368,16 +428,16 @@ back_to_open: ret = poll_port(gpkt.value); send_report(cfd, ret); break; - case KEY_OPEN_BIGFILE: - ret = open_bigfile(gpkt.value); + case KEY_OPEN_HOST_BIGFILE: + ret = open_host_bigfile(gpkt.value); send_report(cfd, ret); break; - case KEY_BYTESTREAM: - ret = save_bytestream(gpkt.value); + case KEY_HOST_BYTESTREAM: + ret = recv_bytestream(gpkt.value); send_report(cfd, ret); break; - case KEY_CSUM: - ret = send_csum(gpkt.value); + case KEY_HOST_CSUM: + ret = send_host_csum(gpkt.value); send_report(cfd, ret); break; case KEY_CHECK_SYSFS: @@ -388,6 +448,18 @@ back_to_open: ret = check_udev(gpkt.value); send_report(cfd, ret); break; + case KEY_OPEN_GUEST_BIGFILE: + ret = open_guest_bigfile(gpkt.value); + send_report(cfd, ret); + break; + case KEY_GUEST_BYTESTREAM: + ret = send_bytestream(gpkt.value); + send_report(cfd, ret); + break; + case KEY_GUEST_CSUM: + ret = send_guest_csum(gpkt.value); + send_report(cfd, ret); + break; } } return 0; |