Use _exit() instead of exit() in child processes
[piglit.git] / tests / cl / api / get-context-info.c
blobfdd1f6735ba22160c2ee78fadf661f360051f32a
1 /*
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
13 * Software.
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.
24 /**
25 * @file get-context-info.c
27 * Test API function:
29 * cl_int clGetContextInfo (cl_context context,
30 * cl_context_info param_name,
31 * size_t param_value_size,
32 * void *param_value,
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
49 enum piglit_result
50 piglit_cl_test(const int argc,
51 const char** argv,
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;
57 int i;
58 cl_int errNo;
59 cl_context cl_ctx;
61 size_t param_value_size;
62 void* param_value;
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,
75 CL_DEVICE_TYPE_ALL,
76 NULL,
77 NULL,
78 &errNo);
79 if(errNo == CL_DEVICE_NOT_FOUND) {
80 fprintf(stderr, "No available devices.\n");
81 return PIGLIT_SKIP;
83 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
84 fprintf(stderr,
85 "Failed (error code: %s): Create context.\n",
86 piglit_cl_get_error_name(errNo));
87 return PIGLIT_FAIL;
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,
94 context_infos[i],
96 NULL,
97 &param_value_size);
98 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
99 fprintf(stderr,
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);
104 continue;
107 param_value = malloc(param_value_size);
108 errNo = clGetContextInfo(cl_ctx,
109 context_infos[i],
110 param_value_size,
111 param_value,
112 NULL);
113 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
114 fprintf(stderr,
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
122 printf("\n");
123 free(param_value);
126 /*** Errors ***/
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
132 * value.
134 errNo = clGetContextInfo(cl_ctx,
135 CL_PLATFORM_NAME,
137 NULL,
138 &param_value_size);
139 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
140 fprintf(stderr,
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,
149 param_value,
150 NULL);
151 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
152 fprintf(stderr,
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,
162 CL_CONTEXT_DEVICES,
164 NULL,
165 &param_value_size);
166 if(!piglit_cl_check_error(errNo, CL_INVALID_CONTEXT)) {
167 fprintf(stderr,
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);
176 return result;