summaryrefslogtreecommitdiffstats
path: root/auto-virtserial.c
diff options
context:
space:
mode:
Diffstat (limited to 'auto-virtserial.c')
-rw-r--r--auto-virtserial.c106
1 files changed, 72 insertions, 34 deletions
diff --git a/auto-virtserial.c b/auto-virtserial.c
index 58bf779..f9cd4cd 100644
--- a/auto-virtserial.c
+++ b/auto-virtserial.c
@@ -54,6 +54,7 @@
#define UNIX_PATH_MAX 108
static unsigned int nr_passed, nr_failed;
+static bool guest_ok = false;
static struct host_chars {
char *path;
@@ -110,9 +111,18 @@ static int host_connect_chardev(int nr)
sock.sun_family = AF_UNIX;
memcpy(&sock.sun_path, chardevs[nr].path, sizeof(sock.sun_path));
ret = connect(chardevs[nr].sock, (struct sockaddr *)&sock, sizeof(sock));
- if (ret == -1)
- error(errno, errno, "connect: %s", chardevs[nr].path);
- return 0;
+ /*
+ * It's ok if we can't connect to the control port in case
+ * we're running on old qemu
+ */
+ if (ret < 0 && nr == 1 && !guest_ok) {
+ debug("%s: error connecting to %s\n",
+ __func__, chardevs[nr].path);
+ } else {
+ if (ret < 0)
+ error(errno, errno, "connect: %s", chardevs[nr].path);
+ }
+ return ret;
}
static int host_close_chardev(int nr)
@@ -666,11 +676,13 @@ static int test_console(int nr)
struct pollfd pollfds[1];
int ret;
- ret = guest_open_port(nr);
- if (ret != -ENXIO) {
- fail(__func__, "open");
- debug("%s: guest_open ret: %d\n", __func__, ret);
- return ret;
+ if (guest_ok) {
+ ret = guest_open_port(nr);
+ if (ret != -ENXIO) {
+ fail(__func__, "open");
+ debug("%s: guest_open ret: %d\n", __func__, ret);
+ return ret;
+ }
}
host_connect_chardev(nr);
@@ -766,35 +778,44 @@ out:
static int start_tests(void)
{
- test_open(2);
- test_close(2);
- test_read_without_host(2);
+ if (guest_ok) {
+ /*
+ * These tests can only be tried when the guest
+ * program is up. The guest program will terminate in
+ * case we're running on an incompatible kernel or
+ * qemu version.
+ */
- test_blocking_read(2);
- test_nonblocking_read(2);
+ test_open(2);
+ test_close(2);
+ test_read_without_host(2);
- test_poll(2);
+ test_blocking_read(2);
+ test_nonblocking_read(2);
- /* Throttling is not enabled on this port */
- test_guest_throttle(2);
- /* Throttling is enabled on this port */
- test_guest_throttle(4);
+ test_poll(2);
- /* Throttling is not enabled on this port */
- test_host_throttle(2);
- /* Throttling is enabled on this port */
- test_host_throttle(4);
+ /* Throttling is not enabled on this port */
+ test_guest_throttle(2);
+ /* Throttling is enabled on this port */
+ test_guest_throttle(4);
- /* Caching is enabled on this port */
- test_guest_caching(2);
- /* Caching is not enabled on this port */
- test_guest_caching(3);
+ /* Throttling is not enabled on this port */
+ test_host_throttle(2);
+ /* Throttling is enabled on this port */
+ test_host_throttle(4);
- /* Caching is enabled on this port */
- test_host_caching(2);
- /* Caching is not enabled on this port */
- test_host_caching(3);
+ /* Caching is enabled on this port */
+ test_guest_caching(2);
+ /* Caching is not enabled on this port */
+ test_guest_caching(3);
+ /* Caching is enabled on this port */
+ test_host_caching(2);
+ /* Caching is not enabled on this port */
+ test_host_caching(3);
+ }
+ /* The console test should work in any case. */
test_console(0);
return 0;
@@ -814,7 +835,12 @@ int main(int argc, const char *argv[])
if (strlen(chardevs[i].path) > UNIX_PATH_MAX)
error(E2BIG, E2BIG, "%s", chardevs[i].path);
}
- host_connect_chardev(1);
+ ret = host_connect_chardev(1);
+ if (ret < 0) {
+ /* old qemu case -- Give the guest time to finish its bootup */
+ sleep(20);
+ goto next;
+ }
/*
* Send a message to the guest indicating we're ready. If the
* guest isn't ready yet, it'll connect and let us know.
@@ -827,16 +853,27 @@ int main(int argc, const char *argv[])
/* Now wait till we receive guest's response */
pollfd[0].fd = chardevs[1].sock;
pollfd[0].events = POLLIN;
+
+ /* Wait for 20s to see if guest tries to reach us */
+ ret = poll(pollfd, 1, 20000);
+ if (ret == -1)
+ error(errno, errno, "poll %s", chardevs[1].path);
+ if (ret == 0) {
+ /*
+ * This perhaps is an old kernel or an old qemu -
+ * guest won't contact us.
+ */
+ debug("%s: No contact from Guest\n", __func__);
+ goto next;
+ }
while (1) {
- ret = poll(pollfd, 1, -1);
- if (ret == -1)
- error(errno, errno, "poll %s", chardevs[1].path);
debug("poll revents = %u\n", pollfd[0].revents);
if (pollfd[0].revents & POLLIN) {
ret = read(chardevs[1].sock, &gpkt, sizeof(gpkt));
if (ret < sizeof(gpkt))
error(EINVAL, EINVAL, "Read error");
if (gpkt.key == KEY_STATUS_OK && gpkt.value) {
+ guest_ok = true;
debug("Guest is up %d\n", gpkt.key);
break;
}
@@ -846,6 +883,7 @@ int main(int argc, const char *argv[])
}
}
}
+next:
/* Now we're all set to start our tests. */
start_tests();
show_stats();