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)main
parent
4fcb6637f0
commit
7e4f0664ac
|
@ -29,15 +29,15 @@ LDADD = $(top_builddir)/libdrm.la
|
||||||
|
|
||||||
check_PROGRAMS = \
|
check_PROGRAMS = \
|
||||||
dristat \
|
dristat \
|
||||||
drmstat \
|
drmstat
|
||||||
hash
|
|
||||||
|
|
||||||
if HAVE_NOUVEAU
|
if HAVE_NOUVEAU
|
||||||
SUBDIRS += nouveau
|
SUBDIRS += nouveau
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TESTS = \
|
TESTS = \
|
||||||
drmsl
|
drmsl \
|
||||||
|
hash
|
||||||
|
|
||||||
if HAVE_LIBUDEV
|
if HAVE_LIBUDEV
|
||||||
|
|
||||||
|
|
24
tests/hash.c
24
tests/hash.c
|
@ -121,7 +121,7 @@ static void compute_dist(HashTablePtr table)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_table(HashTablePtr table,
|
static int check_table(HashTablePtr table,
|
||||||
unsigned long key, void * value)
|
unsigned long key, void * value)
|
||||||
{
|
{
|
||||||
void *retval;
|
void *retval;
|
||||||
|
@ -138,28 +138,32 @@ static void check_table(HashTablePtr table,
|
||||||
key, value, retval);
|
key, value, retval);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
if (value != retval)
|
if (value != retval) {
|
||||||
printf("Bad value: key = %lu, expected = %p, returned = %p\n",
|
printf("Bad value: key = %lu, expected = %p, returned = %p\n",
|
||||||
key, value, retval);
|
key, value, retval);
|
||||||
|
retcode = -1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n",
|
printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n",
|
||||||
retcode, key, value, retval);
|
retcode, key, value, retval);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
HashTablePtr table;
|
HashTablePtr table;
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
printf("\n***** 256 consecutive integers ****\n");
|
printf("\n***** 256 consecutive integers ****\n");
|
||||||
table = drmHashCreate();
|
table = drmHashCreate();
|
||||||
for (i = 0; i < 256; i++)
|
for (i = 0; i < 256; i++)
|
||||||
drmHashInsert(table, i, (void *)(i << 16 | i));
|
drmHashInsert(table, i, (void *)(i << 16 | i));
|
||||||
for (i = 0; i < 256; 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);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
|
@ -168,7 +172,7 @@ int main(void)
|
||||||
for (i = 0; i < 1024; i++)
|
for (i = 0; i < 1024; i++)
|
||||||
drmHashInsert(table, i, (void *)(i << 16 | i));
|
drmHashInsert(table, i, (void *)(i << 16 | i));
|
||||||
for (i = 0; i < 1024; 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);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
|
@ -177,7 +181,7 @@ int main(void)
|
||||||
for (i = 0; i < 1024; i++)
|
for (i = 0; i < 1024; i++)
|
||||||
drmHashInsert(table, i*4096, (void *)(i << 16 | i));
|
drmHashInsert(table, i*4096, (void *)(i << 16 | i));
|
||||||
for (i = 0; i < 1024; 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);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
|
@ -188,10 +192,10 @@ int main(void)
|
||||||
drmHashInsert(table, random(), (void *)(i << 16 | i));
|
drmHashInsert(table, random(), (void *)(i << 16 | i));
|
||||||
srandom(0xbeefbeef);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 1024; i++)
|
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);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 1024; i++)
|
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);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
|
@ -202,12 +206,12 @@ int main(void)
|
||||||
drmHashInsert(table, random(), (void *)(i << 16 | i));
|
drmHashInsert(table, random(), (void *)(i << 16 | i));
|
||||||
srandom(0xbeefbeef);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 5000; i++)
|
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);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 5000; i++)
|
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);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue