Forráskód Böngészése

tests/ examples/: make check uses a loader to execute tests and examples, and kills them if they are not finished within a timeout

Nathalie Furmento 14 éve
szülő
commit
9854c31df2
3 módosított fájl, 139 hozzáadás és 13 törlés
  1. 14 8
      examples/Makefile.am
  2. 16 5
      tests/Makefile.am
  3. 109 0
      tests/loader.c

+ 14 - 8
examples/Makefile.am

@@ -19,8 +19,6 @@ LIBS = $(top_builddir)/src/libstarpu.la $(HWLOC_LIBS) @LIBS@
 AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/examples/ -I$(top_builddir)/include
 AM_LDFLAGS = $(STARPU_CUDA_LDFLAGS) $(STARPU_OPENCL_LDFLAGS)
 
-TESTS	=	$(check_PROGRAMS)
-
 SUBDIRS = stencil
 
 if STARPU_HAVE_FFTW
@@ -29,8 +27,6 @@ SUBDIRS += starpufft
 endif
 endif
 
-check_PROGRAMS =
-
 BUILT_SOURCES =
 
 if STARPU_USE_OPENCL
@@ -123,6 +119,16 @@ noinst_HEADERS = 				\
 # What to install and what to check #
 #####################################
 
+STARPU_EXAMPLES	=
+check_PROGRAMS	=	$(LOADER) $(STARPU_EXAMPLES)
+TESTS		=	$(STARPU_EXAMPLES)
+
+## test loader program
+LOADER			=	loader
+LOADER_BIN		=	$(abs_top_builddir)/examples/$(LOADER)
+loader_SOURCES		=	../tests/loader.c
+TESTS_ENVIRONMENT	=	$(LOADER_BIN)
+
 examplebin_PROGRAMS +=				\
 	basic_examples/hello_world		\
 	basic_examples/vector_scal		\
@@ -175,7 +181,7 @@ examplebin_PROGRAMS +=				\
 	spmv/dw_block_spmv
 endif
 
-check_PROGRAMS +=				\
+STARPU_EXAMPLES +=				\
 	basic_examples/hello_world		\
 	basic_examples/vector_scal		\
 	basic_examples/mult			\
@@ -198,12 +204,12 @@ check_PROGRAMS +=				\
 	reductions/minmax_reduction
 
 if STARPU_HAVE_F77_H
-check_PROGRAMS +=				\
+STARPU_EXAMPLES +=				\
 	basic_examples/vector_scal_fortran
 endif
 
 if !NO_BLAS_LIB
-check_PROGRAMS +=				\
+STARPU_EXAMPLES +=				\
 	axpy/axpy				\
 	mult/sgemm 				\
 	mult/dgemm				\
@@ -220,7 +226,7 @@ check_PROGRAMS +=				\
 endif
 
 if ATLAS_BLAS_LIB
-check_PROGRAMS +=				\
+STARPU_EXAMPLES +=				\
 	spmv/dw_block_spmv
 endif
 

+ 16 - 5
tests/Makefile.am

@@ -32,6 +32,7 @@ CLEANFILES = 					\
 	datawizard/sync_and_notify_data_gordon_kernels.spuelf
 
 BUILT_SOURCES =
+SUBDIRS =
 
 if STARPU_USE_OPENCL
 nobase_STARPU_OPENCL_DATA_DATA =
@@ -72,12 +73,18 @@ SPU_LD ?= spu-ld
 
 endif
 
-
 testbindir = $(libdir)/starpu/tests
 
-SUBDIRS =
+#####################################
+# What to install and what to check #
+#####################################
 
-TESTS = $(check_PROGRAMS)
+## test loader program
+LOADER			=	loader
+LOADER_BIN		=	$(abs_top_builddir)/tests/$(LOADER)
+TESTS_ENVIRONMENT	=	$(LOADER_BIN)
+
+TESTS = $(testbin_PROGRAMS)
 
 if STARPU_COVERAGE_ENABLED
 TESTS	+=	coverage/coverage.sh
@@ -156,8 +163,12 @@ testbin_PROGRAMS =				\
 	perfmodels/regression_based		\
 	perfmodels/non_linear_regression_based
 
-check_PROGRAMS =
-	$(testbin_PROGRAMS)
+check_PROGRAMS =				\
+	$(LOADER) $(testbin_PROGRAMS)
+
+#######################
+# Source files        #
+#######################
 
 datawizard_acquire_release_SOURCES =		\
 	datawizard/acquire_release.c

+ 109 - 0
tests/loader.c

@@ -0,0 +1,109 @@
+/*
+ * PM2: Parallel Multithreaded Machine
+ * Copyright (C) 2001 the PM2 team (see AUTHORS file)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+
+#include <sys/wait.h>
+#include <sys/resource.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+
+#define  DEFAULT_TIMEOUT       250
+#define  AUTOTEST_SKIPPED_TEST 77
+
+static pid_t child_pid = 0;
+
+static void test_cleaner(int sig)
+{
+	pid_t child_gid;
+
+	// send signal to all loader family members
+	child_gid = getpgid(child_pid);
+	kill(-child_gid, SIGKILL);
+	exit(EXIT_FAILURE);
+}
+
+int main(int argc, char *argv[])
+{
+	int   timeout;
+	int   child_exit_status;
+	char *test_name;
+	int   status;
+	struct sigaction sa;
+
+	timeout = 0;
+	test_name = argv[1];
+
+	if (!test_name)
+	{
+		fprintf(stderr, "Error. Need name of program to start\n");
+		exit(-1);
+	}
+
+	/* get user-defined iter_max value */
+	if (getenv("STARPU_TIMEOUT_ENV"))
+		timeout = strtol(getenv("STARPU_TIMEOUT_ENV"), NULL, 10);
+	if (timeout <= 0)
+		timeout = DEFAULT_TIMEOUT;
+
+	/* set SIGALARM handler */
+	sa.sa_flags = 0;
+	sigemptyset(&sa.sa_mask);
+	sa.sa_handler = test_cleaner;
+	if (-1 == sigaction(SIGALRM, &sa, NULL))
+		perror("sigaction");
+
+	child_pid = fork();
+	if (child_pid == 0)
+	{
+		// get a new pgid
+		if (setpgid(0, 0) == -1)
+		{
+			perror("setpgid");
+			exit(EXIT_FAILURE);
+		}
+		execl(test_name, test_name, NULL);
+		exit(EXIT_FAILURE);
+	}
+	if (child_pid == -1)
+		exit(EXIT_FAILURE);
+
+	alarm(timeout);
+	if (child_pid == waitpid(child_pid, &child_exit_status, 0))
+	{
+		if (WIFEXITED(child_exit_status))
+		{
+			status = WEXITSTATUS(child_exit_status);
+			if (status == EXIT_SUCCESS)
+			{
+				alarm(0);
+			}
+			else
+			{
+				if (status != AUTOTEST_SKIPPED_TEST)
+					fprintf(stdout, "Exited with return code %d\n", status);
+				return status;
+			}
+		}
+		else
+		{
+			return EXIT_FAILURE;
+		}
+	}
+
+	return EXIT_SUCCESS;
+}