cl: add clGetExtensionFunctionAddressForPlatform

Submitted by Serge Martin on Sept. 27, 2015, 1:35 p.m.

Details

Message ID 1443360905-27842-1-git-send-email-edb+piglit@sigluy.net
State New
Headers show

Not browsing as part of any series.

Commit Message

Serge Martin Sept. 27, 2015, 1:35 p.m.
---
 tests/cl/api/CMakeLists.cl.txt                     |   1 +
 .../get-extension-function-address-for-platform.c  | 121 +++++++++++++++++++++
 2 files changed, 122 insertions(+)
 create mode 100644 tests/cl/api/get-extension-function-address-for-platform.c

Patch hide | download patch | download mbox

diff --git a/tests/cl/api/CMakeLists.cl.txt b/tests/cl/api/CMakeLists.cl.txt
index 4a90c58..99303d9 100644
--- a/tests/cl/api/CMakeLists.cl.txt
+++ b/tests/cl/api/CMakeLists.cl.txt
@@ -7,6 +7,7 @@  piglit_cl_add_api_test (create-context create-context.c)
 piglit_cl_add_api_test (create-context-from-type create-context-from-type.c)
 piglit_cl_add_api_test (get-context-info get-context-info.c)
 piglit_cl_add_api_test (retain_release-context retain_release-context.c)
+piglit_cl_add_api_test (get-extension-function-address-for-platform get-extension-function-address-for-platform.c)
 
 # Command queues
 piglit_cl_add_api_test (create-command-queue create-command-queue.c)
diff --git a/tests/cl/api/get-extension-function-address-for-platform.c b/tests/cl/api/get-extension-function-address-for-platform.c
new file mode 100644
index 0000000..e53a429
--- /dev/null
+++ b/tests/cl/api/get-extension-function-address-for-platform.c
@@ -0,0 +1,121 @@ 
+/*
+ * Copyright © 2015 Serge Martin <edb+piglit@sigluy.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file get-extension-function-address-for-platform.c
+ *
+ * Test API function:
+ *
+ *   void *
+ *   clGetExtensionFunctionAddressForPlatform(cl_platform_id platform,
+ *                                            const char *funcname)
+ */
+
+#include "piglit-framework-cl-api.h"
+
+
+PIGLIT_CL_API_TEST_CONFIG_BEGIN
+
+	config.name = "clGetExtensionFunctionAddressForPlatform";
+	config.version_min = 12;
+
+	config.run_per_platform = true;
+
+PIGLIT_CL_API_TEST_CONFIG_END
+
+
+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)
+{
+#if defined(CL_VERSION_1_2)
+	enum piglit_result result = PIGLIT_PASS;
+
+	size_t pos;
+	size_t last_pos;
+	void *ptr;
+	char *exts_list = piglit_cl_get_platform_info(env->platform_id,
+	                                              CL_PLATFORM_EXTENSIONS);
+
+	if(!exts_list) {
+		fprintf(stderr, "clGetPlatformInfo error.\n");
+		return PIGLIT_FAIL;
+	}
+
+	printf("extensions list: %s\n", exts_list);
+
+	/*** Normal usage ***/
+
+	last_pos = 0;
+	pos = strcspn(exts_list + last_pos, " ");
+	while (pos) {
+		char *extension = NULL;
+		char *function_name = NULL;
+		ptr = NULL;
+
+		if (strncmp(exts_list + last_pos, "cl_khr_icd", pos) == 0) {
+			extension = "cl_khr_icd";
+			function_name = "clIcdGetPlatformIDsKHR";
+		}
+
+		if (function_name) {
+			printf("%s: %s\n", extension, function_name);
+			ptr = clGetExtensionFunctionAddressForPlatform(env->platform_id,
+	                                                     function_name);
+			if (!ptr) {
+				fprintf(stderr, "Failed to get %s address\n",
+				        function_name);
+				piglit_merge_result(&result, PIGLIT_FAIL);
+			}
+		}
+
+		last_pos += pos + 1;
+		pos = strcspn(exts_list + last_pos, " ");
+	}
+
+	/*** Errors ***/
+
+	/* clIcdGetPlatformIDsKHR is present in most of OpenCL 1.2 libs */
+	ptr = clGetExtensionFunctionAddressForPlatform(NULL,
+	                                               "clIcdGetPlatformIDsKHR");
+	if (ptr) {
+		fprintf(stderr, "Failed: return NULL if platform is not a valid platform\n");
+		piglit_merge_result(&result, PIGLIT_FAIL);
+	}
+
+	ptr = clGetExtensionFunctionAddressForPlatform(env->platform_id,
+	                                               "invalid_name");
+	if (ptr) {
+		fprintf(stderr, "Failed: return NULL if the specified function does not exist\n");
+		piglit_merge_result(&result, PIGLIT_FAIL);
+	}
+
+	free(exts_list);
+
+	return result;
+#else
+	return PIGLIT_SKIP;
+#endif
+}