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();
51 startup_ptr
= (server_startup_st
*)world_ptr
;
52 servers
= (memcached_server_st
*)startup_ptr
->servers
;
55 collection_to_run
= argv
[1];
60 for (next
= collection
; next
->name
; next
++)
65 if (collection_to_run
&& fnmatch(collection_to_run
, next
->name
, 0))
68 fprintf(stderr
, "\n%s\n\n", next
->name
);
70 for (x
= 0; run
->name
; run
++)
75 struct timeval start_time
, end_time
;
78 if (wildcard
&& fnmatch(wildcard
, run
->name
, 0))
81 fprintf(stderr
, "Testing %s", run
->name
);
83 memc
= memcached_create(NULL
);
86 rc
= memcached_server_push(memc
, servers
);
87 assert(rc
== MEMCACHED_SUCCESS
);
89 if (run
->requires_flush
)
91 memcached_flush(memc
, 0);
95 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
97 assert(memc
->hosts
[loop
].fd
== -1);
98 assert(memc
->hosts
[loop
].cursor_active
== 0);
106 if (rc
!= MEMCACHED_SUCCESS
)
108 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
113 gettimeofday(&start_time
, NULL
);
114 failed
= run
->function(memc
);
115 gettimeofday(&end_time
, NULL
);
116 load_time
= timedif(end_time
, start_time
);
118 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ failed ]\n", load_time
/ 1000,
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");
136 world
.destroy(world_ptr
);