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
;
36 collection
= gets_collections();
40 collection_to_run
= argv
[1];
45 if (!(server_list
= getenv("MEMCACHED_SERVERS")))
46 server_list
= "localhost";
48 printf("servers %s\n", server_list
);
51 servers
= memcached_servers_parse(server_list
);
54 for (x
= 0; x
< memcached_server_list_count(servers
); x
++)
56 printf("\t%s : %u\n", servers
[x
].hostname
, servers
[x
].port
);
57 assert(servers
[x
].stack_responses
== 0);
58 assert(servers
[x
].fd
== -1);
59 assert(servers
[x
].cursor_active
== 0);
65 for (next
= collection
; next
->name
; next
++)
70 if (collection_to_run
&& strcmp(collection_to_run
, next
->name
))
73 fprintf(stderr
, "\n%s\n\n", next
->name
);
75 for (x
= 0; run
->name
; run
++)
77 if (wildcard
&& strcmp(wildcard
, run
->name
))
80 fprintf(stderr
, "Testing %s", run
->name
);
84 struct timeval start_time
, end_time
;
86 memc
= memcached_create(NULL
);
89 if (run
->requires_flush
)
90 memcached_flush(memc
, 0);
92 rc
= memcached_server_push(memc
, servers
);
93 assert(rc
== MEMCACHED_SUCCESS
);
96 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
98 assert(memc
->hosts
[loop
].stack_responses
== 0);
99 assert(memc
->hosts
[loop
].fd
== -1);
100 assert(memc
->hosts
[loop
].cursor_active
== 0);
108 if (rc
!= MEMCACHED_SUCCESS
)
110 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
115 gettimeofday(&start_time
, NULL
);
117 gettimeofday(&end_time
, NULL
);
118 long int load_time
= timedif(end_time
, start_time
);
119 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
123 (void)next
->post(memc
);
127 memcached_free(memc
);
131 fprintf(stderr
, "All tests completed successfully\n\n");
133 memcached_server_list_free(servers
);