[Piglit] [PATCH 3/7] cl-program-tester: Add a helper function for getting type sizes

Aaron Watry awatry at gmail.com
Tue Oct 15 00:14:01 CEST 2013


On Mon, Sep 30, 2013 at 9:47 AM, Tom Stellard <tom at stellard.net> wrote:
> From: Tom Stellard <thomas.stellard at amd.com>
>
> ---
>  tests/cl/program/program-tester.c | 99 +++++++++++++++++----------------------
>  tests/util/piglit-util-cl.c       | 20 ++++++++
>  tests/util/piglit-util-cl.h       | 20 ++++++++
>  3 files changed, 84 insertions(+), 55 deletions(-)
>
> diff --git a/tests/cl/program/program-tester.c b/tests/cl/program/program-tester.c
> index 0071c2e..9cddd9c 100644
> --- a/tests/cl/program/program-tester.c
> +++ b/tests/cl/program/program-tester.c
> @@ -200,22 +200,10 @@ enum test_arg_type {
>         TEST_ARG_BUFFER,
>  };
>
> -enum cl_type {
> -       TYPE_CHAR,
> -       TYPE_UCHAR,
> -       TYPE_SHORT,
> -       TYPE_USHORT,
> -       TYPE_INT,
> -       TYPE_UINT,
> -       TYPE_LONG,
> -       TYPE_ULONG,
> -       TYPE_FLOAT,
> -};
> -
>  struct test_arg {
>         enum test_arg_type type;
>
> -       enum cl_type cl_type;
> +       enum piglit_cl_type cl_type;
>         size_t vec_elements; // 1 for int, 3 for int3
>         size_t vec_mem_elements; // 1 for int, 4 for int3
>         size_t length; // for buffers
> @@ -236,7 +224,7 @@ struct test_arg create_test_arg()
>         struct test_arg ta = {
>                 .type = TEST_ARG_VALUE,
>
> -               .cl_type = TYPE_CHAR,
> +               .cl_type = PIGLIT_CL_TYPE_CHAR,
>                 .vec_elements = 1,
>                 .vec_mem_elements = 1,
>                 .length = 0,
> @@ -877,15 +865,15 @@ get_test_arg_value(struct test_arg* test_arg, const char* value, size_t length)
>                 break;
>
>         switch(test_arg->cl_type) {
> -               CASE(TYPE_CHAR,   cl_char,    get_int_array,    int_array)
> -               CASE(TYPE_UCHAR,  cl_uchar,   get_uint_array,   uint_array)
> -               CASE(TYPE_SHORT,  cl_short,   get_int_array,    int_array)
> -               CASE(TYPE_USHORT, cl_ushort,  get_uint_array,   uint_array)
> -               CASE(TYPE_INT,    cl_int,     get_int_array,    int_array)
> -               CASE(TYPE_UINT,   cl_uint,    get_uint_array,   uint_array)
> -               CASE(TYPE_LONG,   cl_long,    get_int_array,    int_array)
> -               CASE(TYPE_ULONG,  cl_ulong,   get_uint_array,   uint_array)
> -               CASE(TYPE_FLOAT,  cl_float,   get_float_array,  float_array)
> +               CASE(PIGLIT_CL_TYPE_CHAR,   cl_char,    get_int_array,    int_array)
> +               CASE(PIGLIT_CL_TYPE_UCHAR,  cl_uchar,   get_uint_array,   uint_array)
> +               CASE(PIGLIT_CL_TYPE_SHORT,  cl_short,   get_int_array,    int_array)
> +               CASE(PIGLIT_CL_TYPE_USHORT, cl_ushort,  get_uint_array,   uint_array)
> +               CASE(PIGLIT_CL_TYPE_INT,    cl_int,     get_int_array,    int_array)
> +               CASE(PIGLIT_CL_TYPE_UINT,   cl_uint,    get_uint_array,   uint_array)
> +               CASE(PIGLIT_CL_TYPE_LONG,   cl_long,    get_int_array,    int_array)
> +               CASE(PIGLIT_CL_TYPE_ULONG,  cl_ulong,   get_uint_array,   uint_array)
> +               CASE(PIGLIT_CL_TYPE_FLOAT,  cl_float,   get_float_array,  float_array)
>         }
>
>  #undef CASE
> @@ -909,19 +897,19 @@ get_test_arg_tolerance(struct test_arg* test_arg, const char* tolerance_str)
>                 regex_get_match_str(&value_str, tolerance_str, pmatch, 1);
>
>                 switch(test_arg->cl_type) {
> -               case TYPE_CHAR:
> -               case TYPE_SHORT:
> -               case TYPE_INT:
> -               case TYPE_LONG:
> +               case PIGLIT_CL_TYPE_CHAR:
> +               case PIGLIT_CL_TYPE_SHORT:
> +               case PIGLIT_CL_TYPE_INT:
> +               case PIGLIT_CL_TYPE_LONG:
>                         test_arg->toli = get_int(value_str);
>                         break;
> -               case TYPE_UCHAR:
> -               case TYPE_USHORT:
> -               case TYPE_UINT:
> -               case TYPE_ULONG:
> +               case PIGLIT_CL_TYPE_UCHAR:
> +               case PIGLIT_CL_TYPE_USHORT:
> +               case PIGLIT_CL_TYPE_UINT:
> +               case PIGLIT_CL_TYPE_ULONG:
>                         test_arg->tolu = get_uint(value_str);
>                         break;
> -               case TYPE_FLOAT:
> +               case PIGLIT_CL_TYPE_FLOAT:
>                         test_arg->tolf = get_float(value_str);
>                         break;
>                 }
> @@ -976,23 +964,24 @@ get_test_arg(const char* src, struct test* test, bool arg_in)
>                 test_arg.vec_mem_elements = 1;
>         }
>
> -#define IF(regex_type, enum_type, main_type)                       \
> +#define IF(regex_type, enum_type)                       \
>         if(regex_match(type, REGEX_FULL_MATCH(regex_type))) {          \
>                 test_arg.cl_type = enum_type;                              \
> -               test_arg.size = sizeof(main_type) * test_arg.vec_mem_elements;  \
> +               test_arg.size = piglit_cl_type_get_size(enum_type) \
> +                                       * test_arg.vec_mem_elements;  \
>         }
> -#define ELSEIF(regex_type, enum_type, main_type) \
> -       else IF(regex_type, enum_type, main_type)
> -
> -       IF    (REGEX_TYPE_CHAR,   TYPE_CHAR,   cl_char)
> -       ELSEIF(REGEX_TYPE_UCHAR,  TYPE_UCHAR,  cl_uchar)
> -       ELSEIF(REGEX_TYPE_SHORT,  TYPE_SHORT,  cl_short)
> -       ELSEIF(REGEX_TYPE_USHORT, TYPE_USHORT, cl_ushort)
> -       ELSEIF(REGEX_TYPE_INT,    TYPE_INT,    cl_int)
> -       ELSEIF(REGEX_TYPE_UINT,   TYPE_UINT,   cl_uint)
> -       ELSEIF(REGEX_TYPE_LONG,   TYPE_LONG,   cl_long)
> -       ELSEIF(REGEX_TYPE_ULONG,  TYPE_ULONG,  cl_ulong)
> -       ELSEIF(REGEX_TYPE_FLOAT,  TYPE_FLOAT,  cl_float)
> +#define ELSEIF(regex_type, enum_type) \
> +       else IF(regex_type, enum_type)
> +
> +       IF    (REGEX_TYPE_CHAR,   PIGLIT_CL_TYPE_CHAR)
> +       ELSEIF(REGEX_TYPE_UCHAR,  PIGLIT_CL_TYPE_UCHAR)
> +       ELSEIF(REGEX_TYPE_SHORT,  PIGLIT_CL_TYPE_SHORT)
> +       ELSEIF(REGEX_TYPE_USHORT, PIGLIT_CL_TYPE_USHORT)
> +       ELSEIF(REGEX_TYPE_INT,    PIGLIT_CL_TYPE_INT)
> +       ELSEIF(REGEX_TYPE_UINT,   PIGLIT_CL_TYPE_UINT)
> +       ELSEIF(REGEX_TYPE_LONG,   PIGLIT_CL_TYPE_LONG)
> +       ELSEIF(REGEX_TYPE_ULONG,  PIGLIT_CL_TYPE_ULONG)
> +       ELSEIF(REGEX_TYPE_FLOAT,  PIGLIT_CL_TYPE_FLOAT)
>
>  #undef IF
>  #undef ELSEIF
> @@ -1667,15 +1656,15 @@ check_test_arg_value(struct test_arg test_arg,
>                 return true;
>
>         switch(test_arg.cl_type) {
> -               CASEI(TYPE_CHAR,   "char",   cl_char)
> -               CASEU(TYPE_UCHAR,  "uchar",  cl_uchar)
> -               CASEI(TYPE_SHORT,  "short",  cl_short)
> -               CASEU(TYPE_USHORT, "ushort", cl_ushort)
> -               CASEI(TYPE_INT,    "int",    cl_int)
> -               CASEU(TYPE_UINT,   "uint",   cl_uint)
> -               CASEI(TYPE_LONG,   "long",   cl_long)
> -               CASEU(TYPE_ULONG,  "ulong",  cl_ulong)
> -               CASEF(TYPE_FLOAT,  "float",  cl_float)
> +               CASEI(PIGLIT_CL_TYPE_CHAR,   "char",   cl_char)
> +               CASEU(PIGLIT_CL_TYPE_UCHAR,  "uchar",  cl_uchar)
> +               CASEI(PIGLIT_CL_TYPE_SHORT,  "short",  cl_short)
> +               CASEU(PIGLIT_CL_TYPE_USHORT, "ushort", cl_ushort)
> +               CASEI(PIGLIT_CL_TYPE_INT,    "int",    cl_int)
> +               CASEU(PIGLIT_CL_TYPE_UINT,   "uint",   cl_uint)
> +               CASEI(PIGLIT_CL_TYPE_LONG,   "long",   cl_long)
> +               CASEU(PIGLIT_CL_TYPE_ULONG,  "ulong",  cl_ulong)
> +               CASEF(PIGLIT_CL_TYPE_FLOAT,  "float",  cl_float)
>         }
>
>  #undef CASEF
> diff --git a/tests/util/piglit-util-cl.c b/tests/util/piglit-util-cl.c
> index 85c7a5d..a3e31b9 100644
> --- a/tests/util/piglit-util-cl.c
> +++ b/tests/util/piglit-util-cl.c
> @@ -25,6 +25,26 @@
>
>  #include "piglit-util-cl.h"
>
> +unsigned piglit_cl_type_get_size(enum piglit_cl_type type)

This is returning unsigned, but it's getting used to multiply by a
size_t and the result is stored in size_t.  Given the meaning of what
it being returned, I wouldn't mind changing the return type.

--Aaron

> +{
> +       switch (type) {
> +       case PIGLIT_CL_TYPE_CHAR:
> +       case PIGLIT_CL_TYPE_UCHAR:
> +               return 1;
> +       case PIGLIT_CL_TYPE_SHORT:
> +       case PIGLIT_CL_TYPE_USHORT:
> +               return 2;
> +       case PIGLIT_CL_TYPE_INT:
> +       case PIGLIT_CL_TYPE_UINT:
> +       case PIGLIT_CL_TYPE_FLOAT:
> +               return 4;
> +       case PIGLIT_CL_TYPE_LONG:
> +       case PIGLIT_CL_TYPE_ULONG:
> +       case PIGLIT_CL_TYPE_DOUBLE:
> +               return 8;
> +       }
> +}
> +
>  unsigned
>  piglit_cl_get_num_mem_elements(unsigned num_elements)
>  {
> diff --git a/tests/util/piglit-util-cl.h b/tests/util/piglit-util-cl.h
> index c017495..b392359 100644
> --- a/tests/util/piglit-util-cl.h
> +++ b/tests/util/piglit-util-cl.h
> @@ -44,6 +44,26 @@
>  extern "C" {
>  #endif
>
> +/* CL type helpers */
> +
> +enum piglit_cl_type {
> +       PIGLIT_CL_TYPE_CHAR,
> +       PIGLIT_CL_TYPE_UCHAR,
> +       PIGLIT_CL_TYPE_SHORT,
> +       PIGLIT_CL_TYPE_USHORT,
> +       PIGLIT_CL_TYPE_INT,
> +       PIGLIT_CL_TYPE_UINT,
> +       PIGLIT_CL_TYPE_LONG,
> +       PIGLIT_CL_TYPE_ULONG,
> +       PIGLIT_CL_TYPE_FLOAT,
> +       PIGLIT_CL_TYPE_DOUBLE
> +};
> +
> +/**
> + * \returns The size of \p type in bytes.
> + */
> +unsigned piglit_cl_type_get_size(enum piglit_cl_type type);
> +
>  /**
>   * \returns The number of elements this vector type has when stored in memory.
>   *          The value returned  the alignment in memory of the vector in units of
> --
> 1.7.11.4
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list