1 /*
2  * Copyright © 2012 Blaž Tomažič <blaz.tomazic@gmail.com>
3  *
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:
10  *
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.
14  *
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.
22  */
23 
24 /**
25  * @file get-platform-info.c
26  *
27  * Test API function:
28  *
29  *   cl_int clGetPlatformInfo(cl_platform_id platform,
30  *                            cl_platform_info param_name,
31  *                            size_t param_value_size,
32  *                            void *param_value,
33  *                            size_t *param_value_size_ret)
34  */
35 
36 #include "piglit-framework-cl-api.h"
37 
38 
39 PIGLIT_CL_API_TEST_CONFIG_BEGIN
40 
41 	config.name = "clGetPlatformInfo";
42 	config.version_min = 10;
43 
44 	config.run_per_platform = true;
45 
46 PIGLIT_CL_API_TEST_CONFIG_END
47 
48 
49 enum piglit_result
piglit_cl_test(const int argc,const char ** argv,const struct piglit_cl_api_test_config * config,const struct piglit_cl_api_test_env * env)50 piglit_cl_test(const int argc,
51                const char** argv,
52                const struct piglit_cl_api_test_config* config,
53                const struct piglit_cl_api_test_env* env)
54 {
55 	enum piglit_result result = PIGLIT_PASS;
56 
57 	int i;
58 	cl_int errNo;
59 
60 	size_t param_value_size;
61 	void* param_value;
62 
63 	bool found_invalid_platform = false;
64 	cl_platform_id* platform_ids;
65 	unsigned int num_platform_ids;
66 	cl_platform_id invalid_platform_id;
67 
68 	int num_platform_infos =
69 		PIGLIT_CL_ENUM_NUM(cl_platform_info, env->version);
70 	const cl_platform_info *platform_infos =
71 		PIGLIT_CL_ENUM_ARRAY(cl_platform_info);
72 
73 	/* Find invalid platform_id */
74 	invalid_platform_id = 0;
75 	num_platform_ids = piglit_cl_get_platform_ids(&platform_ids);
76 	while(!found_invalid_platform) {
77 		found_invalid_platform = true;
78 		invalid_platform_id = (cl_platform_id)1;
79 		for(i = 0; i < num_platform_ids; i++) {
80 			if(invalid_platform_id == platform_ids[i]) {
81 				found_invalid_platform = false;
82 				break;
83 			}
84 		}
85 	}
86 	free(platform_ids);
87 
88 	/*** Normal usage ***/
89 
90 	for(i = 0; i < num_platform_infos; i++) {
91 		printf("%s: ", piglit_cl_get_enum_name(platform_infos[i]));
92 
93 		errNo = clGetPlatformInfo(env->platform_id,
94 		                          platform_infos[i],
95 		                          0,
96 		                          NULL,
97 		                          &param_value_size);
98 		if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
99 			fprintf(stderr,
100 			        "Failed (error code: %s): Get size of %s.\n",
101 			        piglit_cl_get_error_name(errNo),
102 			        piglit_cl_get_enum_name(platform_infos[i]));
103 			piglit_merge_result(&result, PIGLIT_FAIL);
104 			continue;
105 		}
106 
107 		param_value = malloc(param_value_size);
108 		errNo = clGetPlatformInfo(env->platform_id,
109 		                          platform_infos[i],
110 		                          param_value_size,
111 		                          param_value,
112 		                          NULL);
113 		if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
114 			fprintf(stderr,
115 			        "Failed (error code: %s): Get value of %s.\n",
116 			        piglit_cl_get_error_name(errNo),
117 			        piglit_cl_get_enum_name(platform_infos[i]));
118 			piglit_merge_result(&result, PIGLIT_FAIL);
119 		}
120 
121 		printf("%s\n", (char*)param_value);
122 		free(param_value);
123 	}
124 
125 	/*** Errors **/
126 
127 	/*
128 	 * CL_INVALID_VALUE if param_name is not one of the supported
129 	 * values or if size in bytes specified by param_value_size is
130 	 * less than size of return type and param_value is not a NULL
131 	 * value.
132 	 */
133 	errNo = clGetPlatformInfo(env->platform_id,
134 	                          CL_PLATFORM_PROFILE,
135 	                          1,
136 	                          param_value,
137 	                          NULL);
138 	if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
139 		fprintf(stderr,
140 		        "Failed (error code: %s): Trigger CL_INVALID_VALUE if param_name is not one of the supported values.\n",
141 		        piglit_cl_get_error_name(errNo));
142 		piglit_merge_result(&result, PIGLIT_FAIL);
143 	}
144 
145 	errNo = clGetPlatformInfo(env->platform_id,
146 	                          CL_DEVICE_NAME,
147 	                          0,
148 	                          NULL,
149 	                          &param_value_size);
150 	if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
151 		fprintf(stderr,
152 		        "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",
153 		        piglit_cl_get_error_name(errNo));
154 		piglit_merge_result(&result, PIGLIT_FAIL);
155 	}
156 
157     return result;
158 }
159