summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDenis Steckelmacher <steckdenis@yahoo.fr>2011-05-17 18:32:29 +0200
committerDenis Steckelmacher <steckdenis@yahoo.fr>2011-05-17 18:32:29 +0200
commit802c9f6fd1ed72f73594091c692ad9ed6c054e3e (patch)
treed8204b082c53b75e9fd2e89aabd4b3feffc7ebd7 /tests
parent5c1591d4226f396087548607f4c3ccdc0753341c (diff)
Implement the Platform API, with tests.
Bug code cleanup, also in the tests. My implementation looks like the one of the previous author, but is a bit more complete.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt6
-rw-r--r--tests/test_context.cpp52
-rw-r--r--tests/test_context.h17
-rw-r--r--tests/test_device.cpp89
-rw-r--r--tests/test_device.h17
-rw-r--r--tests/tests.c33
6 files changed, 13 insertions, 201 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 7aa0510..752a991 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -3,8 +3,7 @@ LINK_DIRECTORIES(${Coal_BINARY_DIR}/src ${CHECK_LIBRARY_DIRS})
set(OPENCL_TESTS_SOURCE
tests.c
- test_device.cpp
- test_context.cpp
+ test_platform.cpp
)
add_executable(tests ${OPENCL_TESTS_SOURCE})
@@ -14,5 +13,4 @@ MACRO(OPENCL_TEST EXECUTABLE_NAME TEST_NAME)
add_test(${TEST_NAME} ${EXECUTABLE_NAME} ${TEST_NAME})
ENDMACRO(OPENCL_TEST)
-OPENCL_TEST(tests device)
-OPENCL_TEST(tests context)
+OPENCL_TEST(tests platform)
diff --git a/tests/test_context.cpp b/tests/test_context.cpp
deleted file mode 100644
index 4798a93..0000000
--- a/tests/test_context.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "test_context.h"
-
-#include "CL/cl.h"
-
-START_TEST (test_create_context)
-{
- cl_context context = NULL;
- cl_device_id device;
- cl_int result = -1;
- cl_int err_code;
- cl_int result_context;
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_CPU, 1, &device, NULL);
- if(result == CL_SUCCESS) {
- //in clover we need plataform argument?
- context = clCreateContext(0, 1, &device, NULL, NULL, NULL);
- fail_if(context == NULL, "It should work, context not created");
- result_context = clReleaseContext(context);
- fail_if((result_context != CL_SUCCESS) || (context != NULL),
- "It should work, context no released");
-
- context = clCreateContext(0, 1, NULL, NULL, NULL, &err_code);
- fail_if((context != NULL) || (err_code != CL_INVALID_VALUE),
- "It should not work, context or err_code returning wrong");
- result_context = clReleaseContext(context);
-
- context = clCreateContext(0, 0, &device, NULL, NULL, &err_code);
- fail_if((context != NULL) || (err_code != CL_INVALID_VALUE),
- "It should not work, context or err_code returning wrong");
- result_context = clReleaseContext(context);
- }
-}
-END_TEST
-
-START_TEST (test_create_context_from_type)
-{
- cl_int result = -1;
- cl_context context = NULL;
-
- context = clCreateContextFromType(0, CL_DEVICE_TYPE_CPU, NULL, NULL, NULL);
- fail_if(context == NULL, "It should work, context not created");
-}
-END_TEST
-
-TCase *cl_context_tcase_create(void)
-{
- TCase *tc = NULL;
- tc = tcase_create("context");
- tcase_add_test(tc, test_create_context);
- tcase_add_test(tc, test_create_context_from_type);
- return tc;
-}
diff --git a/tests/test_context.h b/tests/test_context.h
deleted file mode 100644
index 39723d2..0000000
--- a/tests/test_context.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef __UTEST_CONTEXT__
-#define __UTEST_CONTEXT__
-
-#include <check.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-TCase *cl_context_tcase_create(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/tests/test_device.cpp b/tests/test_device.cpp
deleted file mode 100644
index ef09782..0000000
--- a/tests/test_device.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-#include "test_device.h"
-
-#include "CL/cl.h"
-
-#define CL_DEVICE_TYPE_INVALID 0x30 //i hope it be an invalid device
-
-static cl_device_id device;
-
-START_TEST (test_get_device_ids)
-{
- cl_int result = -1;
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_DEFAULT, 1, &device, NULL);
- fail_if(result != CL_SUCCESS, "It is not possible get default device id");
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_CPU, 1, &device, NULL);
- fail_if(result != CL_SUCCESS, "It is not possible get cpu device id");
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_GPU, 1, &device, NULL);
- fail_if(result != CL_SUCCESS, "It is not possible get gpu device id");
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_ACCELERATOR, 1, &device, NULL);
- fail_if(result != CL_SUCCESS, "It is not possible get accelarator device id");
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_ALL, 1, &device, NULL);
- fail_if(result != CL_SUCCESS, "It is not possible get all device ids");
-
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_DEFAULT, 0, &device, NULL);
- fail_if(result != CL_INVALID_VALUE, "It should not be working");
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_DEFAULT, 1, NULL, NULL);
- fail_if(result != CL_INVALID_VALUE, "It should not be working");
-
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_INVALID, 1, &device, NULL);
- fail_if(result != CL_INVALID_DEVICE_TYPE, "It should not be working,\
- device type does not exist");
-}
-END_TEST
-
-START_TEST (test_get_device_info)
-{
- cl_int result = -1;
-
- result = clGetDeviceIDs(CL_DEVICE_TYPE_CPU, 1, &device, NULL);
- if(result == CL_SUCCESS) {
- cl_int device_info_result;
- cl_device_type device_type;
-
- device_info_result = clGetDeviceInfo(device, CL_DEVICE_TYPE,
- sizeof(device_type), &device_type, NULL);
- fail_if((device_info_result != CL_SUCCESS) ||
- (device_type != CL_DEVICE_TYPE_CPU), "It should work");
-
- //FIXME: check all cl_device_info
-
- device_info_result = clGetDeviceInfo(0x0, CL_DEVICE_TYPE,
- sizeof(device_type), &device_type, NULL);
- fail_if(device_info_result != CL_INVALID_DEVICE, "It should not be working,\
- invalid device");
-
- device_info_result = clGetDeviceInfo(device, CL_DEVICE_TYPE_INVALID,
- sizeof(device_type), &device_type, NULL);
- fail_if(device_info_result != CL_INVALID_VALUE,"It should not be working,\
- invalid param name");
-
- device_info_result = clGetDeviceInfo(device, CL_DEVICE_TYPE,
- sizeof(device_type), NULL, NULL);
- // in opencl specification if param_value is NULL it should be ignored
- // device_info_result should return cl_success? we think so
- fail_if(device_info_result != CL_SUCCESS, "It should work");
-
- device_info_result = clGetDeviceInfo(device, CL_DEVICE_TYPE,
- sizeof(device_type)-10, &device_type, NULL);
- fail_if(device_info_result != CL_INVALID_VALUE, "It should not be working,\
- param_value_size is < size of return type");
- }
-}
-END_TEST
-
-TCase *cl_device_tcase_create(void)
-{
- TCase *tc = NULL;
- tc = tcase_create("device");
- tcase_add_test(tc, test_get_device_ids);
- tcase_add_test(tc, test_get_device_info);
- return tc;
-}
diff --git a/tests/test_device.h b/tests/test_device.h
deleted file mode 100644
index 34c2237..0000000
--- a/tests/test_device.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef __UTEST_DEVICE__
-#define __UTEST_DEVICE__
-
-#include <check.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-TCase *cl_device_tcase_create(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/tests/tests.c b/tests/tests.c
index 0138b3f..7fd0291 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -1,23 +1,8 @@
-#include "test_device.h"
-#include "test_context.h"
+#include "test_platform.h"
#include <stdlib.h>
#include <stdio.h>
-static Suite *device_suite(void)
-{
- Suite *s = suite_create("device");
- suite_add_tcase(s, cl_device_tcase_create());
- return s;
-}
-
-static Suite *context_suite(void)
-{
- Suite *s = suite_create("context");
- suite_add_tcase(s, cl_context_tcase_create());
- return s;
-}
-
int main(int argc, char **argv)
{
int n_failed_tests;
@@ -27,13 +12,17 @@ int main(int argc, char **argv)
printf("there is not enough arguments");
return EXIT_FAILURE;
}
+
+#define TESTSUITE(name, string) \
+ if (!strcmp(string, argv[1])) { \
+ s = suite_create(string); \
+ suite_add_tcase(s, cl_##name##_tcase_create()); \
+ }
+
+ TESTSUITE(platform, "platform");
- if (!strcmp("device",argv[1])) {
- s = device_suite();
- } else if (!strcmp("context", argv[1])){
- s = context_suite();
- } else {
- printf("test case does not exist");
+ if (s == NULL) {
+ printf("test case %s does not exist", argv[1]);
return EXIT_FAILURE;
}