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
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
= {
31 .create_context
= false,
33 .program_source
= NULL
,
37 /* Return default values for test configuration */
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
,
49 struct piglit_cl_api_test_config
* config
= void_config
;
52 if(config
->_init_test
!= NULL
) {
53 config
->_init_test(argc
, argv
, void_config
);
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",
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,
69 piglit_report_result(PIGLIT_WARN
);
72 if(config
->version_max
< 0) {
73 fprintf(stderr
, "Invalid configuration, version_max is %d.\n",
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
);
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
);
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;
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 */
106 piglit_cl_api_test_run(const int argc
,
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
);
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
;
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
);
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
,
155 context
= piglit_cl_create_context(platform_id
,
160 } else { // config->run_per_device
161 context
= piglit_cl_create_context(platform_id
, &device_id
, 1);
164 if(context
== NULL
) {
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
);
177 program
= piglit_cl_build_program_with_source(context
,
179 &config
->program_source
,
183 if(program
== NULL
) {
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
);