fix the spelling in whole piglit
[piglit.git] / tests / cl / api / enqueue-fill-image.c
blobedb3e0888596be5ccaef659433ba72202d67e8d8
1 /*
2 * Copyright © 2015 Serge Martin <edb+piglit@sigluy.net>
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 enqueue-fill-image.c
27 * Test API function:
29 * cl_int
30 * clEnqueueFillImage(cl_command_queue command_queue, cl_mem image,
31 * const void *fill_color, size_t *origin, size_t *region
32 * cl_uint num_events_in_wait_list,
33 * const cl_event *event_wait_list,
34 * cl_event *event )
37 #include "piglit-framework-cl-api.h"
40 PIGLIT_CL_API_TEST_CONFIG_BEGIN
42 config.name = "clEnqueueFillImage";
43 config.version_min = 12;
45 config.run_per_device = true;
46 config.create_context = true;
48 PIGLIT_CL_API_TEST_CONFIG_END
51 #if defined(CL_VERSION_1_2)
52 static bool
53 test(cl_command_queue queue, cl_mem image,
54 const void *fill_color, size_t *origin, size_t *region,
55 cl_uint num_events_in_wait_list,
56 const cl_event *event_wait_list,
57 cl_event *event,
58 cl_int expected_error, enum piglit_result* result,
59 const char* test_str) {
60 cl_int errNo;
62 errNo = clEnqueueFillImage(queue, image,
63 fill_color, origin, region,
64 num_events_in_wait_list, event_wait_list,
65 event);
67 if(!piglit_cl_check_error(errNo, expected_error)) {
68 fprintf(stderr, "Failed (error code: %s): %s.\n",
69 piglit_cl_get_error_name(errNo), test_str);
70 piglit_merge_result(result, PIGLIT_FAIL);
71 return false;
74 return true;
76 #endif
78 enum piglit_result
79 piglit_cl_test(const int argc,
80 const char **argv,
81 const struct piglit_cl_api_test_config* config,
82 const struct piglit_cl_api_test_env* env)
84 #if defined(CL_VERSION_1_2)
85 enum piglit_result result = PIGLIT_PASS;
86 cl_int err;
88 #define IMG_WIDTH 4
89 #define IMG_HEIGHT 4
90 #define IMG_DATA_SIZE 4
91 #define IMG_BUFFER_SIZE IMG_WIDTH * IMG_HEIGHT * IMG_DATA_SIZE
93 unsigned char img_buf[IMG_BUFFER_SIZE] = {0};
94 unsigned char dst_buf[IMG_BUFFER_SIZE] = {0};
95 unsigned char exp_buf[IMG_BUFFER_SIZE] = {0};
96 int pattern[4] = {129, 33, 77, 255};
97 size_t origin[3] = {0, 0, 0};
98 size_t region[3] = {2, 2, 1};
99 size_t tmp;
100 cl_event event;
101 cl_mem image;
102 cl_image_format img_format;
103 cl_image_desc img_desc = {0};
104 cl_command_queue queue = env->context->command_queues[0];
105 int i;
107 if (!piglit_cl_get_device_image_support(env->context->device_ids[0])) {
108 fprintf(stderr, "No image support\n");
109 return PIGLIT_SKIP;
112 img_format.image_channel_order = CL_RGBA;
113 img_format.image_channel_data_type = CL_UNSIGNED_INT8;
114 img_desc.image_type = CL_MEM_OBJECT_IMAGE2D;
115 img_desc.image_width = IMG_WIDTH;
116 img_desc.image_height = IMG_HEIGHT;
117 img_desc.buffer = NULL;
119 /*** Normal usage ***/
120 image = clCreateImage(env->context->cl_ctx,
121 CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
122 &img_format, &img_desc, &img_buf, &err);
124 if(!piglit_cl_check_error(err, CL_SUCCESS)) {
125 fprintf(stderr, "Failed (error code: %s): Creating an image\n",
126 piglit_cl_get_error_name(err));
127 return PIGLIT_FAIL;
130 if (!test(queue, image, pattern, origin, region,
131 0, NULL, NULL,
132 CL_SUCCESS, &result, "Enqueuing the image to be filled")) {
133 return PIGLIT_FAIL;
136 region[0] = IMG_WIDTH;
137 region[1] = IMG_HEIGHT;
138 err = clEnqueueReadImage(queue, image, 1, origin, region, 0, 0,
139 dst_buf, 0, NULL, NULL);
140 if(!piglit_cl_check_error(err, CL_SUCCESS)) {
141 fprintf(stderr, "Failed (error code: %s): Reading image\n",
142 piglit_cl_get_error_name(err));
143 return PIGLIT_FAIL;
147 * fill the host buffer with the pattern
148 * for example : pattern == 1234
150 * 12341234abcdabcd
151 * 12341234abcdabcd
152 * abcdabcdabcdabcd
153 * abcdabcdabcdabcd
155 exp_buf[0] = pattern[0];
156 exp_buf[1] = pattern[1];
157 exp_buf[2] = pattern[2];
158 exp_buf[3] = pattern[3];
159 memcpy(exp_buf + (IMG_DATA_SIZE * 1), exp_buf, IMG_DATA_SIZE);
160 memcpy(exp_buf + (IMG_DATA_SIZE * 4), exp_buf, IMG_DATA_SIZE);
161 memcpy(exp_buf + (IMG_DATA_SIZE * 5), exp_buf, IMG_DATA_SIZE);
163 for (i = 0; i < sizeof(dst_buf) / sizeof(dst_buf[0]); ++i) {
164 if (!piglit_cl_probe_integer(dst_buf[i], exp_buf[i], 0)) {
165 fprintf(stderr, "Error at %d: got %d, expected %d\n",
166 i, dst_buf[i], exp_buf[i]);
167 return PIGLIT_FAIL;
171 /*** Errors ***/
174 * CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue.
176 test(NULL, image, pattern, origin, region,
177 0, NULL, NULL,
178 CL_INVALID_COMMAND_QUEUE, &result,
179 "CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue");
182 * CL_INVALID_CONTEXT if the context associated with command_queue and
183 * image are not the same or if the context associated with command_queue
184 * and events in event_wait_list are not the same.
187 piglit_cl_context context;
188 cl_int err;
189 context = piglit_cl_create_context(env->platform_id,
190 env->context->device_ids, 1);
191 if (context) {
192 event = clCreateUserEvent(context->cl_ctx, &err);
193 if (err == CL_SUCCESS) {
194 err = clSetUserEventStatus(event, CL_COMPLETE);
195 if (err == CL_SUCCESS) {
196 test(context->command_queues[0], image, pattern, origin, region,
197 0, NULL, NULL,
198 CL_INVALID_CONTEXT, &result,
199 "CL_INVALID_CONTEXT if the context associated with command_queue and image are not the same");
201 test(queue, image, pattern, origin, region,
202 1, &event, NULL,
203 CL_INVALID_CONTEXT, &result,
204 "CL_INVALID_CONTEXT if the context associated with command_queue and events in event_wait_list are not the same");
205 } else {
206 fprintf(stderr, "Could not set event status.\n");
207 piglit_merge_result(&result, PIGLIT_WARN);
209 clReleaseEvent(event);
210 } else {
211 fprintf(stderr, "Could not create user event.\n");
212 piglit_merge_result(&result, PIGLIT_WARN);
215 piglit_cl_release_context(context);
216 } else {
217 fprintf(stderr, "Could not test triggering CL_INVALID_CONTEXT.\n");
218 piglit_merge_result(&result, PIGLIT_WARN);
223 * CL_INVALID_MEM_OBJECT if image is not a valid buffer object.
225 test(queue, NULL, pattern, origin, region,
226 0, NULL, NULL,
227 CL_INVALID_MEM_OBJECT, &result,
228 "CL_INVALID_MEM_OBJECT if image is not a valid buffer object");
231 * CL_INVALID_VALUE if fill_color is NULL.
233 test(queue, image, NULL, origin, region,
234 0, NULL, NULL,
235 CL_INVALID_VALUE, &result,
236 "CL_INVALID_VALUE if fill_color is NULL");
239 * CL_INVALID_VALUE if the region being written specified by origin and
240 * region is out of bounds or if ptr is a NULL value.
242 tmp = origin[0];
243 origin[0] = IMG_WIDTH + 1;
244 test(queue, image, pattern, origin, region,
245 0, NULL, NULL,
246 CL_INVALID_VALUE, &result,
247 "CL_INVALID_VALUE if the region being written specified by origin and region is out of bounds (origin)");
248 origin[0] = tmp;
250 tmp = region[0];
251 region[0] = IMG_WIDTH + 1;
252 test(queue, image, pattern, origin, region,
253 0, NULL, NULL,
254 CL_INVALID_VALUE, &result,
255 "CL_INVALID_VALUE if the region being written specified by origin and region is out of bounds (region)");
256 region[0] = tmp;
258 test(queue, image, pattern, NULL, region,
259 0, NULL, NULL,
260 CL_INVALID_VALUE, &result,
261 "CL_INVALID_VALUE if ptr is a NULL value (origin)");
263 test(queue, image, pattern, origin, NULL,
264 0, NULL, NULL,
265 CL_INVALID_VALUE, &result,
266 "CL_INVALID_VALUE if ptr is a NULL value (region)");
269 * CL_INVALID_VALUE if values in origin and region do not follow rules
270 * described in the argument description for origin and region.
272 tmp = origin[2];
273 origin[2] = 1;
274 test(queue, image, pattern, origin, region,
275 0, NULL, NULL,
276 CL_INVALID_VALUE, &result,
277 "CL_INVALID_VALUE if values in origin do not follow rules described in the argument description for origin");
278 origin[2] = tmp;
280 tmp = region[2];
281 region[2] = 0;
282 test(queue, image, pattern, origin, region,
283 0, NULL, NULL,
284 CL_INVALID_VALUE, &result,
285 "CL_INVALID_VALUE if values in region do not follow rules described in the argument description for region");
286 region[2] = tmp;
289 * CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and
290 * num_events_in_wait_list > 0, or event_wait_list is not NULL and
291 * num_events_in_wait_list is 0, or if event objects in event_wait_list
292 * are not valid events.
294 event = NULL;
295 test(queue, image, pattern, origin, region,
296 1, NULL, NULL,
297 CL_INVALID_EVENT_WAIT_LIST, &result,
298 "CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0");
300 test(queue, image, pattern, origin, region,
301 0, &event, NULL,
302 CL_INVALID_EVENT_WAIT_LIST, &result,
303 "CL_INVALID_EVENT_WAIT_LIST if event_wait_list is not NULL and num_events_in_wait_list is 0");
305 test(queue, image, pattern, origin, region,
306 1, &event, NULL,
307 CL_INVALID_EVENT_WAIT_LIST, &result,
308 "CL_INVALID_EVENT_WAIT_LIST if event objects in event_wait_list are not valid events");
311 * CL_INVALID_IMAGE_SIZE if image dimensions (image width, height, specified
312 * or compute row and/or slice pitch) for image are not supported by device
313 * associated with queue.
315 /* This is a per device test, clCreateImage would have failed before */
318 * CL_INVALID_IMAGE_FORMAT if image format (image channel order and data type)
319 * for image are not supported by device associated with queue.
321 /* This is a per device test, clCreateImage would have failed before */
323 clReleaseMemObject(image);
324 return result;
325 #else
326 return PIGLIT_SKIP;
327 #endif