]> xenbits.xensource.com Git - people/iwj/ring3-xl-test.git/commitdiff
Move wait_until into the test library
authorEuan Harris <euan.harris@citrix.com>
Tue, 16 Jun 2015 14:56:49 +0000 (14:56 +0000)
committerEuan Harris <euan.harris@citrix.com>
Tue, 16 Jun 2015 14:56:49 +0000 (14:56 +0000)
Signed-off-by: Euan Harris <euan.harris@citrix.com>
test_domain_create_new.c
testcase_runner.c
testcase_runner.h

index c2a7bcb9533f4470915f22186c00fc048cba55ba..ea7de20ae5df132420ebc14dc557e10567ac04fb 100644 (file)
@@ -5,7 +5,6 @@
 #include "eventloop_runner.h"
 #include "testcase_utils.h"
 
-
 /*
  * This test calls libxl_domain_create_new() repeatedly, cancelling
  * it at different points in its lifecycle.   
  *   cancellation point.
  */
 
-int wait_for_events(struct test *tc, struct event *ev, int count)
-{
-    /* Wait for some number of events before cancelling.
-       Eventloop timeouts are ignored as they could happen at
-       any time.  The test ends if the callback occurs while
-       we are still waiting for an event - after the callback,
-       the API call can no longer be cancelled.
-     */
-    int i;
-    for (i = 0; i < count; i++) {
-        wait_for(tc, ~EV_EVENTLOOP, ev);
-        if (ev->type == EV_LIBXL_CALLBACK) {
-            return 0;
-        }
-    }
-    return 1;
-}
 
-void teardown(struct test *tc, libxl_domain_config *dc, int domid)
+void teardown(struct test *tc, libxl_domain_config * dc, int domid)
 {
     libxl_domain_config_dispose(dc);
     libxl_domain_destroy(tc->ctx, domid, 0);
@@ -55,7 +37,7 @@ void *testcase(struct test *tc)
 {
     int count;
 
-    for (count = 1; count < 100; count ++) {
+    for (count = 1; count < 100; count++) {
         uint32_t domid;
         libxl_domain_config dc;
         struct event ev;
@@ -70,10 +52,10 @@ void *testcase(struct test *tc)
 
         do_domain_create(tc, &dc, &domid);
 
-       if (!wait_for_events(tc, &ev, count)) {
-                teardown(tc, &dc, domid);
-               break;
-       }
+        if (wait_until_n(tc, EV_LIBXL_CALLBACK, count, &ev)) {
+            teardown(tc, &dc, domid);
+            break;
+        }
 
         libxl_ao_cancel(tc->ctx, &tc->ao_how);
         wait_for(tc, EV_LIBXL_CALLBACK, &ev);
index 8e3a8b84fa02744411d40de5a57b2d6be1c3217f..c8d0e93b24e495bf7179678e5815b0626b8f1238 100644 (file)
@@ -46,9 +46,10 @@ void test_destroy(struct test *tc)
     libxl_ctx_free(tc->ctx);
 }
 
-void test_exit() {
-       eventloop_halt();
-       pthread_exit(NULL);
+void test_exit()
+{
+    eventloop_halt();
+    pthread_exit(NULL);
 }
 
 int send_event(struct test *tc, struct event ev)
@@ -81,6 +82,21 @@ wait_for_n(struct test *tc, enum event_type mask, int count, struct event *ev)
     }
 }
 
+/* Wait until an event matching the mask is posted, or count other events
+   are posted.  Returns 1 if the matching event is posted, 0 otherwise.
+ */
+int wait_until_n(struct test *tc, enum event_type mask, int count,
+                 struct event *ev)
+{
+    while (count--) {
+        wait_for(tc, ~EV_EVENTLOOP, ev);
+        if (ev->type & mask) {
+            return 1;
+        }
+    }
+    return 0;
+}
+
 int send_fd_event(struct test *tc, int fd)
 {
     struct event ev;
index 56df746a04fb789d25e8737a1d52efbeddb99477..c830a809a698c752fffd9522c10ae39c896dfe9c 100644 (file)
@@ -62,6 +62,8 @@ void recv_event(struct test *tc, struct event *ev);
 void wait_for(struct test *tc, enum event_type mask, struct event *ev);
 void wait_for_n(struct test *tc, enum event_type mask, int count,
                 struct event *ev);
+int wait_until_n(struct test *tc, enum event_type mask, int count,
+                 struct event *ev);
 int send_fd_event(struct test *tc, int fd);
 int send_libxl_callback_event(struct test *tc, int rc);
 int send_libxl_event(struct test *tc, libxl_event_type type);