fix the spelling in whole piglit
[piglit.git] / tests / cl / api / create-program-with-source.c
blob857257b4860c762f9b39901587356ddf05f5e5ba
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 create-program-with-source.c
27 * Test API function:
29 * cl_program clCreateProgramWithSource (cl_context context,
30 * cl_uint count,
31 * const char **strings,
32 * const size_t *lengths,
33 * cl_int *errcode_ret)
36 #include "piglit-framework-cl-api.h"
39 PIGLIT_CL_API_TEST_CONFIG_BEGIN
41 config.name = "clCreateProgramWithSource";
42 config.version_min = 10;
44 config.run_per_platform = true;
45 config.create_context = true;
47 PIGLIT_CL_API_TEST_CONFIG_END
50 char* dummy_function = "void dummy_function() {}";
51 char* dummy_kernel = "kernel void dummy_kernel() { dummy_function(); }";
53 static void
54 test(cl_context cl_ctx,
55 cl_uint count,
56 const char **strings,
57 const size_t *lengths,
58 cl_int expected_error,
59 enum piglit_result* result,
60 const char* test_str) {
61 cl_int errNo;
62 cl_program program;
64 /* with errNo */
65 program = clCreateProgramWithSource(cl_ctx,
66 count,
67 strings,
68 lengths,
69 &errNo);
71 if(!piglit_cl_check_error(errNo, expected_error)) {
72 fprintf(stderr, "Failed (error code: %s): %s.\n",
73 piglit_cl_get_error_name(errNo), test_str);
74 piglit_merge_result(result, PIGLIT_FAIL);
75 return;
77 if(expected_error == CL_SUCCESS) {
78 if(program == NULL) {
79 printf("Expecting non-NULL cl_program\n");
80 fprintf(stderr, "Failed (NULL value returned): %s.\n", test_str);
81 piglit_merge_result(result, PIGLIT_FAIL);
82 return;
84 clReleaseProgram(program);
85 } else if (program != NULL) {
86 printf("Expecting NULL cl_program\n");
87 fprintf(stderr, "Failed (non-NULL value returned): %s.\n", test_str);
88 piglit_merge_result(result, PIGLIT_FAIL);
89 return;
92 /* without errNo */
93 program = clCreateProgramWithSource(cl_ctx,
94 count,
95 strings,
96 lengths,
97 NULL);
99 if(expected_error == CL_SUCCESS) {
100 if(program == NULL) {
101 printf("Expecting non-NULL cl_program\n");
102 fprintf(stderr, "Failed (NULL value returned): %s.\n", test_str);
103 piglit_merge_result(result, PIGLIT_FAIL);
104 return;
106 clReleaseProgram(program);
107 } else if (program != NULL) {
108 printf("Expecting NULL cl_program\n");
109 fprintf(stderr, "Failed (non-NULL value returned): %s.\n", test_str);
110 piglit_merge_result(result, PIGLIT_FAIL);
111 return;
115 enum piglit_result
116 piglit_cl_test(const int argc,
117 const char** argv,
118 const struct piglit_cl_api_test_config* config,
119 const struct piglit_cl_api_test_env* env)
121 enum piglit_result result = PIGLIT_PASS;
123 int i;
125 const char* null = NULL;
126 const char** strings = malloc(2 * sizeof(char*));
127 size_t* lengths = malloc(2 * sizeof(size_t));
129 strings[0] = dummy_function;
130 strings[1] = dummy_kernel;
131 lengths[0] = strlen(dummy_function);
132 lengths[1] = strlen(dummy_kernel);
134 /*** Normal usage ***/
136 for(i = 0; i < 2; i++) {
137 size_t* partial_lengths = malloc(2 * sizeof(size_t));
139 /* separate */
140 test(env->context->cl_ctx, 1, &strings[i], &lengths[i],
141 CL_SUCCESS, &result,
142 "Create program with 1 source string and defined length");
143 test(env->context->cl_ctx, 1, &strings[i], NULL,
144 CL_SUCCESS, &result,
145 "Create program with 1 source string and lengths == NULL");
147 /* all, i-th length is 0 */
148 partial_lengths[i] = 0;
149 partial_lengths[(i+1)%2] = lengths[(i+1)%2];
151 test(env->context->cl_ctx, 2, strings, partial_lengths,
152 CL_SUCCESS, &result,
153 "Create program with multiple source strings and only some lengths defined (others are NULL)");
155 free(partial_lengths);
158 /* all */
159 test(env->context->cl_ctx, 2, strings, lengths,
160 CL_SUCCESS, &result,
161 "Create program with multiple source strings and defined lengths");
162 test(env->context->cl_ctx, 2, strings, NULL,
163 CL_SUCCESS, &result,
164 "Create program with multiple source strings and lengths == NULL");
167 /*** Errors ***/
170 * CL_INVALID_CONTEXT if context is not a valid context.
172 test(NULL, 2, strings, NULL,
173 CL_INVALID_CONTEXT, &result,
174 "Trigger CL_INVALID_CONTEXT when context is not a valid context");
177 * CL_INVALID_VALUE if count is zero or if strings or
178 * any entry in strings is NULL.
180 test(env->context->cl_ctx, 0, strings, NULL,
181 CL_INVALID_VALUE, &result,
182 "Trigger CL_INVALID_VALUE when count is zero");
183 test(env->context->cl_ctx, 0, NULL, NULL,
184 CL_INVALID_VALUE, &result,
185 "Trigger CL_INVALID_VALUE when strings is NULL");
186 test(env->context->cl_ctx, 1, &null, NULL,
187 CL_INVALID_VALUE, &result,
188 "Trigger CL_INVALID_VALUE when any entry in strings is NULL");
190 free(strings);
191 free(lengths);
193 return result;