tests/hash: misc compilation fixes
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). v2: - Use void * instead of unsigned long. - Change value to key << 16 | key. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Jan Vesely <jan.vesely@rutgers.edu>main
parent
79f9cf3eb7
commit
c53da3ac57
41
tests/hash.c
41
tests/hash.c
|
@ -116,28 +116,28 @@ static void compute_dist(HashTablePtr table)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_table(HashTablePtr table,
|
static void check_table(HashTablePtr table,
|
||||||
unsigned long key, unsigned long value)
|
unsigned long key, void * value)
|
||||||
{
|
{
|
||||||
unsigned long retval = 0;
|
void *retval;
|
||||||
int retcode = drmHashLookup(table, key, &retval);
|
int retcode = drmHashLookup(table, key, &retval);
|
||||||
|
|
||||||
switch (retcode) {
|
switch (retcode) {
|
||||||
case -1:
|
case -1:
|
||||||
printf("Bad magic = 0x%08lx:"
|
printf("Bad magic = 0x%08lx:"
|
||||||
" key = %lu, expected = %lu, returned = %lu\n",
|
" key = %lu, expected = %p, returned = %p\n",
|
||||||
table->magic, key, value, retval);
|
table->magic, key, value, retval);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
printf("Not found: key = %lu, expected = %lu returned = %lu\n",
|
printf("Not found: key = %lu, expected = %p, returned = %p\n",
|
||||||
key, value, retval);
|
key, value, retval);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
if (value != retval)
|
if (value != retval)
|
||||||
printf("Bad value: key = %lu, expected = %lu, returned = %lu\n",
|
printf("Bad value: key = %lu, expected = %p, returned = %p\n",
|
||||||
key, value, retval);
|
key, value, retval);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Bad retcode = %d: key = %lu, expected = %lu, returned = %lu\n",
|
printf("Bad retcode = %d: key = %lu, expected = %p, returned = %p\n",
|
||||||
retcode, key, value, retval);
|
retcode, key, value, retval);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -146,51 +146,48 @@ static void check_table(HashTablePtr table,
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
HashTablePtr table;
|
HashTablePtr table;
|
||||||
int i;
|
unsigned long i;
|
||||||
|
|
||||||
printf("\n***** 256 consecutive integers ****\n");
|
printf("\n***** 256 consecutive integers ****\n");
|
||||||
table = drmHashCreate();
|
table = drmHashCreate();
|
||||||
for (i = 0; i < 256; i++) drmHashInsert(table, i, i);
|
for (i = 0; i < 256; i++) drmHashInsert(table, i, (void *)(i << 16 | i));
|
||||||
for (i = 0; i < 256; i++) check_table(table, i, i);
|
for (i = 0; i < 256; i++) check_table(table, i, (void *)(i << 16 | i));
|
||||||
for (i = 256; i >= 0; i--) check_table(table, i, i);
|
|
||||||
compute_dist(table);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
printf("\n***** 1024 consecutive integers ****\n");
|
printf("\n***** 1024 consecutive integers ****\n");
|
||||||
table = drmHashCreate();
|
table = drmHashCreate();
|
||||||
for (i = 0; i < 1024; i++) drmHashInsert(table, i, i);
|
for (i = 0; i < 1024; i++) drmHashInsert(table, i, (void *)(i << 16 | i));
|
||||||
for (i = 0; i < 1024; i++) check_table(table, i, i);
|
for (i = 0; i < 1024; i++) check_table(table, i, (void *)(i << 16 | i));
|
||||||
for (i = 1024; i >= 0; i--) check_table(table, i, i);
|
|
||||||
compute_dist(table);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
printf("\n***** 1024 consecutive page addresses (4k pages) ****\n");
|
printf("\n***** 1024 consecutive page addresses (4k pages) ****\n");
|
||||||
table = drmHashCreate();
|
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 << 16 | i));
|
||||||
for (i = 0; i < 1024; i++) check_table(table, i*4096, i);
|
for (i = 0; i < 1024; i++) check_table(table, i*4096, (void *)(i << 16 | i));
|
||||||
for (i = 1024; i >= 0; i--) check_table(table, i*4096, i);
|
|
||||||
compute_dist(table);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
printf("\n***** 1024 random integers ****\n");
|
printf("\n***** 1024 random integers ****\n");
|
||||||
table = drmHashCreate();
|
table = drmHashCreate();
|
||||||
srandom(0xbeefbeef);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 1024; i++) drmHashInsert(table, random(), i);
|
for (i = 0; i < 1024; i++) drmHashInsert(table, random(), (void *)(i << 16 | i));
|
||||||
srandom(0xbeefbeef);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 1024; i++) check_table(table, random(), i);
|
for (i = 0; i < 1024; i++) check_table(table, random(), (void *)(i << 16 | i));
|
||||||
srandom(0xbeefbeef);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 1024; i++) check_table(table, random(), i);
|
for (i = 0; i < 1024; i++) check_table(table, random(), (void *)(i << 16 | i));
|
||||||
compute_dist(table);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
printf("\n***** 5000 random integers ****\n");
|
printf("\n***** 5000 random integers ****\n");
|
||||||
table = drmHashCreate();
|
table = drmHashCreate();
|
||||||
srandom(0xbeefbeef);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 5000; i++) drmHashInsert(table, random(), i);
|
for (i = 0; i < 5000; i++) drmHashInsert(table, random(), (void *)(i << 16 | i));
|
||||||
srandom(0xbeefbeef);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 5000; i++) check_table(table, random(), i);
|
for (i = 0; i < 5000; i++) check_table(table, random(), (void *)(i << 16 | i));
|
||||||
srandom(0xbeefbeef);
|
srandom(0xbeefbeef);
|
||||||
for (i = 0; i < 5000; i++) check_table(table, random(), i);
|
for (i = 0; i < 5000; i++) check_table(table, random(), (void *)(i << 16 | i));
|
||||||
compute_dist(table);
|
compute_dist(table);
|
||||||
drmHashDestroy(table);
|
drmHashDestroy(table);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue