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 8/9] libxl: event tests: Introduce `fdderegrace' test
Date: Thu, 9 Jul 2015 18:47:56 +0100 [thread overview]
Message-ID: <1436464077-2752-9-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1436464077-2752-1-git-send-email-ian.jackson@eu.citrix.com>
This exercises the potential race between fd deregistration and
poll(). (Because we have control of the individual steps, we can do
the whole test in a single thread and ensure that the pessimal order
is always reached.)
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
.gitignore | 1 +
tools/libxl/Makefile | 2 +-
tools/libxl/test_fdderegrace.c | 56 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 tools/libxl/test_fdderegrace.c
diff --git a/.gitignore b/.gitignore
index 3f42ded..464f3f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -289,6 +289,7 @@ tools/libxl/testidl.c
tools/libxl/*.pyc
tools/libxl/libxl-save-helper
tools/libxl/test_timedereg
+tools/libxl/test_fdderegrace
tools/libxl/xen-init-dom0
tools/blktap2/control/tap-ctl
tools/firmware/etherboot/eb-roms.h
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index b92809c..95195c5 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -100,7 +100,7 @@ LIBXL_OBJS += libxl_genid.o
LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
LIBXL_TESTS += timedereg
-LIBXL_TESTS_PROGS = $(LIBXL_TESTS)
+LIBXL_TESTS_PROGS = $(LIBXL_TESTS) fdderegrace
LIBXL_TESTS_INSIDE = $(LIBXL_TESTS) fdevent
# Each entry FOO in LIBXL_TESTS has two main .c files:
diff --git a/tools/libxl/test_fdderegrace.c b/tools/libxl/test_fdderegrace.c
new file mode 100644
index 0000000..b644d7a
--- /dev/null
+++ b/tools/libxl/test_fdderegrace.c
@@ -0,0 +1,56 @@
+#include "test_common.h"
+#include "libxl_test_fdevent.h"
+
+int main(int argc, char **argv) {
+ int rc, i;
+ libxl_asyncop_how how;
+ libxl_event *event;
+
+ test_common_setup(XTL_DEBUG);
+
+ how.callback = NULL;
+ how.u.for_event = 1;
+
+ int fd = open("/dev/null", O_RDONLY);
+ assert(fd > 0);
+
+ rc = libxl_test_fdevent(ctx, fd, POLLIN, &how);
+ assert(!rc);
+
+ test_common_beforepoll();
+
+ rc = libxl_ao_abort(ctx, &how);
+ assert(!rc);
+
+ rc = libxl_event_check(ctx, &event, LIBXL_EVENTMASK_ALL, 0,0);
+ assert(!rc);
+ assert(event);
+ assert(event->for_user = how.u.for_event);
+ assert(event->type == LIBXL_EVENT_TYPE_OPERATION_COMPLETE);
+ assert(event->u.operation_complete.rc == ERROR_ABORTED);
+
+ close(fd);
+
+ test_common_dopoll();
+
+ for (i=0; i<poll_nfds; i++) {
+ if (poll_fds[i].fd == fd && (poll_fds[i].revents & POLLNVAL)) {
+ fprintf(stderr, "POLLNVAL on fd=%d in slot i=%d as expected\n",
+ fd, i);
+ goto found;
+ }
+ }
+ abort();
+ found:;
+
+ int fd2 = open("/dev/null", O_RDONLY);
+ assert(fd2 == fd);
+
+ how.u.for_event++;
+ rc = libxl_test_fdevent(ctx, fd, POLLIN, &how);
+ assert(!rc);
+
+ test_common_afterpoll();
+
+ fprintf(stderr, "complete\n");
+}
--
1.7.10.4
next prev 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 ` [PATCH 7/9] libxl: event tests: Provide miniature poll machinery Ian Jackson
2015-07-10 10:44 ` Wei Liu
2015-07-09 17:47 ` Ian Jackson [this message]
2015-07-10 10:45 ` [PATCH 8/9] libxl: event tests: Introduce `fdderegrace' test 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-9-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.