X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest.c;h=3945df8b077d41c177f151c69b5b5ce55e74dd2c;hb=ffe371b7498a26133a892591c7dc56d3e6212d10;hp=60c6211a09e86a1dc20936abb99852647f4bb6d2;hpb=a6fa1b62336cfddaf0d9efb7f431490a7c2f3ac9;p=awesomized%2Flibmemcached diff --git a/tests/test.c b/tests/test.c index 60c6211a..3945df8b 100644 --- a/tests/test.c +++ b/tests/test.c @@ -37,6 +37,43 @@ void allocation_test(memcached_st *not_used) memcached_free(memc); } +void clone_test(memcached_st *memc) +{ + /* All null? */ + { + memcached_st *clone; + clone= memcached_clone(NULL, NULL); + assert(clone); + memcached_free(clone); + } + + /* Can we init from null? */ + { + memcached_st *clone; + clone= memcached_clone(NULL, memc); + assert(clone); + memcached_free(clone); + } + + /* Can we init from struct? */ + { + memcached_st declared_clone; + memcached_st *clone; + clone= memcached_clone(&declared_clone, NULL); + assert(clone); + memcached_free(clone); + } + + /* Can we init from struct? */ + { + memcached_st declared_clone; + memcached_st *clone; + clone= memcached_clone(&declared_clone, memc); + assert(clone); + memcached_free(clone); + } +} + void connection_test(memcached_st *memc) { memcached_return rc; @@ -572,9 +609,11 @@ void user_supplied_bug2(memcached_st *memc) memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter); getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE); getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE); -#endif for (x= 0, errors= 0, total= 0 ; total < 20 * 1024576 ; x++) +#endif + + for (x= 0, errors= 0, total= 0 ; total < 24576 ; x++) { memcached_return rc= MEMCACHED_SUCCESS; char buffer[SMALL_STRING_LEN]; @@ -641,7 +680,7 @@ void user_supplied_bug3(memcached_st *memc) /* Turn this into a help function */ { - char *return_key; + char return_key[MEMCACHED_MAX_KEY]; size_t return_key_length; char *return_value; size_t return_value_length; @@ -683,7 +722,7 @@ void string_alloc_with_size_toobig(memcached_st *memc) { memcached_string_st *string; - string= memcached_string_create(memc, 1024*100000000000); + string= memcached_string_create(memc, INT64_MAX); assert(string == NULL); } @@ -726,7 +765,7 @@ void string_alloc_append_toobig(memcached_st *memc) rc= memcached_string_append(memc, string, buffer, SMALL_STRING_LEN); assert(rc == MEMCACHED_SUCCESS); } - rc= memcached_string_append(memc, string, buffer, 1024*100000000000); + rc= memcached_string_append(memc, string, buffer, INT64_MAX); assert(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE); memcached_string_free(memc, string); } @@ -761,24 +800,54 @@ 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_crc(memcached_st *memc) +{ + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CRC_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]; @@ -807,6 +876,7 @@ int main(int argc, char *argv[]) {"flush", 0, flush_test }, {"init", 0, init_test }, {"allocation", 0, allocation_test }, + {"clone_test", 0, clone_test }, {"error", 0, error_test }, {"set", 0, set_test }, {"set2", 0, set_test2 }, @@ -842,131 +912,40 @@ int main(int argc, char *argv[]) test_st user_tests[] ={ {"user_supplied_bug1", 0, user_supplied_bug1 }, {"user_supplied_bug2", 0, user_supplied_bug2 }, -// {"user_supplied_bug3", 0, user_supplied_bug3 }, + {"user_supplied_bug3", 0, user_supplied_bug3 }, {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}, + {"crc", pre_crc, 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) + 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); + run= next->tests; - if (tests[x].requires_flush) - memcached_flush(memc, 0); + if (collection_to_run && strcmp(collection_to_run, next->name)) + continue; - rc= memcached_server_push(memc, servers); - assert(rc == MEMCACHED_SUCCESS); + fprintf(stderr, "\n%s\n\n", next->name); - 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); - } - } - - 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; + if (wildcard && strcmp(wildcard, run->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 ((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; @@ -975,88 +954,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); - rc= memcached_server_push(memc, servers); - assert(rc == MEMCACHED_SUCCESS); + if (next->post) + next->post(memc); - 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); }