From b662f45011eb691eab9fdf8e8e683c42c1e5694f Mon Sep 17 00:00:00 2001 From: Date: Fri, 26 Oct 2007 00:26:36 -0700 Subject: [PATCH] Rewrote test loop to remove copy/paste code. WATCHPOINT now uses stderr. --- configure.in | 2 +- include/memcached.h | 10 +- tests/test.c | 250 ++++++++++++-------------------------------- 3 files changed, 71 insertions(+), 191 deletions(-) diff --git a/configure.in b/configure.in index 7a95f8cb..adbfd5dd 100644 --- a/configure.in +++ b/configure.in @@ -16,7 +16,7 @@ if test "$GCC" = "yes" then if test "$ENABLE_DEBUG" = "yes" then - CFLAGS="-Wall -ggdb" + CFLAGS="-Wall -ggdb -DHAVE_DEBUG" else CFLAGS="-Wall -O3" fi diff --git a/include/memcached.h b/include/memcached.h index 6854035b..1131de2b 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -212,11 +212,11 @@ char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat, /* Some personal debugging functions */ #ifdef HAVE_DEBUG -#define WATCHPOINT printf("\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); -#define WATCHPOINT_ERROR(A) printf("\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); -#define WATCHPOINT_STRING(A) printf("\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); -#define WATCHPOINT_NUMBER(A) printf("\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); -#define WATCHPOINT_ERRNO(A) printf("\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));A= 0;fflush(stdout); +#define WATCHPOINT fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); +#define WATCHPOINT_ERROR(A) fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); +#define WATCHPOINT_STRING(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); +#define WATCHPOINT_NUMBER(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); +#define WATCHPOINT_ERRNO(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));A= 0;fflush(stdout); #define WATCHPOINT_ASSERT(A) assert((A)); #else /* diff --git a/tests/test.c b/tests/test.c index 7a0919fb..258feb44 100644 --- a/tests/test.c +++ b/tests/test.c @@ -726,9 +726,7 @@ void string_alloc_append_toobig(memcached_st *memc) rc= memcached_string_append(memc, string, buffer, SMALL_STRING_LEN); assert(rc == MEMCACHED_SUCCESS); } - WATCHPOINT; rc= memcached_string_append(memc, string, buffer, UINT64_MAX); - WATCHPOINT; assert(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE); memcached_string_free(memc, string); } @@ -763,24 +761,49 @@ void add_host_test1(memcached_st *memc) memcached_server_list_free(servers); } +void pre_nonblock(memcached_st *memc) +{ + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL); +} + +void pre_md5(memcached_st *memc) +{ + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_MD5_HASHING, NULL); +} + +void pre_nodelay(memcached_st *memc) +{ + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL); +} + +typedef struct collection_st collection_st; typedef struct test_st test_st; struct test_st { - char *function_name; + char *name; unsigned int requires_flush; void (*function)(memcached_st *memc); }; +struct collection_st { + char *name; + void (*pre)(memcached_st *memc); + void (*post)(memcached_st *memc); + test_st *tests; +}; + int main(int argc, char *argv[]) { unsigned int x; char *server_list; - char *test_to_run= NULL; + char *collection_to_run= NULL; char *wildcard= NULL; memcached_server_st *servers; + if (argc > 1) - test_to_run= argv[1]; + collection_to_run= argv[1]; if (argc == 3) wildcard= argv[2]; @@ -848,127 +871,39 @@ int main(int argc, char *argv[]) {0, 0, 0} }; - if ((test_to_run && !strcmp(test_to_run, "block")) || !test_to_run) - { - fprintf(stderr, "\nBlock tests\n\n"); - for (x= 0; tests[x].function_name; x++) - { - if (wildcard) - if (strcmp(wildcard, tests[x].function_name)) - continue; - - memcached_st *memc; - memcached_return rc; - struct timeval start_time, end_time; - - memc= memcached_create(NULL); - assert(memc); - - if (tests[x].requires_flush) - memcached_flush(memc, 0); - - rc= memcached_server_push(memc, servers); - assert(rc == MEMCACHED_SUCCESS); - - unsigned int loop; - for (loop= 0; loop < memcached_server_list_count(servers); loop++) - { - assert(memc->hosts[loop].stack_responses == 0); - assert(memc->hosts[loop].fd == -1); - assert(memc->hosts[loop].cursor_active == 0); - } - fprintf(stderr, "Testing %s", tests[x].function_name); - gettimeofday(&start_time, NULL); - tests[x].function(memc); - gettimeofday(&end_time, NULL); - long int load_time= timedif(end_time, start_time); - fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000, - load_time % 1000); - assert(memc); - memcached_free(memc); - } - } + collection_st collection[] ={ + {"block", 0, 0, tests}, + {"nonblock", pre_nonblock, 0, tests}, + {"nodelay", pre_nodelay, 0, tests}, + {"md5", pre_md5, 0, tests}, + {"string", 0, 0, string_tests}, + {"user", 0, 0, user_tests}, + {0, 0, 0, 0} + }; - if ((test_to_run && !strcmp(test_to_run, "nonblock")) || !test_to_run) + /* + unsigned int next; + for (next= 0; collection[next].name; next++) +*/ + collection_st *next; + for (next= collection; next->name; next++) { - fprintf(stderr, "\nNonblock tests\n\n"); - for (x= 0; tests[x].function_name; x++) - { - if (wildcard) - if (strcmp(wildcard, tests[x].function_name)) - continue; - - memcached_st *memc; - memcached_return rc; - struct timeval start_time, end_time; + test_st *run; - memc= memcached_create(NULL); - assert(memc); - - if (tests[x].requires_flush) - memcached_flush(memc, 0); + run= next->tests; - rc= memcached_server_push(memc, servers); - assert(rc == MEMCACHED_SUCCESS); + if (collection_to_run && strcmp(collection_to_run, next->name)) + continue; - fprintf(stderr, "Testing %s", tests[x].function_name); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL); - gettimeofday(&start_time, NULL); - tests[x].function(memc); - gettimeofday(&end_time, NULL); - long int load_time= timedif(end_time, start_time); - fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000, - load_time % 1000); - assert(memc); - memcached_free(memc); - } - } + fprintf(stderr, "\n%s\n\n", next->name); - if ((test_to_run && !strcmp(test_to_run, "nodelay")) || !test_to_run) - { - fprintf(stderr, "\nTCP Nodelay tests\n\n"); - for (x= 0; tests[x].function_name; x++) + for (x= 0; run->name; run++) { - if (wildcard) - if (strcmp(wildcard, tests[x].function_name)) - continue; - - memcached_st *memc; - memcached_return rc; - struct timeval start_time, end_time; - - memc= memcached_create(NULL); - assert(memc); - - if (tests[x].requires_flush) - memcached_flush(memc, 0); - - rc= memcached_server_push(memc, servers); - assert(rc == MEMCACHED_SUCCESS); - - fprintf(stderr, "Testing %s", tests[x].function_name); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL); - gettimeofday(&start_time, NULL); - tests[x].function(memc); - gettimeofday(&end_time, NULL); - long int load_time= timedif(end_time, start_time); - fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000, - load_time % 1000); - assert(memc); - memcached_free(memc); - } - } + if (wildcard && strcmp(wildcard, run->name)) + continue; - if ((test_to_run && !strcmp(test_to_run, "md5")) || !test_to_run) - { - fprintf(stderr, "\nMD5 Hashing\n\n"); - for (x= 0; tests[x].function_name; x++) - { - if (wildcard) - if (strcmp(wildcard, tests[x].function_name)) - continue; + fprintf(stderr, "Testing %s", run->name); memcached_st *memc; memcached_return rc; @@ -977,88 +912,33 @@ int main(int argc, char *argv[]) memc= memcached_create(NULL); assert(memc); - if (tests[x].requires_flush) + if (run->requires_flush) memcached_flush(memc, 0); rc= memcached_server_push(memc, servers); assert(rc == MEMCACHED_SUCCESS); - fprintf(stderr, "Testing %s", tests[x].function_name); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_MD5_HASHING, NULL); - gettimeofday(&start_time, NULL); - tests[x].function(memc); - gettimeofday(&end_time, NULL); - long int load_time= timedif(end_time, start_time); - fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000, - load_time % 1000); - assert(memc); - memcached_free(memc); - } - } - - if ((test_to_run && !strcmp(test_to_run, "string")) || !test_to_run) - { - fprintf(stderr, "\nString tests (internal API)\n\n"); - for (x= 0; string_tests[x].function_name; x++) - { - if (wildcard) - if (strcmp(wildcard, string_tests[x].function_name)) - continue; - - memcached_st *memc; - memcached_return rc; - struct timeval start_time, end_time; - - memc= memcached_create(NULL); - assert(memc); - - if (tests[x].requires_flush) - memcached_flush(memc, 0); + unsigned int loop; + for (loop= 0; loop < memcached_server_list_count(servers); loop++) + { + assert(memc->hosts[loop].stack_responses == 0); + assert(memc->hosts[loop].fd == -1); + assert(memc->hosts[loop].cursor_active == 0); + } - rc= memcached_server_push(memc, servers); - assert(rc == MEMCACHED_SUCCESS); + if (next->pre) + next->pre(memc); - fprintf(stderr, "Testing %s", string_tests[x].function_name); gettimeofday(&start_time, NULL); - string_tests[x].function(memc); + run->function(memc); gettimeofday(&end_time, NULL); long int load_time= timedif(end_time, start_time); fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000, load_time % 1000); - assert(memc); - memcached_free(memc); - } - } - - if ((test_to_run && !strcmp(test_to_run, "user")) || !test_to_run) - { - fprintf(stderr, "\nUser Supplied tests\n\n"); - for (x= 0; user_tests[x].function_name; x++) - { - if (wildcard) - if (strcmp(wildcard, user_tests[x].function_name)) - continue; - - memcached_st *memc; - memcached_return rc; - struct timeval start_time, end_time; - - memc= memcached_create(NULL); - assert(memc); - if (tests[x].requires_flush) - memcached_flush(memc, 0); + if (next->post) + next->post(memc); - rc= memcached_server_push(memc, servers); - assert(rc == MEMCACHED_SUCCESS); - - fprintf(stderr, "Testing %s", user_tests[x].function_name); - gettimeofday(&start_time, NULL); - user_tests[x].function(memc); - gettimeofday(&end_time, NULL); - long int load_time= timedif(end_time, start_time); - fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000, - load_time % 1000); assert(memc); memcached_free(memc); } -- 2.30.2