X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fhtable%2Ftest%2Frun-extra.c;fp=ccan%2Fhtable%2Ftest%2Frun-extra.c;h=33821545abdb1ea9946720fe55e743ef84c37fe2;hp=0000000000000000000000000000000000000000;hb=6a8bb2092789b5b8cf9430bc188597074a17d995;hpb=fe328d06ed6df8d5a92eaab4be2d645affeeb99e diff --git a/ccan/htable/test/run-extra.c b/ccan/htable/test/run-extra.c new file mode 100644 index 00000000..33821545 --- /dev/null +++ b/ccan/htable/test/run-extra.c @@ -0,0 +1,51 @@ +#include "../htable.c" + +static size_t hash(const void *ptr, void *priv UNNEEDED) +{ + /* We're hashing pointers; no need to get too fancy. */ + return ((size_t)ptr / sizeof(ptr)) ^ ((size_t)ptr % sizeof(ptr)); +} + +/* 24042: Waiting on 0x5570a500c3f8 (11742786623615) +24042: Waiting on 0x5570a500c430 (11742786623622) +24042: Searching for 0x5570a500c3f8 (11742786623615) in 2 elems +24042: Searching for 0x5570a500c3f8 (11742786623615) in 2 elems +*/ +static struct htable waittable = HTABLE_INITIALIZER(waittable, hash, NULL); + +int main(void) +{ + const void *p1 = (void *)0x5570a500c3f8ULL; + const void *p2 = (void *)0x5570a500c430ULL; + size_t h; + struct htable_iter i; + void *p; + bool found; + + printf("hash %p == %zu\n", p1, hash(p1, NULL)); + printf("hash %p == %zu\n", p2, hash(p2, NULL)); + htable_add(&waittable, hash(p1, NULL), p1); + htable_add(&waittable, hash(p2, NULL), p2); + + found = false; + h = hash(p1, NULL); + for (p = htable_firstval(&waittable, &i, h); + p; + p = htable_nextval(&waittable, &i, h)) { + if (p == p1) + found = true; + } + assert(found); + + found = false; + h = hash(p2, NULL); + for (p = htable_firstval(&waittable, &i, h); + p; + p = htable_nextval(&waittable, &i, h)) { + if (p == p2) + found = true; + } + assert(found); + + return found ? 0 : 1; +}