2 Sample test application.
17 static long int timedif(struct timeval a
, struct timeval b
)
21 us
= (int)(a
.tv_usec
- b
.tv_usec
);
23 s
= (int)(a
.tv_sec
- b
.tv_sec
);
28 int main(int argc
, char *argv
[])
31 char *collection_to_run
= NULL
;
33 server_startup_st
*startup_ptr
;
34 memcached_server_st
*servers
;
36 collection_st
*collection
;
41 memset(&world
, 0, sizeof(world_st
));
43 collection
= world
.collections
;
46 world_ptr
= world
.create();
50 startup_ptr
= (server_startup_st
*)world_ptr
;
51 servers
= (memcached_server_st
*)startup_ptr
->servers
;
54 collection_to_run
= argv
[1];
59 for (next
= collection
; next
->name
; next
++)
64 if (collection_to_run
&& fnmatch(collection_to_run
, next
->name
, 0))
67 fprintf(stderr
, "\n%s\n\n", next
->name
);
69 for (x
= 0; run
->name
; run
++)
74 struct timeval start_time
, end_time
;
77 if (wildcard
&& fnmatch(wildcard
, run
->name
, 0))
80 fprintf(stderr
, "Testing %s", run
->name
);
82 memc
= memcached_create(NULL
);
85 rc
= memcached_server_push(memc
, servers
);
86 assert(rc
== MEMCACHED_SUCCESS
);
88 if (run
->requires_flush
)
90 memcached_flush(memc
, 0);
94 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
96 assert(memc
->hosts
[loop
].fd
== -1);
97 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
);