summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2015-04-05 15:12:16 +0100
committerEmil Velikov <emil.l.velikov@gmail.com>2015-04-05 15:33:06 +0100
commit7e4f0664acfa79448f6e32c1f1b12b94626777b2 (patch)
tree2c8d84c9168e5510c0a76348775edc0b2b2cae6f /tests
parent4fcb6637f0508a0ed0be190d2f5518a2fa9cd041 (diff)
tests/hash: return non-zero on failure
... and wire up to `make check' now that it's useful. v2: Really return non-zero on failure. v3: Initialise ret. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Jan Vesely <jan.vesely@rutgers.edu> (v2)
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am6
-rw-r--r--tests/hash.c26
2 files changed, 18 insertions, 14 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d4674f75..2e0520a7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,15 +29,15 @@ LDADD = $(top_builddir)/libdrm.la
check_PROGRAMS = \
dristat \
- drmstat \
- hash
+ drmstat
if HAVE_NOUVEAU
SUBDIRS += nouveau
endif
TESTS = \
- drmsl
+ drmsl \
+ hash
if HAVE_LIBUDEV
diff --git a/tests/hash.c b/tests/hash.c
index 1543c86a..4475fba9 100644
--- a/tests/hash.c
+++ b/tests/hash.c
@@ -121,8 +121,8 @@ static void compute_dist(HashTablePtr table)
}
}
-static void check_table(HashTablePtr table,
- unsigned long key, void * value)
+static int check_table(HashTablePtr table,
+ unsigned long key, void * value)
{
void *retval;
int retcode = drmHashLookup(table, key, &retval);
@@ -138,28 +138,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 = %p, returned = %p\n",
key, value, retval);
+ retcode = -1;
+ }
break;
default:
printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n",
retcode, key, value, retval);
break;
}
+ return retcode;
}
int main(void)
{
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 << 16 | i));
for (i = 0; i < 256; i++)
- check_table(table, i, (void *)(i << 16 | i));
+ ret |= check_table(table, i, (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
@@ -168,7 +172,7 @@ int main(void)
for (i = 0; i < 1024; i++)
drmHashInsert(table, i, (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
- check_table(table, i, (void *)(i << 16 | i));
+ ret |= check_table(table, i, (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
@@ -177,7 +181,7 @@ int main(void)
for (i = 0; i < 1024; i++)
drmHashInsert(table, i*4096, (void *)(i << 16 | i));
for (i = 0; i < 1024; i++)
- check_table(table, i*4096, (void *)(i << 16 | i));
+ ret |= check_table(table, i*4096, (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
@@ -188,10 +192,10 @@ int main(void)
drmHashInsert(table, random(), (void *)(i << 16 | i));
srandom(0xbeefbeef);
for (i = 0; i < 1024; i++)
- check_table(table, random(), (void *)(i << 16 | i));
+ ret |= check_table(table, random(), (void *)(i << 16 | i));
srandom(0xbeefbeef);
for (i = 0; i < 1024; i++)
- check_table(table, random(), (void *)(i << 16 | i));
+ ret |= check_table(table, random(), (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
@@ -202,12 +206,12 @@ int main(void)
drmHashInsert(table, random(), (void *)(i << 16 | i));
srandom(0xbeefbeef);
for (i = 0; i < 5000; i++)
- check_table(table, random(), (void *)(i << 16 | i));
+ ret |= check_table(table, random(), (void *)(i << 16 | i));
srandom(0xbeefbeef);
for (i = 0; i < 5000; i++)
- check_table(table, random(), (void *)(i << 16 | i));
+ ret |= check_table(table, random(), (void *)(i << 16 | i));
compute_dist(table);
drmHashDestroy(table);
- return 0;
+ return ret;
}