cl: add clGetExtensionFunctionAddressForPlatform

Submitted by Serge Martin on Nov. 6, 2016, 1:43 p.m.

Details

Message ID 1478439820-12872-1-git-send-email-edb+piglit@sigluy.net
State New
Headers show
Series "cl: add clGetExtensionFunctionAddressForPlatform" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Serge Martin Nov. 6, 2016, 1:43 p.m.
---
 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

Patch hide | download patch | download mbox

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@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
+}

Comments

On Sun, 2016-11-06 at 14:43 +0100, Serge Martin wrote:
> ---
>  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@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, " ");

I think the name "pos" is misleading since it's always extension name
length, not position in string.

> +	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";
> +		}

Is the intention to add more extensions in the future? if not, simple
strstr for "cl_khr_icd" would simplify the code. if yes, please add a
comment.

> +
> +		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, " ");

this looks like handcoded strtok. Have you considered using it
directly?

Jan

> +	}
> +
> +	/*** 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
> +}
On Sunday 06 November 2016 13:58:31 Jan Vesely wrote:
> On Sun, 2016-11-06 at 14:43 +0100, Serge Martin wrote:
> > ---
> > 
> >  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@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, " ");
> 
> I think the name "pos" is misleading since it's always extension name
> length, not position in string.
> 
> > +	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";
> > +		}
> 
> Is the intention to add more extensions in the future? if not, simple
> strstr for "cl_khr_icd" would simplify the code. if yes, please add a
> comment.

That was the original intent. However, I think we will stick to test 
cl_khr_icd for a moment. I will v2 with strstr.
> 
> > +
> > +		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, " ");
> 
> this looks like handcoded strtok. Have you considered using it
> directly?
> 
> Jan
> 
> > +	}
> > +
> > +	/*** 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
> > +}