glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / util / piglit-framework-cl-api.c
blobdbd5be772bc70cf0a185c45c4c8b237488b3db03
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 #include "piglit-framework-cl-api.h"
26 /* Default test configuration values */
27 const struct piglit_cl_api_test_config PIGLIT_CL_DEFAULT_API_TEST_CONFIG = {
28 .version_min = 0,
29 .version_max = 0,
31 .create_context = false,
33 .program_source = NULL,
34 .build_options = NULL
37 /* Return default values for test configuration */
38 const void*
39 piglit_cl_get_empty_api_test_config()
41 return &PIGLIT_CL_DEFAULT_API_TEST_CONFIG;
44 /* Check configuration */
45 void piglit_cl_api_test_init(const int argc,
46 const char** argv,
47 void* void_config)
49 struct piglit_cl_api_test_config* config = void_config;
51 /* Run test's init */
52 if(config->_init_test != NULL) {
53 config->_init_test(argc, argv, void_config);
56 // version_min
57 if(config->version_min == 0) {
58 config->version_min = 10;
60 if(config->version_min <= 0) {
61 fprintf(stderr, "Invalid configuration, version_min is %d.\n",
62 config->version_min);
63 piglit_report_result(PIGLIT_WARN);
65 if(config->version_min > PIGLIT_CL_VERSION) {
66 fprintf(stderr, "Piglit was compiled with lower OpenCL version (%d.%d) than version_min: %d.\n",
67 PIGLIT_CL_VERSION/10, PIGLIT_CL_VERSION%10,
68 config->version_min);
69 piglit_report_result(PIGLIT_WARN);
71 // version_max
72 if(config->version_max < 0) {
73 fprintf(stderr, "Invalid configuration, version_max is %d.\n",
74 config->version_max);
75 piglit_report_result(PIGLIT_WARN);
77 if(config->version_max > 0 && config->version_max < config->version_min) {
78 fprintf(stderr, "Invalid configuration, version_max (%d) is lower than version_min (%d).\n",
79 config->version_max, config->version_min);
80 piglit_report_result(PIGLIT_WARN);
82 // create_context
83 if( config->create_context
84 && !(config->run_per_device || config->run_per_platform)) {
85 printf("Invalid configuration, create_context can only be used with run_per_platform or run_per_device.\n");
86 piglit_report_result(PIGLIT_WARN);
88 // program_source
89 if( config->program_source != NULL
90 && !(config->run_per_device || config->run_per_platform)) {
91 printf("Invalid configuration, program_source can only be used with run_per_platform or run_per_device.\n");
92 piglit_report_result(PIGLIT_WARN);
94 if(config->program_source != NULL && !config->create_context) {
95 config->create_context = true;
97 // build options
98 if(config->build_options != NULL && config->program_source == NULL) {
99 fprintf(stderr, "Invalid configuration, build_options can only be used with program_source.\n");
100 piglit_report_result(PIGLIT_WARN);
104 /* Set environment and run test */
105 enum piglit_result
106 piglit_cl_api_test_run(const int argc,
107 const char** argv,
108 void* void_config,
109 int version,
110 cl_platform_id platform_id,
111 cl_device_id device_id)
113 enum piglit_result result;
115 struct piglit_cl_api_test_config* config = void_config;
116 struct piglit_cl_api_test_env env;
118 piglit_cl_context context = NULL;
119 cl_program program = NULL;
121 /* Check version to test against */
122 if(version < config->version_min) {
123 printf("Trying to run test with version (%d.%d) lower than version_min: %d\n",
124 version/10, version%10,
125 config->version_min);
126 return PIGLIT_SKIP;
128 if(config->version_max > 0 && version > config->version_max) {
130 * If version was not provided on the command line
131 * lower it to version_max.
133 if(piglit_cl_get_version_arg(argc, argv) == 0) {
134 printf("# Lowering version to %d.%d because of version_max.\n",
135 config->version_max/10, config->version_max%10);
136 version = config->version_max;
137 } else {
138 printf("Trying to run test with version (%d.%d) higher than version_max: %d\n",
139 version/10, version%10,
140 config->version_max);
141 return PIGLIT_SKIP;
145 /* Create context */
146 if(config->create_context) {
147 if(config->run_per_platform) {
148 unsigned int num_devices;
149 cl_device_id* device_ids;
151 num_devices = piglit_cl_get_device_ids(platform_id,
152 CL_DEVICE_TYPE_ALL,
153 &device_ids);
155 context = piglit_cl_create_context(platform_id,
156 device_ids,
157 num_devices);
159 free(device_ids);
160 } else { // config->run_per_device
161 context = piglit_cl_create_context(platform_id, &device_id, 1);
164 if(context == NULL) {
165 return PIGLIT_FAIL;
169 /* Create and build program */
170 if(config->program_source != NULL) {
171 if(config->build_options != NULL) {
172 program = piglit_cl_build_program_with_source(context,
174 &config->program_source,
175 config->build_options);
176 } else {
177 program = piglit_cl_build_program_with_source(context,
179 &config->program_source,
180 "");
183 if(program == NULL) {
184 return PIGLIT_FAIL;
189 /* Set environment */
190 env.platform_id = platform_id;
191 env.device_id = device_id;
192 env.context = context;
193 env.version = version;
194 env.program = program;
197 /* Run the actual test */
198 result = config->_api_test(argc, argv, config, &env);
201 /* Release program */
202 if(config->program_source != NULL) {
203 clReleaseProgram(program);
206 /* Release context */
207 if(config->create_context) {
208 piglit_cl_release_context(context);
211 return result;