All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Ian Campbell <Ian.Campbell@citrix.com>
Subject: [PATCH 7/9] libxl: event tests: Provide miniature poll machinery
Date: Thu, 9 Jul 2015 18:47:55 +0100	[thread overview]
Message-ID: <1436464077-2752-8-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1436464077-2752-1-git-send-email-ian.jackson@eu.citrix.com>

This allows a test case to have a poll-based event loop with exact
control of the sequence of operations.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
 tools/libxl/test_common.c |   44 +++++++++++++++++++++++++++++++++++++++++++-
 tools/libxl/test_common.h |   15 +++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/tools/libxl/test_common.c b/tools/libxl/test_common.c
index 83b94eb..c6bbbab 100644
--- a/tools/libxl/test_common.c
+++ b/tools/libxl/test_common.c
@@ -12,4 +12,46 @@ void test_common_setup(int level)
 
     int rc = libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, logger);
     assert(!rc);
-}    
+}
+
+struct timeval now;
+
+void test_common_get_now(void)
+{
+    int r = gettimeofday(&now, 0);  assert(!r);
+}
+
+int poll_nfds, poll_nfds_allocd;
+struct pollfd *poll_fds;
+int poll_timeout;
+
+void test_common_beforepoll(void)
+{
+    for (;;) {
+        test_common_get_now();
+
+        poll_timeout = -1;
+        poll_nfds = poll_nfds_allocd;
+        int rc = libxl_osevent_beforepoll(ctx, &poll_nfds, poll_fds,
+                                          &poll_timeout, now);
+        if (!rc) return;
+        assert(rc == ERROR_BUFFERFULL);
+
+        assert(poll_nfds > poll_nfds_allocd);
+        poll_fds = realloc(poll_fds, poll_nfds * sizeof(poll_fds[0]));
+        assert(poll_fds);
+        poll_nfds_allocd = poll_nfds;
+    }
+}
+
+void test_common_dopoll(void) {
+    errno = 0;
+    int r = poll(poll_fds, poll_nfds, poll_timeout);
+    fprintf(stderr, "poll: r=%d errno=%s\n", r, strerror(errno));
+}
+
+void test_common_afterpoll(void)
+{
+    test_common_get_now();
+    libxl_osevent_afterpoll(ctx, poll_nfds, poll_fds, now);
+}
diff --git a/tools/libxl/test_common.h b/tools/libxl/test_common.h
index 8b2471e..10c7166 100644
--- a/tools/libxl/test_common.h
+++ b/tools/libxl/test_common.h
@@ -6,9 +6,24 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 void test_common_setup(int level);
 
 extern libxl_ctx *ctx;
 
+void test_common_get_now(void);
+
+extern struct timeval now;
+
+void test_common_beforepoll(void);
+void test_common_dopoll(void);
+void test_common_afterpoll(void);
+
+extern int poll_nfds, poll_nfds_allocd;
+extern struct pollfd *poll_fds;
+extern int poll_timeout;
+
 #endif /*TEST_COMMON_H*/
-- 
1.7.10.4

  parent reply	other threads:[~2015-07-09 17:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-09 17:47 [PATCH 0/9] libxl: poll: Avoid fd deregistration race POLLNVAL Ian Jackson
2015-07-09 17:47 ` [PATCH 1/9] libxl: poll: Make libxl__poller_get have only one success return path Ian Jackson
2015-07-10 10:39   ` Wei Liu
2015-07-09 17:47 ` [PATCH 2/9] libxl: poll: Use poller_get and poller_put for poller_app Ian Jackson
2015-07-10 10:39   ` Wei Liu
2015-07-09 17:47 ` [PATCH 3/9] libxl: poll: Avoid fd deregistration race POLLNVAL crash Ian Jackson
2015-07-10 10:41   ` Wei Liu
2015-07-09 17:47 ` [PATCH 4/9] libxl: event tests: Improve Makefile doc comment Ian Jackson
2015-07-10 10:41   ` Wei Liu
2015-07-09 17:47 ` [PATCH 5/9] libxl: event tests: Contemplate separate tests Ian Jackson
2015-07-10 10:42   ` Wei Liu
2015-07-09 17:47 ` [PATCH 6/9] libxl: event tests: Provide libxl_test_fdevent Ian Jackson
2015-07-10 10:43   ` Wei Liu
2015-07-09 17:47 ` Ian Jackson [this message]
2015-07-10 10:44   ` [PATCH 7/9] libxl: event tests: Provide miniature poll machinery Wei Liu
2015-07-09 17:47 ` [PATCH 8/9] libxl: event tests: Introduce `fdderegrace' test Ian Jackson
2015-07-10 10:45   ` Wei Liu
2015-07-09 17:47 ` [PATCH 9/9] libxl: event tests: test_timedereg: Fix rc handling Ian Jackson
2015-07-10 10:46   ` Wei Liu
2015-07-15 10:43     ` [PATCH 9/9] libxl: event tests: test_timedereg: Fix rc handling [and 1 more messages] Ian Jackson
2015-07-13 15:14 ` [PATCH 0/9] libxl: poll: Avoid fd deregistration race POLLNVAL Jim Fehlig
2015-07-13 15:54   ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436464077-2752-8-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.