2 Sample test application.
16 long int timedif(struct timeval a
, struct timeval b
)
20 us
= a
.tv_usec
- b
.tv_usec
;
22 s
= a
.tv_sec
- b
.tv_sec
;
27 int main(int argc
, char *argv
[])
31 char *collection_to_run
= NULL
;
33 memcached_server_st
*servers
;
34 collection_st
*collection
;
37 collection
= gets_collections();
41 collection_to_run
= argv
[1];
46 if (!(server_list
= getenv("MEMCACHED_SERVERS")))
47 server_list
= "localhost";
49 printf("servers %s\n", server_list
);
52 servers
= memcached_servers_parse(server_list
);
55 for (x
= 0; x
< memcached_server_list_count(servers
); x
++)
57 printf("\t%s : %u\n", servers
[x
].hostname
, servers
[x
].port
);
58 assert(servers
[x
].stack_responses
== 0);
59 assert(servers
[x
].fd
== -1);
60 assert(servers
[x
].cursor_active
== 0);
66 for (next
= collection
; next
->name
; next
++)
71 if (collection_to_run
&& strcmp(collection_to_run
, next
->name
))
74 fprintf(stderr
, "\n%s\n\n", next
->name
);
76 for (x
= 0; run
->name
; run
++)
78 if (wildcard
&& strcmp(wildcard
, run
->name
))
81 fprintf(stderr
, "Testing %s", run
->name
);
85 struct timeval start_time
, end_time
;
87 memc
= memcached_create(NULL
);
90 if (run
->requires_flush
)
91 memcached_flush(memc
, 0);
93 rc
= memcached_server_push(memc
, servers
);
94 assert(rc
== MEMCACHED_SUCCESS
);
97 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
99 assert(memc
->hosts
[loop
].stack_responses
== 0);
100 assert(memc
->hosts
[loop
].fd
== -1);
101 assert(memc
->hosts
[loop
].cursor_active
== 0);
109 if (rc
!= MEMCACHED_SUCCESS
)
111 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
116 gettimeofday(&start_time
, NULL
);
117 failed
= run
->function(memc
);
118 gettimeofday(&end_time
, NULL
);
119 long int load_time
= timedif(end_time
, start_time
);
121 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ failed ]\n", load_time
/ 1000,
124 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
128 (void)next
->post(memc
);
132 memcached_free(memc
);
136 fprintf(stderr
, "All tests completed successfully\n\n");
138 memcached_server_list_free(servers
);