[Piglit] [PATCH 2/2] cl: add value cheking to clGetKernelArgInfo test
Serge Martin
edb+piglit at sigluy.net
Sun Nov 27 13:54:24 UTC 2016
---
tests/cl/api/get-kernel-arg-info.c | 312 +++++++++++++++++++++++++++----------
1 file changed, 231 insertions(+), 81 deletions(-)
diff --git a/tests/cl/api/get-kernel-arg-info.c b/tests/cl/api/get-kernel-arg-info.c
index 7b336e4..59877f2 100644
--- a/tests/cl/api/get-kernel-arg-info.c
+++ b/tests/cl/api/get-kernel-arg-info.c
@@ -48,16 +48,176 @@ PIGLIT_CL_API_TEST_CONFIG_BEGIN
config.run_per_platform = true;
config.create_context = true;
- config.program_source = "kernel void dummy_kernel(int param_1) {}";
+ config.program_source =
+ "typedef struct struct_arg {\n"
+ " int m1;\n"
+ " float m3;\n"
+ "} struct_arg_t;\n"
+ "\n"
+ "kernel void dummy_kernel(global int* g_int_p, \
+ local int* l_int_p, \
+ constant int* c_int_p, \
+ float float_num, \
+ sampler_t sampler, \
+ read_only image2d_t i2d, \
+ const int3 vec3, \
+ struct_arg_t s_arg \
+ ) { g_int_p[0] = s_arg.m1; }";
config.build_options = "-cl-kernel-arg-info";
PIGLIT_CL_API_TEST_CONFIG_END
-static void
-set_failure(enum piglit_result *result, const char* sub_name)
+#define NUMARGS 8
+#define BUFFER_SIZE 16
+
+static bool
+check_size(cl_uint arg_indx, cl_kernel_arg_info param_name,
+ size_t value_size)
+{
+ static size_t sizes[NUMARGS][2] = {
+ /* type, name */
+ {4 + 1, 7 + 1},
+ {4 + 1, 7 + 1},
+ {4 + 1, 7 + 1},
+ {5 + 1, 9 + 1},
+ {9 + 1, 7 + 1},
+ {9 + 1, 3 + 1},
+ {4 + 1, 4 + 1},
+ {12 + 1, 5 + 1},
+ };
+
+ size_t expected_size = 0;
+ size_t type_name_size = 0;
+ size_t arg_name_size = 0;
+
+ type_name_size = sizes[arg_indx][0];
+ arg_name_size = sizes[arg_indx][1];
+
+#define CASE(_enum_, _type_, _n_) \
+case _enum_: \
+ expected_size = sizeof(_type_) * ( _n_ ); \
+ break;
+
+ switch (param_name) {
+ CASE(CL_KERNEL_ARG_ADDRESS_QUALIFIER,
+ cl_kernel_arg_address_qualifier, 1)
+ CASE(CL_KERNEL_ARG_ACCESS_QUALIFIER,
+ cl_kernel_arg_access_qualifier, 1)
+ CASE(CL_KERNEL_ARG_TYPE_NAME, char, type_name_size)
+ CASE(CL_KERNEL_ARG_TYPE_QUALIFIER,
+ cl_kernel_arg_type_qualifier, 1)
+ CASE(CL_KERNEL_ARG_NAME, char, arg_name_size)
+ }
+
+#undef CASE
+
+ if (value_size != expected_size) {
+ fprintf(stderr,
+ "Failed: arg #%d the returned size doesn't matches. Expected %lu, got %lu\n",
+ arg_indx, expected_size, value_size);
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+check_value(cl_uint arg_indx, cl_kernel_arg_info param_name,
+ char* value)
{
- piglit_merge_result(result, PIGLIT_FAIL);
- piglit_report_subtest_result(PIGLIT_FAIL, "%s", sub_name);
+ static cl_kernel_arg_address_qualifier add_qual[NUMARGS] = {
+ CL_KERNEL_ARG_ADDRESS_GLOBAL,
+ CL_KERNEL_ARG_ADDRESS_LOCAL,
+ CL_KERNEL_ARG_ADDRESS_CONSTANT,
+ CL_KERNEL_ARG_ADDRESS_PRIVATE,
+ CL_KERNEL_ARG_ADDRESS_PRIVATE,
+ CL_KERNEL_ARG_ADDRESS_GLOBAL,
+ CL_KERNEL_ARG_ADDRESS_PRIVATE,
+ CL_KERNEL_ARG_ADDRESS_PRIVATE
+ };
+
+ static cl_kernel_arg_address_qualifier acc_qual[NUMARGS] = {
+ CL_KERNEL_ARG_ACCESS_NONE,
+ CL_KERNEL_ARG_ACCESS_NONE,
+ CL_KERNEL_ARG_ACCESS_NONE,
+ CL_KERNEL_ARG_ACCESS_NONE,
+ CL_KERNEL_ARG_ACCESS_NONE,
+ CL_KERNEL_ARG_ACCESS_READ_ONLY,
+ CL_KERNEL_ARG_ACCESS_NONE,
+ CL_KERNEL_ARG_ACCESS_NONE
+ };
+
+ static char* typ_name[NUMARGS] = {
+ "int*",
+ "int*",
+ "int*",
+ "float",
+ "sampler_t",
+ "image2d_t",
+ "int3",
+ "struct_arg_t",
+ };
+
+ static cl_kernel_arg_type_qualifier typ_qual[NUMARGS] = {
+ CL_KERNEL_ARG_TYPE_NONE,
+ CL_KERNEL_ARG_TYPE_NONE,
+ CL_KERNEL_ARG_TYPE_CONST,
+ CL_KERNEL_ARG_TYPE_NONE,
+ CL_KERNEL_ARG_TYPE_NONE,
+ CL_KERNEL_ARG_TYPE_NONE,
+ CL_KERNEL_ARG_TYPE_CONST,
+ CL_KERNEL_ARG_TYPE_NONE
+ };
+
+ static char* arg_name[NUMARGS] = {
+ "g_int_p",
+ "l_int_p",
+ "c_int_p",
+ "float_num",
+ "sampler",
+ "i2d",
+ "vec3",
+ "s_arg",
+ };
+
+ bool value_ok = false;
+
+ switch (param_name) {
+ case CL_KERNEL_ARG_ADDRESS_QUALIFIER:
+ if (*(cl_kernel_arg_address_qualifier*)value ==
+ add_qual[arg_indx])
+ value_ok = true;
+ break;
+
+ case CL_KERNEL_ARG_ACCESS_QUALIFIER:
+ if (*(cl_kernel_arg_access_qualifier*)value ==
+ acc_qual[arg_indx])
+ value_ok = true;
+ break;
+
+ case CL_KERNEL_ARG_TYPE_NAME:
+ if (strcmp(value, typ_name[arg_indx]) == 0)
+ value_ok = true;
+ break;
+
+ case CL_KERNEL_ARG_TYPE_QUALIFIER:
+ if (*(cl_kernel_arg_type_qualifier*)value ==
+ typ_qual[arg_indx])
+ value_ok = true;
+ break;
+
+ case CL_KERNEL_ARG_NAME:
+ if (strcmp(value, arg_name[arg_indx]) == 0)
+ value_ok = true;
+ }
+
+ if (!value_ok) {
+ fprintf(stderr,
+ "Failed: arg #%d the value doesn't matches.\n", arg_indx);
+ return false;
+ }
+
+ return true;
}
enum piglit_result
@@ -69,14 +229,13 @@ piglit_cl_test(const int argc,
#if defined(CL_VERSION_1_2)
enum piglit_result result = PIGLIT_PASS;
- int i;
+ int i, j;
cl_int errNo;
cl_kernel kernel;
+ cl_uint* num_args_ptr;
size_t param_value_size;
size_t ret_value_size;
- size_t expected_size;
-#define BUFFER_SIZE 8
char param_value[BUFFER_SIZE];
int num_kernel_arg_infos = PIGLIT_CL_ENUM_NUM(cl_kernel_arg_info, env->version);
@@ -92,86 +251,77 @@ piglit_cl_test(const int argc,
return PIGLIT_FAIL;
}
+ num_args_ptr = piglit_cl_get_kernel_info(kernel, CL_KERNEL_NUM_ARGS);
+ if (*num_args_ptr != NUMARGS) {
+ fprintf(stderr,
+ "Failed : Invalid number of arguments to be tested\n");
+ return PIGLIT_FAIL;
+ }
+ free(num_args_ptr);
+
/*** Normal usage ***/
for(i = 0; i < num_kernel_arg_infos; ++i) {
const char* enum_name = piglit_cl_get_enum_name(kernel_arg_infos[i]);
+ enum piglit_result sub_result = PIGLIT_PASS;
printf("%s\n", enum_name);
- param_value_size = 0;
- ret_value_size = 0;
-
- errNo = clGetKernelArgInfo(kernel,
- 0,
- kernel_arg_infos[i],
- 0,
- NULL,
- ¶m_value_size);
- if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
- fprintf(stderr,
- "Failed (error code: %s): Get size of %s.\n",
- piglit_cl_get_error_name(errNo), enum_name);
- set_failure(&result, enum_name);
- continue;
- }
-
- if (param_value_size > BUFFER_SIZE) {
- fprintf(stderr,
- "Failed: BUFFER_SIZE is too small\n");
- set_failure(&result, enum_name);
- continue;
- }
-
- errNo = clGetKernelArgInfo(kernel,
- 0,
- kernel_arg_infos[i],
- BUFFER_SIZE,
- ¶m_value,
- &ret_value_size);
- if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
- fprintf(stderr,
- "Failed (error code: %s): Get value of %s.\n",
- piglit_cl_get_error_name(errNo), enum_name);
- set_failure(&result, enum_name);
- continue;
- }
-
- if (param_value_size != ret_value_size) {
- fprintf(stderr,
- "Failed: the returned size doesn't matches the queried one\n");
- set_failure(&result, enum_name);
- continue;
+ for (j = 0; j < NUMARGS; ++j) {
+ param_value_size = 0;
+ ret_value_size = 0;
+
+ errNo = clGetKernelArgInfo(kernel,
+ j,
+ kernel_arg_infos[i],
+ 0,
+ NULL,
+ ¶m_value_size);
+ if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+ fprintf(stderr,
+ "Failed (error code: %s): Get size of %s.\n",
+ piglit_cl_get_error_name(errNo), enum_name);
+ piglit_merge_result(&sub_result, PIGLIT_FAIL);
+ continue;
+ }
+
+ if (param_value_size > BUFFER_SIZE) {
+ fprintf(stderr,
+ "Failed: BUFFER_SIZE is too small\n");
+ piglit_merge_result(&sub_result, PIGLIT_FAIL);
+ continue;
+ }
+
+ errNo = clGetKernelArgInfo(kernel,
+ j,
+ kernel_arg_infos[i],
+ BUFFER_SIZE,
+ ¶m_value,
+ &ret_value_size);
+ if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+ fprintf(stderr,
+ "Failed (error code: %s): Get value of %s.\n",
+ piglit_cl_get_error_name(errNo), enum_name);
+ piglit_merge_result(&sub_result, PIGLIT_FAIL);
+ continue;
+ }
+
+ if (param_value_size != ret_value_size) {
+ fprintf(stderr,
+ "Failed: the returned size doesn't matches the queried one\n");
+ piglit_merge_result(&sub_result, PIGLIT_FAIL);
+ continue;
+ }
+
+ if (!check_size(j, kernel_arg_infos[i], ret_value_size)) {
+ piglit_merge_result(&sub_result, PIGLIT_FAIL);
+ continue;
+ }
+
+ if (!check_value(j, kernel_arg_infos[i], param_value))
+ piglit_merge_result(&sub_result, PIGLIT_FAIL);
}
-#define CASE(_enum_, _type_, _n_) \
- case _enum_: \
- expected_size = sizeof(_type_) * ( _n_ ); \
- break;
-
- expected_size = 0;
- switch (kernel_arg_infos[i]) {
- CASE(CL_KERNEL_ARG_ADDRESS_QUALIFIER,
- cl_kernel_arg_address_qualifier, 1)
- CASE(CL_KERNEL_ARG_ACCESS_QUALIFIER,
- cl_kernel_arg_access_qualifier, 1)
- CASE(CL_KERNEL_ARG_TYPE_NAME, char, 3 + 1)
- CASE(CL_KERNEL_ARG_TYPE_QUALIFIER,
- cl_kernel_arg_type_qualifier, 1)
- CASE(CL_KERNEL_ARG_NAME, char, 7 + 1)
- }
-
-#undef CASE
-
- if (ret_value_size != expected_size) {
- fprintf(stderr,
- "Failed: the returned size doesn't matches. Expected %lu, got %lu\n",
- expected_size, ret_value_size);
- set_failure(&result, enum_name);
- continue;
- }
-
- //TODO: test returned values
-
- piglit_report_subtest_result(PIGLIT_PASS, "%s", enum_name);
+ piglit_report_subtest_result(sub_result, "%s", enum_name);
+ piglit_merge_result(&result, sub_result);
}
/*** Errors ***/
--
2.5.5
More information about the Piglit
mailing list