All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emil Velikov <emil.l.velikov@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: emil.l.velikov@gmail.com
Subject: [PATCH libdrm 3/9] tests/hash: misc compilation fixes
Date: Sun, 22 Mar 2015 22:03:39 +0000	[thread overview]
Message-ID: <1427061825-27470-4-git-send-email-emil.l.velikov@gmail.com> (raw)
In-Reply-To: <1427061825-27470-1-git-send-email-emil.l.velikov@gmail.com>

Get the test from completely broken to working like a charm.

 - Use the same variable type for both HashInsert and HashLookup.
 - Use correct storage type for the HashLookup return value.
 - Remove useless backward iteration of HashLookup(i).

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
 tests/hash.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/tests/hash.c b/tests/hash.c
index d57d2dc..902919f 100644
--- a/tests/hash.c
+++ b/tests/hash.c
@@ -139,27 +139,27 @@ static void compute_dist(HashTablePtr table)
 static void check_table(HashTablePtr table,
 			unsigned long key, unsigned long value)
 {
-    unsigned long retval  = 0;
-    int           retcode = drmHashLookup(table, key, &retval);
+    unsigned long *retval;
+    int           retcode = drmHashLookup(table, key, (void **)&retval);
 
     switch (retcode) {
     case -1:
 	printf("Bad magic = 0x%08lx:"
 	       " key = %lu, expected = %lu, returned = %lu\n",
-	       table->magic, key, value, retval);
+	       table->magic, key, value, *retval);
 	break;
     case 1:
-	printf("Not found: key = %lu, expected = %lu returned = %lu\n",
-	       key, value, retval);
+	printf("Not found: key = %lu, expected = %lu, returned = %lu\n",
+	       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);
+		   key, value, *retval);
 	break;
     default:
 	printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n",
-	       retcode, key, value, retval);
+	       retcode, key, value, *retval);
 	break;
     }
 }
@@ -167,36 +167,33 @@ static void check_table(HashTablePtr table,
 int main(void)
 {
     HashTablePtr table;
-    int          i;
+    unsigned long  i;
 
     printf("\n***** 256 consecutive integers ****\n");
     table = drmHashCreate();
-    for (i = 0; i < 256; i++) drmHashInsert(table, i, i);
+    for (i = 0; i < 256; i++) drmHashInsert(table, i, (void *)&i);
     for (i = 0; i < 256; i++) check_table(table, i, i);
-    for (i = 256; i >= 0; i--) check_table(table, i, i);
     compute_dist(table);
     drmHashDestroy(table);
 
     printf("\n***** 1024 consecutive integers ****\n");
     table = drmHashCreate();
-    for (i = 0; i < 1024; i++) drmHashInsert(table, i, i);
+    for (i = 0; i < 1024; i++) drmHashInsert(table, i, (void *)&i);
     for (i = 0; i < 1024; i++) check_table(table, i, i);
-    for (i = 1024; i >= 0; i--) check_table(table, i, i);
     compute_dist(table);
     drmHashDestroy(table);
 
     printf("\n***** 1024 consecutive page addresses (4k pages) ****\n");
     table = drmHashCreate();
-    for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, i);
+    for (i = 0; i < 1024; i++) drmHashInsert(table, i*4096, (void *)&i);
     for (i = 0; i < 1024; i++) check_table(table, i*4096, i);
-    for (i = 1024; i >= 0; i--) check_table(table, i*4096, i);
     compute_dist(table);
     drmHashDestroy(table);
 
     printf("\n***** 1024 random integers ****\n");
     table = drmHashCreate();
     srandom(0xbeefbeef);
-    for (i = 0; i < 1024; i++) drmHashInsert(table, random(), i);
+    for (i = 0; i < 1024; i++) drmHashInsert(table, random(), (void *)&i);
     srandom(0xbeefbeef);
     for (i = 0; i < 1024; i++) check_table(table, random(), i);
     srandom(0xbeefbeef);
@@ -207,7 +204,7 @@ int main(void)
     printf("\n***** 5000 random integers ****\n");
     table = drmHashCreate();
     srandom(0xbeefbeef);
-    for (i = 0; i < 5000; i++) drmHashInsert(table, random(), i);
+    for (i = 0; i < 5000; i++) drmHashInsert(table, random(), (void *)&i);
     srandom(0xbeefbeef);
     for (i = 0; i < 5000; i++) check_table(table, random(), i);
     srandom(0xbeefbeef);
-- 
2.3.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2015-03-22 22:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-22 22:03 [PATCH libdrm 0/9] Rework remaining tests Emil Velikov
2015-03-22 22:03 ` [PATCH libdrm 1/9] tests/dristat: don't include C files Emil Velikov
2015-03-23 22:10   ` Jan Vesely
2015-03-26 14:59     ` Emil Velikov
2015-03-22 22:03 ` [PATCH libdrm 2/9] tests/hash: extract test out of xf86drmHash.c Emil Velikov
2015-03-23 22:27   ` Jan Vesely
2015-03-22 22:03 ` Emil Velikov [this message]
2015-03-23 22:42   ` [PATCH libdrm 3/9] tests/hash: misc compilation fixes Jan Vesely
2015-03-22 22:03 ` [PATCH libdrm 4/9] tests/hash: style fixes Emil Velikov
2015-03-23 22:46   ` Jan Vesely
2015-03-22 22:03 ` [PATCH libdrm 5/9] tests/hash: return non-zero on failure Emil Velikov
2015-03-23 23:08   ` Jan Vesely
2015-03-22 22:03 ` [PATCH libdrm 6/9] tests/random: extract test out of xf86drmRandom.c Emil Velikov
2015-03-24 22:10   ` Jan Vesely
2015-03-22 22:03 ` [PATCH libdrm 7/9] tests/random: return non-zero on test failure Emil Velikov
2015-03-24 22:12   ` Jan Vesely
2015-03-22 22:03 ` [PATCH libdrm 8/9] drm: replace HASH_DEBUG with DEBUG Emil Velikov
2015-03-24  0:01   ` Jan Vesely
2015-03-22 22:03 ` [PATCH libdrm 9/9] drm: use correct printf modifiers Emil Velikov
2015-03-24  0:04   ` Jan Vesely
2015-03-24 23:20 ` [PATCH libdrm 0/9] Rework remaining tests Jan Vesely
2015-03-26 15:14   ` Emil Velikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427061825-27470-4-git-send-email-emil.l.velikov@gmail.com \
    --to=emil.l.velikov@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.