浏览代码

tests: add core/starpu_init.c which tests starpu_init behaviour regarding environment variables and starpu_conf

Nathalie Furmento 13 年之前
父节点
当前提交
ac6b545847
共有 2 个文件被更改,包括 90 次插入0 次删除
  1. 1 0
      tests/Makefile.am
  2. 89 0
      tests/core/starpu_init.c

+ 1 - 0
tests/Makefile.am

@@ -136,6 +136,7 @@ noinst_PROGRAMS =				\
 	core/declare_deps_after_submission	\
 	core/declare_deps_after_submission_synchronous	\
 	core/get_current_task			\
+	core/starpu_init			\
 	core/starpu_worker_exists               \
 	datawizard/acquire_cb			\
 	datawizard/acquire_cb_insert		\

+ 89 - 0
tests/core/starpu_init.c

@@ -0,0 +1,89 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2012  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
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU 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 Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu.h>
+#include "../helper.h"
+#include <stdlib.h>
+
+static int check_cpu(int env_cpu, int conf_cpu, int expected_cpu, int *cpu)
+{
+	int ret;
+
+	if (env_cpu != -1)
+	{
+		char string[50];
+		sprintf(string, "STARPU_NCPUS=%d", env_cpu);
+		putenv(string);
+	}
+
+	struct starpu_conf user_conf;
+	starpu_conf_init(&user_conf);
+	user_conf.ncpus = conf_cpu;
+	ret = starpu_init(&user_conf);
+
+	if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+
+	*cpu = starpu_cpu_worker_get_count();
+	starpu_shutdown();
+
+	if (env_cpu != -1)
+	{
+		unsetenv("STARPU_NCPUS");
+	}
+
+	if (expected_cpu == -1)
+	{
+		FPRINTF(stderr, "Number of CPUS: %3d\n", *cpu);
+		return 0;
+	}
+	else
+	{
+		FPRINTF(stderr, "Number of CPUS: %3d -- Number of expected CPUs: %3d\n", *cpu, expected_cpu);
+		return (*cpu != expected_cpu);
+	}
+}
+
+int main(int argc, char **argv)
+{
+	int ret;
+	int cpu, cpu_init;
+
+	unsetenv("STARPU_NCPUS");
+
+	ret = check_cpu(-1, -1, -1, &cpu_init);
+	if (ret) return ret;
+
+	ret = check_cpu(12, -1, 12, &cpu);
+	if (ret) return ret;
+
+	ret = check_cpu(-1, -1, -1, &cpu);
+	if (ret) return ret;
+	if (cpu != cpu_init)
+	{
+		FPRINTF(stderr, "The number of CPUs is incorrect\n");
+		return 1;
+	}
+
+	ret = check_cpu(-1, 3, 3, &cpu);
+	if (ret) return ret;
+
+	ret = check_cpu(8, 11, 11, &cpu);
+	if (ret) return ret;
+
+	return ret;
+}
+