r5507 - in trunk/varnish-cache: . bin/varnishtest

phk at varnish-cache.org phk at varnish-cache.org
Thu Nov 4 12:28:08 CET 2010


Author: phk
Date: 2010-11-04 12:28:06 +0100 (Thu, 04 Nov 2010)
New Revision: 5507

Modified:
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/bin/varnishtest/vtc.h
   trunk/varnish-cache/configure.ac
Log:
Add a SIGALRM based timeout mechanism for test-termnation, for OS's
like Solaris which do not have pthread_timedjoin_np()

Fixes: #800


Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2010-11-04 11:03:01 UTC (rev 5506)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2010-11-04 11:28:06 UTC (rev 5507)
@@ -37,6 +37,7 @@
 #include <fcntl.h>
 #include <math.h>
 #include <limits.h>
+#include <signal.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -59,7 +60,7 @@
 #define		MAX_TOKENS		200
 
 static char		*vtc_desc;
-int			vtc_error;	/* Error encountered */
+volatile sig_atomic_t	vtc_error;	/* Error encountered */
 int			vtc_stop;	/* Stops current test without error */
 pthread_t		vtc_thread;
 char			vtc_tmpdir[PATH_MAX];
@@ -525,13 +526,29 @@
 	return (NULL);
 }
 
+#ifndef HAVE_PTHREAD_TIMEDJOIN_NP
+static volatile sig_atomic_t alrm_flag = 0;
+
+static void
+sigalrm(int x)
+{
+
+	(void)x;
+	alrm_flag = 1;
+	vtc_error = 1;
+}
+#endif
+
 static double
 exec_file(const char *fn, unsigned dur)
 {
-	double t0, t;
+	double t0;
 	struct priv_exec pe;
 	pthread_t pt;
+#ifdef HAVE_PTHREAD_TIMEDJOIN_NP
+	double t;
 	struct timespec ts;
+#endif
 	void *v;
 	int i;
 
@@ -546,6 +563,7 @@
 		    fn, strerror(errno));
 	pe.fn = fn;
 
+#ifdef HAVE_PTHREAD_TIMEDJOIN_NP
 	t = TIM_real() + dur;
 	ts.tv_sec = (long)floor(t);
 	ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9);
@@ -553,6 +571,16 @@
 	AZ(pthread_create(&pt, NULL, exec_file_thread, &pe));
 	i = pthread_timedjoin_np(pt, &v, &ts);
 	memset(&vtc_thread, 0, sizeof vtc_thread);
+#else
+	alrm_flag = 0;
+	(void)signal(SIGALRM, sigalrm);
+	alarm(dur);
+	AZ(pthread_create(&pt, NULL, exec_file_thread, &pe));
+	i = pthread_join(pt, &v);
+	alarm(0);
+	if (alrm_flag)
+		i = ETIMEDOUT;
+#endif
 
 	if (i != 0) {
 		if (i != ETIMEDOUT)

Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h	2010-11-04 11:03:01 UTC (rev 5506)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h	2010-11-04 11:28:06 UTC (rev 5507)
@@ -58,7 +58,7 @@
 cmd_f cmd_sema;
 
 extern int vtc_verbosity;
-extern int vtc_error;		/* Error, bail out */
+extern volatile sig_atomic_t vtc_error; /* Error, bail out */
 extern int vtc_stop;		/* Abandon current test, no error */
 extern pthread_t	vtc_thread;
 extern char vtc_tmpdir[PATH_MAX];

Modified: trunk/varnish-cache/configure.ac
===================================================================
--- trunk/varnish-cache/configure.ac	2010-11-04 11:03:01 UTC (rev 5506)
+++ trunk/varnish-cache/configure.ac	2010-11-04 11:28:06 UTC (rev 5507)
@@ -172,6 +172,7 @@
 LIBS="${PTHREAD_LIBS}"
 AC_CHECK_FUNCS([pthread_set_name_np])
 AC_CHECK_FUNCS([pthread_mutex_isowned_np])
+AC_CHECK_FUNCS([pthread_timedjoin_np])
 LIBS="${save_LIBS}"
 
 # sendfile is tricky: there are multiple versions, and most of them




More information about the varnish-commit mailing list