Unverified Commit 95d6297d authored by sundb's avatar sundb Committed by GitHub
Browse files

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)
parent 53774e69
...@@ -17,7 +17,7 @@ jobs: ...@@ -17,7 +17,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: make - name: make
run: make run: make REDIS_CFLAGS='-Werror -DREDIS_TEST'
- name: test - name: test
run: | run: |
sudo apt-get install tcl8.6 sudo apt-get install tcl8.6
...@@ -28,6 +28,8 @@ jobs: ...@@ -28,6 +28,8 @@ jobs:
run: ./runtest-sentinel run: ./runtest-sentinel
- name: cluster tests - name: cluster tests
run: ./runtest-cluster run: ./runtest-cluster
- name: unittest
run: ./src/redis-server test all
test-ubuntu-libc-malloc: test-ubuntu-libc-malloc:
runs-on: ubuntu-latest runs-on: ubuntu-latest
...@@ -76,7 +78,7 @@ jobs: ...@@ -76,7 +78,7 @@ jobs:
- name: make - name: make
run: | run: |
sudo apt-get update && sudo apt-get install libc6-dev-i386 sudo apt-get update && sudo apt-get install libc6-dev-i386
make 32bit make 32bit REDIS_CFLAGS='-Werror -DREDIS_TEST'
- name: test - name: test
run: | run: |
sudo apt-get install tcl8.6 sudo apt-get install tcl8.6
...@@ -89,6 +91,8 @@ jobs: ...@@ -89,6 +91,8 @@ jobs:
run: ./runtest-sentinel run: ./runtest-sentinel
- name: cluster tests - name: cluster tests
run: ./runtest-cluster run: ./runtest-cluster
- name: unittest
run: ./src/redis-server test all
test-ubuntu-tls: test-ubuntu-tls:
runs-on: ubuntu-latest runs-on: ubuntu-latest
...@@ -142,7 +146,7 @@ jobs: ...@@ -142,7 +146,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: make - name: make
run: make valgrind run: make valgrind REDIS_CFLAGS='-Werror -DREDIS_TEST'
- name: test - name: test
run: | run: |
sudo apt-get update sudo apt-get update
...@@ -150,6 +154,10 @@ jobs: ...@@ -150,6 +154,10 @@ jobs:
./runtest --valgrind --verbose --clients 1 --dump-logs ./runtest --valgrind --verbose --clients 1 --dump-logs
- name: module api test - name: module api test
run: ./runtest-moduleapi --valgrind --no-latency --verbose --clients 1 run: ./runtest-moduleapi --valgrind --no-latency --verbose --clients 1
- name: unittest
run: |
valgrind --track-origins=yes --suppressions=./src/valgrind.sup --show-reachable=no --show-possibly-lost=no --leak-check=full --log-file=err.txt ./src/redis-server test all
if grep -q 0x err.txt; then cat err.txt; exit 1; fi
test-valgrind-no-malloc-usable-size: test-valgrind-no-malloc-usable-size:
runs-on: ubuntu-latest runs-on: ubuntu-latest
......
...@@ -351,9 +351,6 @@ $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ) ...@@ -351,9 +351,6 @@ $(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ) $(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/hdr_histogram/hdr_histogram.o $(FINAL_LIBS) $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/hdr_histogram/hdr_histogram.o $(FINAL_LIBS)
dict-benchmark: dict.c zmalloc.c sds.c siphash.c mt19937-64.c
$(REDIS_CC) $(FINAL_CFLAGS) $^ -D DICT_BENCHMARK_MAIN -o $@ $(FINAL_LIBS)
DEP = $(REDIS_SERVER_OBJ:%.o=%.d) $(REDIS_CLI_OBJ:%.o=%.d) $(REDIS_BENCHMARK_OBJ:%.o=%.d) DEP = $(REDIS_SERVER_OBJ:%.o=%.d) $(REDIS_CLI_OBJ:%.o=%.d) $(REDIS_BENCHMARK_OBJ:%.o=%.d)
-include $(DEP) -include $(DEP)
...@@ -364,7 +361,7 @@ DEP = $(REDIS_SERVER_OBJ:%.o=%.d) $(REDIS_CLI_OBJ:%.o=%.d) $(REDIS_BENCHMARK_OBJ ...@@ -364,7 +361,7 @@ DEP = $(REDIS_SERVER_OBJ:%.o=%.d) $(REDIS_CLI_OBJ:%.o=%.d) $(REDIS_BENCHMARK_OBJ
$(REDIS_CC) -MMD -o $@ -c $< $(REDIS_CC) -MMD -o $@ -c $<
clean: clean:
rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep
rm -f $(DEP) rm -f $(DEP)
.PHONY: clean .PHONY: clean
......
...@@ -127,9 +127,10 @@ uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l) { ...@@ -127,9 +127,10 @@ uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l) {
#include <stdio.h> #include <stdio.h>
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int crc64Test(int argc, char *argv[]) { int crc64Test(int argc, char *argv[], int accurate) {
UNUSED(argc); UNUSED(argc);
UNUSED(argv); UNUSED(argv);
UNUSED(accurate);
crc64_init(); crc64_init();
printf("[calcula]: e9c6d914c4b8d9ca == %016" PRIx64 "\n", printf("[calcula]: e9c6d914c4b8d9ca == %016" PRIx64 "\n",
(uint64_t)_crc64(0, "123456789", 9)); (uint64_t)_crc64(0, "123456789", 9));
......
...@@ -7,7 +7,7 @@ void crc64_init(void); ...@@ -7,7 +7,7 @@ void crc64_init(void);
uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l); uint64_t crc64(uint64_t crc, const unsigned char *s, uint64_t l);
#ifdef REDIS_TEST #ifdef REDIS_TEST
int crc64Test(int argc, char *argv[]); int crc64Test(int argc, char *argv[], int accurate);
#endif #endif
#endif #endif
...@@ -45,11 +45,7 @@ ...@@ -45,11 +45,7 @@
#include "dict.h" #include "dict.h"
#include "zmalloc.h" #include "zmalloc.h"
#ifndef DICT_BENCHMARK_MAIN
#include "redisassert.h" #include "redisassert.h"
#else
#include <assert.h>
#endif
/* Using dictEnableResize() / dictDisableResize() we make possible to /* Using dictEnableResize() / dictDisableResize() we make possible to
* enable/disable resizing of the hash table as needed. This is very important * 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) { ...@@ -1175,20 +1171,18 @@ void dictGetStats(char *buf, size_t bufsize, dict *d) {
/* ------------------------------- Benchmark ---------------------------------*/ /* ------------------------------- Benchmark ---------------------------------*/
#ifdef DICT_BENCHMARK_MAIN #ifdef REDIS_TEST
#include "sds.h"
uint64_t hashCallback(const void *key) { 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 compareCallback(void *privdata, const void *key1, const void *key2) {
int l1,l2; int l1,l2;
DICT_NOTUSED(privdata); DICT_NOTUSED(privdata);
l1 = sdslen((sds)key1); l1 = strlen((char*)key1);
l2 = sdslen((sds)key2); l2 = strlen((char*)key2);
if (l1 != l2) return 0; if (l1 != l2) return 0;
return memcmp(key1, key2, l1) == 0; return memcmp(key1, key2, l1) == 0;
} }
...@@ -1196,7 +1190,19 @@ int compareCallback(void *privdata, const void *key1, const void *key2) { ...@@ -1196,7 +1190,19 @@ int compareCallback(void *privdata, const void *key1, const void *key2) {
void freeCallback(void *privdata, void *val) { void freeCallback(void *privdata, void *val) {
DICT_NOTUSED(privdata); 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 = { dictType BenchmarkDictType = {
...@@ -1215,22 +1221,26 @@ dictType BenchmarkDictType = { ...@@ -1215,22 +1221,26 @@ dictType BenchmarkDictType = {
printf(msg ": %ld items in %lld ms\n", count, elapsed); \ printf(msg ": %ld items in %lld ms\n", count, elapsed); \
} while(0) } while(0)
/* dict-benchmark [count] */ /* ./redis-server test dict [<count> | --accurate] */
int main(int argc, char **argv) { int dictTest(int argc, char **argv, int accurate) {
long j; long j;
long long start, elapsed; long long start, elapsed;
dict *dict = dictCreate(&BenchmarkDictType,NULL); dict *dict = dictCreate(&BenchmarkDictType,NULL);
long count = 0; long count = 0;
if (argc == 2) { if (argc == 4) {
count = strtol(argv[1],NULL,10); if (accurate) {
count = 5000000;
} else {
count = strtol(argv[3],NULL,10);
}
} else { } else {
count = 5000000; count = 5000;
} }
start_benchmark(); start_benchmark();
for (j = 0; j < count; j++) { 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); assert(retval == DICT_OK);
} }
end_benchmark("Inserting"); end_benchmark("Inserting");
...@@ -1243,28 +1253,28 @@ int main(int argc, char **argv) { ...@@ -1243,28 +1253,28 @@ int main(int argc, char **argv) {
start_benchmark(); start_benchmark();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {
sds key = sdsfromlonglong(j); char *key = stringFromLongLong(j);
dictEntry *de = dictFind(dict,key); dictEntry *de = dictFind(dict,key);
assert(de != NULL); assert(de != NULL);
sdsfree(key); zfree(key);
} }
end_benchmark("Linear access of existing elements"); end_benchmark("Linear access of existing elements");
start_benchmark(); start_benchmark();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {
sds key = sdsfromlonglong(j); char *key = stringFromLongLong(j);
dictEntry *de = dictFind(dict,key); dictEntry *de = dictFind(dict,key);
assert(de != NULL); assert(de != NULL);
sdsfree(key); zfree(key);
} }
end_benchmark("Linear access of existing elements (2nd round)"); end_benchmark("Linear access of existing elements (2nd round)");
start_benchmark(); start_benchmark();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {
sds key = sdsfromlonglong(rand() % count); char *key = stringFromLongLong(rand() % count);
dictEntry *de = dictFind(dict,key); dictEntry *de = dictFind(dict,key);
assert(de != NULL); assert(de != NULL);
sdsfree(key); zfree(key);
} }
end_benchmark("Random access of existing elements"); end_benchmark("Random access of existing elements");
...@@ -1277,17 +1287,17 @@ int main(int argc, char **argv) { ...@@ -1277,17 +1287,17 @@ int main(int argc, char **argv) {
start_benchmark(); start_benchmark();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {
sds key = sdsfromlonglong(rand() % count); char *key = stringFromLongLong(rand() % count);
key[0] = 'X'; key[0] = 'X';
dictEntry *de = dictFind(dict,key); dictEntry *de = dictFind(dict,key);
assert(de == NULL); assert(de == NULL);
sdsfree(key); zfree(key);
} }
end_benchmark("Accessing missing"); end_benchmark("Accessing missing");
start_benchmark(); start_benchmark();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {
sds key = sdsfromlonglong(j); char *key = stringFromLongLong(j);
int retval = dictDelete(dict,key); int retval = dictDelete(dict,key);
assert(retval == DICT_OK); assert(retval == DICT_OK);
key[0] += 17; /* Change first number to letter. */ key[0] += 17; /* Change first number to letter. */
...@@ -1295,5 +1305,7 @@ int main(int argc, char **argv) { ...@@ -1295,5 +1305,7 @@ int main(int argc, char **argv) {
assert(retval == DICT_OK); assert(retval == DICT_OK);
} }
end_benchmark("Removing and adding"); end_benchmark("Removing and adding");
dictRelease(dict);
return 0;
} }
#endif #endif
...@@ -201,4 +201,8 @@ extern dictType dictTypeHeapStringCopyKey; ...@@ -201,4 +201,8 @@ extern dictType dictTypeHeapStringCopyKey;
extern dictType dictTypeHeapStrings; extern dictType dictTypeHeapStrings;
extern dictType dictTypeHeapStringCopyKeyValue; extern dictType dictTypeHeapStringCopyKeyValue;
#ifdef REDIS_TEST
int dictTest(int argc, char *argv[], int accurate);
#endif
#endif /* __DICT_H */ #endif /* __DICT_H */
...@@ -105,11 +105,12 @@ uint64_t intrev64(uint64_t v) { ...@@ -105,11 +105,12 @@ uint64_t intrev64(uint64_t v) {
#include <stdio.h> #include <stdio.h>
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int endianconvTest(int argc, char *argv[]) { int endianconvTest(int argc, char *argv[], int accurate) {
char buf[32]; char buf[32];
UNUSED(argc); UNUSED(argc);
UNUSED(argv); UNUSED(argv);
UNUSED(accurate);
sprintf(buf,"ciaoroma"); sprintf(buf,"ciaoroma");
memrev16(buf); memrev16(buf);
......
...@@ -72,7 +72,7 @@ uint64_t intrev64(uint64_t v); ...@@ -72,7 +72,7 @@ uint64_t intrev64(uint64_t v);
#endif #endif
#ifdef REDIS_TEST #ifdef REDIS_TEST
int endianconvTest(int argc, char *argv[]); int endianconvTest(int argc, char *argv[], int accurate);
#endif #endif
#endif #endif
...@@ -392,7 +392,7 @@ static void checkConsistency(intset *is) { ...@@ -392,7 +392,7 @@ static void checkConsistency(intset *is) {
} }
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int intsetTest(int argc, char **argv) { int intsetTest(int argc, char **argv, int accurate) {
uint8_t success; uint8_t success;
int i; int i;
intset *is; intset *is;
...@@ -400,6 +400,7 @@ int intsetTest(int argc, char **argv) { ...@@ -400,6 +400,7 @@ int intsetTest(int argc, char **argv) {
UNUSED(argc); UNUSED(argc);
UNUSED(argv); UNUSED(argv);
UNUSED(accurate);
printf("Value encodings: "); { printf("Value encodings: "); {
assert(_intsetValueEncoding(-32768) == INTSET_ENC_INT16); assert(_intsetValueEncoding(-32768) == INTSET_ENC_INT16);
...@@ -424,6 +425,7 @@ int intsetTest(int argc, char **argv) { ...@@ -424,6 +425,7 @@ int intsetTest(int argc, char **argv) {
is = intsetAdd(is,4,&success); assert(success); is = intsetAdd(is,4,&success); assert(success);
is = intsetAdd(is,4,&success); assert(!success); is = intsetAdd(is,4,&success); assert(!success);
ok(); ok();
zfree(is);
} }
printf("Large number of random adds: "); { printf("Large number of random adds: "); {
...@@ -436,6 +438,7 @@ int intsetTest(int argc, char **argv) { ...@@ -436,6 +438,7 @@ int intsetTest(int argc, char **argv) {
assert(intrev32ifbe(is->length) == inserts); assert(intrev32ifbe(is->length) == inserts);
checkConsistency(is); checkConsistency(is);
ok(); ok();
zfree(is);
} }
printf("Upgrade from int16 to int32: "); { printf("Upgrade from int16 to int32: "); {
...@@ -447,6 +450,7 @@ int intsetTest(int argc, char **argv) { ...@@ -447,6 +450,7 @@ int intsetTest(int argc, char **argv) {
assert(intsetFind(is,32)); assert(intsetFind(is,32));
assert(intsetFind(is,65535)); assert(intsetFind(is,65535));
checkConsistency(is); checkConsistency(is);
zfree(is);
is = intsetNew(); is = intsetNew();
is = intsetAdd(is,32,NULL); is = intsetAdd(is,32,NULL);
...@@ -457,6 +461,7 @@ int intsetTest(int argc, char **argv) { ...@@ -457,6 +461,7 @@ int intsetTest(int argc, char **argv) {
assert(intsetFind(is,-65535)); assert(intsetFind(is,-65535));
checkConsistency(is); checkConsistency(is);
ok(); ok();
zfree(is);
} }
printf("Upgrade from int16 to int64: "); { printf("Upgrade from int16 to int64: "); {
...@@ -468,6 +473,7 @@ int intsetTest(int argc, char **argv) { ...@@ -468,6 +473,7 @@ int intsetTest(int argc, char **argv) {
assert(intsetFind(is,32)); assert(intsetFind(is,32));
assert(intsetFind(is,4294967295)); assert(intsetFind(is,4294967295));
checkConsistency(is); checkConsistency(is);
zfree(is);
is = intsetNew(); is = intsetNew();
is = intsetAdd(is,32,NULL); is = intsetAdd(is,32,NULL);
...@@ -478,6 +484,7 @@ int intsetTest(int argc, char **argv) { ...@@ -478,6 +484,7 @@ int intsetTest(int argc, char **argv) {
assert(intsetFind(is,-4294967295)); assert(intsetFind(is,-4294967295));
checkConsistency(is); checkConsistency(is);
ok(); ok();
zfree(is);
} }
printf("Upgrade from int32 to int64: "); { printf("Upgrade from int32 to int64: "); {
...@@ -489,6 +496,7 @@ int intsetTest(int argc, char **argv) { ...@@ -489,6 +496,7 @@ int intsetTest(int argc, char **argv) {
assert(intsetFind(is,65535)); assert(intsetFind(is,65535));
assert(intsetFind(is,4294967295)); assert(intsetFind(is,4294967295));
checkConsistency(is); checkConsistency(is);
zfree(is);
is = intsetNew(); is = intsetNew();
is = intsetAdd(is,65535,NULL); is = intsetAdd(is,65535,NULL);
...@@ -499,6 +507,7 @@ int intsetTest(int argc, char **argv) { ...@@ -499,6 +507,7 @@ int intsetTest(int argc, char **argv) {
assert(intsetFind(is,-4294967295)); assert(intsetFind(is,-4294967295));
checkConsistency(is); checkConsistency(is);
ok(); ok();
zfree(is);
} }
printf("Stress lookups: "); { printf("Stress lookups: "); {
...@@ -512,6 +521,7 @@ int intsetTest(int argc, char **argv) { ...@@ -512,6 +521,7 @@ int intsetTest(int argc, char **argv) {
for (i = 0; i < num; i++) intsetSearch(is,rand() % ((1<<bits)-1),NULL); for (i = 0; i < num; i++) intsetSearch(is,rand() % ((1<<bits)-1),NULL);
printf("%ld lookups, %ld element set, %lldusec\n", printf("%ld lookups, %ld element set, %lldusec\n",
num,size,usec()-start); num,size,usec()-start);
zfree(is);
} }
printf("Stress add+delete: "); { printf("Stress add+delete: "); {
...@@ -528,6 +538,7 @@ int intsetTest(int argc, char **argv) { ...@@ -528,6 +538,7 @@ int intsetTest(int argc, char **argv) {
} }
checkConsistency(is); checkConsistency(is);
ok(); ok();
zfree(is);
} }
return 0; return 0;
......
...@@ -49,7 +49,7 @@ size_t intsetBlobLen(intset *is); ...@@ -49,7 +49,7 @@ size_t intsetBlobLen(intset *is);
int intsetValidateIntegrity(const unsigned char *is, size_t size, int deep); int intsetValidateIntegrity(const unsigned char *is, size_t size, int deep);
#ifdef REDIS_TEST #ifdef REDIS_TEST
int intsetTest(int argc, char *argv[]); int intsetTest(int argc, char *argv[], int accurate);
#endif #endif
#endif // __INTSET_H #endif // __INTSET_H
This diff is collapsed.
...@@ -199,7 +199,7 @@ quicklistNode *quicklistBookmarkFind(quicklist *ql, const char *name); ...@@ -199,7 +199,7 @@ quicklistNode *quicklistBookmarkFind(quicklist *ql, const char *name);
void quicklistBookmarksClear(quicklist *ql); void quicklistBookmarksClear(quicklist *ql);
#ifdef REDIS_TEST #ifdef REDIS_TEST
int quicklistTest(int argc, char *argv[]); int quicklistTest(int argc, char *argv[], int accurate);
#endif #endif
/* Directions for iterators */ /* Directions for iterators */
......
...@@ -1234,9 +1234,10 @@ static sds sdsTestTemplateCallback(sds varname, void *arg) { ...@@ -1234,9 +1234,10 @@ static sds sdsTestTemplateCallback(sds varname, void *arg) {
else return NULL; else return NULL;
} }
int sdsTest(int argc, char **argv) { int sdsTest(int argc, char **argv, int accurate) {
UNUSED(argc); UNUSED(argc);
UNUSED(argv); UNUSED(argv);
UNUSED(accurate);
{ {
sds x = sdsnew("foo"), y; sds x = sdsnew("foo"), y;
......
...@@ -277,7 +277,7 @@ void *sds_realloc(void *ptr, size_t size); ...@@ -277,7 +277,7 @@ void *sds_realloc(void *ptr, size_t size);
void sds_free(void *ptr); void sds_free(void *ptr);
#ifdef REDIS_TEST #ifdef REDIS_TEST
int sdsTest(int argc, char *argv[]); int sdsTest(int argc, char *argv[], int accurate);
#endif #endif
#endif #endif
...@@ -6030,36 +6030,78 @@ int iAmMaster(void) { ...@@ -6030,36 +6030,78 @@ int iAmMaster(void) {
(server.cluster_enabled && nodeIsMaster(server.cluster->myself))); (server.cluster_enabled && nodeIsMaster(server.cluster->myself)));
} }
#ifdef REDIS_TEST
typedef int redisTestProc(int argc, char **argv, int accurate);
struct redisTest {
char *name;
redisTestProc *proc;
int failed;
} redisTests[] = {
{"ziplist", ziplistTest},
{"quicklist", quicklistTest},
{"intset", intsetTest},
{"zipmap", zipmapTest},
{"sha1test", sha1Test},
{"util", utilTest},
{"endianconv", endianconvTest},
{"crc64", crc64Test},
{"zmalloc", zmalloc_test},
{"sds", sdsTest},
{"dict", dictTest}
};
redisTestProc *getTestProcByName(const char *name) {
int numtests = sizeof(redisTests)/sizeof(struct redisTest);
for (int j = 0; j < numtests; j++) {
if (!strcasecmp(name,redisTests[j].name)) {
return redisTests[j].proc;
}
}
return NULL;
}
#endif
int main(int argc, char **argv) { int main(int argc, char **argv) {
struct timeval tv; struct timeval tv;
int j; int j;
char config_from_stdin = 0; char config_from_stdin = 0;
#ifdef REDIS_TEST #ifdef REDIS_TEST
if (argc == 3 && !strcasecmp(argv[1], "test")) { if (argc >= 3 && !strcasecmp(argv[1], "test")) {
if (!strcasecmp(argv[2], "ziplist")) { int accurate = 0;
return ziplistTest(argc, argv); for (j = 3; j < argc; j++) {
} else if (!strcasecmp(argv[2], "quicklist")) { if (!strcasecmp(argv[j], "--accurate")) {
quicklistTest(argc, argv); accurate = 1;
} else if (!strcasecmp(argv[2], "intset")) { }
return intsetTest(argc, argv);
} else if (!strcasecmp(argv[2], "zipmap")) {
return zipmapTest(argc, argv);
} else if (!strcasecmp(argv[2], "sha1test")) {
return sha1Test(argc, argv);
} else if (!strcasecmp(argv[2], "util")) {
return utilTest(argc, argv);
} else if (!strcasecmp(argv[2], "endianconv")) {
return endianconvTest(argc, argv);
} else if (!strcasecmp(argv[2], "crc64")) {
return crc64Test(argc, argv);
} else if (!strcasecmp(argv[2], "zmalloc")) {
return zmalloc_test(argc, argv);
} else if (!strcasecmp(argv[2], "sds")) {
return sdsTest(argc, argv);
} }
return -1; /* test not found */ if (!strcasecmp(argv[2], "all")) {
int numtests = sizeof(redisTests)/sizeof(struct redisTest);
for (j = 0; j < numtests; j++) {
redisTests[j].failed = (redisTests[j].proc(argc,argv,accurate) != 0);
}
/* Report tests result */
int failed_num = 0;
for (j = 0; j < numtests; j++) {
if (redisTests[j].failed) {
failed_num++;
printf("[failed] Test - %s\n", redisTests[j].name);
} else {
printf("[ok] Test - %s\n", redisTests[j].name);
}
}
printf("%d tests, %d passed, %d failed\n", numtests,
numtests-failed_num, failed_num);
return failed_num == 0 ? 0 : 1;
} else {
redisTestProc *proc = getTestProcByName(argv[2]);
if (!proc) return -1; /* test not found */
return proc(argc,argv,accurate);
}
return 0;
} }
#endif #endif
......
...@@ -201,7 +201,7 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context) ...@@ -201,7 +201,7 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
#define BUFSIZE 4096 #define BUFSIZE 4096
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int sha1Test(int argc, char **argv) int sha1Test(int argc, char **argv, int accurate)
{ {
SHA1_CTX ctx; SHA1_CTX ctx;
unsigned char hash[20], buf[BUFSIZE]; unsigned char hash[20], buf[BUFSIZE];
...@@ -209,6 +209,7 @@ int sha1Test(int argc, char **argv) ...@@ -209,6 +209,7 @@ int sha1Test(int argc, char **argv)
UNUSED(argc); UNUSED(argc);
UNUSED(argv); UNUSED(argv);
UNUSED(accurate);
for(i=0;i<BUFSIZE;i++) for(i=0;i<BUFSIZE;i++)
buf[i] = i; buf[i] = i;
......
...@@ -19,6 +19,6 @@ void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len); ...@@ -19,6 +19,6 @@ void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
void SHA1Final(unsigned char digest[20], SHA1_CTX* context); void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
#ifdef REDIS_TEST #ifdef REDIS_TEST
int sha1Test(int argc, char **argv); int sha1Test(int argc, char **argv, int accurate);
#endif #endif
#endif #endif
...@@ -946,9 +946,10 @@ static void test_ll2string(void) { ...@@ -946,9 +946,10 @@ static void test_ll2string(void) {
} }
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int utilTest(int argc, char **argv) { int utilTest(int argc, char **argv, int accurate) {
UNUSED(argc); UNUSED(argc);
UNUSED(argv); UNUSED(argv);
UNUSED(accurate);
test_string2ll(); test_string2ll();
test_string2l(); test_string2l();
......
...@@ -66,7 +66,7 @@ long getTimeZone(void); ...@@ -66,7 +66,7 @@ long getTimeZone(void);
int pathIsBaseName(char *path); int pathIsBaseName(char *path);
#ifdef REDIS_TEST #ifdef REDIS_TEST
int utilTest(int argc, char **argv); int utilTest(int argc, char **argv, int accurate);
#endif #endif
#endif #endif
...@@ -1823,15 +1823,17 @@ static size_t strEntryBytesLarge(size_t slen) { ...@@ -1823,15 +1823,17 @@ static size_t strEntryBytesLarge(size_t slen) {
return slen + zipStorePrevEntryLength(NULL, ZIP_BIG_PREVLEN) + zipStoreEntryEncoding(NULL, 0, slen); return slen + zipStorePrevEntryLength(NULL, ZIP_BIG_PREVLEN) + zipStoreEntryEncoding(NULL, 0, slen);
} }
int ziplistTest(int argc, char **argv) { /* ./redis-server test ziplist <randomseed> --accurate */
int ziplistTest(int argc, char **argv, int accurate) {
unsigned char *zl, *p; unsigned char *zl, *p;
unsigned char *entry; unsigned char *entry;
unsigned int elen; unsigned int elen;
long long value; long long value;
int iteration;
/* If an argument is given, use it as the random seed. */ /* If an argument is given, use it as the random seed. */
if (argc == 2) if (argc >= 4)
srand(atoi(argv[1])); srand(atoi(argv[3]));
zl = createIntList(); zl = createIntList();
ziplistRepr(zl); ziplistRepr(zl);
...@@ -2339,7 +2341,8 @@ int ziplistTest(int argc, char **argv) { ...@@ -2339,7 +2341,8 @@ int ziplistTest(int argc, char **argv) {
unsigned int slen; unsigned int slen;
long long sval; long long sval;
for (i = 0; i < 20000; i++) { iteration = accurate ? 20000 : 20;
for (i = 0; i < iteration; i++) {
zl = ziplistNew(); zl = ziplistNew();
ref = listCreate(); ref = listCreate();
listSetFreeMethod(ref,(void (*)(void*))sdsfree); listSetFreeMethod(ref,(void (*)(void*))sdsfree);
...@@ -2405,15 +2408,17 @@ int ziplistTest(int argc, char **argv) { ...@@ -2405,15 +2408,17 @@ int ziplistTest(int argc, char **argv) {
printf("Stress with variable ziplist size:\n"); printf("Stress with variable ziplist size:\n");
{ {
unsigned long long start = usec(); unsigned long long start = usec();
stress(ZIPLIST_HEAD,100000,16384,256); int maxsize = accurate ? 16384 : 16;
stress(ZIPLIST_TAIL,100000,16384,256); stress(ZIPLIST_HEAD,100000,maxsize,256);
stress(ZIPLIST_TAIL,100000,maxsize,256);
printf("Done. usec=%lld\n\n", usec()-start); printf("Done. usec=%lld\n\n", usec()-start);
} }
/* Benchmarks */ /* Benchmarks */
{ {
zl = ziplistNew(); zl = ziplistNew();
for (int i=0; i<100000; i++) { iteration = accurate ? 100000 : 100;
for (int i=0; i<iteration; i++) {
char buf[4096] = "asdf"; char buf[4096] = "asdf";
zl = ziplistPush(zl, (unsigned char*)buf, 4, ZIPLIST_TAIL); zl = ziplistPush(zl, (unsigned char*)buf, 4, ZIPLIST_TAIL);
zl = ziplistPush(zl, (unsigned char*)buf, 40, ZIPLIST_TAIL); zl = ziplistPush(zl, (unsigned char*)buf, 40, ZIPLIST_TAIL);
...@@ -2462,7 +2467,8 @@ int ziplistTest(int argc, char **argv) { ...@@ -2462,7 +2467,8 @@ int ziplistTest(int argc, char **argv) {
{ {
char data[ZIP_BIG_PREVLEN]; char data[ZIP_BIG_PREVLEN];
zl = ziplistNew(); zl = ziplistNew();
for (int i = 0; i < 100000; i++) { iteration = accurate ? 100000 : 100;
for (int i = 0; i < iteration; i++) {
zl = ziplistPush(zl, (unsigned char*)data, ZIP_BIG_PREVLEN-4, ZIPLIST_TAIL); zl = ziplistPush(zl, (unsigned char*)data, ZIP_BIG_PREVLEN-4, ZIPLIST_TAIL);
} }
unsigned long long start = usec(); unsigned long long start = usec();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment