summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-02-25 13:02:04 +0100
committerantirez <antirez@gmail.com>2015-02-25 13:02:04 +0100
commitcc0d339bd19d37367806cc95111f1539aa268004 (patch)
treeab55ff1e6668901641c681394905c61cbebdbaa9 /utils
parent126462ee3676777e8e72669d1abb3ae5c429805f (diff)
downloadredis-cc0d339bd19d37367806cc95111f1539aa268004.tar.gz
utils/hashtable/rehashing.c test updated to use new API.
Diffstat (limited to 'utils')
-rw-r--r--utils/hashtable/rehashing.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/utils/hashtable/rehashing.c b/utils/hashtable/rehashing.c
index c900a8d2f..b57a9043a 100644
--- a/utils/hashtable/rehashing.c
+++ b/utils/hashtable/rehashing.c
@@ -68,26 +68,30 @@ int sortPointers(const void *a, const void *b) {
return la-lb;
}
-void stressGetKeys(dict *d, int times) {
+void stressGetKeys(dict *d, int times, int *perfect_run, int *approx_run) {
int j;
+
dictEntry **des = zmalloc(sizeof(dictEntry*)*dictSize(d));
for (j = 0; j < times; j++) {
int requested = rand() % (dictSize(d)+1);
int returned = dictGetSomeKeys(d, des, requested);
- if (requested != returned) {
- printf("*** ERROR! Req: %d, Ret: %d\n", requested, returned);
- exit(1);
- }
+ int dup = 0;
+
qsort(des,returned,sizeof(dictEntry*),sortPointers);
if (returned > 1) {
int i;
for (i = 0; i < returned-1; i++) {
- if (des[i] == des[i+1]) {
- printf("*** ERROR! Duplicated element detected\n");
- exit(1);
- }
+ if (des[i] == des[i+1]) dup++;
}
}
+
+ if (requested == returned && dup == 0) {
+ (*perfect_run)++;
+ } else {
+ (*approx_run)++;
+ printf("Requested, returned, duplicated: %d %d %d\n",
+ requested, returned, dup);
+ }
}
zfree(des);
}
@@ -113,18 +117,24 @@ int main(void) {
dictRelease(d);
d = dictCreate(&dictTypeTest,NULL);
- printf("Getkeys stress test\n");
+
+ printf("Stress testing dictGetSomeKeys\n");
+ int perfect_run = 0, approx_run = 0;
for (i = 0; i < MAX2; i++) {
dictAdd(d,(void*)i,NULL);
- stressGetKeys(d,100);
+ stressGetKeys(d,100,&perfect_run,&approx_run);
}
for (i = 0; i < MAX2; i++) {
dictDelete(d,(void*)i);
dictResize(d);
- stressGetKeys(d,100);
+ stressGetKeys(d,100,&perfect_run,&approx_run);
}
+
+ printf("dictGetSomeKey, %d perfect runs, %d approximated runs\n",
+ perfect_run, approx_run);
+
dictRelease(d);
printf("TEST PASSED!\n");