#include <sys/time.h>
#ifdef HAVE_FORK
-#include <sys/types.h>
-#include <sys/wait.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+#include <signal.h>
#include <Eina.h>
#endif
void (*build)(TCase *tc);
};
+static int timeout_pid = 0;
+
static void
_efl_tests_list(const Efl_Test_Case *etc)
{
#ifdef HAVE_FORK
EINA_UNUSED static int
-_efl_suite_wait_on_fork(int *num_forks)
+_efl_suite_wait_on_fork(int *num_forks, Eina_Bool *timeout)
{
- int status = 0, ret;
- waitpid(0, &status, 0);
+ int status = 0, ret, pid;
+ pid = waitpid(0, &status, 0);
if (WIFEXITED(status))
ret = WEXITSTATUS(status);
else
ret = 1;
- (*num_forks)--;
+ if (pid == timeout_pid)
+ *timeout = EINA_TRUE;
+ else
+ (*num_forks)--;
return ret;
}
#endif
int do_fork;
int num_forks = 0;
int can_fork = 0;
+ Eina_Bool timeout_reached = EINA_FALSE;
#ifdef ENABLE_TIMING_INFO
double tstart, tcstart;
int timing = _timing_enabled();
#ifdef HAVE_FORK
if (do_fork && can_fork)
{
+ if (!timeout_pid)
+ {
+ timeout_pid = fork();
+ if (!timeout_pid)
+ execl("/bin/sh", "/bin/sh", "-c", PACKAGE_BUILD_DIR "/src/tests/timeout", (char *)NULL);
+ }
if (num_forks == eina_cpu_count())
- failed_count += _efl_suite_wait_on_fork(&num_forks);
+ failed_count += _efl_suite_wait_on_fork(&num_forks, &timeout_reached);
+ if (timeout_reached) break;
pid = fork();
if (pid > 0)
{
}
#ifdef HAVE_FORK
- if (num_forks)
+ if (num_forks && (!timeout_reached))
{
do
{
- failed_count += _efl_suite_wait_on_fork(&num_forks);
- } while (num_forks);
+ failed_count += _efl_suite_wait_on_fork(&num_forks, &timeout_reached);
+ } while (num_forks && (!timeout_reached));
+ if (timeout_reached)
+ {
+ timeout_pid = 0;
+ printf("FAILSAFE TIMEOUT REACHED!\n");
+ fflush(stdout);
+ failed_count++;
+ }
}
else
#endif
failed_count = _efl_suite_run_end(sr, NULL);
+#ifdef HAVE_FORK
+ if (timeout_pid)
+ {
+ kill(timeout_pid, SIGKILL);
+ timeout_pid = 0;
+ }
+#endif
+
#ifdef ENABLE_TIMING_INFO
if (timing)
{