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 static const char *test_strerror(test_return_t code
)
35 case TEST_MEMORY_ALLOCATION_FAILURE
:
36 return "memory allocation";
39 case TEST_MAXIMUM_RETURN
:
41 fprintf(stderr
, "Unknown return value\n");
47 int main(int argc
, char *argv
[])
51 char *collection_to_run
= NULL
;
53 server_startup_st
*startup_ptr
;
54 memcached_server_st
*servers
;
56 collection_st
*collection
;
60 memset(&world
, 0, sizeof(world_st
));
62 collection
= world
.collections
;
65 world_ptr
= world
.create();
69 startup_ptr
= (server_startup_st
*)world_ptr
;
70 servers
= (memcached_server_st
*)startup_ptr
->servers
;
73 collection_to_run
= argv
[1];
78 for (next
= collection
; next
->name
; next
++)
83 if (collection_to_run
&& fnmatch(collection_to_run
, next
->name
, 0))
86 fprintf(stderr
, "\n%s\n\n", next
->name
);
88 for (x
= 0; run
->name
; run
++)
93 struct timeval start_time
, end_time
;
96 if (wildcard
&& fnmatch(wildcard
, run
->name
, 0))
99 fprintf(stderr
, "Testing %s", run
->name
);
101 memc
= memcached_create(NULL
);
104 rc
= memcached_server_push(memc
, servers
);
105 test_truth(rc
== MEMCACHED_SUCCESS
);
107 if (run
->requires_flush
)
109 memcached_flush(memc
, 0);
110 memcached_quit(memc
);
113 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
115 test_truth(memc
->hosts
[loop
].fd
== -1);
116 test_truth(memc
->hosts
[loop
].cursor_active
== 0);
123 if (rc
!= MEMCACHED_SUCCESS
)
125 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
130 gettimeofday(&start_time
, NULL
);
131 failed
= run
->function(memc
);
132 gettimeofday(&end_time
, NULL
);
133 load_time
= timedif(end_time
, start_time
);
135 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ %s ]\n", load_time
/ 1000,
136 load_time
% 1000, test_strerror(failed
));
139 (void)next
->post(memc
);
143 memcached_free(memc
);
147 fprintf(stderr
, "All tests completed successfully\n\n");
150 world
.destroy(world_ptr
);