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 void create_core(void)
49 if (getenv("LIBMEMCACHED_NO_COREDUMP") == NULL
&& fork() == 0)
53 int main(int argc
, char *argv
[])
57 char *collection_to_run
= NULL
;
59 server_startup_st
*startup_ptr
;
60 memcached_server_st
*servers
;
62 collection_st
*collection
;
66 memset(&world
, 0, sizeof(world_st
));
68 collection
= world
.collections
;
71 world_ptr
= world
.create();
75 startup_ptr
= (server_startup_st
*)world_ptr
;
76 servers
= (memcached_server_st
*)startup_ptr
->servers
;
79 collection_to_run
= argv
[1];
84 for (next
= collection
; next
->name
; next
++)
89 if (collection_to_run
&& fnmatch(collection_to_run
, next
->name
, 0))
92 fprintf(stderr
, "\n%s\n\n", next
->name
);
94 for (x
= 0; run
->name
; run
++)
98 memcached_return_t rc
;
99 struct timeval start_time
, end_time
;
102 if (wildcard
&& fnmatch(wildcard
, run
->name
, 0))
105 fprintf(stderr
, "Testing %s", run
->name
);
107 memc
= memcached_create(NULL
);
110 rc
= memcached_server_push(memc
, servers
);
111 test_truth(rc
== MEMCACHED_SUCCESS
);
113 if (run
->requires_flush
)
115 memcached_flush(memc
, 0);
116 memcached_quit(memc
);
119 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
121 test_truth(memc
->hosts
[loop
].fd
== -1);
122 test_truth(memc
->hosts
[loop
].cursor_active
== 0);
129 if (rc
!= MEMCACHED_SUCCESS
)
131 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
136 gettimeofday(&start_time
, NULL
);
137 failed
= run
->function(memc
);
138 gettimeofday(&end_time
, NULL
);
139 load_time
= timedif(end_time
, start_time
);
141 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ %s ]\n", load_time
/ 1000,
142 load_time
% 1000, test_strerror(failed
));
145 (void)next
->post(memc
);
149 memcached_free(memc
);
153 fprintf(stderr
, "All tests completed successfully\n\n");
156 world
.destroy(world_ptr
);