[PATCH libdrm 5/9] tests/hash: return non-zero on failure

Jan Vesely jan.vesely at rutgers.edu
Mon Mar 23 16:08:13 PDT 2015


On Sun, 2015-03-22 at 22:03 +0000, Emil Velikov wrote:
> ... and wire up to `make check' now that it's useful.
> 
> Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
> ---
>  tests/Makefile.am | 12 +++++++-----
>  tests/hash.c      | 26 +++++++++++++++-----------
>  2 files changed, 22 insertions(+), 16 deletions(-)
> 
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index ea826b5..392abf5 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -29,13 +29,15 @@ LDADD = $(top_builddir)/libdrm.la
>  
>  check_PROGRAMS = \
>  	dristat \
> -	drmstat \
> -	hash
> +	drmstat
>  
>  if HAVE_NOUVEAU
>  SUBDIRS += nouveau
>  endif
>  
> +TESTS = \
> +	hash
> +
>  if HAVE_LIBUDEV
>  
>  check_LTLIBRARIES = libdrmtest.la
> @@ -53,7 +55,7 @@ XFAIL_TESTS =					\
>  	auth					\
>  	lock
>  
> -TESTS =						\
> +TESTS  += \
>  	openclose				\
>  	getversion				\
>  	getclient				\
> @@ -62,6 +64,6 @@ TESTS =						\
>  	updatedraw				\
>  	name_from_fd
>  
> -check_PROGRAMS += $(TESTS)
> -
>  endif
> +
> +check_PROGRAMS += $(TESTS)
> diff --git a/tests/hash.c b/tests/hash.c
> index fa9264a..46f52f8 100644
> --- a/tests/hash.c
> +++ b/tests/hash.c
> @@ -142,7 +142,7 @@ static void compute_dist(HashTablePtr table)
>      }
>  }
>  
> -static void check_table(HashTablePtr table,
> +static int check_table(HashTablePtr table,
>                          unsigned long key, unsigned long value)
>  {
>      unsigned long *retval;
> @@ -159,28 +159,32 @@ static void check_table(HashTablePtr table,
>                 key, value, *retval);
>          break;
>      case 0:
> -        if (value != *retval)
> +        if (value != *retval) {
>              printf("Bad value: key = %lu, expected = %lu, returned = %lu\n",
>                     key, value, *retval);
> +            retcode = -1;
> +        }
>          break;
>      default:
>          printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n",
>                 retcode, key, value, *retval);
>          break;
>      }
> +    return retcode;
>  }
>  
>  int main(void)
>  {
> -    HashTablePtr table;
> -    unsigned long  i;
> +    HashTablePtr  table;
> +    unsigned long i;
> +    int           ret = 0;
>  
>      printf("\n***** 256 consecutive integers ****\n");
>      table = drmHashCreate();
>      for (i = 0; i < 256; i++)
>          drmHashInsert(table, i, (void *)&i);
>      for (i = 0; i < 256; i++)
> -        check_table(table, i, i);
> +        ret = check_table(table, i, i) && ret;
>      compute_dist(table);
>      drmHashDestroy(table);
>  
> @@ -189,7 +193,7 @@ int main(void)
>      for (i = 0; i < 1024; i++)
>          drmHashInsert(table, i, (void *)&i);
>      for (i = 0; i < 1024; i++)
> -        check_table(table, i, i);
> +        ret = check_table(table, i, i) && ret;
>      compute_dist(table);
>      drmHashDestroy(table);
>  
> @@ -198,7 +202,7 @@ int main(void)
>      for (i = 0; i < 1024; i++)
>          drmHashInsert(table, i*4096, (void *)&i);
>      for (i = 0; i < 1024; i++)
> -        check_table(table, i*4096, i);
> +        ret = check_table(table, i*4096, i) && ret;
>      compute_dist(table);
>      drmHashDestroy(table);
>  
> @@ -209,10 +213,10 @@ int main(void)
>          drmHashInsert(table, random(), (void *)&i);
>      srandom(0xbeefbeef);
>      for (i = 0; i < 1024; i++)
> -        check_table(table, random(), i);
> +        ret = check_table(table, random(), i) && ret;
>      srandom(0xbeefbeef);
>      for (i = 0; i < 1024; i++)
> -        check_table(table, random(), i);
> +        ret = check_table(table, random(), i) && ret;
>      compute_dist(table);
>      drmHashDestroy(table);
>  
> @@ -223,10 +227,10 @@ int main(void)
>          drmHashInsert(table, random(), (void *)&i);
>      srandom(0xbeefbeef);
>      for (i = 0; i < 5000; i++)
> -        check_table(table, random(), i);
> +        ret = check_table(table, random(), i) && ret;
>      srandom(0xbeefbeef);
>      for (i = 0; i < 5000; i++)
> -        check_table(table, random(), i);
> +        ret = check_table(table, random(), i) && ret;
>      compute_dist(table);
>      drmHashDestroy(table);
>  
Reviewed-by: Jan Vesely <jan.vesely at rutgesr.edu>

-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/dri-devel/attachments/20150323/bea5ac91/attachment.sig>


More information about the dri-devel mailing list