2 * Copyright © 2012 Blaž Tomažič <blaz.tomazic@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * @file create-context-from-type.c
29 * cl_context clCreateContextFromType(cl_context_properties *properties,
30 * cl_device_type device_type,
32 * const char *errinfo,
33 * const void *private_info,
38 * cl_int *errcode_ret)
41 #include "piglit-framework-cl-api.h"
44 PIGLIT_CL_API_TEST_CONFIG_BEGIN
46 config
.name
= "clCreateContextFromType";
47 config
.version_min
= 10;
49 config
.run_per_platform
= true;
51 PIGLIT_CL_API_TEST_CONFIG_END
55 test(cl_context_properties
*properties
,
56 const cl_device_type device_type
,
59 const void *private_info
,
64 cl_int expected_error
,
65 enum piglit_result
* result
,
66 const char* test_str
) {
71 cl_ctx
= clCreateContextFromType(properties
,
77 if(errNo
!= CL_DEVICE_NOT_FOUND
) {
78 if(!piglit_cl_check_error(errNo
, expected_error
)) {
79 fprintf(stderr
, "Failed (error code: %s): %s.\n",
80 piglit_cl_get_error_name(errNo
), test_str
);
81 piglit_merge_result(result
, PIGLIT_FAIL
);
84 if(expected_error
== CL_SUCCESS
) {
86 printf("Expecting non-NULL cl_context\n");
87 fprintf(stderr
, "Failed (NULL value returned): %s.\n", test_str
);
88 piglit_merge_result(result
, PIGLIT_FAIL
);
91 clReleaseContext(cl_ctx
);
92 } else if(cl_ctx
!= NULL
) {
93 printf("Expecting NULL cl_context\n");
94 fprintf(stderr
, "Failed (non-NULL value returned): %s.\n", test_str
);
95 piglit_merge_result(result
, PIGLIT_FAIL
);
101 cl_ctx
= clCreateContextFromType(properties
,
107 if(errNo
!= CL_DEVICE_NOT_FOUND
) {
108 if(expected_error
== CL_SUCCESS
) {
110 printf("Expecting non-NULL cl_context\n");
111 fprintf(stderr
, "Failed (NULL value returned): %s.\n", test_str
);
112 piglit_merge_result(result
, PIGLIT_FAIL
);
115 clReleaseContext(cl_ctx
);
116 } else if(cl_ctx
!= NULL
) {
117 printf("Expecting NULL cl_context\n");
118 fprintf(stderr
, "Failed (non-NULL value returned): %s.\n", test_str
);
119 piglit_merge_result(result
, PIGLIT_FAIL
);
126 * @param mask Defines which fields to use
128 static cl_device_type
129 get_mixed_device_types(int mask
, const cl_device_type device_types
[]) {
131 cl_device_type mixed_device_types
= 0;
135 mixed_device_types
|= device_types
[i
];
141 return mixed_device_types
;
146 piglit_cl_test(const int argc
,
148 const struct piglit_cl_api_test_config
* config
,
149 const struct piglit_cl_api_test_env
* env
)
151 enum piglit_result result
= PIGLIT_PASS
;
155 cl_device_type mixed_device_types
;
157 bool found_invalid_platform
= false;
158 cl_platform_id
* platform_ids
;
159 unsigned int num_platform_ids
;
160 cl_platform_id invalid_platform_id
;
162 //TODO: test also CL_CONTEXT_INTEROP_USER_SYNC
163 cl_context_properties context_properties
[] = {
164 CL_CONTEXT_PLATFORM
, (cl_context_properties
)env
->platform_id
,
167 cl_context_properties invalid_context_properties
[] = {
168 CL_DEVICE_NAME
, (cl_context_properties
)env
->platform_id
,
171 cl_context_properties multiple_platform_context_properties
[] = {
172 CL_CONTEXT_PLATFORM
, (cl_context_properties
)env
->platform_id
,
173 CL_CONTEXT_PLATFORM
, (cl_context_properties
)env
->platform_id
,
177 int num_device_types
= PIGLIT_CL_ENUM_NUM(cl_device_type
, env
->version
);
178 const cl_device_type
*device_types
= PIGLIT_CL_ENUM_ARRAY(cl_device_type
);
180 /* Find invalid platform_id */
181 invalid_platform_id
= 0;
182 num_platform_ids
= piglit_cl_get_platform_ids(&platform_ids
);
183 while(!found_invalid_platform
) {
184 found_invalid_platform
= true;
185 invalid_platform_id
= (cl_platform_id
)1;
186 for(i
= 0; i
< num_platform_ids
; i
++) {
187 if(invalid_platform_id
== platform_ids
[i
]) {
188 found_invalid_platform
= false;
195 /*** Normal usage ***/
198 * For each device types mix.
199 * There are 2^(num_device_types)-1 possible options.
201 for(mask
= 1; mask
< (1 << num_device_types
); mask
++) {
202 mixed_device_types
= get_mixed_device_types(mask
, device_types
);
205 "Create context using 0x%X as device types",
206 (unsigned int)mixed_device_types
);
208 test(context_properties
, mixed_device_types
, NULL
, NULL
,
209 CL_SUCCESS
, &result
, test_str
);
210 //TODO: test callback functions
217 * CL_INVALID_VALUE if context property name in properties is
218 * not a supported property name, or if pfn_notify is NULL but
219 * user_data is not NULL.
223 * CL_INVALID_VALUE if pfn_notify is NULL but user_data is
228 if(env
->version
<= 10) {
229 test(invalid_context_properties
, CL_DEVICE_TYPE_ALL
, NULL
, NULL
,
230 CL_INVALID_VALUE
, &result
,
231 "Trigger CL_INVALID_VALUE if context property name in properties is not a supported property name");
234 test(context_properties
, CL_DEVICE_TYPE_ALL
, NULL
, &context_properties
,
235 CL_INVALID_VALUE
, &result
,
236 "Trigger CL_INVALID_VALUE if pfn_notify is NULL and user_data is not NULL");
240 * CL_INVALID_PROPERTY if context property name in properties
241 * is not a supported property name, if the value specified for
242 * a supported property name is not valid, or if the same
243 * property name is specified more than once.
247 * Note: 'if the value specified for a supported property name is
248 * not valid' was already tested
250 #if defined(CL_VERSION_1_1)
251 if(env
->version
>= 11) {
252 test(multiple_platform_context_properties
, CL_DEVICE_TYPE_ALL
,
254 CL_INVALID_PROPERTY
, &result
,
255 "Trigger CL_INVALID_PROPERTY if the same property name is pecified more than once");
260 * CL_DEVICE_NOT_AVAILABLE if a device in devices is currently
261 * not available even though the device was returned by clGetDeviceIDs.