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.
This commit is contained in:
Ryan Lortie 2011-07-25 17:43:28 +02:00
parent 7f15910e79
commit 0584f0c504
3 changed files with 45 additions and 2 deletions

View File

@ -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 ***

View File

@ -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

View File

@ -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 ();
}