d31f8bc5f68ac36b648b67b8cd5ae09e9ce3a79b
2 Sample test application.
10 #include <sys/types.h>
14 #include "../lib/common.h"
18 long int timedif(struct timeval a
, struct timeval b
)
22 us
= a
.tv_usec
- b
.tv_usec
;
24 s
= a
.tv_sec
- b
.tv_sec
;
29 int main(int argc
, char *argv
[])
33 char *collection_to_run
= NULL
;
35 memcached_server_st
*servers
;
36 collection_st
*collection
;
38 collection
= gets_collections();
42 collection_to_run
= argv
[1];
47 if (!(server_list
= getenv("MEMCACHED_SERVERS")))
48 server_list
= "localhost";
50 printf("servers %s\n", server_list
);
53 servers
= memcached_servers_parse(server_list
);
56 for (x
= 0; x
< memcached_server_list_count(servers
); x
++)
58 printf("\t%s : %u\n", servers
[x
].hostname
, servers
[x
].port
);
59 assert(servers
[x
].stack_responses
== 0);
60 assert(servers
[x
].fd
== -1);
61 assert(servers
[x
].cursor_active
== 0);
67 for (next
= collection
; next
->name
; next
++)
72 if (collection_to_run
&& strcmp(collection_to_run
, next
->name
))
75 fprintf(stderr
, "\n%s\n\n", next
->name
);
77 for (x
= 0; run
->name
; run
++)
79 if (wildcard
&& strcmp(wildcard
, run
->name
))
82 fprintf(stderr
, "Testing %s", run
->name
);
86 struct timeval start_time
, end_time
;
88 memc
= memcached_create(NULL
);
91 if (run
->requires_flush
)
92 memcached_flush(memc
, 0);
94 rc
= memcached_server_push(memc
, servers
);
95 assert(rc
== MEMCACHED_SUCCESS
);
98 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
100 assert(memc
->hosts
[loop
].stack_responses
== 0);
101 assert(memc
->hosts
[loop
].fd
== -1);
102 assert(memc
->hosts
[loop
].cursor_active
== 0);
110 if (rc
!= MEMCACHED_SUCCESS
)
112 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
117 gettimeofday(&start_time
, NULL
);
119 gettimeofday(&end_time
, NULL
);
120 long int load_time
= timedif(end_time
, start_time
);
121 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
125 (void)next
->post(memc
);
129 memcached_free(memc
);
133 fprintf(stderr
, "All tests completed successfully\n\n");
135 memcached_server_list_free(servers
);