Use _exit() instead of exit() in child processes
[piglit.git] / tests / cl / api / get-program-info.c
blob1c4a307a6a8d1a0a208620b45bc9e26d6b7f89d1
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-program-info.c
27 * Test API function:
29 * cl_int clGetProgramInfo (cl_program program,
30 * cl_program_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 = "clGetProgramInfo";
42 config.version_min = 10;
44 config.run_per_platform = true;
45 config.create_context = true;
47 config.program_source = "kernel void dummy_kernel() {}";
49 PIGLIT_CL_API_TEST_CONFIG_END
52 enum piglit_result
53 piglit_cl_test(const int argc,
54 const char** argv,
55 const struct piglit_cl_api_test_config* config,
56 const struct piglit_cl_api_test_env* env)
58 enum piglit_result result = PIGLIT_PASS;
60 int i;
61 cl_int errNo;
63 size_t param_value_size;
64 void* param_value;
66 int num_program_infos = PIGLIT_CL_ENUM_NUM(cl_program_info, env->version);
67 const cl_program_info* program_infos = PIGLIT_CL_ENUM_ARRAY(cl_program_info);
69 /*** Normal usage ***/
70 for(i = 0; i < num_program_infos; i++) {
71 printf("%s ", piglit_cl_get_enum_name(program_infos[i]));
73 errNo = clGetProgramInfo(env->program,
74 program_infos[i],
76 NULL,
77 &param_value_size);
78 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
79 fprintf(stderr,
80 "Failed (error code: %s): Get size of %s.\n",
81 piglit_cl_get_error_name(errNo),
82 piglit_cl_get_enum_name(program_infos[i]));
83 piglit_merge_result(&result, PIGLIT_FAIL);
84 continue;
87 param_value = malloc(param_value_size);
88 if(program_infos[i] != CL_PROGRAM_BINARIES) {
89 errNo = clGetProgramInfo(env->program,
90 program_infos[i],
91 param_value_size,
92 param_value,
93 NULL);
94 if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
95 fprintf(stderr,
96 "Failed (error code: %s): Get value of %s.\n",
97 piglit_cl_get_error_name(errNo),
98 piglit_cl_get_enum_name(program_infos[i]));
99 piglit_merge_result(&result, PIGLIT_FAIL);
101 } else {
102 bool success= false;
103 int j;
104 size_t binary_sizes_size;
105 size_t* binary_sizes;
107 errNo = clGetProgramInfo(env->program,
108 CL_PROGRAM_BINARY_SIZES,
110 NULL,
111 &binary_sizes_size);
112 if(piglit_cl_check_error(errNo, CL_SUCCESS)) {
113 binary_sizes = malloc(binary_sizes_size);
115 errNo = clGetProgramInfo(env->program,
116 CL_PROGRAM_BINARY_SIZES,
117 binary_sizes_size,
118 binary_sizes,
119 NULL);
120 if(piglit_cl_check_error(errNo, CL_SUCCESS)) {
121 for(j = 0; j < binary_sizes_size/sizeof(size_t); j++) {
122 ((unsigned char**)param_value)[j] = malloc(binary_sizes[j]);
125 errNo = clGetProgramInfo(env->program,
126 program_infos[i],
127 param_value_size,
128 param_value,
129 NULL);
130 if(piglit_cl_check_error(errNo, CL_SUCCESS)) {
131 success = true;
134 for(j = 0; j < binary_sizes_size/sizeof(size_t); j++) {
135 free(((unsigned char***)param_value)[j]);
139 free(binary_sizes);
142 if(!success) {
143 fprintf(stderr,
144 "Failed (error code: %s): Get value of %s.\n",
145 piglit_cl_get_error_name(errNo),
146 piglit_cl_get_enum_name(program_infos[i]));
147 piglit_merge_result(&result, PIGLIT_FAIL);
151 //TODO: output returned values
152 printf("\n");
153 free(param_value);
156 /*** Errors ***/
159 * CL_INVALID_VALUE if param_name is not one of the supported
160 * values or if size in bytes specified by param_value_size is
161 * less than size of return type and param_value is not a NULL
162 * value.
164 errNo = clGetProgramInfo(env->program,
165 CL_DEVICE_NAME,
167 NULL,
168 &param_value_size);
169 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
170 fprintf(stderr,
171 "Failed (error code: %s): Trigger CL_INVALID_VALUE if param_name is not one of the supported values.\n",
172 piglit_cl_get_error_name(errNo));
173 piglit_merge_result(&result, PIGLIT_FAIL);
176 errNo = clGetProgramInfo(env->program,
177 CL_PROGRAM_REFERENCE_COUNT,
179 param_value,
180 NULL);
181 if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
182 fprintf(stderr,
183 "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",
184 piglit_cl_get_error_name(errNo));
185 piglit_merge_result(&result, PIGLIT_FAIL);
189 * CL_INVALID_PROGRAM if program is not a valid program object.
191 errNo = clGetProgramInfo(NULL,
192 CL_PROGRAM_REFERENCE_COUNT,
194 NULL,
195 &param_value_size);
196 if(!piglit_cl_check_error(errNo, CL_INVALID_PROGRAM)) {
197 fprintf(stderr,
198 "Failed (error code: %s): Trigger CL_INVALID_PROGRAM if program is not a valid program object.\n",
199 piglit_cl_get_error_name(errNo));
200 piglit_merge_result(&result, PIGLIT_FAIL);
204 * CL_INVALID_PROGRAM_EXECUTABLE if param_name is CL_PROGRAM_NUM_KERNELS or
205 * CL_PROGRAM_KERNEL_NAMES and a successful program executable has not been
206 * built for at least one device in the list of devices associated with
207 * program.
209 * Version: 1.2
211 * TODO
214 return result;