6c6bea645c4da1376069b70ef387e48a97447ccf
2 Sample test application.
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
[])
32 char *collection_to_run
= NULL
;
34 server_startup_st
*startup_ptr
;
35 memcached_server_st
*servers
;
37 collection_st
*collection
;
42 memset(&world
, 0, sizeof(world_st
));
44 collection
= world
.collections
;
47 world_ptr
= world
.create();
49 startup_ptr
= (server_startup_st
*)world_ptr
;
50 servers
= (memcached_server_st
*)startup_ptr
->servers
;
53 collection_to_run
= argv
[1];
58 for (next
= collection
; next
->name
; next
++)
63 if (collection_to_run
&& fnmatch(collection_to_run
, next
->name
, 0))
66 fprintf(stderr
, "\n%s\n\n", next
->name
);
68 for (x
= 0; run
->name
; run
++)
73 struct timeval start_time
, end_time
;
76 if (wildcard
&& fnmatch(wildcard
, run
->name
, 0))
79 fprintf(stderr
, "Testing %s", run
->name
);
81 memc
= memcached_create(NULL
);
84 rc
= memcached_server_push(memc
, servers
);
85 assert(rc
== MEMCACHED_SUCCESS
);
87 if (run
->requires_flush
)
89 memcached_flush(memc
, 0);
93 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
95 assert(memc
->hosts
[loop
].fd
== -1);
96 assert(memc
->hosts
[loop
].cursor_active
== 0);
104 if (rc
!= MEMCACHED_SUCCESS
)
106 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
111 gettimeofday(&start_time
, NULL
);
112 failed
= run
->function(memc
);
113 gettimeofday(&end_time
, NULL
);
114 load_time
= timedif(end_time
, start_time
);
116 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ failed ]\n", load_time
/ 1000,
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");
134 world
.destroy(world_ptr
);