diff options
author | Matt Stancliff <matt@genges.com> | 2014-11-12 21:58:57 -0500 |
---|---|---|
committer | Matt Stancliff <matt@genges.com> | 2014-12-23 09:31:03 -0500 |
commit | 8febcffdc597566f1e307c0534014b2bdf687c02 (patch) | |
tree | 74cf78291298cce2dfc1abf5fe1c25aacd86aa4f /src/intset.c | |
parent | 8380655e85f0afd1f0afc99b464717cb97002b7a (diff) | |
download | redis-8febcffdc597566f1e307c0534014b2bdf687c02.tar.gz |
Allow all code tests to run using Redis args
Previously, many files had individual main() functions for testing,
but each required being compiled with their own testing flags.
That gets difficult when you have 8 different flags you need
to set just to run all tests (plus, some test files required
other files to be compiled aaginst them, and it seems some didn't
build at all without including the rest of Redis).
Now all individual test main() funcions are renamed to a test
function for the file itself and one global REDIS_TEST define enables
testing across the entire codebase.
Tests can now be run with:
- `./redis-server test <test>`
e.g. ./redis-server test ziplist
If REDIS_TEST is not defined, then no tests get included and no
tests are included in the final redis-server binary.
Diffstat (limited to 'src/intset.c')
-rw-r--r-- | src/intset.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/intset.c b/src/intset.c index 92c4ecd6e..762bd48c8 100644 --- a/src/intset.c +++ b/src/intset.c @@ -365,44 +365,46 @@ size_t intsetBlobLen(intset *is) { return sizeof(intset)+intrev32ifbe(is->length)*intrev32ifbe(is->encoding); } -#ifdef INTSET_TEST_MAIN +#ifdef REDIS_TEST #include <sys/time.h> +#include <time.h> -void intsetRepr(intset *is) { - int i; - for (i = 0; i < intrev32ifbe(is->length); i++) { +#if 0 +static void intsetRepr(intset *is) { + for (uint32_t i = 0; i < intrev32ifbe(is->length); i++) { printf("%lld\n", (uint64_t)_intsetGet(is,i)); } printf("\n"); } -void error(char *err) { +static void error(char *err) { printf("%s\n", err); exit(1); } +#endif -void ok(void) { +static void ok(void) { printf("OK\n"); } -long long usec(void) { +static long long usec(void) { struct timeval tv; gettimeofday(&tv,NULL); return (((long long)tv.tv_sec)*1000000)+tv.tv_usec; } #define assert(_e) ((_e)?(void)0:(_assert(#_e,__FILE__,__LINE__),exit(1))) -void _assert(char *estr, char *file, int line) { +static void _assert(char *estr, char *file, int line) { printf("\n\n=== ASSERTION FAILED ===\n"); printf("==> %s:%d '%s' is not true\n",file,line,estr); } -intset *createSet(int bits, int size) { +static intset *createSet(int bits, int size) { uint64_t mask = (1<<bits)-1; - uint64_t i, value; + uint64_t value; intset *is = intsetNew(); - for (i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { if (bits > 32) { value = (rand()*rand()) & mask; } else { @@ -413,10 +415,8 @@ intset *createSet(int bits, int size) { return is; } -void checkConsistency(intset *is) { - int i; - - for (i = 0; i < (intrev32ifbe(is->length)-1); i++) { +static void checkConsistency(intset *is) { + for (uint32_t i = 0; i < (intrev32ifbe(is->length)-1); i++) { uint32_t encoding = intrev32ifbe(is->encoding); if (encoding == INTSET_ENC_INT16) { @@ -432,11 +432,15 @@ void checkConsistency(intset *is) { } } -int main(int argc, char **argv) { +#define UNUSED(x) (void)(x) +int intsetTest(int argc, char **argv) { uint8_t success; int i; intset *is; - sranddev(); + srand(time(NULL)); + + UNUSED(argc); + UNUSED(argv); printf("Value encodings: "); { assert(_intsetValueEncoding(-32768) == INTSET_ENC_INT16); @@ -464,7 +468,7 @@ int main(int argc, char **argv) { } printf("Large number of random adds: "); { - int inserts = 0; + uint32_t inserts = 0; is = intsetNew(); for (i = 0; i < 1024; i++) { is = intsetAdd(is,rand()%0x800,&success); @@ -566,5 +570,7 @@ int main(int argc, char **argv) { checkConsistency(is); ok(); } + + return 0; } #endif |