Selaa lähdekoodia

tests: move the starpu_tag_get_task() test from examples

This adds the new file main/tag_get_task.c that contains the test.
Samuel Pitoiset 9 vuotta sitten
vanhempi
commit
62986d891e
3 muutettua tiedostoa jossa 80 lisäystä ja 32 poistoa
  1. 0 32
      examples/tag_example/tag_example.c
  2. 1 0
      tests/Makefile.am
  3. 79 0
      tests/main/tag_get_task.c

+ 0 - 32
examples/tag_example/tag_example.c

@@ -217,34 +217,6 @@ static void express_deps(unsigned i, unsigned j, unsigned piter)
 	}
 }
 
-static int test_starpu_tag_get_task()
-{
-	struct starpu_task *task;
-	int ret;
-
-	/* create a new task with a tag */
-	task = starpu_task_create();
-	task->callback_func = callback_cpu;
-	task->cl = &cl;
-	task->cl_arg = NULL;
-	task->destroy = 0; /* tell StarPU to not destroy the task */
-	task->use_tag = 1;
-	task->tag_id = TAG(99, 99, 99); /* arbitrary numbers */
-
-	/* execute the task */
-	ret = starpu_task_submit(task);
-	if (ret == -ENODEV) return 77;
-		STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
-	starpu_task_wait_for_all();
-
-	/* check that starpu_tag_get_task() returns the correct task */
-	assert(starpu_tag_get_task(task->tag_id) == task);
-
-	starpu_task_destroy(task);
-
-	return 0;
-}
-
 int main(int argc STARPU_ATTRIBUTE_UNUSED , char **argv STARPU_ATTRIBUTE_UNUSED)
 {
 	int ret;
@@ -270,10 +242,6 @@ int main(int argc STARPU_ATTRIBUTE_UNUSED , char **argv STARPU_ATTRIBUTE_UNUSED)
 	if (ret == 0)
 	     starpu_task_wait_for_all();
 
-	ret = test_starpu_tag_get_task();
-	if (ret)
-		return ret;
-
 	tag_cleanup_grid(nk-2);
 	tag_cleanup_grid(nk-1);
 

+ 1 - 0
tests/Makefile.am

@@ -140,6 +140,7 @@ noinst_PROGRAMS =				\
 	main/empty_task_sync_point_tasks	\
 	main/empty_task_chain			\
 	main/tag_wait_api			\
+	main/tag_get_task			\
 	main/task_wait_api			\
 	main/declare_deps_in_callback		\
 	main/declare_deps_after_submission	\

+ 79 - 0
tests/main/tag_get_task.c

@@ -0,0 +1,79 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2016  INRIA
+ *
+ * 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 <stdio.h>
+#include <unistd.h>
+
+#include <starpu.h>
+#include "../helper.h"
+
+void dummy_func(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg STARPU_ATTRIBUTE_UNUSED)
+{
+}
+
+static struct starpu_codelet dummy_codelet =
+{
+	.cpu_funcs = {dummy_func},
+	.cuda_funcs = {dummy_func},
+	.opencl_funcs = {dummy_func},
+	.cpu_funcs_name = {"dummy_func"},
+	.model = NULL,
+	.nbuffers = 0
+};
+
+static void callback(void *tag)
+{
+	fflush(stderr);
+	FPRINTF(stderr, "Callback for tag %p\n", tag);
+	fflush(stderr);
+}
+
+int main(int argc, char **argv)
+{
+	struct starpu_task *task;
+	starpu_tag_t tag = 0x42;
+	int ret;
+
+	ret = starpu_initialize(NULL, &argc, &argv);
+	if (ret == -ENODEV)
+		return STARPU_TEST_SKIPPED;
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+
+	/* create a new dummy task with a tag */
+	task = starpu_task_create();
+	task->callback_func = callback;
+	task->callback_arg = (void *)tag;
+	task->cl = &dummy_codelet;
+	task->cl_arg = NULL;
+	task->destroy = 0; /* tell StarPU to not destroy the task */
+	task->use_tag = 1;
+	task->tag_id = tag;
+
+	/* execute the task */
+	ret = starpu_task_submit(task);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
+	ret = starpu_task_wait_for_all();
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
+
+	/* check that starpu_tag_get_task() returns the correct task */
+	ret = (starpu_tag_get_task(task->tag_id) != task);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_tag_get_task");
+
+	starpu_task_destroy(task);
+	starpu_shutdown();
+
+	return EXIT_SUCCESS;
+}