]> xenbits.xensource.com Git - people/iwj/ring3-xl-test.git/commitdiff
Refactor test teardown
authorEuan Harris <euan.harris@citrix.com>
Tue, 16 Jun 2015 11:29:24 +0000 (11:29 +0000)
committerEuan Harris <euan.harris@citrix.com>
Tue, 16 Jun 2015 11:29:24 +0000 (11:29 +0000)
Signed-off-by: Euan Harris <euan.harris@citrix.com>
test_domain_create_new.c
testcase_runner.c
testcase_runner.h

index 238e2fd4a5c9eea2e7b07cf2674761f4669c3a9c..28d5cd7f764d518738ac021a19009b363808a12b 100644 (file)
    it because we provide the kernel and ramdisk along with the root image.
  */
 
+
 #if 0
-void cleanup_and_exit(libxl_domain_config * dc)
+void wait_or_exit(struct test *tc, libxl_domain_config *dc, int domid)
 {
-
 }
 #endif
 
+
+void teardown(struct test *tc, libxl_domain_config *dc, int domid)
+{
+    libxl_domain_config_dispose(dc);
+    libxl_domain_destroy(tc->ctx, domid, 0);
+
+}
+
+
 void *testcase(struct test *tc)
 {
     int count = 0;
-    int run = 1;
 
-    while (run) {
+    while (1) {
         uint32_t domid;
         libxl_domain_config dc;
         struct event ev;
@@ -49,29 +57,20 @@ void *testcase(struct test *tc)
         for (i = 0; i < count; i++) {
             wait_for(tc, ~EV_EVENTLOOP, &ev);
             if (ev.type == EV_LIBXL_CALLBACK) {
-                run = 0;
-                break;
-            }
-            if (run) {
-                libxl_ao_cancel(tc->ctx, &tc->ao_how);
-                wait_for(tc, EV_LIBXL_CALLBACK, &ev);
+               teardown(tc, &dc, domid);
+               test_exit();
             }
+        }
 
-            printf("domid: %d\n", domid);
-            libxl_domain_config_dispose(&dc);
+        libxl_ao_cancel(tc->ctx, &tc->ao_how);
+        wait_for(tc, EV_LIBXL_CALLBACK, &ev);
 
-            /* If cancellation succeeded, the domain will probably have
-               been created with all of its associated devices attached, but
-               the device emulator will probably not have been spawned - no
-               qemu-system-i386 process with -xen-domid equal to our domid 
-               will exist */
+        printf("domid: %d\n", domid);
+        assert(!libxl_domain_info(tc->ctx, NULL, domid));
 
-            assert(!libxl_domain_info(tc->ctx, NULL, domid));
-            libxl_domain_destroy(tc->ctx, domid, 0);
-            /* wait_for(tc, EV_LIBXL_CALLBACK, &ev); */
-        }
+        teardown(tc, &dc, domid);
     }
 
-    eventloop_halt();
-    pthread_exit(NULL);
+    test_exit();
+    return NULL;
 }
index 5143a2a8b97f19df4550cccada01218dde7d715e..8e3a8b84fa02744411d40de5a57b2d6be1c3217f 100644 (file)
@@ -6,6 +6,7 @@
 #include <unistd.h>
 
 #include "testcase_runner.h"
+#include "eventloop_runner.h"
 
 enum { RX = 0, TX = 1 };
 
@@ -45,6 +46,11 @@ void test_destroy(struct test *tc)
     libxl_ctx_free(tc->ctx);
 }
 
+void test_exit() {
+       eventloop_halt();
+       pthread_exit(NULL);
+}
+
 int send_event(struct test *tc, struct event ev)
 {
     return write(tc->mailbox[TX], (char *)&ev, sizeof(ev));
index d09e562ac776e443931f3d4f9fca3635076d0b6b..56df746a04fb789d25e8737a1d52efbeddb99477 100644 (file)
@@ -55,6 +55,7 @@ struct test {
 int test_spawn(struct test *tc, xentoollog_logger * logger,
                void *(*fn) (struct test *));
 void test_join(struct test *tc);
+void test_exit();
 void test_destroy(struct test *tc);
 int send_event(struct test *tc, struct event ev);
 void recv_event(struct test *tc, struct event *ev);