We keep having problems with it being this large so for release I am
[awesomized/libmemcached] / tests / test.c
1 /*
2 Sample test application.
3 */
4 #include <assert.h>
5 #include <memcached.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/time.h>
10 #include <time.h>
11
12 long int timedif(struct timeval a, struct timeval b)
13 {
14 register int us, s;
15
16 us = a.tv_usec - b.tv_usec;
17 us /= 1000;
18 s = a.tv_sec - b.tv_sec;
19 s *= 1000;
20 return s + us;
21 }
22
23 void init_test(memcached_st *not_used)
24 {
25 memcached_st memc;
26
27 (void)memcached_create(&memc);
28 memcached_free(&memc);
29 }
30
31 void allocation_test(memcached_st *not_used)
32 {
33 memcached_st *memc;
34 memc= memcached_create(NULL);
35 assert(memc);
36 memcached_free(memc);
37 }
38
39 void connection_test(memcached_st *memc)
40 {
41 memcached_return rc;
42
43 rc= memcached_server_add(memc, "localhost", 0);
44 assert(rc == MEMCACHED_SUCCESS);
45 }
46
47 void error_test(memcached_st *memc)
48 {
49 memcached_return rc;
50
51 for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
52 {
53 printf("Error %d -> %s\n", rc, memcached_strerror(memc, rc));
54 }
55 }
56
57 void set_test(memcached_st *memc)
58 {
59 memcached_return rc;
60 char *key= "foo";
61 char *value= "when we sanitize";
62
63 rc= memcached_set(memc, key, strlen(key),
64 value, strlen(value),
65 (time_t)0, (uint16_t)0);
66 assert(rc == MEMCACHED_SUCCESS);
67 }
68
69 void add_test(memcached_st *memc)
70 {
71 memcached_return rc;
72 char *key= "foo";
73 char *value= "when we sanitize";
74
75 rc= memcached_add(memc, key, strlen(key),
76 value, strlen(value),
77 (time_t)0, (uint16_t)0);
78 assert(rc == MEMCACHED_NOTSTORED);
79 }
80
81 void replace_test(memcached_st *memc)
82 {
83 memcached_return rc;
84 char *key= "foo";
85 char *value= "when we sanitize";
86
87 rc= memcached_replace(memc, key, strlen(key),
88 value, strlen(value),
89 (time_t)0, (uint16_t)0);
90 assert(rc == MEMCACHED_SUCCESS);
91 }
92
93 void delete_test(memcached_st *memc)
94 {
95 memcached_return rc;
96 char *key= "foo";
97 char *value= "when we sanitize";
98
99 rc= memcached_set(memc, key, strlen(key),
100 value, strlen(value),
101 (time_t)0, (uint16_t)0);
102 assert(rc == MEMCACHED_SUCCESS);
103
104 rc= memcached_delete(memc, key, strlen(key), (time_t)0);
105 assert(rc == MEMCACHED_SUCCESS);
106 }
107
108 void flush_test(memcached_st *memc)
109 {
110 memcached_return rc;
111
112 rc= memcached_flush(memc, 0);
113 assert(rc == MEMCACHED_SUCCESS);
114 }
115
116 void get_test(memcached_st *memc)
117 {
118 memcached_return rc;
119 char *key= "foo";
120 char *string;
121 size_t string_length;
122 uint16_t flags;
123
124 string= memcached_get(memc, key, strlen(key),
125 &string_length, &flags, &rc);
126
127 assert(rc == MEMCACHED_NOTFOUND);
128 assert(string_length == 0);
129 assert(!string);
130 }
131
132 void get_test2(memcached_st *memc)
133 {
134 memcached_return rc;
135 char *key= "foo";
136 char *value= "when we sanitize";
137 char *string;
138 size_t string_length;
139 uint16_t flags;
140
141 rc= memcached_set(memc, key, strlen(key),
142 value, strlen(value),
143 (time_t)0, (uint16_t)0);
144 assert(rc == MEMCACHED_SUCCESS);
145
146 string= memcached_get(memc, key, strlen(key),
147 &string_length, &flags, &rc);
148
149 assert(string);
150 assert(rc == MEMCACHED_SUCCESS);
151 assert(string_length == strlen(value));
152 assert(!memcmp(string, value, string_length));
153
154 free(string);
155 }
156
157 void set_test2(memcached_st *memc)
158 {
159 memcached_return rc;
160 char *key= "foo";
161 char *value= "train in the brain";
162 size_t value_length= strlen(value);
163 unsigned int x;
164
165 for (x= 0; x < 10; x++)
166 {
167 rc= memcached_set(memc, key, strlen(key),
168 value, value_length,
169 (time_t)0, (uint16_t)0);
170 assert(rc == MEMCACHED_SUCCESS);
171 }
172 }
173
174 void set_test3(memcached_st *memc)
175 {
176 memcached_return rc;
177 char *key= "foo";
178 char *value;
179 size_t value_length= 8191;
180 unsigned int x;
181
182 value = (char*)malloc(value_length);
183 assert(value);
184
185 for (x= 0; x < value_length; x++)
186 value[x] = (char) (x % 127);
187
188 for (x= 0; x < 1; x++)
189 {
190 rc= memcached_set(memc, key, strlen(key),
191 value, value_length,
192 (time_t)0, (uint16_t)0);
193 assert(rc == MEMCACHED_SUCCESS);
194 }
195
196 free(value);
197 }
198
199 void get_test3(memcached_st *memc)
200 {
201 memcached_return rc;
202 char *key= "foo";
203 char *value;
204 size_t value_length= 8191;
205 char *string;
206 size_t string_length;
207 uint16_t flags;
208 int x;
209
210 value = (char*)malloc(value_length);
211 assert(value);
212
213 for (x= 0; x < value_length; x++)
214 value[x] = (char) (x % 127);
215
216 rc= memcached_set(memc, key, strlen(key),
217 value, value_length,
218 (time_t)0, (uint16_t)0);
219 assert(rc == MEMCACHED_SUCCESS);
220
221 string= memcached_get(memc, key, strlen(key),
222 &string_length, &flags, &rc);
223
224 assert(rc == MEMCACHED_SUCCESS);
225 assert(string);
226 assert(string_length == value_length);
227 assert(!memcmp(string, value, string_length));
228
229 free(string);
230 free(value);
231 }
232
233 void get_test4(memcached_st *memc)
234 {
235 memcached_return rc;
236 char *key= "foo";
237 char *value;
238 size_t value_length= 8191;
239 char *string;
240 size_t string_length;
241 uint16_t flags;
242 int x;
243
244 value = (char*)malloc(value_length);
245 assert(value);
246
247 for (x= 0; x < value_length; x++)
248 value[x] = (char) (x % 127);
249
250 rc= memcached_set(memc, key, strlen(key),
251 value, value_length,
252 (time_t)0, (uint16_t)0);
253 assert(rc == MEMCACHED_SUCCESS);
254
255 for (x= 0; x < 10; x++)
256 {
257 string= memcached_get(memc, key, strlen(key),
258 &string_length, &flags, &rc);
259
260 assert(rc == MEMCACHED_SUCCESS);
261 assert(string);
262 assert(string_length == value_length);
263 assert(!memcmp(string, value, string_length));
264 free(string);
265 }
266
267 free(value);
268 }
269
270 void stats_servername_test(memcached_st *memc)
271 {
272 memcached_return rc;
273 memcached_stat_st stat;
274 rc= memcached_stat_servername(&stat, NULL,
275 "localhost",
276 MEMCACHED_DEFAULT_PORT);
277 }
278
279 void increment_test(memcached_st *memc)
280 {
281 unsigned int new_number;
282 memcached_return rc;
283 char *key= "number";
284 char *value= "0";
285
286 rc= memcached_set(memc, key, strlen(key),
287 value, strlen(value),
288 (time_t)0, (uint16_t)0);
289 assert(rc == MEMCACHED_SUCCESS);
290
291 rc= memcached_increment(memc, key, strlen(key),
292 1, &new_number);
293 assert(rc == MEMCACHED_SUCCESS);
294 assert(new_number == 1);
295
296 rc= memcached_increment(memc, key, strlen(key),
297 1, &new_number);
298 assert(rc == MEMCACHED_SUCCESS);
299 assert(new_number == 2);
300 }
301
302 void decrement_test(memcached_st *memc)
303 {
304 unsigned int new_number;
305 memcached_return rc;
306 char *key= "number";
307 char *value= "3";
308
309 rc= memcached_set(memc, key, strlen(key),
310 value, strlen(value),
311 (time_t)0, (uint16_t)0);
312 assert(rc == MEMCACHED_SUCCESS);
313
314 rc= memcached_decrement(memc, key, strlen(key),
315 1, &new_number);
316 assert(rc == MEMCACHED_SUCCESS);
317 assert(new_number == 2);
318
319 rc= memcached_decrement(memc, key, strlen(key),
320 1, &new_number);
321 assert(rc == MEMCACHED_SUCCESS);
322 assert(new_number == 1);
323 }
324
325 void quit_test(memcached_st *memc)
326 {
327 memcached_return rc;
328 char *key= "fudge";
329 char *value= "sanford and sun";
330
331 rc= memcached_set(memc, key, strlen(key),
332 value, strlen(value),
333 (time_t)10, (uint16_t)3);
334 assert(rc == MEMCACHED_SUCCESS);
335 memcached_quit(memc);
336
337 rc= memcached_set(memc, key, strlen(key),
338 value, strlen(value),
339 (time_t)50, (uint16_t)9);
340 assert(rc == MEMCACHED_SUCCESS);
341 }
342
343 void mget_test(memcached_st *memc)
344 {
345 memcached_return rc;
346 char *keys[]= {"fudge", "son", "food"};
347 size_t key_length[]= {5, 3, 4};
348 unsigned int x;
349 uint16_t flags;
350
351 char return_key[MEMCACHED_MAX_KEY];
352 size_t return_key_length;
353 char *return_value;
354 size_t return_value_length;
355
356 /* We need to empty the server before continueing test */
357 rc= memcached_flush(memc, 0);
358 assert(rc == MEMCACHED_SUCCESS);
359
360 rc= memcached_mget(memc, keys, key_length, 3);
361 assert(rc == MEMCACHED_SUCCESS);
362
363 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
364 &return_value_length, &flags, &rc)) != NULL)
365 {
366 assert(return_value);
367 }
368 assert(!return_value);
369 assert(return_value_length == 0);
370 assert(rc == MEMCACHED_NOTFOUND);
371
372 for (x= 0; x < 3; x++)
373 {
374 rc= memcached_set(memc, keys[x], key_length[x],
375 keys[x], key_length[x],
376 (time_t)50, (uint16_t)9);
377 assert(rc == MEMCACHED_SUCCESS);
378 }
379
380 rc= memcached_mget(memc, keys, key_length, 3);
381 assert(rc == MEMCACHED_SUCCESS);
382
383 x= 0;
384 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
385 &return_value_length, &flags, &rc)))
386 {
387 assert(return_value);
388 assert(rc == MEMCACHED_SUCCESS);
389 assert(return_key_length == return_value_length);
390 assert(!memcmp(return_value, return_key, return_value_length));
391 free(return_value);
392 x++;
393 }
394 }
395
396 void get_stats_keys(memcached_st *memc)
397 {
398 char **list;
399 char **ptr;
400 memcached_stat_st stat;
401 memcached_return rc;
402
403 list= memcached_stat_get_keys(memc, &stat, &rc);
404 assert(rc == MEMCACHED_SUCCESS);
405 for (ptr= list; *ptr; ptr++)
406 printf("Found key %s\n", *ptr);
407 fflush(stdout);
408
409 free(list);
410 }
411
412 void get_stats(memcached_st *memc)
413 {
414 unsigned int x;
415 char **list;
416 char **ptr;
417 memcached_return rc;
418 memcached_stat_st *stat;
419
420 stat= memcached_stat(memc, NULL, &rc);
421 assert(rc == MEMCACHED_SUCCESS);
422
423 assert(rc == MEMCACHED_SUCCESS);
424 assert(stat);
425
426 for (x= 0; x < memcached_server_count(memc); x++)
427 {
428 list= memcached_stat_get_keys(memc, &stat[x], &rc);
429 assert(rc == MEMCACHED_SUCCESS);
430 for (ptr= list; *ptr; ptr++)
431 printf("Found key %s\n", *ptr);
432
433 free(list);
434 }
435
436 free(stat);
437 }
438
439 void add_host_test(memcached_st *memc)
440 {
441 unsigned int x;
442 memcached_server_st *servers;
443 memcached_return rc;
444 char servername[]= "0.example.com";
445
446 servers= memcached_server_list_append(NULL, servername, 400, &rc);
447 assert(servers);
448 assert(1 == memcached_server_list_count(servers));
449
450 for (x= 2; x < 20; x++)
451 {
452 char buffer[SMALL_STRING_LEN];
453
454 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
455 servers= memcached_server_list_append(servers, buffer, 401,
456 &rc);
457 assert(rc == MEMCACHED_SUCCESS);
458 assert(x == memcached_server_list_count(servers));
459 }
460
461 rc= memcached_server_push(memc, servers);
462 assert(rc == MEMCACHED_SUCCESS);
463 rc= memcached_server_push(memc, servers);
464 assert(rc == MEMCACHED_SUCCESS);
465
466 memcached_server_list_free(servers);
467 }
468
469 /* We don't test the behavior itself, we test the switches */
470 void behavior_test(memcached_st *memc)
471 {
472 unsigned long long value;
473 unsigned int set= 1;
474
475 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
476 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
477 assert(value == 1);
478
479 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
480 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
481 assert(value == 1);
482
483 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_MD5_HASHING, &set);
484 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_MD5_HASHING);
485 assert(value == 1);
486
487 set= 0;
488
489 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
490 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
491 assert(value == 0);
492
493 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
494 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
495 assert(value == 0);
496
497 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_MD5_HASHING, &set);
498 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_MD5_HASHING);
499 assert(value == 0);
500
501 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
502 assert(value > 0);
503
504 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
505 assert(value > 0);
506 }
507
508 /* Test case provided by Cal Haldenbrand */
509 void user_supplied_bug1(memcached_st *memc)
510 {
511 unsigned int setter= 1;
512 unsigned int x;
513
514 long total= 0;
515 int size= 0;
516 srand(time(NULL));
517 char key[10];
518 char *randomstuff = (char *)malloc(6 * 1024);
519 memset(randomstuff, 0, 6 * 1024);
520
521 memcached_return rc;
522
523 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
524 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
525
526
527 /* add key */
528 for (x= 0 ; total < 20 * 1024576 ; x++ )
529 {
530 unsigned int j= 0;
531
532 size= (rand() % ( 5 * 1024 ) ) + 400;
533 memset(randomstuff, 0, 6 * 1024);
534 assert(size < 6 * 1024); /* Being safe here */
535
536 for (j= 0 ; j < size ;j++)
537 randomstuff[j] = (char) (rand() % 26) + 97;
538
539 total += size;
540 sprintf(key, "%d", x);
541 rc = memcached_set(memc, key, strlen(key),
542 randomstuff, strlen(randomstuff), 10, 0);
543 /* If we fail, lets try again */
544 if (rc != MEMCACHED_SUCCESS)
545 rc = memcached_set(memc, key, strlen(key),
546 randomstuff, strlen(randomstuff), 10, 0);
547 assert(rc == MEMCACHED_SUCCESS);
548 }
549 }
550 void add_host_test1(memcached_st *memc)
551 {
552 unsigned int x;
553 memcached_return rc;
554 char servername[]= "0.example.com";
555 memcached_server_st *servers;
556
557 servers= memcached_server_list_append(NULL, servername, 400, &rc);
558 assert(servers);
559 assert(1 == memcached_server_list_count(servers));
560
561 for (x= 2; x < 20; x++)
562 {
563 char buffer[SMALL_STRING_LEN];
564
565 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
566 servers= memcached_server_list_append(servers, buffer, 401,
567 &rc);
568 assert(rc == MEMCACHED_SUCCESS);
569 assert(x == memcached_server_list_count(servers));
570 }
571
572 rc= memcached_server_push(memc, servers);
573 assert(rc == MEMCACHED_SUCCESS);
574 rc= memcached_server_push(memc, servers);
575 assert(rc == MEMCACHED_SUCCESS);
576
577 memcached_server_list_free(servers);
578 }
579
580 typedef struct test_st test_st;
581
582 struct test_st {
583 char *function_name;
584 unsigned int requires_flush;
585 void (*function)(memcached_st *memc);
586 };
587
588 int main(int argc, char *argv[])
589 {
590 unsigned int x;
591 char *server_list;
592 char *test_to_run= NULL;
593 char *wildcard= NULL;
594 memcached_server_st *servers;
595
596 if (argc > 2)
597 test_to_run= argv[1];
598
599 if (argc == 3)
600 wildcard= argv[2];
601
602 if (!(server_list= getenv("MEMCACHED_SERVERS")))
603 server_list= "localhost";
604
605 printf("servers %s\n", server_list);
606 srandom(time(NULL));
607
608 servers= memcached_servers_parse(server_list);
609 assert(servers);
610
611 for (x= 0; x < memcached_server_list_count(servers); x++)
612 {
613 printf("\t%s : %u\n", servers[x].hostname, servers[x].port);
614 assert(servers[x].stack_responses == 0);
615 assert(servers[x].fd == -1);
616 assert(servers[x].cursor_active == 0);
617 }
618
619 printf("\n");
620
621 /* Clean the server before beginning testing */
622 test_st tests[] ={
623 {"flush", 0, flush_test },
624 {"init", 0, init_test },
625 {"allocation", 0, allocation_test },
626 {"error", 0, error_test },
627 {"set", 0, set_test },
628 {"set2", 0, set_test2 },
629 {"set3", 0, set_test3 },
630 {"add", 0, add_test },
631 {"replace", 0, replace_test },
632 {"delete", 1, delete_test },
633 {"get", 0, get_test },
634 {"get2", 0, get_test2 },
635 {"get3", 0, get_test3 },
636 {"get4", 0, get_test4 },
637 {"stats_servername", 0, stats_servername_test },
638 {"increment", 0, increment_test },
639 {"decrement", 0, decrement_test },
640 {"quit", 0, quit_test },
641 {"mget", 0, mget_test },
642 {"get_stats", 0, get_stats },
643 {"add_host_test", 0, add_host_test },
644 {"get_stats_keys", 0, get_stats_keys },
645 {"behavior_test", 0, get_stats_keys },
646 {0, 0, 0}
647 };
648
649 test_st user_tests[] ={
650 {"user_supplied_bug1", 0, user_supplied_bug1 },
651 {0, 0, 0}
652 };
653
654 if ((test_to_run && !strcmp(test_to_run, "block")) || !test_to_run)
655 {
656 fprintf(stderr, "\nBlock tests\n\n");
657 for (x= 0; tests[x].function_name; x++)
658 {
659 if (wildcard)
660 if (strcmp(wildcard, tests[x].function_name))
661 continue;
662
663 memcached_st *memc;
664 memcached_return rc;
665 struct timeval start_time, end_time;
666
667 memc= memcached_create(NULL);
668 assert(memc);
669
670 rc= memcached_server_push(memc, servers);
671 assert(rc == MEMCACHED_SUCCESS);
672
673 unsigned int loop;
674 for (loop= 0; loop < memcached_server_list_count(servers); loop++)
675 {
676 assert(memc->hosts[loop].stack_responses == 0);
677 assert(memc->hosts[loop].fd == -1);
678 assert(memc->hosts[loop].cursor_active == 0);
679 }
680
681 fprintf(stderr, "Testing %s", tests[x].function_name);
682 gettimeofday(&start_time, NULL);
683 tests[x].function(memc);
684 gettimeofday(&end_time, NULL);
685 long int load_time= timedif(end_time, start_time);
686 fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000,
687 load_time % 1000);
688 assert(memc);
689 memcached_free(memc);
690 }
691 }
692
693 if ((test_to_run && !strcmp(test_to_run, "nonblock")) || !test_to_run)
694 {
695 fprintf(stderr, "\nNonblock tests\n\n");
696 for (x= 0; tests[x].function_name; x++)
697 {
698 if (wildcard)
699 if (strcmp(wildcard, tests[x].function_name))
700 continue;
701
702 memcached_st *memc;
703 memcached_return rc;
704 struct timeval start_time, end_time;
705
706 memc= memcached_create(NULL);
707 assert(memc);
708
709 rc= memcached_server_push(memc, servers);
710 assert(rc == MEMCACHED_SUCCESS);
711
712 fprintf(stderr, "Testing %s", tests[x].function_name);
713 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
714 gettimeofday(&start_time, NULL);
715 tests[x].function(memc);
716 gettimeofday(&end_time, NULL);
717 long int load_time= timedif(end_time, start_time);
718 fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000,
719 load_time % 1000);
720 assert(memc);
721 memcached_free(memc);
722 }
723 }
724
725 if ((test_to_run && !strcmp(test_to_run, "nodelay")) || !test_to_run)
726 {
727 fprintf(stderr, "\nTCP Nodelay tests\n\n");
728 for (x= 0; tests[x].function_name; x++)
729 {
730 if (wildcard)
731 if (strcmp(wildcard, tests[x].function_name))
732 continue;
733
734 memcached_st *memc;
735 memcached_return rc;
736 struct timeval start_time, end_time;
737
738 memc= memcached_create(NULL);
739 assert(memc);
740
741 rc= memcached_server_push(memc, servers);
742 assert(rc == MEMCACHED_SUCCESS);
743
744 fprintf(stderr, "Testing %s", tests[x].function_name);
745 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
746 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL);
747 gettimeofday(&start_time, NULL);
748 tests[x].function(memc);
749 gettimeofday(&end_time, NULL);
750 long int load_time= timedif(end_time, start_time);
751 fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000,
752 load_time % 1000);
753 assert(memc);
754 memcached_free(memc);
755 }
756 }
757
758 if ((test_to_run && !strcmp(test_to_run, "md5")) || !test_to_run)
759 {
760 fprintf(stderr, "\nMD5 Hashing\n\n");
761 for (x= 0; tests[x].function_name; x++)
762 {
763 if (wildcard)
764 if (strcmp(wildcard, tests[x].function_name))
765 continue;
766
767 memcached_st *memc;
768 memcached_return rc;
769 struct timeval start_time, end_time;
770
771 memc= memcached_create(NULL);
772 assert(memc);
773
774 rc= memcached_server_push(memc, servers);
775 assert(rc == MEMCACHED_SUCCESS);
776
777 fprintf(stderr, "Testing %s", tests[x].function_name);
778 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_MD5_HASHING, NULL);
779 gettimeofday(&start_time, NULL);
780 tests[x].function(memc);
781 gettimeofday(&end_time, NULL);
782 long int load_time= timedif(end_time, start_time);
783 fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000,
784 load_time % 1000);
785 assert(memc);
786 memcached_free(memc);
787 }
788 }
789
790 if ((test_to_run && !strcmp(test_to_run, "user")) || !test_to_run)
791 {
792 fprintf(stderr, "\nUser Supplied tests\n\n");
793 for (x= 0; user_tests[x].function_name; x++)
794 {
795 if (wildcard)
796 if (strcmp(wildcard, tests[x].function_name))
797 continue;
798
799 memcached_st *memc;
800 memcached_return rc;
801 struct timeval start_time, end_time;
802
803 memc= memcached_create(NULL);
804 assert(memc);
805
806 rc= memcached_server_push(memc, servers);
807 assert(rc == MEMCACHED_SUCCESS);
808
809 fprintf(stderr, "Testing %s", user_tests[x].function_name);
810 gettimeofday(&start_time, NULL);
811 user_tests[x].function(memc);
812 gettimeofday(&end_time, NULL);
813 long int load_time= timedif(end_time, start_time);
814 fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000,
815 load_time % 1000);
816 assert(memc);
817 memcached_free(memc);
818 }
819 }
820
821 /* Clean up whatever we might have left */
822 {
823 memcached_st *memc;
824 memc= memcached_create(NULL);
825 assert(memc);
826 flush_test(memc);
827 memcached_free(memc);
828 }
829
830 fprintf(stderr, "All tests completed successfully\n\n");
831
832 return 0;
833 }