Browse Source

tests: improve error checking mechanism

Nathalie Furmento 13 years ago
parent
commit
2c1f736e4c

+ 4 - 2
tests/core/multithreaded.c

@@ -23,7 +23,7 @@
 #include <pthread.h>
 
 #include <starpu.h>
-#define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
+#include "../common/helper.h"
 
 pthread_t threads[16];
 
@@ -94,10 +94,12 @@ int main(int argc, char **argv)
 	double timing;
 	struct timeval start;
 	struct timeval end;
+	int ret;
 
 	parse_args(argc, argv);
 
-	starpu_init(NULL);
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
 #ifdef STARPU_SLOW_MACHINE
 	ntasks /= 10;

+ 31 - 29
tests/core/multithreaded_init.c

@@ -18,48 +18,50 @@
 #include <stdio.h>
 #include <pthread.h>
 #include <starpu.h>
+#include "../common/helper.h"
 
 #define NUM_THREADS 5
-#define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
 
 void *launch_starpu(void *id)
-{ 
-   starpu_init(NULL);
-   return NULL;
+{
+	int ret;
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+	return NULL;
 }
 
 int main(int argc, char **argv)
-{ 
-  unsigned i;
-  double timing;
-  struct timeval start;
-  struct timeval end;
+{
+	unsigned i;
+	double timing;
+	struct timeval start;
+	struct timeval end;
 
-  pthread_t threads[NUM_THREADS];
-  
-  gettimeofday(&start, NULL);
+	pthread_t threads[NUM_THREADS];
 
-  for (i = 0; i < NUM_THREADS; ++i)
-    {
-      int ret = pthread_create(&threads[i], NULL, launch_starpu, NULL);
-      STARPU_ASSERT(ret == 0);
-    }
+	gettimeofday(&start, NULL);
 
-  for (i = 0; i < NUM_THREADS; ++i)
-    {
-      int ret = pthread_join(threads[i], NULL);
-      STARPU_ASSERT(ret == 0);
-    }
+	for (i = 0; i < NUM_THREADS; ++i)
+	{
+		int ret = pthread_create(&threads[i], NULL, launch_starpu, NULL);
+		STARPU_ASSERT(ret == 0);
+	}
 
-  gettimeofday(&end, NULL);
+	for (i = 0; i < NUM_THREADS; ++i)
+	{
+		int ret = pthread_join(threads[i], NULL);
+		STARPU_ASSERT(ret == 0);
+	}
 
-  timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
+	gettimeofday(&end, NULL);
 
-  FPRINTF(stderr, "Success : %d threads launching simultaneously starpu_init\n", NUM_THREADS);
-  FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
-  FPRINTF(stderr, "Per task: %f usecs\n", timing/NUM_THREADS);
+	timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
 
-  starpu_shutdown();
+	FPRINTF(stderr, "Success : %d threads launching simultaneously starpu_init\n", NUM_THREADS);
+	FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
+	FPRINTF(stderr, "Per task: %f usecs\n", timing/NUM_THREADS);
 
-  return 0;
+	starpu_shutdown();
+
+	return 0;
 }

+ 3 - 2
tests/datawizard/mpi_like.c

@@ -18,10 +18,10 @@
 #include <starpu.h>
 #include <errno.h>
 #include <pthread.h>
+#include "../common/helper.h"
 
 #define NTHREADS	4
 #define NITER		128
-#define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
 
 //static pthread_cond_t cond;
 //static pthread_mutex_t mutex;
@@ -160,7 +160,8 @@ int main(int argc, char **argv)
 {
 	int ret;
 
-	starpu_init(NULL);
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
 	unsigned t;
 	for (t = 0; t < NTHREADS; t++)

+ 3 - 2
tests/datawizard/mpi_like_async.c

@@ -17,10 +17,10 @@
 
 #include <starpu.h>
 #include <pthread.h>
+#include "../common/helper.h"
 
 #define NTHREADS	16
 #define NITER		128
-#define FPRINTF(ofile, fmt, args ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ##args); }} while(0)
 
 //#define DEBUG_MESSAGES	1
 
@@ -284,7 +284,8 @@ int main(int argc, char **argv)
 	int ret;
 	void *retval;
 
-	starpu_init(NULL);
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
 	/* Create a thread to perform blocking calls */
 	pthread_t progress_thread;

+ 5 - 2
tests/errorcheck/invalid_blocking_calls.c

@@ -16,6 +16,7 @@
  */
 
 #include <starpu.h>
+#include "../common/helper.h"
 
 #define TAG	0x42
 
@@ -37,7 +38,7 @@ static void wrong_func(void *descr[], void *arg)
 		exit(-1);
 }
 
-static starpu_codelet wrong_codelet = 
+static starpu_codelet wrong_codelet =
 {
 	.where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
 	.cpu_func = wrong_func,
@@ -64,7 +65,8 @@ int main(int argc, char **argv)
 {
 	int ret;
 
-	starpu_init(NULL);
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
 	/* register a piece of data */
 	starpu_vector_data_register(&handle, 0, (uintptr_t)&data,
@@ -106,5 +108,6 @@ enodev:
 	fprintf(stderr, "WARNING: No one can execute this task\n");
 	/* yes, we do not perform the computation but we did detect that no one
 	 * could perform the kernel, so this is not an error from StarPU */
+	starpu_shutdown();
 	return 77;
 }

+ 4 - 2
tests/errorcheck/invalid_tasks.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010  Université de Bordeaux 1
- * Copyright (C) 2010  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -16,6 +16,7 @@
  */
 
 #include <starpu.h>
+#include "../common/helper.h"
 
 static void dummy_func(void *descr[], void *arg)
 {
@@ -38,7 +39,8 @@ int main(int argc, char **argv)
 	memset(&conf, 0, sizeof(conf));
 	conf.ncpus = 1;
 
-	starpu_init(&conf);
+	ret = starpu_init(&conf);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
 	struct starpu_task *task = starpu_task_create();
 	task->cl = &cuda_only_cl;

+ 8 - 3
tests/parallel_tasks/spmd_pgreedy.c

@@ -17,6 +17,7 @@
 #include <starpu.h>
 #include <limits.h>
 #include <unistd.h>
+#include "../common/helper.h"
 
 #define N	1000
 #define VECTORSIZE	1024
@@ -53,13 +54,17 @@ static starpu_codelet cl = {
 
 int main(int argc, char **argv)
 {
+	int ret;
+
         struct starpu_conf conf;
 	starpu_conf_init(&conf);
-        conf.sched_policy_name = "pgreedy",
+        conf.sched_policy_name = "pgreedy";
 
-	starpu_init(&conf);
+	ret = starpu_init(&conf);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
 
-	starpu_malloc((void **)&v, VECTORSIZE*sizeof(unsigned));
+	ret = starpu_malloc((void **)&v, VECTORSIZE*sizeof(unsigned));
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_malloc");
 	starpu_vector_data_register(&v_handle, 0, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));
 
 	unsigned iter;//, worker;