From 9c0050081c8954775d0d71a36cb8013f08100934 Mon Sep 17 00:00:00 2001
From: David Heidelberg <david@ixit.cz>
Date: Wed, 4 Sep 2024 12:46:28 +0900
Subject: [PATCH] testing/piglit: check OCL support

Signed-off-by: David Heidelberg <david@ixit.cz>
---
 testing/piglit/949.patch | 205 +++++++++++++++++++++++++++++++++++++++
 testing/piglit/APKBUILD  |   8 +-
 2 files changed, 210 insertions(+), 3 deletions(-)
 create mode 100644 testing/piglit/949.patch

diff --git a/testing/piglit/949.patch b/testing/piglit/949.patch
new file mode 100644
index 000000000000..a52b34f60c31
--- /dev/null
+++ b/testing/piglit/949.patch
@@ -0,0 +1,205 @@
+From a1b3500fdd9fc86391d9df2864e43854348ab257 Mon Sep 17 00:00:00 2001
+From: David Heidelberg <david@ixit.cz>
+Date: Wed, 4 Sep 2024 13:19:19 +0900
+Subject: [PATCH 1/4] cl: compile with OpenCL 3.0 support
+
+Signed-off-by: David Heidelberg <david@ixit.cz>
+---
+ tests/cl/api/get-device-info.c       | 11 ++++++++---
+ tests/cl/program/predefined-macros.c | 15 ++++++++++++++-
+ tests/util/piglit-util-cl.h          |  4 +++-
+ 3 files changed, 25 insertions(+), 5 deletions(-)
+
+diff --git a/tests/cl/api/get-device-info.c b/tests/cl/api/get-device-info.c
+index ba96221180..4abe28adfd 100644
+--- a/tests/cl/api/get-device-info.c
++++ b/tests/cl/api/get-device-info.c
+@@ -189,9 +189,14 @@ check_info(const struct piglit_cl_api_test_env* env,
+ 			}
+ 			break;
+ 		case CL_DEVICE_VERSION:
+-			if (check_string_not_empty(param_value_size, param_value, result) &&
+-			    ((env->version == 12 && check_sub_string("OpenCL 1.2", param_value, result)) ||
+-			      check_sub_string("OpenCL 1.1", param_value, result))) {
++			if (
++				check_string_not_empty(param_value_size, param_value, result) &&
++			    	(
++					(env->version == 30 && check_sub_string("OpenCL 3.0", param_value, result)) ||
++			     		(env->version == 12 && check_sub_string("OpenCL 1.2", param_value, result)) ||
++			      		check_sub_string("OpenCL 1.1", param_value, result)
++				)
++			    ) {
+ 				print_s(param_value);
+ 			}
+ 			break;
+diff --git a/tests/cl/program/predefined-macros.c b/tests/cl/program/predefined-macros.c
+index e1f66ac11d..c904413209 100644
+--- a/tests/cl/program/predefined-macros.c
++++ b/tests/cl/program/predefined-macros.c
+@@ -85,6 +85,13 @@ char *program_source =
+ "	cl_version_defined[3] = 0; \n"
+ "#endif \n"
+ "\n"
++"#ifdef CL_VERSION_3_0 \n"
++"	cl_version_defined[3] = 1; \n"
++"	cl_version[3] = CL_VERSION_3_0; \n"
++"#else \n"
++"	cl_version_defined[3] = 0; \n"
++"#endif \n"
++"\n"
+ "#ifdef __ENDIAN_LITTLE__ \n"
+ "	*endian_little_defined = 1; \n"
+ "	*endian_little = __ENDIAN_LITTLE__; \n"
+@@ -121,7 +128,7 @@ version_from_string(char* string, int *version)
+ 	return 1;
+ }
+ 
+-#define NUM_CL_VERSION 4
++#define NUM_CL_VERSION 5
+ 
+ enum piglit_result
+ piglit_cl_test(const int argc,
+@@ -414,6 +421,9 @@ piglit_cl_test(const int argc,
+ 	piglit_report_subtest_result(result_cl_version_defined[3],
+ 	                             "CL_VERSION_2_0 must be defined for OpenCL 2.0 and later");
+ 	piglit_merge_result(&result, result_cl_version_defined[3]);
++	piglit_report_subtest_result(result_cl_version_defined[4],
++	                             "CL_VERSION_3_0 must be defined for OpenCL 3.0 and later");
++	piglit_merge_result(&result, result_cl_version_defined[4]);
+ 	piglit_report_subtest_result(result_cl_version[0],
+ 	                             "CL_VERSION_1_0 must be 100 if defined");
+ 	piglit_merge_result(&result, result_cl_version[0]);
+@@ -426,6 +436,9 @@ piglit_cl_test(const int argc,
+ 	piglit_report_subtest_result(result_cl_version[3],
+ 	                             "CL_VERSION_2_0 must be 200 if defined");
+ 	piglit_merge_result(&result, result_cl_version[3]);
++	piglit_report_subtest_result(result_cl_version[4],
++	                             "CL_VERSION_3_0 must be 300 if defined");
++	piglit_merge_result(&result, result_cl_version[4]);
+ 	piglit_report_subtest_result(result_endian_little_defined,
+ 	                             "__ENDIAN_LITTLE__ must be consistent with host");
+ 	piglit_merge_result(&result, result_endian_little_defined);
+diff --git a/tests/util/piglit-util-cl.h b/tests/util/piglit-util-cl.h
+index af5b805615..820e7e0629 100644
+--- a/tests/util/piglit-util-cl.h
++++ b/tests/util/piglit-util-cl.h
+@@ -31,7 +31,9 @@
+ 
+ /* Define with which version of OpenCL Piglit was compiled */
+ 
+-#if defined(CL_VERSION_2_0)
++#if defined(CL_VERSION_3_0)
++#  define PIGLIT_CL_VERSION 30
++#elif defined(CL_VERSION_2_0)
+ #  define PIGLIT_CL_VERSION 20
+ #elif defined(CL_VERSION_1_2)
+ #  define PIGLIT_CL_VERSION 12
+-- 
+GitLab
+
+
+From 3972de1ca957f141e1259cb9e1bce0c6f9b7ca39 Mon Sep 17 00:00:00 2001
+From: David Heidelberg <david@ixit.cz>
+Date: Wed, 4 Sep 2024 12:14:46 +0900
+Subject: [PATCH 2/4] cl: add imperfect CL_DEVICE_OPENCL_C_VERSION check
+
+Signed-off-by: David Heidelberg <david@ixit.cz>
+---
+ tests/cl/api/get-device-info.c | 11 ++++++++---
+ 1 file changed, 8 insertions(+), 3 deletions(-)
+
+diff --git a/tests/cl/api/get-device-info.c b/tests/cl/api/get-device-info.c
+index 4abe28adfd..87f42f8200 100644
+--- a/tests/cl/api/get-device-info.c
++++ b/tests/cl/api/get-device-info.c
+@@ -201,9 +201,14 @@ check_info(const struct piglit_cl_api_test_env* env,
+ 			}
+ 			break;
+ 		case CL_DEVICE_OPENCL_C_VERSION:
+-			if (check_string_not_empty(param_value_size, param_value, result) &&
+-			    ((env->version == 12 && check_sub_string("OpenCL C 1.2", param_value, result)) ||
+-			      check_sub_string("OpenCL C 1.1", param_value, result))) {
++			if (
++				check_string_not_empty(param_value_size, param_value, result) &&
++			    	(
++			     		(env->version == 30 && check_sub_string("OpenCL C 1.2 ", param_value, result)) || /* TODO: vendor part after space */
++			    		(env->version == 12 && check_sub_string("OpenCL C 1.2", param_value, result)) ||
++			      		check_sub_string("OpenCL C 1.1", param_value, result)
++			   	)
++			    ) {
+ 				print_s(param_value);
+ 			}
+ 			break;
+-- 
+GitLab
+
+
+From e61c8baec5087c2622dde078a3f180d77f57851d Mon Sep 17 00:00:00 2001
+From: David Heidelberg <david@ixit.cz>
+Date: Wed, 4 Sep 2024 12:31:02 +0900
+Subject: [PATCH 3/4] cl: correct CL_DEVICE_DOUBLE_FP_CONFIG check for OpenCL >
+ 1.2
+
+Signed-off-by: David Heidelberg <david@ixit.cz>
+---
+ tests/cl/api/get-device-info.c | 14 +++++++++-----
+ 1 file changed, 9 insertions(+), 5 deletions(-)
+
+diff --git a/tests/cl/api/get-device-info.c b/tests/cl/api/get-device-info.c
+index 87f42f8200..c3a98a9417 100644
+--- a/tests/cl/api/get-device-info.c
++++ b/tests/cl/api/get-device-info.c
+@@ -413,12 +413,16 @@ check_info(const struct piglit_cl_api_test_env* env,
+ 			    check_fp_config(kind, *(cl_device_fp_config*)param_value, result)) {
+ 				cl_device_fp_config value = *(cl_device_fp_config*)param_value;
+ 				if (device_config->type != CL_DEVICE_TYPE_CUSTOM &&
+-				    device_config->has_double &&
+-				    !(value & (CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_ROUND_TO_ZERO|
++				    device_config->has_double) {
++					if (env->version <= 12 && !(value & (CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_ROUND_TO_ZERO|
+ 				               CL_FP_ROUND_TO_INF|CL_FP_INF_NAN|CL_FP_DENORM))) {
+-					printf(": failed, expected CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_ROUND_TO_ZERO|" \
+-					       "CL_FP_ROUND_TO_INF|CL_FP_INF_NAN|CL_FP_DENORM. Got %lx", value);
+-					piglit_merge_result(result, PIGLIT_FAIL);
++						printf(": failed, expected CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_ROUND_TO_ZERO|" \
++						       "CL_FP_ROUND_TO_INF|CL_FP_INF_NAN|CL_FP_DENORM. Got %lx", value);
++						piglit_merge_result(result, PIGLIT_FAIL);
++					} else if /* OpenCL >= 2.0 */ (!(value & (CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_INF_NAN|CL_FP_DENORM))) {
++						printf(": failed, expected CL_FP_FMA|CL_FP_ROUND_TO_NEAREST|CL_FP_INF_NAN|CL_FP_DENORM. Got %lx", value);
++						piglit_merge_result(result, PIGLIT_FAIL);
++					}
+ 				} else {
+ 					printf(": %lx", value);
+ 				}
+-- 
+GitLab
+
+
+From 9cdc472a0a88991a92ce50a79194ed6b5c8975c9 Mon Sep 17 00:00:00 2001
+From: David Heidelberg <david@ixit.cz>
+Date: Wed, 4 Sep 2024 12:32:18 +0900
+Subject: [PATCH 4/4] cl: initialize device_config
+
+Prevent having random values leading to undefined behaviour.
+
+Signed-off-by: David Heidelberg <david@ixit.cz>
+---
+ tests/cl/api/get-device-info.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tests/cl/api/get-device-info.c b/tests/cl/api/get-device-info.c
+index c3a98a9417..db0b5652ea 100644
+--- a/tests/cl/api/get-device-info.c
++++ b/tests/cl/api/get-device-info.c
+@@ -650,7 +650,7 @@ piglit_cl_test(const int argc,
+ {
+ 	enum piglit_result result = PIGLIT_PASS;
+ 
+-	struct device_config device_config;
++	struct device_config device_config = {0};
+ 
+ 	int i;
+ 	cl_int errNo;
+-- 
+GitLab
+
diff --git a/testing/piglit/APKBUILD b/testing/piglit/APKBUILD
index 702fa4da220d..9892ef30d5f9 100644
--- a/testing/piglit/APKBUILD
+++ b/testing/piglit/APKBUILD
@@ -2,10 +2,10 @@
 pkgname=piglit
 pkgver=0_git20240826
 _gitrev=eeb74a85ac0484f896995d196814db1b247656a1
-pkgrel=0
+pkgrel=999
 pkgdesc="a collection of automated tests for OpenGL, Vulkan, and OpenCL implementations"
 url="https://gitlab.freedesktop.org/mesa/piglit"
-arch="all"
+arch="aarch64"
 license="MIT AND GPL-2.0-only AND GPL-3.0-or-later AND GPL-2.0-or-later AND LGPL-2.1-or-later AND LGPL-3.0-or-later AND BSD-3-clause"
 depends="
 	py3-mako
@@ -31,7 +31,8 @@ makedepends="
 	waffle-dev
 	wayland-protocols"
 
-source="$pkgname-$pkgver.tar.gz::https://gitlab.freedesktop.org/mesa/piglit/-/archive/$_gitrev/piglit-$_gitrev.tar.gz"
+source="$pkgname-$pkgver.tar.gz::https://gitlab.freedesktop.org/mesa/piglit/-/archive/$_gitrev/piglit-$_gitrev.tar.gz
+	949.patch"
 
 builddir="$srcdir/piglit-$_gitrev"
 
@@ -59,4 +60,5 @@ package() {
 
 sha512sums="
 e5addd75a069b335fb6fd7067b1f4964fbfa9cad4c882f8e7e4c453682f4de48c663b2d83e7ea859bb64646722b2032c930f5d08613d30be29cc617b97b5d40e  piglit-0_git20240826.tar.gz
+c366d5c6b40391bd33cec437b8049acd4da3e4c29407ce6ef84c97e4687402bcebdcc4fe9e31848e6bc94bae57244133798eaa296678c0fe288903e308822502  949.patch
 "
-- 
GitLab