summaryrefslogtreecommitdiff
path: root/src/dict.c
diff options
context:
space:
mode:
authorsundb <sundbcn@gmail.com>2021-03-10 15:13:11 +0800
committerGitHub <noreply@github.com>2021-03-10 09:13:11 +0200
commit95d6297db868fc5400fb833c6753c8d25da486c7 (patch)
treeb17d7104207ca020b35e9ffebb09cd5bfe89de37 /src/dict.c
parent53774e69fa68450859a566e84f06d4b8a7a53eca (diff)
downloadredis-95d6297db868fc5400fb833c6753c8d25da486c7.tar.gz
Add run all test support with define REDIS_TEST (#8570)
1. Add `redis-server test all` support to run all tests. 2. Add redis test to daily ci. 3. Add `--accurate` option to run slow tests for more iterations (so that by default we run less cycles (shorter time, and less prints). 4. Move dict benchmark to REDIS_TEST. 5. fix some leaks in tests 6. make quicklist tests run on a specific fill set of options rather than huge ranges 7. move some prints in quicklist test outside their loops to reduce prints 8. removing sds.h from dict.c since it is now used in both redis-server and redis-cli (uses hiredis sds)
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/dict.c b/src/dict.c
index 4a9f3fb0a..21c616e6f 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -45,11 +45,7 @@
#include "dict.h"
#include "zmalloc.h"
-#ifndef DICT_BENCHMARK_MAIN
#include "redisassert.h"
-#else
-#include <assert.h>
-#endif
/* Using dictEnableResize() / dictDisableResize() we make possible to
* enable/disable resizing of the hash table as needed. This is very important
@@ -1175,20 +1171,18 @@ void dictGetStats(char *buf, size_t bufsize, dict *d) {
/* ------------------------------- Benchmark ---------------------------------*/
-#ifdef DICT_BENCHMARK_MAIN
-
-#include "sds.h"
+#ifdef REDIS_TEST
uint64_t hashCallback(const void *key) {
- return dictGenHashFunction((unsigned char*)key, sdslen((char*)key));
+ return dictGenHashFunction((unsigned char*)key, strlen((char*)key));
}
int compareCallback(void *privdata, const void *key1, const void *key2) {
int l1,l2;
DICT_NOTUSED(privdata);
- l1 = sdslen((sds)key1);
- l2 = sdslen((sds)key2);
+ l1 = strlen((char*)key1);
+ l2 = strlen((char*)key2);
if (l1 != l2) return 0;
return memcmp(key1, key2, l1) == 0;
}
@@ -1196,7 +1190,19 @@ int compareCallback(void *privdata, const void *key1, const void *key2) {
void freeCallback(void *privdata, void *val) {
DICT_NOTUSED(privdata);
- sdsfree(val);
+ zfree(val);
+}
+
+char *stringFromLongLong(long long value) {
+ char buf[32];
+ int len;
+ char *s;
+
+ len = sprintf(buf,"%lld",value);
+ s = zmalloc(len+1);
+ memcpy(s, buf, len);
+ s[len] = '\0';
+ return s;
}
dictType BenchmarkDictType = {
@@ -1215,22 +1221,26 @@ dictType BenchmarkDictType = {
printf(msg ": %ld items in %lld ms\n", count, elapsed); \
} while(0)
-/* dict-benchmark [count] */
-int main(int argc, char **argv) {
+/* ./redis-server test dict [<count> | --accurate] */
+int dictTest(int argc, char **argv, int accurate) {
long j;
long long start, elapsed;
dict *dict = dictCreate(&BenchmarkDictType,NULL);
long count = 0;
- if (argc == 2) {
- count = strtol(argv[1],NULL,10);
+ if (argc == 4) {
+ if (accurate) {
+ count = 5000000;
+ } else {
+ count = strtol(argv[3],NULL,10);
+ }
} else {
- count = 5000000;
+ count = 5000;
}
start_benchmark();
for (j = 0; j < count; j++) {
- int retval = dictAdd(dict,sdsfromlonglong(j),(void*)j);
+ int retval = dictAdd(dict,stringFromLongLong(j),(void*)j);
assert(retval == DICT_OK);
}
end_benchmark("Inserting");
@@ -1243,28 +1253,28 @@ int main(int argc, char **argv) {
start_benchmark();
for (j = 0; j < count; j++) {
- sds key = sdsfromlonglong(j);
+ char *key = stringFromLongLong(j);
dictEntry *de = dictFind(dict,key);
assert(de != NULL);
- sdsfree(key);
+ zfree(key);
}
end_benchmark("Linear access of existing elements");
start_benchmark();
for (j = 0; j < count; j++) {
- sds key = sdsfromlonglong(j);
+ char *key = stringFromLongLong(j);
dictEntry *de = dictFind(dict,key);
assert(de != NULL);
- sdsfree(key);
+ zfree(key);
}
end_benchmark("Linear access of existing elements (2nd round)");
start_benchmark();
for (j = 0; j < count; j++) {
- sds key = sdsfromlonglong(rand() % count);
+ char *key = stringFromLongLong(rand() % count);
dictEntry *de = dictFind(dict,key);
assert(de != NULL);
- sdsfree(key);
+ zfree(key);
}
end_benchmark("Random access of existing elements");
@@ -1277,17 +1287,17 @@ int main(int argc, char **argv) {
start_benchmark();
for (j = 0; j < count; j++) {
- sds key = sdsfromlonglong(rand() % count);
+ char *key = stringFromLongLong(rand() % count);
key[0] = 'X';
dictEntry *de = dictFind(dict,key);
assert(de == NULL);
- sdsfree(key);
+ zfree(key);
}
end_benchmark("Accessing missing");
start_benchmark();
for (j = 0; j < count; j++) {
- sds key = sdsfromlonglong(j);
+ char *key = stringFromLongLong(j);
int retval = dictDelete(dict,key);
assert(retval == DICT_OK);
key[0] += 17; /* Change first number to letter. */
@@ -1295,5 +1305,7 @@ int main(int argc, char **argv) {
assert(retval == DICT_OK);
}
end_benchmark("Removing and adding");
+ dictRelease(dict);
+ return 0;
}
#endif