summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--tests/integration_tests/CMakeLists.txt45
-rwxr-xr-xtests/integration_tests/run_local.sh4
-rw-r--r--tests/integration_tests/test-complete-local-setup.c129
-rw-r--r--tests/integration_tests/test-complete-remote-setup.c143
-rw-r--r--tests/integration_tests/test-suite.c45
-rw-r--r--tests/integration_tests/test-suite.h7
7 files changed, 374 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 476ddee..83c174d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,7 @@ endif()
add_definitions(-DG_LOG_DOMAIN="Ufo")
add_subdirectory(src)
+add_subdirectory(tests/integration_tests)
# --- Package generation ------------------------------------------------------
diff --git a/tests/integration_tests/CMakeLists.txt b/tests/integration_tests/CMakeLists.txt
new file mode 100644
index 0000000..d02b501
--- /dev/null
+++ b/tests/integration_tests/CMakeLists.txt
@@ -0,0 +1,45 @@
+cmake_minimum_required(VERSION 2.8)
+
+# configure unit tests
+set(TEST_SRCS
+ test-suite.c
+ test-complete-local-setup.c
+ test-complete-remote-setup.c
+)
+
+set(SUITE_BIN "test-suite")
+add_executable(${SUITE_BIN} ${TEST_SRCS})
+
+include_directories(
+ ${GLIB2_INCLUDE_DIRS}
+)
+
+# prefer a ufo-core instance if it is located in same folder
+# as ufo-filters (usefull for development)
+get_filename_component(LOCAL_UFO_DIR "${PROJECT_SOURCE_DIR}/../ufo-core/" ABSOLUTE)
+
+if (EXISTS ${LOCAL_UFO_DIR} AND IS_DIRECTORY ${LOCAL_UFO_DIR})
+ message ("Using local UFO at: ${LOCAL_UFO_DIR}")
+
+ include_directories(${LOCAL_UFO_DIR})
+ link_directories(${LOCAL_UFO_DIR/ufo/})
+
+ set (LOCAL_UFO_LIB ${LOCAL_UFO_DIR}/ufo/libufo.so)
+ target_link_libraries(${SUITE_BIN}
+ ${LOCAL_UFO_LIB}
+ )
+else ()
+ message ("Using system wide UFO installation")
+ include_directories(
+ ${UFO_INCLUDE_DIRS}
+ )
+ link_directories(
+ ${UFO_LIBRARY_DIRS}
+ )
+ target_link_libraries(${SUITE_BIN}
+ ufo
+ )
+endif ()
+
+
+
diff --git a/tests/integration_tests/run_local.sh b/tests/integration_tests/run_local.sh
new file mode 100755
index 0000000..33d75d2
--- /dev/null
+++ b/tests/integration_tests/run_local.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+# use the filters in this project, not the system-wide intalled ones
+UFO_PLUGIN_PATH="`pwd`/../../src/" ./test-suite
diff --git a/tests/integration_tests/test-complete-local-setup.c b/tests/integration_tests/test-complete-local-setup.c
new file mode 100644
index 0000000..266305c
--- /dev/null
+++ b/tests/integration_tests/test-complete-local-setup.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2011-2013 Karlsruhe Institute of Technology
+ *
+ * This file is part of Ufo.
+ *
+ * This library 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 3 of the License, or (at your option) any later version.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ufo/ufo.h>
+#include <glib/gstdio.h>
+#include "test-suite.h"
+
+typedef struct {
+ UfoConfig *config;
+ gchar *tmpdir;
+} Fixture;
+
+static void
+setup (Fixture *fixture, gconstpointer data)
+{
+ fixture->config = ufo_config_new ();
+ fixture->tmpdir = g_strdup ("ufotemp-XXXXXX");
+ g_mkdtemp (fixture->tmpdir);
+}
+
+static void
+teardown (Fixture *fixture, gconstpointer data)
+{
+ g_rmdir (fixture->tmpdir);
+ g_free (fixture->tmpdir);
+}
+
+static void
+test_simple_invert (Fixture *fixture,
+ gconstpointer unused)
+{
+ //double-invert an image should equal original image
+ UfoPluginManager *mgr = ufo_plugin_manager_new (NULL);
+
+ const gchar *input_image = "../data/sinogram-00000.tif";
+ const gchar *output_image = g_strconcat (fixture->tmpdir, "/", "sinogram-00000-inverted.tif", NULL);
+
+ const gchar *kernel_source =
+ "__kernel void invert(__global float *input, __global float *output) "
+ "{ "
+ "int index = get_global_id(1) * get_global_size(0) + get_global_id(0); "
+ "output[index] = 1.0f - input[index]; "
+ "} "
+ ;
+
+ UfoTaskNode *reader = ufo_plugin_manager_get_task (mgr, "reader", NULL);
+ UfoTaskNode *writer = ufo_plugin_manager_get_task (mgr, "writer", NULL);
+ UfoTaskNode *cl1 = ufo_plugin_manager_get_task (mgr, "opencl", NULL);
+ UfoTaskNode *cl2 = ufo_plugin_manager_get_task (mgr, "opencl", NULL);
+
+ GValue input_file = G_VALUE_INIT,
+ output_file = G_VALUE_INIT,
+ output_single = G_VALUE_INIT,
+ kernel_code = G_VALUE_INIT,
+ kernel_name = G_VALUE_INIT;
+
+ g_value_init (&input_file, G_TYPE_STRING);
+ g_value_init (&output_file, G_TYPE_STRING);
+ g_value_init (&output_single, G_TYPE_BOOLEAN);
+ g_value_init (&kernel_code, G_TYPE_STRING);
+ g_value_init (&kernel_name, G_TYPE_STRING);
+
+ g_value_set_static_string (&input_file, input_image);
+ g_object_set_property (G_OBJECT (reader), "path", &input_file);
+
+ g_value_set_static_string (&output_file, output_image);
+ g_object_set_property (G_OBJECT (writer), "filename", &output_file);
+ g_value_set_boolean (&output_single, TRUE);
+ g_object_set_property (G_OBJECT (writer), "single-file", &output_single);
+
+ g_value_set_static_string (&kernel_code, kernel_source);
+ g_object_set_property (G_OBJECT (cl1), "source", &kernel_code);
+ g_object_set_property (G_OBJECT (cl2), "source", &kernel_code);
+ g_value_set_static_string (&kernel_name, "invert");
+ g_object_set_property (G_OBJECT (cl1), "kernel", &kernel_name);
+ g_object_set_property (G_OBJECT (cl2), "kernel", &kernel_name);
+
+ UfoGraph *graph = UFO_GRAPH (ufo_task_graph_new ());
+ ufo_graph_connect_nodes (graph, UFO_NODE (reader), UFO_NODE (cl1), NULL);
+ ufo_graph_connect_nodes (graph, UFO_NODE (cl1), UFO_NODE (cl2), NULL);
+ ufo_graph_connect_nodes (graph, UFO_NODE (cl2), UFO_NODE (writer), NULL);
+
+ UfoScheduler *sched = ufo_scheduler_new (NULL, NULL);
+ ufo_scheduler_run (sched, UFO_TASK_GRAPH (graph), NULL);
+
+ // test that an output was generated
+ g_assert (g_file_test (output_image, G_FILE_TEST_EXISTS));
+
+ // check that the file size matches our expectation
+ GMappedFile *file_out = g_mapped_file_new (output_image, FALSE, NULL);
+ gsize len_actual = g_mapped_file_get_length (file_out);
+ gsize len_expected = 1048722;
+
+ g_assert (len_expected == len_actual);
+
+ g_mapped_file_unref (file_out);
+ g_remove (output_image);
+
+ g_object_unref (reader);
+ g_object_unref (writer);
+ g_object_unref (cl1);
+ g_object_unref (cl2);
+ g_object_unref (graph);
+ g_object_unref (mgr);
+}
+
+void
+test_add_complete_local_setup (void)
+{
+ g_test_add ("/complete_local_setup/simple_invert",
+ Fixture, NULL,
+ setup, test_simple_invert, teardown);
+}
diff --git a/tests/integration_tests/test-complete-remote-setup.c b/tests/integration_tests/test-complete-remote-setup.c
new file mode 100644
index 0000000..9a4b749
--- /dev/null
+++ b/tests/integration_tests/test-complete-remote-setup.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2011-2013 Karlsruhe Institute of Technology
+ *
+ * This file is part of Ufo.
+ *
+ * This library 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 3 of the License, or (at your option) any later version.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ufo/ufo.h>
+#include <glib/gstdio.h>
+#include "test-suite.h"
+
+typedef struct {
+ UfoConfig *config;
+ UfoDaemon *daemon;
+ gchar *tmpdir;
+} Fixture;
+
+static void
+setup (Fixture *fixture, gconstpointer data)
+{
+ fixture->config = ufo_config_new ();
+ gchar *addr = g_strdup ("tcp://127.0.0.1:5555");
+ fixture->config = ufo_config_new ();
+
+ fixture->daemon = ufo_daemon_new (fixture->config, addr);
+ ufo_daemon_start (fixture->daemon);
+
+ fixture->tmpdir = g_strdup ("ufotemp-XXXXXX");
+ g_mkdtemp (fixture->tmpdir);
+}
+
+static void
+teardown (Fixture *fixture, gconstpointer data)
+{
+ ufo_daemon_stop (fixture->daemon);
+ g_object_unref (fixture->daemon);
+
+ g_rmdir (fixture->tmpdir);
+ g_free (fixture->tmpdir);
+}
+
+static void
+test_simple_invert (Fixture *fixture,
+ gconstpointer unused)
+{
+ //double-invert an image should equal original image
+ UfoPluginManager *mgr = ufo_plugin_manager_new (NULL);
+
+ const gchar *input_image = "../data/sinogram-00000.tif";
+ const gchar *output_image = g_strconcat (fixture->tmpdir, "/", "sinogram-00000-inverted.tif", NULL);
+
+ const gchar *kernel_source =
+ "__kernel void invert(__global float *input, __global float *output) "
+ "{ "
+ "int index = get_global_id(1) * get_global_size(0) + get_global_id(0); "
+ "output[index] = 1.0f - input[index]; "
+ "} "
+ ;
+
+ UfoTaskNode *reader = ufo_plugin_manager_get_task (mgr, "reader", NULL);
+ UfoTaskNode *writer = ufo_plugin_manager_get_task (mgr, "writer", NULL);
+ UfoTaskNode *cl1 = ufo_plugin_manager_get_task (mgr, "opencl", NULL);
+ UfoTaskNode *cl2 = ufo_plugin_manager_get_task (mgr, "opencl", NULL);
+
+ GValue input_file = G_VALUE_INIT,
+ output_file = G_VALUE_INIT,
+ output_single = G_VALUE_INIT,
+ kernel_code = G_VALUE_INIT,
+ kernel_name = G_VALUE_INIT;
+
+ g_value_init (&input_file, G_TYPE_STRING);
+ g_value_init (&output_file, G_TYPE_STRING);
+ g_value_init (&output_single, G_TYPE_BOOLEAN);
+ g_value_init (&kernel_code, G_TYPE_STRING);
+ g_value_init (&kernel_name, G_TYPE_STRING);
+
+ g_value_set_static_string (&input_file, input_image);
+ g_object_set_property (G_OBJECT (reader), "path", &input_file);
+
+ g_value_set_static_string (&output_file, output_image);
+ g_object_set_property (G_OBJECT (writer), "filename", &output_file);
+ g_value_set_boolean (&output_single, TRUE);
+ g_object_set_property (G_OBJECT (writer), "single-file", &output_single);
+
+ g_value_set_static_string (&kernel_code, kernel_source);
+ g_object_set_property (G_OBJECT (cl1), "source", &kernel_code);
+ g_object_set_property (G_OBJECT (cl2), "source", &kernel_code);
+ g_value_set_static_string (&kernel_name, "invert");
+ g_object_set_property (G_OBJECT (cl1), "kernel", &kernel_name);
+ g_object_set_property (G_OBJECT (cl2), "kernel", &kernel_name);
+
+ UfoGraph *graph = UFO_GRAPH (ufo_task_graph_new ());
+ ufo_graph_connect_nodes (graph, UFO_NODE (reader), UFO_NODE (cl1), NULL);
+ ufo_graph_connect_nodes (graph, UFO_NODE (cl1), UFO_NODE (cl2), NULL);
+ ufo_graph_connect_nodes (graph, UFO_NODE (cl2), UFO_NODE (writer), NULL);
+
+ gchar *remote = g_strdup ("tcp://127.0.0.1:5555");
+ GList *remotes = g_list_append (NULL, remote);
+ UfoScheduler *sched = ufo_scheduler_new (NULL, remotes);
+
+ ufo_scheduler_run (sched, UFO_TASK_GRAPH (graph), NULL);
+ g_free(remote);
+
+ // test that an output was generated
+ g_assert (g_file_test (output_image, G_FILE_TEST_EXISTS));
+
+ // check that the file size matches our expectation
+ GMappedFile *file_out = g_mapped_file_new (output_image, FALSE, NULL);
+ gsize len_actual = g_mapped_file_get_length (file_out);
+ gsize len_expected = 1048722;
+
+ g_assert (len_expected == len_actual);
+
+ g_mapped_file_unref (file_out);
+ g_remove (output_image);
+
+ g_object_unref (reader);
+ g_object_unref (writer);
+ g_object_unref (cl1);
+ g_object_unref (cl2);
+ g_object_unref (graph);
+ g_object_unref (mgr);
+}
+
+void
+test_add_complete_remote_setup (void)
+{
+ g_test_add ("/complete_remote_setup/simple_invert",
+ Fixture, NULL,
+ setup, test_simple_invert, teardown);
+}
diff --git a/tests/integration_tests/test-suite.c b/tests/integration_tests/test-suite.c
new file mode 100644
index 0000000..3a1bbe8
--- /dev/null
+++ b/tests/integration_tests/test-suite.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011-2013 Karlsruhe Institute of Technology
+ *
+ * This file is part of Ufo.
+ *
+ * This library 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 3 of the License, or (at your option) any later version.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib-object.h>
+#include "test-suite.h"
+
+static void
+test_log (const gchar *domain,
+ GLogLevelFlags flags,
+ const gchar *message,
+ gpointer data)
+{
+ // g_print ("%s\n",message);
+}
+
+int main(int argc, char *argv[])
+{
+ g_type_init();
+ g_test_init(&argc, &argv, NULL);
+ g_test_bug_base("http://ufo.kit.edu/ufo/ticket");
+
+ g_log_set_handler ("Ufo", G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, test_log, NULL);
+ g_log_set_handler ("ocl", G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, test_log, NULL);
+
+ test_add_complete_local_setup ();
+ test_add_complete_remote_setup ();
+ g_test_run();
+ return 0;
+}
diff --git a/tests/integration_tests/test-suite.h b/tests/integration_tests/test-suite.h
new file mode 100644
index 0000000..b476a0e
--- /dev/null
+++ b/tests/integration_tests/test-suite.h
@@ -0,0 +1,7 @@
+#ifndef TEST_SUITE_H
+#define TEST_SUITE_H
+
+void test_add_complete_local_setup (void);
+void test_add_complete_remote_setup (void);
+
+#endif