The 'test-lock' program took too long before the improvements done in
December 2016 / January 2017. But still, it takes a too long time on
Linux/ia64.

A test suite should never "hang". Better fail the test.


2019-04-27  Bruno Haible  <br...@clisp.org>

        lock tests: Prevent that the test takes too long.
        * tests/test-lock.c: Include <signal.h>, <unistd.h>.
        (main): Let the test fail if it takes more than 10 minutes.
        * modules/lock-tests (configure.ac): Test whether 'alarm' is declared.

diff --git a/tests/test-lock.c b/tests/test-lock.c
index 1ad0c72..166f85b 100644
--- a/tests/test-lock.c
+++ b/tests/test-lock.c
@@ -120,6 +120,11 @@
 # include <unistd.h>
 #endif
 
+#if HAVE_DECL_ALARM
+# include <signal.h>
+# include <unistd.h>
+#endif
+
 #if ENABLE_DEBUGGING
 # define dbgprintf printf
 #else
@@ -715,6 +720,14 @@ test_once (void)
 int
 main ()
 {
+#if HAVE_DECL_ALARM
+  /* Declare failure if test takes too long, by using default abort
+     caused by SIGALRM.  */
+  int alarm_value = 600;
+  signal (SIGALRM, SIG_DFL);
+  alarm (alarm_value);
+#endif
+
 #if TEST_PTH_THREADS
   if (!pth_init ())
     abort ();
diff --git a/modules/lock-tests b/modules/lock-tests
index 802471e..5d647fa 100644
--- a/modules/lock-tests
+++ b/modules/lock-tests
@@ -11,6 +11,7 @@ yield
 
 configure.ac:
 AC_CHECK_HEADERS_ONCE([semaphore.h])
+AC_CHECK_DECLS_ONCE([alarm])
 
 Makefile.am:
 TESTS += test-rwlock1 test-lock test-once1 test-once2


Reply via email to