summaryrefslogtreecommitdiffstats
path: root/auto-virtserial-guest.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-guest.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-guest.c')
-rw-r--r--auto-virtserial-guest.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/auto-virtserial-guest.c b/auto-virtserial-guest.c
index db1814e..90af245 100644
--- a/auto-virtserial-guest.c
+++ b/auto-virtserial-guest.c
@@ -31,12 +31,15 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include "virtserial.h"
#define CONTROL_PORT "/dev/vcon1"
/* The fd to work with for read / write requests. Set by the open message */
static int fd;
+/* The fd to stuff in bytes for a big file receive command */
+static int bigfile_fd;
/* The length to read / write. Set by the length message. Unset at close */
static int length;
@@ -157,6 +160,61 @@ static int spawn_console(int val)
return 0;
}
+static int open_bigfile(int val)
+{
+ bigfile_fd = open(BIG_FILE, O_RDWR | O_CREAT);
+ if (bigfile_fd < 0)
+ return -errno;
+ return 0;
+}
+
+static int save_bytestream(int val)
+{
+ int ret;
+ char *buf;
+
+ buf = malloc(length);
+ if (!buf)
+ return -ENOMEM;
+
+ while((ret = read(fd, buf, length))) {
+ ret = write(bigfile_fd, buf, ret);
+ if (ret < 0)
+ break;
+ }
+ free(buf);
+ return ret;
+}
+
+static int send_csum(int nr)
+{
+ char *buf;
+ int ret, csum_fd;
+
+ buf = malloc(length);
+
+ ret = system("sha1sum /tmp/amit/big-file > /tmp/amit/csumfile");
+ if (ret == -1)
+ return -errno;
+ if (WIFEXITED(ret) != true)
+ return -1;
+ if (WEXITSTATUS(ret) != 0)
+ return -WEXITSTATUS(ret);
+
+ csum_fd = open("/tmp/amit/csumfile", O_RDONLY);
+ if (!csum_fd) {
+ return -errno;
+ }
+ ret = read(csum_fd, buf, length);
+ close(csum_fd);
+
+ ret = write(fd, buf, ret);
+ if (ret < 0)
+ ret = -errno;
+ free(buf);
+ return ret;
+}
+
static void send_report(int cfd, int ret)
{
struct guest_packet gpkt;
@@ -251,6 +309,18 @@ back_to_open:
ret = poll_port(gpkt.value);
send_report(cfd, ret);
break;
+ case KEY_OPEN_BIGFILE:
+ ret = open_bigfile(gpkt.value);
+ send_report(cfd, ret);
+ break;
+ case KEY_BYTESTREAM:
+ ret = save_bytestream(gpkt.value);
+ send_report(cfd, ret);
+ break;
+ case KEY_CSUM:
+ ret = send_csum(gpkt.value);
+ send_report(cfd, ret);
+ break;
}
}
return 0;