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)
55 int main(int argc
, char *argv
[])
59 char *collection_to_run
= NULL
;
61 server_startup_st
*startup_ptr
;
62 memcached_server_st
*servers
;
64 collection_st
*collection
;
68 memset(&world
, 0, sizeof(world_st
));
70 collection
= world
.collections
;
73 world_ptr
= world
.create();
77 startup_ptr
= (server_startup_st
*)world_ptr
;
78 servers
= (memcached_server_st
*)startup_ptr
->servers
;
81 collection_to_run
= argv
[1];
86 for (next
= collection
; next
->name
; next
++)
91 if (collection_to_run
&& fnmatch(collection_to_run
, next
->name
, 0))
94 fprintf(stderr
, "\n%s\n\n", next
->name
);
96 for (x
= 0; run
->name
; run
++)
101 struct timeval start_time
, end_time
;
104 if (wildcard
&& fnmatch(wildcard
, run
->name
, 0))
107 fprintf(stderr
, "Testing %s", run
->name
);
109 memc
= memcached_create(NULL
);
112 rc
= memcached_server_push(memc
, servers
);
113 test_truth(rc
== MEMCACHED_SUCCESS
);
115 if (run
->requires_flush
)
117 memcached_flush(memc
, 0);
118 memcached_quit(memc
);
121 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
123 test_truth(memc
->hosts
[loop
].fd
== -1);
124 test_truth(memc
->hosts
[loop
].cursor_active
== 0);
131 if (rc
!= MEMCACHED_SUCCESS
)
133 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
138 gettimeofday(&start_time
, NULL
);
139 failed
= run
->function(memc
);
140 gettimeofday(&end_time
, NULL
);
141 load_time
= timedif(end_time
, start_time
);
143 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ %s ]\n", load_time
/ 1000,
144 load_time
% 1000, test_strerror(failed
));
147 (void)next
->post(memc
);
151 memcached_free(memc
);
155 fprintf(stderr
, "All tests completed successfully\n\n");
158 world
.destroy(world_ptr
);