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 get-context-info.c
29 * cl_int clGetContextInfo (cl_context context,
30 * cl_context_info param_name,
31 * size_t param_value_size,
33 * size_t param_value_size_ret)
36 #include "piglit-framework-cl-api.h"
39 PIGLIT_CL_API_TEST_CONFIG_BEGIN
41 config
.name
= "clGetContextInfo";
42 config
.version_min
= 10;
44 config
.run_per_platform
= true;
46 PIGLIT_CL_API_TEST_CONFIG_END
50 piglit_cl_test(const int argc
,
52 const struct piglit_cl_api_test_config
* config
,
53 const struct piglit_cl_api_test_env
* env
)
55 enum piglit_result result
= PIGLIT_PASS
;
61 size_t param_value_size
;
64 cl_context_properties context_properties
[] = {
65 CL_CONTEXT_PLATFORM
, (cl_context_properties
)env
->platform_id
,
69 int num_context_infos
= PIGLIT_CL_ENUM_NUM(cl_context_info
, env
->version
);
70 const cl_context_info
*context_infos
= PIGLIT_CL_ENUM_ARRAY(cl_context_info
);
72 /*** Normal usage ***/
74 cl_ctx
= clCreateContextFromType(context_properties
,
79 if(errNo
== CL_DEVICE_NOT_FOUND
) {
80 fprintf(stderr
, "No available devices.\n");
83 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)) {
85 "Failed (error code: %s): Create context.\n",
86 piglit_cl_get_error_name(errNo
));
90 for(i
= 0; i
< num_context_infos
; i
++) {
91 printf("%s ", piglit_cl_get_enum_name(context_infos
[i
]));
93 errNo
= clGetContextInfo(cl_ctx
,
98 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)) {
100 "Failed (error code: %s): Get size of %s.\n",
101 piglit_cl_get_error_name(errNo
),
102 piglit_cl_get_enum_name(context_infos
[i
]));
103 piglit_merge_result(&result
, PIGLIT_FAIL
);
107 param_value
= malloc(param_value_size
);
108 errNo
= clGetContextInfo(cl_ctx
,
113 if(!piglit_cl_check_error(errNo
, CL_SUCCESS
)) {
115 "Failed (error code: %s): Get value of %s.\n",
116 piglit_cl_get_error_name(errNo
),
117 piglit_cl_get_enum_name(context_infos
[i
]));
118 piglit_merge_result(&result
, PIGLIT_FAIL
);
121 //TODO: output returned values
129 * CL_INVALID_VALUE if param_name is not one of the supported
130 * values or if size in bytes specified by param_value_size is
131 * less than size of return type and param_value is not a NULL
134 errNo
= clGetContextInfo(cl_ctx
,
139 if(!piglit_cl_check_error(errNo
, CL_INVALID_VALUE
)) {
141 "Failed (error code: %s): Trigger CL_INVALID_VALUE if param_name is not one of the supported values.\n",
142 piglit_cl_get_error_name(errNo
));
143 piglit_merge_result(&result
, PIGLIT_FAIL
);
146 errNo
= clGetContextInfo(cl_ctx
,
147 CL_CONTEXT_REFERENCE_COUNT
,
151 if(!piglit_cl_check_error(errNo
, CL_INVALID_VALUE
)) {
153 "Failed (error code: %s): Trigger CL_INVALID_VALUE if size in bytes specified by param_value is less than size of return type and param_value is not a NULL value.\n",
154 piglit_cl_get_error_name(errNo
));
155 piglit_merge_result(&result
, PIGLIT_FAIL
);
159 * CL_INVALID_CONTEXT if context is not a valid context.
161 errNo
= clGetContextInfo(NULL
,
166 if(!piglit_cl_check_error(errNo
, CL_INVALID_CONTEXT
)) {
168 "Failed (error code: %s): Trigger CL_INVALID_CONTEXT if context is not a valid context.\n",
169 piglit_cl_get_error_name(errNo
));
170 piglit_merge_result(&result
, PIGLIT_FAIL
);
174 clReleaseContext(cl_ctx
);