[glib/gwakeup] GWakeup: test fallback case
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/gwakeup] GWakeup: test fallback case
- Date: Mon, 25 Jul 2011 15:46:55 +0000 (UTC)
commit 0584f0c50495e4c1d6691f30d9f598799a5d54ce
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Jul 25 17:43:28 2011 +0200
GWakeup: test fallback case
We need to test the case of eventfd in the libc but no kernel support.
In order to do that, we add a separate compile of the GWakeup testcase
that interposes an 'eventfd' symbol that always returns -1 with errno
set. That will trigger the fallback case.
configure.ac | 1 +
gthread/tests/Makefile.am | 7 +++++++
gthread/tests/gwakeup.c | 39 +++++++++++++++++++++++++++++++++++++--
3 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b58258f..38d9379 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2641,6 +2641,7 @@ main (void)
if test x"$glib_cv_eventfd" = x"yes"; then
AC_DEFINE(HAVE_EVENTFD, 1, [we have the eventfd(2) system call])
fi
+AM_CONDITIONAL(HAVE_EVENTFD, [test "$glib_cv_eventfd" = "yes"])
dnl ****************************************
dnl *** GLib POLL* compatibility defines ***
diff --git a/gthread/tests/Makefile.am b/gthread/tests/Makefile.am
index 4f5a252..cc60d0f 100644
--- a/gthread/tests/Makefile.am
+++ b/gthread/tests/Makefile.am
@@ -46,3 +46,10 @@ spawn_singlethread_LDADD = $(progs_ldadd) $(top_builddir)/gthread/libgthread-
TEST_PROGS += gwakeup
gwakeup_LDADD = $(progs_ldadd) $(top_builddir)/gthread/libgthread-2.0.la
+
+if HAVE_EVENTFD
+TEST_PROGS += gwakeup-fallback
+gwakeup_fallback_SOURCES = gwakeup.c
+gwakeup_fallback_CFLAGS = $(AM_CFLAGS) -DTEST_EVENTFD_FALLBACK
+gwakeup_fallback_LDADD = $(progs_ldadd) $(top_builddir)/gthread/libgthread-2.0.la
+endif
diff --git a/gthread/tests/gwakeup.c b/gthread/tests/gwakeup.c
index e6c712e..f1545d8 100644
--- a/gthread/tests/gwakeup.c
+++ b/gthread/tests/gwakeup.c
@@ -1,6 +1,32 @@
#include <unistd.h>
#include <glib.h>
+#ifdef TEST_EVENTFD_FALLBACK
+ #include <errno.h>
+
+ static gboolean we_broke_eventfd;
+
+ /* We interpose over the eventfd() call in the libc to ensure that a
+ * failed call to eventfd() gives us a working fallback.
+ *
+ * We need to do this because older kernel versions don't have eventfd
+ * support, and some of them have eventfd but without support for some
+ * of the flags we use.
+ *
+ * We use the we_broke_eventfd boolean to make sure that it actually
+ * worked.
+ */
+ int eventfd (void) {
+ we_broke_eventfd = TRUE;
+ errno = EINVAL;
+
+ return -1;
+ }
+ #define TESTNAME_SUFFIX "-fallback"
+#else
+ #define TESTNAME_SUFFIX ""
+#endif
+
#ifdef _WIN32
void alarm (int sec) { }
#endif
@@ -32,9 +58,18 @@ test_semantics (void)
/* prevent the test from deadlocking */
alarm (30);
+#ifdef TEST_EVENTFD_FALLBACK
+ we_broke_eventfd = FALSE;
+#endif
+
wakeup = g_wakeup_new ();
g_assert (!check_signaled (wakeup));
+#ifdef TEST_EVENTFD_FALLBACK
+ /* make sure our interposed eventfd call worked */
+ g_assert (we_broke_eventfd);
+#endif
+
g_wakeup_signal (wakeup);
g_assert (check_signaled (wakeup));
@@ -261,8 +296,8 @@ main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/gwakeup/semantics", test_semantics);
- g_test_add_func ("/gwakeup/threaded", test_threaded);
+ g_test_add_func ("/gwakeup/semantics" TESTNAME_SUFFIX, test_semantics);
+ g_test_add_func ("/gwakeup/threaded" TESTNAME_SUFFIX, test_threaded);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]