#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/time.h>
+
+long int timedif(struct timeval a, struct timeval b)
+{
+ register int us, s;
+
+ us = a.tv_usec - b.tv_usec;
+ us /= 1000;
+ s = a.tv_sec - b.tv_sec;
+ s *= 1000;
+ return s + us;
+}
void init_test(memcached_st *not_used)
{
{
unsigned int x;
char *server_list;
+ char *test_to_run= NULL;
char *wildcard= NULL;
memcached_server_st *servers;
- if (argc == 2)
- wildcard= argv[1];
+ if (argc > 2)
+ test_to_run= argv[1];
+
+ if (argc == 3)
+ wildcard= argv[2];
if (!(server_list= getenv("MEMCACHED_SERVERS")))
server_list= "localhost";
{0, 0, 0}
};
- fprintf(stderr, "\nBlock tests\n\n");
- for (x= 0; tests[x].function_name; x++)
+ if ((test_to_run && !strcmp(test_to_run, "block")) || !test_to_run)
{
- if (wildcard)
- if (strcmp(wildcard, tests[x].function_name))
- continue;
-
- memcached_st *memc;
- memcached_return rc;
- memc= memcached_create(NULL);
- assert(memc);
-
- rc= memcached_server_push(memc, servers);
- assert(rc == MEMCACHED_SUCCESS);
-
- unsigned int loop;
- for (loop= 0; loop < memcached_server_list_count(servers); loop++)
+ fprintf(stderr, "\nBlock tests\n\n");
+ for (x= 0; tests[x].function_name; x++)
{
- assert(memc->hosts[loop].stack_responses == 0);
- assert(memc->hosts[loop].fd == -1);
- assert(memc->hosts[loop].cursor_active == 0);
+ 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);
+
+ 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);
}
-
- fprintf(stderr, "Testing %s", tests[x].function_name);
- tests[x].function(memc);
- fprintf(stderr, "\t\t\t\t\t[ ok ]\n");
- assert(memc);
- memcached_free(memc);
}
- fprintf(stderr, "\nNonblock tests\n\n");
- for (x= 0; tests[x].function_name; x++)
+ if ((test_to_run && !strcmp(test_to_run, "nonblock")) || !test_to_run)
{
- if (wildcard)
- if (strcmp(wildcard, tests[x].function_name))
- continue;
-
- memcached_st *memc;
- memcached_return rc;
- memc= memcached_create(NULL);
- assert(memc);
-
- 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);
- tests[x].function(memc);
- fprintf(stderr, "\t\t\t\t\t[ ok ]\n");
- assert(memc);
- memcached_free(memc);
+ 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;
+
+ memc= memcached_create(NULL);
+ assert(memc);
+
+ 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);
+ 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, "\nTCP Nodelay tests\n\n");
- for (x= 0; tests[x].function_name; x++)
+ if ((test_to_run && !strcmp(test_to_run, "nodelay")) || !test_to_run)
{
- if (wildcard)
- if (strcmp(wildcard, tests[x].function_name))
- continue;
-
- memcached_st *memc;
- memcached_return rc;
- memc= memcached_create(NULL);
- assert(memc);
-
- 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);
- tests[x].function(memc);
- fprintf(stderr, "\t\t\t\t\t[ ok ]\n");
- assert(memc);
- memcached_free(memc);
+ fprintf(stderr, "\nTCP Nodelay 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);
+
+ 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);
+ }
}
- fprintf(stderr, "\nMD5 Hashing\n\n");
- for (x= 0; tests[x].function_name; x++)
+ if ((test_to_run && !strcmp(test_to_run, "md5")) || !test_to_run)
{
- if (wildcard)
- if (strcmp(wildcard, tests[x].function_name))
- continue;
-
- memcached_st *memc;
- memcached_return rc;
- memc= memcached_create(NULL);
- assert(memc);
-
- 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);
- tests[x].function(memc);
- fprintf(stderr, "\t\t\t\t\t[ ok ]\n");
- assert(memc);
- memcached_free(memc);
+ fprintf(stderr, "\nMD5 Hashing\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);
+
+ 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);
+ }
}
- fprintf(stderr, "\nUser Supplied tests\n\n");
- for (x= 0; user_tests[x].function_name; x++)
+ if ((test_to_run && !strcmp(test_to_run, "user")) || !test_to_run)
{
- if (wildcard)
- if (strcmp(wildcard, tests[x].function_name))
- continue;
-
- memcached_st *memc;
- memcached_return rc;
- memc= memcached_create(NULL);
- assert(memc);
-
- rc= memcached_server_push(memc, servers);
- assert(rc == MEMCACHED_SUCCESS);
-
- fprintf(stderr, "Testing %s", user_tests[x].function_name);
- user_tests[x].function(memc);
- fprintf(stderr, "\t\t\t\t\t[ ok ]\n");
- assert(memc);
- memcached_free(memc);
+ fprintf(stderr, "\nUser Supplied tests\n\n");
+ for (x= 0; user_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);
+
+ 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);
+ }
}
/* Clean up whatever we might have left */