[Piglit] [PATCH] cl: add clGetExtensionFunctionAddressForPlatform

Serge Martin edb+piglit at sigluy.net
Sun Nov 6 13:43:40 UTC 2016


---
 tests/cl.py                                        |   2 +
 tests/cl/api/CMakeLists.cl.txt                     |   1 +
 .../get-extension-function-address-for-platform.c  | 124 +++++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 tests/cl/api/get-extension-function-address-for-platform.c

diff --git a/tests/cl.py b/tests/cl.py
index 73fba0d..5aa76b6 100644
--- a/tests/cl.py
+++ b/tests/cl.py
@@ -34,6 +34,8 @@ with profile.group_manager(PiglitCLTest, 'api') as g:
     # Platform
     g(['cl-api-get-platform-ids'], 'clGetPlatformIDs')
     g(['cl-api-get-platform-info'], 'clGetPlatformInfo')
+    g(['cl-api-get-extension-function-address-for-platform'],
+        'clGetExtensionFunctionAddressForPlatform')
 
     # Device
     g(['cl-api-get-device-ids'], 'clGetDeviceIDs')
diff --git a/tests/cl/api/CMakeLists.cl.txt b/tests/cl/api/CMakeLists.cl.txt
index c0b6540..9cfe9fb 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..4a429ef
--- /dev/null
+++ b/tests/cl/api/get-extension-function-address-for-platform.c
@@ -0,0 +1,124 @@
+/*
+ * Copyright © 2016 Serge Martin <edb+piglit at 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);
+			}
+		}
+
+		extension = NULL;
+		function_name = NULL;
+
+		last_pos += pos + 1;
+		pos = strcspn(exts_list + last_pos, " ");
+	}
+
+	/*** Errors ***/
+
+	/* clIcdGetPlatformIDsKHR should be 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
+}
-- 
2.5.5



More information about the Piglit mailing list