From 955e661cdbe7ca0e35f0757f90f970287e180ed7 Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Sat, 24 Oct 2009 13:38:49 +0530 Subject: auto-test: add support for running old qemu/kernel Signed-off-by: Amit Shah --- auto-virtserial.c | 106 ++++++++++++++++++++++++++++++++++++------------------ run-test.sh | 44 ++++++++++++++++++++++- 2 files changed, 115 insertions(+), 35 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(); diff --git a/run-test.sh b/run-test.sh index 9115185..1c8ebc0 100755 --- a/run-test.sh +++ b/run-test.sh @@ -21,6 +21,7 @@ VNC="-vnc :1" MISCOPT="-net none -enable-kvm -m 1G -smp 2" SNAPSHOT="-snapshot" +# -- Iteration 1: new kernel, new qemu -- QEMU_OPTS="$KERNEL $KERNELARG $CHARDEVS $VIRTSER $VNC $MISCOPT $GUEST $SNAPSHOT" echo $QEMU $QEMU_OPTS @@ -29,4 +30,45 @@ $QEMU $QEMU_OPTS & sleep 5 -./auto-virtserial +time ./auto-virtserial +pkill qemu + + +# -- Iteration 2: old kernel, new qemu -- +sleep 5 + +KERNEL= +KERNELARG= + +QEMU_OPTS="$KERNEL $KERNELARG $CHARDEVS $VIRTSER $VNC $MISCOPT $GUEST $SNAPSHOT" + +echo $QEMU $QEMU_OPTS + +$QEMU $QEMU_OPTS & + +sleep 5 + +time ./auto-virtserial +pkill qemu + +# -- Iteration 3: new kernel, old qemu -- +sleep 5 + +KERNEL="-kernel /home/amit/tmp/linux-2.6/arch/x86/boot/bzImage" +KERNELARG='-append "root=/dev/sda2"' + +QEMU=/home/amit/src/qemu/x86_64-softmmu/qemu-system-x86_64 + +CHARDEVS= +VIRTSER="-virtioconsole unix:/tmp/amit/test0,server,nowait" + +QEMU_OPTS="$KERNEL $KERNELARG $CHARDEVS $VIRTSER $VNC $MISCOPT $GUEST $SNAPSHOT" + +echo $QEMU $QEMU_OPTS + +$QEMU $QEMU_OPTS & + +sleep 5 + +time ./auto-virtserial +pkill qemu -- cgit