diff options
author | Denis Steckelmacher <steckdenis@yahoo.fr> | 2011-05-22 15:04:46 +0200 |
---|---|---|
committer | Denis Steckelmacher <steckdenis@yahoo.fr> | 2011-05-22 15:04:46 +0200 |
commit | 671815a3086713014c161b700a886245ab7ee5d2 (patch) | |
tree | 71723e19e744ebf17fb19d6c73b41fc2ba2617d6 /tests | |
parent | 7e091007fe68a05b17ad0d505e769aac31d6bc3a (diff) |
Implement clGetContextInfo
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_context.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/test_context.cpp b/tests/test_context.cpp index 915d85d..2c4c187 100644 --- a/tests/test_context.cpp +++ b/tests/test_context.cpp @@ -102,11 +102,123 @@ START_TEST (test_create_context_from_type) } END_TEST +START_TEST (test_get_context_info) +{ + cl_context ctx; + cl_int result; + size_t size_ret; + + union { + cl_uint refcount, num_devices; + cl_device_id device; + struct __attribute__((packed)) { + cl_context_properties prop_platform; + cl_platform_id platform; + cl_context_properties null; + } properties; + } context_info; + + const cl_context_properties *properties = + (const cl_context_properties *)&context_info.properties; + + // Test for a dummy context + ctx = clCreateContextFromType(0, CL_DEVICE_TYPE_DEFAULT, 0, 0, &result); + fail_if( + result != CL_SUCCESS || ctx == 0, + "unable to create a valid context with a device of type default" + ); + + result = clGetContextInfo(0, CL_CONTEXT_REFERENCE_COUNT, 0, 0, &size_ret); + fail_if( + result != CL_INVALID_CONTEXT, + "0 is not a valid context" + ); + + result = clGetContextInfo(ctx, 1337, 0, 0, &size_ret); + fail_if( + result != CL_INVALID_VALUE, + "1337 is not a valid param_name" + ); + + result = clGetContextInfo(ctx, CL_CONTEXT_REFERENCE_COUNT, 0, &context_info, + &size_ret); + fail_if( + result != CL_INVALID_VALUE, + "param_value_size is too small to contain a cl_uint" + ); + + result = clGetContextInfo(ctx, CL_CONTEXT_REFERENCE_COUNT, 0, 0, &size_ret); + fail_if( + result != CL_SUCCESS || size_ret != sizeof(cl_uint), + "we must succeed and say that we'll return a cl_uint" + ); + + // Use a real context and check the return values + clReleaseContext(ctx); + + context_info.properties.prop_platform = CL_CONTEXT_PLATFORM; + context_info.properties.platform = 0; + context_info.properties.null = 0; + + ctx = clCreateContextFromType(properties, CL_DEVICE_TYPE_DEFAULT, 0, 0, + &result); + fail_if( + result != CL_SUCCESS || ctx == 0, + "unable to create a valid context with a device of type default" + ); + + // This call clobbers context_info.properties, so we also check that + // they are properly memcpy'ed by Coal::Context. + result = clGetContextInfo(ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(cl_uint), + &context_info, &size_ret); + fail_if( + result != CL_SUCCESS || context_info.refcount != 1, + "context's reference count must be 1 here" + ); + + clRetainContext(ctx); + + result = clGetContextInfo(ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(cl_uint), + &context_info, &size_ret); + fail_if( + result != CL_SUCCESS || size_ret != sizeof(cl_uint) || + context_info.refcount != 2, + "context's reference count must be 2 here" + ); + + result = clGetContextInfo(ctx, CL_CONTEXT_NUM_DEVICES, sizeof(cl_uint), + &context_info, &size_ret); + fail_if( + result != CL_SUCCESS || size_ret != sizeof(cl_uint) || + context_info.num_devices != 1, + "we currently support only one device : CPU" + ); + + result = clGetContextInfo(ctx, CL_CONTEXT_DEVICES, sizeof(cl_device_id), + &context_info, &size_ret); + fail_if( + result != CL_SUCCESS || size_ret != sizeof(cl_device_id) || + context_info.device == 0, + "this context must have a device" + ); + + result = clGetContextInfo(ctx, CL_CONTEXT_PROPERTIES, + sizeof(context_info.properties), &context_info, + &size_ret); + fail_if( + result != CL_SUCCESS || size_ret != sizeof(context_info.properties) || + context_info.properties.prop_platform != CL_CONTEXT_PLATFORM, + "this context must have a valid CL_CONTEXT_PLATFORM property" + ); +} +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); + tcase_add_test(tc, test_get_context_info); return tc; } |