#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);
{
int count;
- for (count = 1; count < 100; count ++) {
+ for (count = 1; count < 100; count++) {
uint32_t domid;
libxl_domain_config dc;
struct event ev;
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);
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)
}
}
+/* 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;
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);