Working on getting version patch working
[awesomized/libmemcached] / tests / function.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 <sys/types.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <time.h>
14 #include "../lib/common.h"
15 #include "../src/generator.h"
16 #include "../src/execute.h"
17
18 #ifndef INT64_MAX
19 #define INT64_MAX LONG_MAX
20 #endif
21 #ifndef INT32_MAX
22 #define INT32_MAX INT_MAX
23 #endif
24
25
26 #include "test.h"
27
28 #define GLOBAL_COUNT 100000
29 static pairs_st *global_pairs;
30 static char *global_keys[GLOBAL_COUNT];
31 static size_t global_keys_length[GLOBAL_COUNT];
32
33 uint8_t init_test(memcached_st *not_used)
34 {
35 memcached_st memc;
36
37 (void)memcached_create(&memc);
38 memcached_free(&memc);
39
40 return 0;
41 }
42
43 uint8_t server_list_null_test(memcached_st *ptr)
44 {
45 memcached_server_st *server_list;
46 memcached_return rc;
47
48 server_list= memcached_server_list_append(NULL, NULL, 0, NULL);
49 assert(server_list == NULL);
50
51 server_list= memcached_server_list_append(NULL, "localhost", 0, NULL);
52 assert(server_list == NULL);
53
54 server_list= memcached_server_list_append(NULL, NULL, 0, &rc);
55 assert(server_list == NULL);
56
57 return 0;
58 }
59
60 uint8_t allocation_test(memcached_st *not_used)
61 {
62 memcached_st *memc;
63 memc= memcached_create(NULL);
64 assert(memc);
65 memcached_free(memc);
66
67 return 0;
68 }
69
70 uint8_t clone_test(memcached_st *memc)
71 {
72 /* All null? */
73 {
74 memcached_st *clone;
75 clone= memcached_clone(NULL, NULL);
76 assert(clone);
77 memcached_free(clone);
78 }
79
80 /* Can we init from null? */
81 {
82 memcached_st *clone;
83 clone= memcached_clone(NULL, memc);
84 assert(clone);
85 memcached_free(clone);
86 }
87
88 /* Can we init from struct? */
89 {
90 memcached_st declared_clone;
91 memcached_st *clone;
92 clone= memcached_clone(&declared_clone, NULL);
93 assert(clone);
94 memcached_free(clone);
95 }
96
97 /* Can we init from struct? */
98 {
99 memcached_st declared_clone;
100 memcached_st *clone;
101 clone= memcached_clone(&declared_clone, memc);
102 assert(clone);
103 memcached_free(clone);
104 }
105
106 return 0;
107 }
108
109 uint8_t connection_test(memcached_st *memc)
110 {
111 memcached_return rc;
112
113 rc= memcached_server_add(memc, "localhost", 0);
114 assert(rc == MEMCACHED_SUCCESS);
115
116 return 0;
117 }
118
119 uint8_t error_test(memcached_st *memc)
120 {
121 memcached_return rc;
122
123 for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
124 {
125 printf("Error %d -> %s\n", rc, memcached_strerror(memc, rc));
126 }
127
128 return 0;
129 }
130
131 uint8_t set_test(memcached_st *memc)
132 {
133 memcached_return rc;
134 char *key= "foo";
135 char *value= "when we sanitize";
136
137 rc= memcached_set(memc, key, strlen(key),
138 value, strlen(value),
139 (time_t)0, (uint32_t)0);
140 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
141
142 return 0;
143 }
144
145 uint8_t append_test(memcached_st *memc)
146 {
147 memcached_return rc;
148 char *key= "fig";
149 char *value= "we";
150 size_t value_length;
151 uint32_t flags;
152
153 rc= memcached_flush(memc, 0);
154 assert(rc == MEMCACHED_SUCCESS);
155
156 rc= memcached_set(memc, key, strlen(key),
157 value, strlen(value),
158 (time_t)0, (uint32_t)0);
159 assert(rc == MEMCACHED_SUCCESS);
160
161 rc= memcached_append(memc, key, strlen(key),
162 " the", strlen(" the"),
163 (time_t)0, (uint32_t)0);
164 assert(rc == MEMCACHED_SUCCESS);
165
166 rc= memcached_append(memc, key, strlen(key),
167 " people", strlen(" people"),
168 (time_t)0, (uint32_t)0);
169 assert(rc == MEMCACHED_SUCCESS);
170
171 value= memcached_get(memc, key, strlen(key),
172 &value_length, &flags, &rc);
173 assert(!memcmp(value, "we the people", strlen("we the people")));
174 assert(strlen("we the people") == value_length);
175 assert(rc == MEMCACHED_SUCCESS);
176 free(value);
177
178 return 0;
179 }
180
181 uint8_t append_binary_test(memcached_st *memc)
182 {
183 memcached_return rc;
184 char *key= "numbers";
185 unsigned int *store_ptr;
186 unsigned int store_list[] = { 23, 56, 499, 98, 32847, 0 };
187 char *value;
188 size_t value_length;
189 uint32_t flags;
190 unsigned int x;
191
192 rc= memcached_flush(memc, 0);
193 assert(rc == MEMCACHED_SUCCESS);
194
195 rc= memcached_set(memc,
196 key, strlen(key),
197 NULL, 0,
198 (time_t)0, (uint32_t)0);
199 assert(rc == MEMCACHED_SUCCESS);
200
201 for (x= 0; store_list[x] ; x++)
202 {
203 rc= memcached_append(memc,
204 key, strlen(key),
205 (char *)&store_list[x], sizeof(unsigned int),
206 (time_t)0, (uint32_t)0);
207 assert(rc == MEMCACHED_SUCCESS);
208 }
209
210 value= memcached_get(memc, key, strlen(key),
211 &value_length, &flags, &rc);
212 assert((value_length == (sizeof(unsigned int) * x)));
213 assert(rc == MEMCACHED_SUCCESS);
214
215 store_ptr= (unsigned int *)value;
216 x= 0;
217 while ((size_t)store_ptr < (size_t)(value + value_length))
218 {
219 assert(*store_ptr == store_list[x++]);
220 store_ptr++;
221 }
222 free(value);
223
224 return 0;
225 }
226
227 uint8_t cas2_test(memcached_st *memc)
228 {
229 memcached_return rc;
230 char *keys[]= {"fudge", "son", "food"};
231 size_t key_length[]= {5, 3, 4};
232 char *value= "we the people";
233 size_t value_length= strlen("we the people");
234 unsigned int x;
235 memcached_result_st results_obj;
236 memcached_result_st *results;
237 unsigned int set= 1;
238
239 rc= memcached_flush(memc, 0);
240 assert(rc == MEMCACHED_SUCCESS);
241
242 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, &set);
243
244 for (x= 0; x < 3; x++)
245 {
246 rc= memcached_set(memc, keys[x], key_length[x],
247 keys[x], key_length[x],
248 (time_t)50, (uint32_t)9);
249 assert(rc == MEMCACHED_SUCCESS);
250 }
251
252 rc= memcached_mget(memc, keys, key_length, 3);
253
254 results= memcached_result_create(memc, &results_obj);
255
256 results= memcached_fetch_result(memc, &results_obj, &rc);
257 assert(results);
258 assert(results->cas);
259 assert(rc == MEMCACHED_SUCCESS);
260 WATCHPOINT_ASSERT(memcached_result_cas(results));
261
262 assert(!memcmp(value, "we the people", strlen("we the people")));
263 assert(strlen("we the people") == value_length);
264 assert(rc == MEMCACHED_SUCCESS);
265
266 memcached_result_free(&results_obj);
267
268 return 0;
269 }
270
271 uint8_t cas_test(memcached_st *memc)
272 {
273 memcached_return rc;
274 char *key= "fun";
275 size_t key_length= strlen("fun");
276 char *value= "we the people";
277 size_t value_length= strlen("we the people");
278 memcached_result_st results_obj;
279 memcached_result_st *results;
280 unsigned int set= 1;
281
282 rc= memcached_flush(memc, 0);
283 assert(rc == MEMCACHED_SUCCESS);
284
285 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, &set);
286
287 rc= memcached_set(memc, key, strlen(key),
288 value, strlen(value),
289 (time_t)0, (uint32_t)0);
290 assert(rc == MEMCACHED_SUCCESS);
291
292 rc= memcached_mget(memc, &key, &key_length, 1);
293
294 results= memcached_result_create(memc, &results_obj);
295
296 results= memcached_fetch_result(memc, &results_obj, &rc);
297 assert(results);
298 assert(rc == MEMCACHED_SUCCESS);
299 WATCHPOINT_ASSERT(memcached_result_cas(results));
300
301 assert(!memcmp(value, "we the people", strlen("we the people")));
302 assert(strlen("we the people") == value_length);
303 assert(rc == MEMCACHED_SUCCESS);
304
305 memcached_result_free(&results_obj);
306
307 return 0;
308 }
309
310 uint8_t prepend_test(memcached_st *memc)
311 {
312 memcached_return rc;
313 char *key= "fig";
314 char *value= "people";
315 size_t value_length;
316 uint32_t flags;
317
318 rc= memcached_flush(memc, 0);
319 assert(rc == MEMCACHED_SUCCESS);
320
321 rc= memcached_set(memc, key, strlen(key),
322 value, strlen(value),
323 (time_t)0, (uint32_t)0);
324 assert(rc == MEMCACHED_SUCCESS);
325
326 rc= memcached_prepend(memc, key, strlen(key),
327 "the ", strlen("the "),
328 (time_t)0, (uint32_t)0);
329 assert(rc == MEMCACHED_SUCCESS);
330
331 rc= memcached_prepend(memc, key, strlen(key),
332 "we ", strlen("we "),
333 (time_t)0, (uint32_t)0);
334 assert(rc == MEMCACHED_SUCCESS);
335
336 value= memcached_get(memc, key, strlen(key),
337 &value_length, &flags, &rc);
338 assert(!memcmp(value, "we the people", strlen("we the people")));
339 assert(strlen("we the people") == value_length);
340 assert(rc == MEMCACHED_SUCCESS);
341 free(value);
342
343 return 0;
344 }
345
346 /*
347 Set the value, then quit to make sure it is flushed.
348 Come back in and test that add fails.
349 */
350 uint8_t add_test(memcached_st *memc)
351 {
352 memcached_return rc;
353 char *key= "foo";
354 char *value= "when we sanitize";
355
356 rc= memcached_set(memc, key, strlen(key),
357 value, strlen(value),
358 (time_t)0, (uint32_t)0);
359 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
360 memcached_quit(memc);
361 rc= memcached_add(memc, key, strlen(key),
362 value, strlen(value),
363 (time_t)0, (uint32_t)0);
364 assert(rc == MEMCACHED_NOTSTORED);
365
366 return 0;
367 }
368
369 uint8_t add_wrapper(memcached_st *memc)
370 {
371 unsigned int x;
372
373 for (x= 0; x < 10000; x++)
374 add_test(memc);
375
376 return 0;
377 }
378
379 uint8_t replace_test(memcached_st *memc)
380 {
381 memcached_return rc;
382 char *key= "foo";
383 char *value= "when we sanitize";
384
385 rc= memcached_replace(memc, key, strlen(key),
386 value, strlen(value),
387 (time_t)0, (uint32_t)0);
388 assert(rc == MEMCACHED_SUCCESS);
389
390 return 0;
391 }
392
393 uint8_t delete_test(memcached_st *memc)
394 {
395 memcached_return rc;
396 char *key= "foo";
397 char *value= "when we sanitize";
398
399 rc= memcached_set(memc, key, strlen(key),
400 value, strlen(value),
401 (time_t)0, (uint32_t)0);
402 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
403
404 rc= memcached_delete(memc, key, strlen(key), (time_t)0);
405 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
406
407 return 0;
408 }
409
410 uint8_t flush_test(memcached_st *memc)
411 {
412 memcached_return rc;
413
414 rc= memcached_flush(memc, 0);
415 assert(rc == MEMCACHED_SUCCESS);
416
417 return 0;
418 }
419
420 uint8_t get_test(memcached_st *memc)
421 {
422 memcached_return rc;
423 char *key= "foo";
424 char *string;
425 size_t string_length;
426 uint32_t flags;
427
428 rc= memcached_delete(memc, key, strlen(key), (time_t)0);
429 assert(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND);
430
431 string= memcached_get(memc, key, strlen(key),
432 &string_length, &flags, &rc);
433
434 assert(rc == MEMCACHED_NOTFOUND);
435 assert(string_length == 0);
436 assert(!string);
437
438 return 0;
439 }
440
441 uint8_t get_test2(memcached_st *memc)
442 {
443 memcached_return rc;
444 char *key= "foo";
445 char *value= "when we sanitize";
446 char *string;
447 size_t string_length;
448 uint32_t flags;
449
450 rc= memcached_set(memc, key, strlen(key),
451 value, strlen(value),
452 (time_t)0, (uint32_t)0);
453 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
454
455 string= memcached_get(memc, key, strlen(key),
456 &string_length, &flags, &rc);
457
458 assert(string);
459 assert(rc == MEMCACHED_SUCCESS);
460 assert(string_length == strlen(value));
461 assert(!memcmp(string, value, string_length));
462
463 free(string);
464
465 return 0;
466 }
467
468 uint8_t set_test2(memcached_st *memc)
469 {
470 memcached_return rc;
471 char *key= "foo";
472 char *value= "train in the brain";
473 size_t value_length= strlen(value);
474 unsigned int x;
475
476 for (x= 0; x < 10; x++)
477 {
478 rc= memcached_set(memc, key, strlen(key),
479 value, value_length,
480 (time_t)0, (uint32_t)0);
481 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
482 }
483
484 return 0;
485 }
486
487 uint8_t set_test3(memcached_st *memc)
488 {
489 memcached_return rc;
490 char *key= "foo";
491 char *value;
492 size_t value_length= 8191;
493 unsigned int x;
494
495 value = (char*)malloc(value_length);
496 assert(value);
497
498 for (x= 0; x < value_length; x++)
499 value[x] = (char) (x % 127);
500
501 for (x= 0; x < 1; x++)
502 {
503 rc= memcached_set(memc, key, strlen(key),
504 value, value_length,
505 (time_t)0, (uint32_t)0);
506 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
507 }
508
509 free(value);
510
511 return 0;
512 }
513
514 uint8_t get_test3(memcached_st *memc)
515 {
516 memcached_return rc;
517 char *key= "foo";
518 char *value;
519 size_t value_length= 8191;
520 char *string;
521 size_t string_length;
522 uint32_t flags;
523 int x;
524
525 value = (char*)malloc(value_length);
526 assert(value);
527
528 for (x= 0; x < value_length; x++)
529 value[x] = (char) (x % 127);
530
531 rc= memcached_set(memc, key, strlen(key),
532 value, value_length,
533 (time_t)0, (uint32_t)0);
534 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
535
536 string= memcached_get(memc, key, strlen(key),
537 &string_length, &flags, &rc);
538
539 assert(rc == MEMCACHED_SUCCESS);
540 assert(string);
541 assert(string_length == value_length);
542 assert(!memcmp(string, value, string_length));
543
544 free(string);
545 free(value);
546
547 return 0;
548 }
549
550 uint8_t get_test4(memcached_st *memc)
551 {
552 memcached_return rc;
553 char *key= "foo";
554 char *value;
555 size_t value_length= 8191;
556 char *string;
557 size_t string_length;
558 uint32_t flags;
559 int x;
560
561 value = (char*)malloc(value_length);
562 assert(value);
563
564 for (x= 0; x < value_length; x++)
565 value[x] = (char) (x % 127);
566
567 rc= memcached_set(memc, key, strlen(key),
568 value, value_length,
569 (time_t)0, (uint32_t)0);
570 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
571
572 for (x= 0; x < 10; x++)
573 {
574 string= memcached_get(memc, key, strlen(key),
575 &string_length, &flags, &rc);
576
577 assert(rc == MEMCACHED_SUCCESS);
578 assert(string);
579 assert(string_length == value_length);
580 assert(!memcmp(string, value, string_length));
581 free(string);
582 }
583
584 free(value);
585
586 return 0;
587 }
588
589 /* Do not copy the style of this code, I just access hosts to testthis function */
590 uint8_t stats_servername_test(memcached_st *memc)
591 {
592 memcached_return rc;
593 memcached_stat_st stat;
594 rc= memcached_stat_servername(&stat, NULL,
595 memc->hosts[0].hostname,
596 memc->hosts[0].port);
597
598 return 0;
599 }
600
601 uint8_t increment_test(memcached_st *memc)
602 {
603 uint64_t new_number;
604 memcached_return rc;
605 char *key= "number";
606 char *value= "0";
607
608 rc= memcached_set(memc, key, strlen(key),
609 value, strlen(value),
610 (time_t)0, (uint32_t)0);
611 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
612
613 rc= memcached_increment(memc, key, strlen(key),
614 1, &new_number);
615 assert(rc == MEMCACHED_SUCCESS);
616 assert(new_number == 1);
617
618 rc= memcached_increment(memc, key, strlen(key),
619 1, &new_number);
620 assert(rc == MEMCACHED_SUCCESS);
621 assert(new_number == 2);
622
623 return 0;
624 }
625
626 uint8_t decrement_test(memcached_st *memc)
627 {
628 uint64_t new_number;
629 memcached_return rc;
630 char *key= "number";
631 char *value= "3";
632
633 rc= memcached_set(memc, key, strlen(key),
634 value, strlen(value),
635 (time_t)0, (uint32_t)0);
636 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
637
638 rc= memcached_decrement(memc, key, strlen(key),
639 1, &new_number);
640 assert(rc == MEMCACHED_SUCCESS);
641 assert(new_number == 2);
642
643 rc= memcached_decrement(memc, key, strlen(key),
644 1, &new_number);
645 assert(rc == MEMCACHED_SUCCESS);
646 assert(new_number == 1);
647
648 return 0;
649 }
650
651 uint8_t quit_test(memcached_st *memc)
652 {
653 memcached_return rc;
654 char *key= "fudge";
655 char *value= "sanford and sun";
656
657 rc= memcached_set(memc, key, strlen(key),
658 value, strlen(value),
659 (time_t)10, (uint32_t)3);
660 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
661 memcached_quit(memc);
662
663 rc= memcached_set(memc, key, strlen(key),
664 value, strlen(value),
665 (time_t)50, (uint32_t)9);
666 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
667
668 return 0;
669 }
670
671 uint8_t mget_result_test(memcached_st *memc)
672 {
673 memcached_return rc;
674 char *keys[]= {"fudge", "son", "food"};
675 size_t key_length[]= {5, 3, 4};
676 unsigned int x;
677
678 memcached_result_st results_obj;
679 memcached_result_st *results;
680
681 results= memcached_result_create(memc, &results_obj);
682 assert(results);
683 assert(&results_obj == results);
684
685 /* We need to empty the server before continueing test */
686 rc= memcached_flush(memc, 0);
687 assert(rc == MEMCACHED_SUCCESS);
688
689 rc= memcached_mget(memc, keys, key_length, 3);
690 assert(rc == MEMCACHED_SUCCESS);
691
692 while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
693 {
694 assert(results);
695 }
696
697 while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
698 assert(!results);
699 assert(rc == MEMCACHED_END);
700
701 for (x= 0; x < 3; x++)
702 {
703 rc= memcached_set(memc, keys[x], key_length[x],
704 keys[x], key_length[x],
705 (time_t)50, (uint32_t)9);
706 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
707 }
708
709 rc= memcached_mget(memc, keys, key_length, 3);
710 assert(rc == MEMCACHED_SUCCESS);
711
712 while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
713 {
714 assert(results);
715 assert(&results_obj == results);
716 assert(rc == MEMCACHED_SUCCESS);
717 assert(memcached_result_key_length(results) == memcached_result_length(results));
718 assert(!memcmp(memcached_result_key_value(results),
719 memcached_result_value(results),
720 memcached_result_length(results)));
721 }
722
723 memcached_result_free(&results_obj);
724
725 return 0;
726 }
727
728 uint8_t mget_result_alloc_test(memcached_st *memc)
729 {
730 memcached_return rc;
731 char *keys[]= {"fudge", "son", "food"};
732 size_t key_length[]= {5, 3, 4};
733 unsigned int x;
734
735 memcached_result_st *results;
736
737 /* We need to empty the server before continueing test */
738 rc= memcached_flush(memc, 0);
739 assert(rc == MEMCACHED_SUCCESS);
740
741 rc= memcached_mget(memc, keys, key_length, 3);
742 assert(rc == MEMCACHED_SUCCESS);
743
744 while ((results= memcached_fetch_result(memc, NULL, &rc)) != NULL)
745 {
746 assert(results);
747 }
748 assert(!results);
749 assert(rc == MEMCACHED_END);
750
751 for (x= 0; x < 3; x++)
752 {
753 rc= memcached_set(memc, keys[x], key_length[x],
754 keys[x], key_length[x],
755 (time_t)50, (uint32_t)9);
756 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
757 }
758
759 rc= memcached_mget(memc, keys, key_length, 3);
760 assert(rc == MEMCACHED_SUCCESS);
761
762 x= 0;
763 while ((results= memcached_fetch_result(memc, NULL, &rc)))
764 {
765 assert(results);
766 assert(rc == MEMCACHED_SUCCESS);
767 assert(memcached_result_key_length(results) == memcached_result_length(results));
768 assert(!memcmp(memcached_result_key_value(results),
769 memcached_result_value(results),
770 memcached_result_length(results)));
771 memcached_result_free(results);
772 x++;
773 }
774
775 return 0;
776 }
777
778 /* Count the results */
779 unsigned int callback_counter(memcached_st *ptr, memcached_result_st *result, void *context)
780 {
781 unsigned int *counter= (unsigned int *)context;
782
783 *counter= *counter + 1;
784
785 return 0;
786 }
787
788 uint8_t mget_result_function(memcached_st *memc)
789 {
790 memcached_return rc;
791 char *keys[]= {"fudge", "son", "food"};
792 size_t key_length[]= {5, 3, 4};
793 unsigned int x;
794 unsigned int counter;
795 unsigned int (*callbacks[1])(memcached_st *, memcached_result_st *, void *);
796
797 /* We need to empty the server before continueing test */
798 rc= memcached_flush(memc, 0);
799 for (x= 0; x < 3; x++)
800 {
801 rc= memcached_set(memc, keys[x], key_length[x],
802 keys[x], key_length[x],
803 (time_t)50, (uint32_t)9);
804 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
805 }
806
807 rc= memcached_mget(memc, keys, key_length, 3);
808 assert(rc == MEMCACHED_SUCCESS);
809
810 callbacks[0]= &callback_counter;
811 counter= 0;
812 rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
813
814 assert(counter == 3);
815
816 return 0;
817 }
818
819 uint8_t mget_test(memcached_st *memc)
820 {
821 memcached_return rc;
822 char *keys[]= {"fudge", "son", "food"};
823 size_t key_length[]= {5, 3, 4};
824 unsigned int x;
825 uint32_t flags;
826
827 char return_key[MEMCACHED_MAX_KEY];
828 size_t return_key_length;
829 char *return_value;
830 size_t return_value_length;
831
832 /* We need to empty the server before continueing test */
833 rc= memcached_flush(memc, 0);
834 assert(rc == MEMCACHED_SUCCESS);
835
836 rc= memcached_mget(memc, keys, key_length, 3);
837 assert(rc == MEMCACHED_SUCCESS);
838
839 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
840 &return_value_length, &flags, &rc)) != NULL)
841 {
842 assert(return_value);
843 }
844 assert(!return_value);
845 assert(return_value_length == 0);
846 assert(rc == MEMCACHED_END);
847
848 for (x= 0; x < 3; x++)
849 {
850 rc= memcached_set(memc, keys[x], key_length[x],
851 keys[x], key_length[x],
852 (time_t)50, (uint32_t)9);
853 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
854 }
855
856 rc= memcached_mget(memc, keys, key_length, 3);
857 assert(rc == MEMCACHED_SUCCESS);
858
859 x= 0;
860 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
861 &return_value_length, &flags, &rc)))
862 {
863 assert(return_value);
864 assert(rc == MEMCACHED_SUCCESS);
865 assert(return_key_length == return_value_length);
866 assert(!memcmp(return_value, return_key, return_value_length));
867 free(return_value);
868 x++;
869 }
870
871 return 0;
872 }
873
874 uint8_t get_stats_keys(memcached_st *memc)
875 {
876 char **list;
877 char **ptr;
878 memcached_stat_st stat;
879 memcached_return rc;
880
881 list= memcached_stat_get_keys(memc, &stat, &rc);
882 assert(rc == MEMCACHED_SUCCESS);
883 for (ptr= list; *ptr; ptr++)
884 assert(*ptr);
885 fflush(stdout);
886
887 free(list);
888
889 return 0;
890 }
891
892 uint8_t version_string_test
893 {
894 const char *version_string;
895 version_string= memcached_lib_version();
896 assert(!strcmp(version_string, MEMCACHE_VERSION_STRING));
897 return 0;
898 }
899
900 uint8_t get_stats(memcached_st *memc)
901 {
902 unsigned int x;
903 char **list;
904 char **ptr;
905 memcached_return rc;
906 memcached_stat_st *stat;
907
908 stat= memcached_stat(memc, NULL, &rc);
909 assert(rc == MEMCACHED_SUCCESS);
910
911 assert(rc == MEMCACHED_SUCCESS);
912 assert(stat);
913
914 for (x= 0; x < memcached_server_count(memc); x++)
915 {
916 list= memcached_stat_get_keys(memc, stat+x, &rc);
917 assert(rc == MEMCACHED_SUCCESS);
918 for (ptr= list; *ptr; ptr++);
919
920 free(list);
921 }
922
923 memcached_stat_free(NULL, stat);
924
925 return 0;
926 }
927
928 uint8_t add_host_test(memcached_st *memc)
929 {
930 unsigned int x;
931 memcached_server_st *servers;
932 memcached_return rc;
933 char servername[]= "0.example.com";
934
935 servers= memcached_server_list_append(NULL, servername, 400, &rc);
936 assert(servers);
937 assert(1 == memcached_server_list_count(servers));
938
939 for (x= 2; x < 20; x++)
940 {
941 char buffer[SMALL_STRING_LEN];
942
943 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
944 servers= memcached_server_list_append(servers, buffer, 401,
945 &rc);
946 assert(rc == MEMCACHED_SUCCESS);
947 assert(x == memcached_server_list_count(servers));
948 }
949
950 rc= memcached_server_push(memc, servers);
951 assert(rc == MEMCACHED_SUCCESS);
952 rc= memcached_server_push(memc, servers);
953 assert(rc == MEMCACHED_SUCCESS);
954
955 memcached_server_list_free(servers);
956
957 return 0;
958 }
959
960 memcached_return clone_test_callback(memcached_st *parent, memcached_st *clone)
961 {
962 return MEMCACHED_SUCCESS;
963 }
964
965 memcached_return cleanup_test_callback(memcached_st *ptr)
966 {
967 return MEMCACHED_SUCCESS;
968 }
969
970 uint8_t callback_test(memcached_st *memc)
971 {
972 /* Test User Data */
973 {
974 int x= 5;
975 int *test_ptr;
976 memcached_return rc;
977
978 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_USER_DATA, &x);
979 assert(rc == MEMCACHED_SUCCESS);
980 test_ptr= (int *)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
981 assert(*test_ptr == x);
982 }
983
984 /* Test Clone Callback */
985 {
986 clone_func temp_function;
987 memcached_return rc;
988
989 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, clone_test_callback);
990 assert(rc == MEMCACHED_SUCCESS);
991 temp_function= (clone_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
992 assert(temp_function == clone_test_callback);
993 }
994
995 /* Test Cleanup Callback */
996 {
997 cleanup_func temp_function;
998 memcached_return rc;
999
1000 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, cleanup_test_callback);
1001 assert(rc == MEMCACHED_SUCCESS);
1002 temp_function= (cleanup_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
1003 assert(temp_function == cleanup_test_callback);
1004 }
1005
1006 return 0;
1007 }
1008
1009 /* We don't test the behavior itself, we test the switches */
1010 uint8_t behavior_test(memcached_st *memc)
1011 {
1012 unsigned long long value;
1013 unsigned int set= 1;
1014
1015 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
1016 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
1017 assert(value == 1);
1018
1019 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
1020 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
1021 assert(value == 1);
1022
1023 set= MEMCACHED_HASH_MD5;
1024 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
1025 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1026 assert(value == MEMCACHED_HASH_MD5);
1027
1028 set= 0;
1029
1030 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
1031 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
1032 assert(value == 0);
1033
1034 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
1035 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
1036 assert(value == 0);
1037
1038 set= MEMCACHED_HASH_DEFAULT;
1039 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
1040 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1041 assert(value == MEMCACHED_HASH_DEFAULT);
1042
1043 set= MEMCACHED_HASH_CRC;
1044 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
1045 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1046 assert(value == MEMCACHED_HASH_CRC);
1047
1048 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1049 assert(value > 0);
1050
1051 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1052 assert(value > 0);
1053
1054 {
1055 int x= 5;
1056 int *test_ptr;
1057
1058 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USER_DATA, &x);
1059 test_ptr= (int *)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_USER_DATA);
1060 assert(*test_ptr == x);
1061 }
1062
1063 return 0;
1064 }
1065
1066 /* Test case provided by Cal Haldenbrand */
1067 uint8_t user_supplied_bug1(memcached_st *memc)
1068 {
1069 unsigned int setter= 1;
1070 unsigned int x;
1071
1072 unsigned long long total= 0;
1073 int size= 0;
1074 char key[10];
1075 char randomstuff[6 * 1024];
1076 memcached_return rc;
1077
1078 memset(randomstuff, 0, 6 * 1024);
1079
1080 /* We just keep looking at the same values over and over */
1081 srandom(10);
1082
1083 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
1084 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
1085
1086
1087 /* add key */
1088 for (x= 0 ; total < 20 * 1024576 ; x++ )
1089 {
1090 unsigned int j= 0;
1091
1092 size= (rand() % ( 5 * 1024 ) ) + 400;
1093 memset(randomstuff, 0, 6 * 1024);
1094 assert(size < 6 * 1024); /* Being safe here */
1095
1096 for (j= 0 ; j < size ;j++)
1097 randomstuff[j] = (char) (rand() % 26) + 97;
1098
1099 total += size;
1100 sprintf(key, "%d", x);
1101 rc = memcached_set(memc, key, strlen(key),
1102 randomstuff, strlen(randomstuff), 10, 0);
1103 /* If we fail, lets try again */
1104 if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED)
1105 rc = memcached_set(memc, key, strlen(key),
1106 randomstuff, strlen(randomstuff), 10, 0);
1107 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
1108 }
1109
1110 return 0;
1111 }
1112
1113 /* Test case provided by Cal Haldenbrand */
1114 uint8_t user_supplied_bug2(memcached_st *memc)
1115 {
1116 int errors;
1117 unsigned int setter;
1118 unsigned int x;
1119 unsigned long long total;
1120
1121 setter= 1;
1122 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
1123 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
1124 #ifdef NOT_YET
1125 setter = 20 * 1024576;
1126 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, &setter);
1127 setter = 20 * 1024576;
1128 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter);
1129 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1130 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1131
1132 for (x= 0, errors= 0, total= 0 ; total < 20 * 1024576 ; x++)
1133 #endif
1134
1135 for (x= 0, errors= 0, total= 0 ; total < 24576 ; x++)
1136 {
1137 memcached_return rc= MEMCACHED_SUCCESS;
1138 char buffer[SMALL_STRING_LEN];
1139 uint32_t flags= 0;
1140 size_t val_len= 0;
1141 char *getval;
1142
1143 memset(buffer, 0, SMALL_STRING_LEN);
1144
1145 snprintf(buffer, SMALL_STRING_LEN, "%u", x);
1146 getval= memcached_get(memc, buffer, strlen(buffer),
1147 &val_len, &flags, &rc);
1148 if (rc != MEMCACHED_SUCCESS)
1149 {
1150 if (rc == MEMCACHED_NOTFOUND)
1151 errors++;
1152 else
1153 assert(0);
1154
1155 continue;
1156 }
1157 total+= val_len;
1158 errors= 0;
1159 free(getval);
1160 }
1161
1162 return 0;
1163 }
1164
1165 /* Do a large mget() over all the keys we think exist */
1166 #define KEY_COUNT 3000 // * 1024576
1167 uint8_t user_supplied_bug3(memcached_st *memc)
1168 {
1169 memcached_return rc;
1170 unsigned int setter;
1171 unsigned int x;
1172 char **keys;
1173 size_t key_lengths[KEY_COUNT];
1174
1175 setter= 1;
1176 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
1177 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
1178 #ifdef NOT_YET
1179 setter = 20 * 1024576;
1180 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, &setter);
1181 setter = 20 * 1024576;
1182 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter);
1183 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1184 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1185 #endif
1186
1187 keys= (char **)malloc(sizeof(char *) * KEY_COUNT);
1188 assert(keys);
1189 memset(keys, 0, (sizeof(char *) * KEY_COUNT));
1190 for (x= 0; x < KEY_COUNT; x++)
1191 {
1192 char buffer[30];
1193
1194 snprintf(buffer, 30, "%u", x);
1195 keys[x]= strdup(buffer);
1196 key_lengths[x]= strlen(keys[x]);
1197 }
1198
1199 rc= memcached_mget(memc, keys, key_lengths, KEY_COUNT);
1200 assert(rc == MEMCACHED_SUCCESS);
1201
1202 /* Turn this into a help function */
1203 {
1204 char return_key[MEMCACHED_MAX_KEY];
1205 size_t return_key_length;
1206 char *return_value;
1207 size_t return_value_length;
1208 uint32_t flags;
1209
1210 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1211 &return_value_length, &flags, &rc)))
1212 {
1213 assert(return_value);
1214 assert(rc == MEMCACHED_SUCCESS);
1215 free(return_value);
1216 }
1217 }
1218
1219 for (x= 0; x < KEY_COUNT; x++)
1220 free(keys[x]);
1221 free(keys);
1222
1223 return 0;
1224 }
1225
1226 /* Make sure we behave properly if server list has no values */
1227 uint8_t user_supplied_bug4(memcached_st *memc)
1228 {
1229 memcached_return rc;
1230 char *keys[]= {"fudge", "son", "food"};
1231 size_t key_length[]= {5, 3, 4};
1232 unsigned int x;
1233 uint32_t flags;
1234 char return_key[MEMCACHED_MAX_KEY];
1235 size_t return_key_length;
1236 char *return_value;
1237 size_t return_value_length;
1238
1239 /* Here we free everything before running a bunch of mget tests */
1240 {
1241 memcached_server_list_free(memc->hosts);
1242 memc->hosts= NULL;
1243 memc->number_of_hosts= 0;
1244 }
1245
1246
1247 /* We need to empty the server before continueing test */
1248 rc= memcached_flush(memc, 0);
1249 assert(rc == MEMCACHED_NO_SERVERS);
1250
1251 rc= memcached_mget(memc, keys, key_length, 3);
1252 assert(rc == MEMCACHED_NO_SERVERS);
1253
1254 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1255 &return_value_length, &flags, &rc)) != NULL)
1256 {
1257 assert(return_value);
1258 }
1259 assert(!return_value);
1260 assert(return_value_length == 0);
1261 assert(rc == MEMCACHED_NO_SERVERS);
1262
1263 for (x= 0; x < 3; x++)
1264 {
1265 rc= memcached_set(memc, keys[x], key_length[x],
1266 keys[x], key_length[x],
1267 (time_t)50, (uint32_t)9);
1268 assert(rc == MEMCACHED_NO_SERVERS);
1269 }
1270
1271 rc= memcached_mget(memc, keys, key_length, 3);
1272 assert(rc == MEMCACHED_NO_SERVERS);
1273
1274 x= 0;
1275 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1276 &return_value_length, &flags, &rc)))
1277 {
1278 assert(return_value);
1279 assert(rc == MEMCACHED_SUCCESS);
1280 assert(return_key_length == return_value_length);
1281 assert(!memcmp(return_value, return_key, return_value_length));
1282 free(return_value);
1283 x++;
1284 }
1285
1286 return 0;
1287 }
1288
1289 #define VALUE_SIZE_BUG5 1048064
1290 uint8_t user_supplied_bug5(memcached_st *memc)
1291 {
1292 memcached_return rc;
1293 char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1294 size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1295 char return_key[MEMCACHED_MAX_KEY];
1296 size_t return_key_length;
1297 char *value;
1298 size_t value_length;
1299 uint32_t flags;
1300 unsigned int count;
1301 unsigned int x;
1302 char insert_data[VALUE_SIZE_BUG5];
1303
1304 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1305 insert_data[x]= rand();
1306
1307 memcached_flush(memc, 0);
1308 value= memcached_get(memc, keys[0], key_length[0],
1309 &value_length, &flags, &rc);
1310 assert(value == NULL);
1311 rc= memcached_mget(memc, keys, key_length, 4);
1312
1313 count= 0;
1314 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1315 &value_length, &flags, &rc)))
1316 count++;
1317 assert(count == 0);
1318
1319 for (x= 0; x < 4; x++)
1320 {
1321 rc= memcached_set(memc, keys[x], key_length[x],
1322 insert_data, VALUE_SIZE_BUG5,
1323 (time_t)0, (uint32_t)0);
1324 assert(rc == MEMCACHED_SUCCESS);
1325 }
1326
1327 for (x= 0; x < 10; x++)
1328 {
1329 value= memcached_get(memc, keys[0], key_length[0],
1330 &value_length, &flags, &rc);
1331 assert(value);
1332 free(value);
1333
1334 rc= memcached_mget(memc, keys, key_length, 4);
1335 count= 0;
1336 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1337 &value_length, &flags, &rc)))
1338 {
1339 count++;
1340 free(value);
1341 }
1342 assert(count == 4);
1343 }
1344
1345 return 0;
1346 }
1347
1348 uint8_t user_supplied_bug6(memcached_st *memc)
1349 {
1350 memcached_return rc;
1351 char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1352 size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1353 char return_key[MEMCACHED_MAX_KEY];
1354 size_t return_key_length;
1355 char *value;
1356 size_t value_length;
1357 uint32_t flags;
1358 unsigned int count;
1359 unsigned int x;
1360 char insert_data[VALUE_SIZE_BUG5];
1361
1362 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1363 insert_data[x]= rand();
1364
1365 memcached_flush(memc, 0);
1366 value= memcached_get(memc, keys[0], key_length[0],
1367 &value_length, &flags, &rc);
1368 assert(value == NULL);
1369 assert(rc == MEMCACHED_NOTFOUND);
1370 rc= memcached_mget(memc, keys, key_length, 4);
1371 assert(rc == MEMCACHED_SUCCESS);
1372
1373 count= 0;
1374 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1375 &value_length, &flags, &rc)))
1376 count++;
1377 assert(count == 0);
1378 assert(rc == MEMCACHED_END);
1379
1380 for (x= 0; x < 4; x++)
1381 {
1382 rc= memcached_set(memc, keys[x], key_length[x],
1383 insert_data, VALUE_SIZE_BUG5,
1384 (time_t)0, (uint32_t)0);
1385 assert(rc == MEMCACHED_SUCCESS);
1386 }
1387
1388 for (x= 0; x < 2; x++)
1389 {
1390 value= memcached_get(memc, keys[0], key_length[0],
1391 &value_length, &flags, &rc);
1392 assert(value);
1393 free(value);
1394
1395 rc= memcached_mget(memc, keys, key_length, 4);
1396 assert(rc == MEMCACHED_SUCCESS);
1397 count= 3;
1398 /* We test for purge of partial complete fetches */
1399 for (count= 3; count; count--)
1400 {
1401 value= memcached_fetch(memc, return_key, &return_key_length,
1402 &value_length, &flags, &rc);
1403 assert(rc == MEMCACHED_SUCCESS);
1404 assert(!(memcmp(value, insert_data, value_length)));
1405 assert(value_length);
1406 free(value);
1407 }
1408 }
1409
1410 return 0;
1411 }
1412
1413 uint8_t user_supplied_bug8(memcached_st *memc)
1414 {
1415 memcached_return rc;
1416 memcached_st *mine;
1417 memcached_st *clone;
1418
1419 memcached_server_st *servers;
1420 char *server_list= "memcache1.memcache.bk.sapo.pt:11211, memcache1.memcache.bk.sapo.pt:11212, memcache1.memcache.bk.sapo.pt:11213, memcache1.memcache.bk.sapo.pt:11214, memcache2.memcache.bk.sapo.pt:11211, memcache2.memcache.bk.sapo.pt:11212, memcache2.memcache.bk.sapo.pt:11213, memcache2.memcache.bk.sapo.pt:11214";
1421
1422 servers= memcached_servers_parse(server_list);
1423 assert(servers);
1424
1425 mine= memcached_create(NULL);
1426 rc= memcached_server_push(mine, servers);
1427 assert(rc == MEMCACHED_SUCCESS);
1428 memcached_server_list_free(servers);
1429
1430 assert(mine);
1431 clone= memcached_clone(NULL, mine);
1432
1433 memcached_quit(mine);
1434 memcached_quit(clone);
1435
1436
1437 memcached_free(mine);
1438 memcached_free(clone);
1439
1440 return 0;
1441 }
1442
1443 /* Test flag store/retrieve */
1444 uint8_t user_supplied_bug7(memcached_st *memc)
1445 {
1446 memcached_return rc;
1447 char *keys= "036790384900";
1448 size_t key_length= strlen("036790384900");
1449 char return_key[MEMCACHED_MAX_KEY];
1450 size_t return_key_length;
1451 char *value;
1452 size_t value_length;
1453 uint32_t flags;
1454 unsigned int x;
1455 char insert_data[VALUE_SIZE_BUG5];
1456
1457 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1458 insert_data[x]= rand();
1459
1460 memcached_flush(memc, 0);
1461
1462 flags= 245;
1463 rc= memcached_set(memc, keys, key_length,
1464 insert_data, VALUE_SIZE_BUG5,
1465 (time_t)0, flags);
1466 assert(rc == MEMCACHED_SUCCESS);
1467
1468 flags= 0;
1469 value= memcached_get(memc, keys, key_length,
1470 &value_length, &flags, &rc);
1471 assert(flags == 245);
1472 assert(value);
1473 free(value);
1474
1475 rc= memcached_mget(memc, &keys, &key_length, 1);
1476
1477 flags= 0;
1478 value= memcached_fetch(memc, return_key, &return_key_length,
1479 &value_length, &flags, &rc);
1480 assert(flags == 245);
1481 assert(value);
1482 free(value);
1483
1484
1485 return 0;
1486 }
1487
1488 uint8_t user_supplied_bug9(memcached_st *memc)
1489 {
1490 memcached_return rc;
1491 char *keys[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1492 size_t key_length[3];
1493 unsigned int x;
1494 uint32_t flags;
1495 unsigned count= 0;
1496
1497 char return_key[MEMCACHED_MAX_KEY];
1498 size_t return_key_length;
1499 char *return_value;
1500 size_t return_value_length;
1501
1502
1503 key_length[0]= strlen("UDATA:edevil@sapo.pt");
1504 key_length[1]= strlen("fudge&*@#");
1505 key_length[2]= strlen("for^#@&$not");
1506
1507
1508 for (x= 0; x < 3; x++)
1509 {
1510 rc= memcached_set(memc, keys[x], key_length[x],
1511 keys[x], key_length[x],
1512 (time_t)50, (uint32_t)9);
1513 assert(rc == MEMCACHED_SUCCESS);
1514 }
1515
1516 rc= memcached_mget(memc, keys, key_length, 3);
1517 assert(rc == MEMCACHED_SUCCESS);
1518
1519 /* We need to empty the server before continueing test */
1520 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1521 &return_value_length, &flags, &rc)) != NULL)
1522 {
1523 assert(return_value);
1524 free(return_value);
1525 count++;
1526 }
1527 assert(count == 3);
1528
1529 return 0;
1530 }
1531
1532 /* We are testing with aggressive timeout to get failures */
1533 uint8_t user_supplied_bug10(memcached_st *memc)
1534 {
1535 char *key= "foo";
1536 char *value;
1537 size_t value_length= 512;
1538 unsigned int x;
1539 int key_len= 3;
1540 memcached_return rc;
1541 unsigned int set= 1;
1542 memcached_st *mclone= memcached_clone(NULL, memc);
1543 int32_t timeout;
1544
1545 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
1546 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
1547 timeout= 2;
1548 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout);
1549
1550 value = (char*)malloc(value_length * sizeof(char));
1551
1552 for (x= 0; x < value_length; x++)
1553 value[x]= (char) (x % 127);
1554
1555 for (x= 1; x <= 100000; ++x)
1556 {
1557 rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
1558
1559 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE || rc == MEMCACHED_BUFFERED);
1560
1561 if (rc == MEMCACHED_WRITE_FAILURE)
1562 x--;
1563 }
1564
1565 free(value);
1566 memcached_free(mclone);
1567
1568 return 0;
1569 }
1570
1571 /*
1572 We are looking failures in the async protocol
1573 */
1574 uint8_t user_supplied_bug11(memcached_st *memc)
1575 {
1576 char *key= "foo";
1577 char *value;
1578 size_t value_length= 512;
1579 unsigned int x;
1580 int key_len= 3;
1581 memcached_return rc;
1582 unsigned int set= 1;
1583 int32_t timeout;
1584 memcached_st *mclone= memcached_clone(NULL, memc);
1585
1586 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
1587 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
1588 timeout= -1;
1589 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout);
1590
1591 timeout= (int32_t)memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
1592
1593 assert(timeout == -1);
1594
1595 value = (char*)malloc(value_length * sizeof(char));
1596
1597 for (x= 0; x < value_length; x++)
1598 value[x]= (char) (x % 127);
1599
1600 for (x= 1; x <= 100000; ++x)
1601 {
1602 rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
1603 }
1604
1605 free(value);
1606 memcached_free(mclone);
1607
1608 return 0;
1609 }
1610
1611 uint8_t result_static(memcached_st *memc)
1612 {
1613 memcached_result_st result;
1614 memcached_result_st *result_ptr;
1615
1616 result_ptr= memcached_result_create(memc, &result);
1617 assert(result.is_allocated == MEMCACHED_NOT_ALLOCATED);
1618 assert(result_ptr);
1619 memcached_result_free(&result);
1620
1621 return 0;
1622 }
1623
1624 uint8_t result_alloc(memcached_st *memc)
1625 {
1626 memcached_result_st *result;
1627
1628 result= memcached_result_create(memc, NULL);
1629 assert(result);
1630 memcached_result_free(result);
1631
1632 return 0;
1633 }
1634
1635 uint8_t string_static_null(memcached_st *memc)
1636 {
1637 memcached_string_st string;
1638 memcached_string_st *string_ptr;
1639
1640 string_ptr= memcached_string_create(memc, &string, 0);
1641 assert(string.is_allocated == MEMCACHED_NOT_ALLOCATED);
1642 assert(string_ptr);
1643 memcached_string_free(&string);
1644
1645 return 0;
1646 }
1647
1648 uint8_t string_alloc_null(memcached_st *memc)
1649 {
1650 memcached_string_st *string;
1651
1652 string= memcached_string_create(memc, NULL, 0);
1653 assert(string);
1654 memcached_string_free(string);
1655
1656 return 0;
1657 }
1658
1659 uint8_t string_alloc_with_size(memcached_st *memc)
1660 {
1661 memcached_string_st *string;
1662
1663 string= memcached_string_create(memc, NULL, 1024);
1664 assert(string);
1665 memcached_string_free(string);
1666
1667 return 0;
1668 }
1669
1670 uint8_t string_alloc_with_size_toobig(memcached_st *memc)
1671 {
1672 memcached_string_st *string;
1673
1674 string= memcached_string_create(memc, NULL, INT64_MAX);
1675 assert(string == NULL);
1676
1677 return 0;
1678 }
1679
1680 uint8_t string_alloc_append(memcached_st *memc)
1681 {
1682 unsigned int x;
1683 char buffer[SMALL_STRING_LEN];
1684 memcached_string_st *string;
1685
1686 /* Ring the bell! */
1687 memset(buffer, 6, SMALL_STRING_LEN);
1688
1689 string= memcached_string_create(memc, NULL, 100);
1690 assert(string);
1691
1692 for (x= 0; x < 1024; x++)
1693 {
1694 memcached_return rc;
1695 rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
1696 assert(rc == MEMCACHED_SUCCESS);
1697 }
1698 memcached_string_free(string);
1699
1700 return 0;
1701 }
1702
1703 uint8_t string_alloc_append_toobig(memcached_st *memc)
1704 {
1705 memcached_return rc;
1706 unsigned int x;
1707 char buffer[SMALL_STRING_LEN];
1708 memcached_string_st *string;
1709
1710 /* Ring the bell! */
1711 memset(buffer, 6, SMALL_STRING_LEN);
1712
1713 string= memcached_string_create(memc, NULL, 100);
1714 assert(string);
1715
1716 for (x= 0; x < 1024; x++)
1717 {
1718 rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
1719 assert(rc == MEMCACHED_SUCCESS);
1720 }
1721 rc= memcached_string_append(string, buffer, INT64_MAX);
1722 assert(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE);
1723 memcached_string_free(string);
1724
1725 return 0;
1726 }
1727
1728 uint8_t cleanup_pairs(memcached_st *memc)
1729 {
1730 pairs_free(global_pairs);
1731
1732 return 0;
1733 }
1734
1735 uint8_t generate_data(memcached_st *memc)
1736 {
1737 unsigned long long x;
1738 global_pairs= pairs_generate(GLOBAL_COUNT);
1739 execute_set(memc, global_pairs, GLOBAL_COUNT);
1740
1741 for (x= 0; x < GLOBAL_COUNT; x++)
1742 {
1743 global_keys[x]= global_pairs[x].key;
1744 global_keys_length[x]= global_pairs[x].key_length;
1745 }
1746
1747 return 0;
1748 }
1749
1750 uint8_t generate_buffer_data(memcached_st *memc)
1751 {
1752 int latch= 0;
1753
1754 latch= 1;
1755 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch);
1756 generate_data(memc);
1757
1758 return 0;
1759 }
1760
1761 #ifdef NOT_DONE
1762 uint8_t mset_data(memcached_st *memc)
1763 {
1764 unsigned long long x;
1765 global_pairs= pairs_generate(GLOBAL_COUNT);
1766
1767 (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
1768
1769 for (x= 0; x < GLOBAL_COUNT; x++)
1770 {
1771 global_keys[x]= global_pairs[x].key;
1772 global_keys_length[x]= global_pairs[x].key_length;
1773 }
1774
1775 return 0;
1776 }
1777 #endif
1778
1779 uint8_t get_read(memcached_st *memc)
1780 {
1781 unsigned int x;
1782 memcached_return rc;
1783
1784 {
1785 char *return_value;
1786 size_t return_value_length;
1787 uint32_t flags;
1788
1789 for (x= 0; x < GLOBAL_COUNT; x++)
1790 {
1791 return_value= memcached_get(memc, global_keys[x], global_keys_length[x],
1792 &return_value_length, &flags, &rc);
1793 /*
1794 assert(return_value);
1795 assert(rc == MEMCACHED_SUCCESS);
1796 */
1797 if (rc == MEMCACHED_SUCCESS && return_value)
1798 free(return_value);
1799 }
1800 }
1801
1802 return 0;
1803 }
1804
1805 uint8_t mget_read(memcached_st *memc)
1806 {
1807 memcached_return rc;
1808
1809 rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
1810 assert(rc == MEMCACHED_SUCCESS);
1811 /* Turn this into a help function */
1812 {
1813 char return_key[MEMCACHED_MAX_KEY];
1814 size_t return_key_length;
1815 char *return_value;
1816 size_t return_value_length;
1817 uint32_t flags;
1818
1819 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1820 &return_value_length, &flags, &rc)))
1821 {
1822 assert(return_value);
1823 assert(rc == MEMCACHED_SUCCESS);
1824 free(return_value);
1825 }
1826 }
1827
1828 return 0;
1829 }
1830
1831 uint8_t mget_read_result(memcached_st *memc)
1832 {
1833 memcached_return rc;
1834
1835 rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
1836 assert(rc == MEMCACHED_SUCCESS);
1837 /* Turn this into a help function */
1838 {
1839 memcached_result_st results_obj;
1840 memcached_result_st *results;
1841
1842 results= memcached_result_create(memc, &results_obj);
1843
1844 while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
1845 {
1846 assert(results);
1847 assert(rc == MEMCACHED_SUCCESS);
1848 }
1849
1850 memcached_result_free(&results_obj);
1851 }
1852
1853 return 0;
1854 }
1855
1856 uint8_t mget_read_function(memcached_st *memc)
1857 {
1858 memcached_return rc;
1859 unsigned int counter;
1860 unsigned int (*callbacks[1])(memcached_st *, memcached_result_st *, void *);
1861
1862 rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
1863 assert(rc == MEMCACHED_SUCCESS);
1864
1865 callbacks[0]= &callback_counter;
1866 counter= 0;
1867 rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
1868
1869 return 0;
1870 }
1871
1872 uint8_t delete_generate(memcached_st *memc)
1873 {
1874 unsigned int x;
1875
1876 for (x= 0; x < GLOBAL_COUNT; x++)
1877 {
1878 (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
1879 }
1880
1881 return 0;
1882 }
1883
1884 uint8_t delete_buffer_generate(memcached_st *memc)
1885 {
1886 int latch= 0;
1887 unsigned int x;
1888
1889 latch= 1;
1890 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch);
1891
1892 for (x= 0; x < GLOBAL_COUNT; x++)
1893 {
1894 (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
1895 }
1896
1897 return 0;
1898 }
1899
1900 uint8_t free_data(memcached_st *memc)
1901 {
1902 pairs_free(global_pairs);
1903
1904 return 0;
1905 }
1906
1907 uint8_t add_host_test1(memcached_st *memc)
1908 {
1909 unsigned int x;
1910 memcached_return rc;
1911 char servername[]= "0.example.com";
1912 memcached_server_st *servers;
1913
1914 servers= memcached_server_list_append(NULL, servername, 400, &rc);
1915 assert(servers);
1916 assert(1 == memcached_server_list_count(servers));
1917
1918 for (x= 2; x < 20; x++)
1919 {
1920 char buffer[SMALL_STRING_LEN];
1921
1922 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
1923 servers= memcached_server_list_append(servers, buffer, 401,
1924 &rc);
1925 assert(rc == MEMCACHED_SUCCESS);
1926 assert(x == memcached_server_list_count(servers));
1927 }
1928
1929 rc= memcached_server_push(memc, servers);
1930 assert(rc == MEMCACHED_SUCCESS);
1931 rc= memcached_server_push(memc, servers);
1932 assert(rc == MEMCACHED_SUCCESS);
1933
1934 memcached_server_list_free(servers);
1935
1936 return 0;
1937 }
1938
1939 memcached_return pre_nonblock(memcached_st *memc)
1940 {
1941 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
1942
1943 return MEMCACHED_SUCCESS;
1944 }
1945
1946 memcached_return pre_md5(memcached_st *memc)
1947 {
1948 memcached_hash value= MEMCACHED_HASH_MD5;
1949 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1950
1951 return MEMCACHED_SUCCESS;
1952 }
1953
1954 memcached_return pre_crc(memcached_st *memc)
1955 {
1956 memcached_hash value= MEMCACHED_HASH_CRC;
1957 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1958
1959 return MEMCACHED_SUCCESS;
1960 }
1961
1962 memcached_return pre_hsieh(memcached_st *memc)
1963 {
1964 memcached_hash value= MEMCACHED_HASH_HSIEH;
1965 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1966
1967 return MEMCACHED_SUCCESS;
1968 }
1969
1970 memcached_return pre_hash_fnv1_64(memcached_st *memc)
1971 {
1972 memcached_hash value= MEMCACHED_HASH_FNV1_64;
1973 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1974
1975 return MEMCACHED_SUCCESS;
1976 }
1977
1978 memcached_return pre_hash_fnv1a_64(memcached_st *memc)
1979 {
1980 memcached_hash value= MEMCACHED_HASH_FNV1A_64;
1981 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1982
1983 return MEMCACHED_SUCCESS;
1984 }
1985
1986 memcached_return pre_hash_fnv1_32(memcached_st *memc)
1987 {
1988 memcached_hash value= MEMCACHED_HASH_FNV1_32;
1989 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1990
1991 return MEMCACHED_SUCCESS;
1992 }
1993
1994 memcached_return pre_hash_fnv1a_32(memcached_st *memc)
1995 {
1996 memcached_hash value= MEMCACHED_HASH_FNV1A_32;
1997 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1998
1999 return MEMCACHED_SUCCESS;
2000 }
2001
2002 memcached_return pre_hash_ketama(memcached_st *memc)
2003 {
2004 memcached_hash value= MEMCACHED_HASH_KETAMA;
2005 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
2006
2007 return MEMCACHED_SUCCESS;
2008 }
2009
2010 memcached_return enable_consistent(memcached_st *memc)
2011 {
2012 memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT;
2013 memcached_hash hash;
2014 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, &value);
2015 pre_hsieh(memc);
2016
2017 value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
2018 assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
2019
2020 hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
2021 assert(hash == MEMCACHED_HASH_HSIEH);
2022
2023
2024 return MEMCACHED_SUCCESS;
2025 }
2026
2027 memcached_return enable_cas(memcached_st *memc)
2028 {
2029 unsigned int set= 1;
2030
2031 memcached_version(memc);
2032
2033 if (memc->hosts[0].major_version >= 1 &&
2034 memc->hosts[0].minor_version >= 2 &&
2035 memc->hosts[0].micro_version >= 4)
2036 {
2037 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, &set);
2038
2039 return MEMCACHED_SUCCESS;
2040 }
2041
2042 return MEMCACHED_FAILURE;
2043 }
2044
2045 memcached_return check_for_1_2_3(memcached_st *memc)
2046 {
2047 memcached_version(memc);
2048
2049 if (memc->hosts[0].major_version >= 1 &&
2050 memc->hosts[0].minor_version >= 2 &&
2051 memc->hosts[0].micro_version >= 4)
2052 return MEMCACHED_SUCCESS;
2053
2054 return MEMCACHED_FAILURE;
2055 }
2056
2057 memcached_return pre_unix_socket(memcached_st *memc)
2058 {
2059 memcached_return rc;
2060 struct stat buf;
2061
2062 memcached_server_list_free(memc->hosts);
2063 memc->hosts= NULL;
2064 memc->number_of_hosts= 0;
2065
2066 if (stat("/tmp/memcached.socket", &buf))
2067 return MEMCACHED_FAILURE;
2068
2069 rc= memcached_server_add_unix_socket(memc, "/tmp/memcached.socket");
2070
2071 return rc;
2072 }
2073
2074 memcached_return pre_udp(memcached_st *memc)
2075 {
2076 memcached_return rc;
2077
2078 memcached_server_list_free(memc->hosts);
2079 memc->hosts= NULL;
2080 memc->number_of_hosts= 0;
2081
2082 if (0)
2083 return MEMCACHED_FAILURE;
2084
2085 rc= memcached_server_add_udp(memc, "localhost", MEMCACHED_DEFAULT_PORT);
2086
2087 return rc;
2088 }
2089
2090 memcached_return pre_nodelay(memcached_st *memc)
2091 {
2092 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
2093 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL);
2094
2095 return MEMCACHED_SUCCESS;
2096 }
2097
2098 memcached_return poll_timeout(memcached_st *memc)
2099 {
2100 int32_t timeout;
2101
2102 timeout= 100;
2103
2104 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout);
2105
2106 timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
2107
2108 assert(timeout == 100);
2109
2110 return MEMCACHED_SUCCESS;
2111 }
2112
2113
2114 /* Clean the server before beginning testing */
2115 test_st tests[] ={
2116 {"flush", 0, flush_test },
2117 {"init", 0, init_test },
2118 {"allocation", 0, allocation_test },
2119 {"server_list_null_test", 0, server_list_null_test},
2120 {"clone_test", 0, clone_test },
2121 {"error", 0, error_test },
2122 {"set", 0, set_test },
2123 {"set2", 0, set_test2 },
2124 {"set3", 0, set_test3 },
2125 {"add", 1, add_test },
2126 {"replace", 0, replace_test },
2127 {"delete", 1, delete_test },
2128 {"get", 1, get_test },
2129 {"get2", 0, get_test2 },
2130 {"get3", 0, get_test3 },
2131 {"get4", 0, get_test4 },
2132 {"stats_servername", 0, stats_servername_test },
2133 {"increment", 0, increment_test },
2134 {"decrement", 0, decrement_test },
2135 {"quit", 0, quit_test },
2136 {"mget", 1, mget_test },
2137 {"mget_result", 1, mget_result_test },
2138 {"mget_result_alloc", 1, mget_result_alloc_test },
2139 {"mget_result_function", 1, mget_result_function },
2140 {"get_stats", 0, get_stats },
2141 {"add_host_test", 0, add_host_test },
2142 {"get_stats_keys", 0, get_stats_keys },
2143 {"behavior_test", 0, get_stats_keys },
2144 {"callback_test", 0, get_stats_keys },
2145 {"version_string_test", 0, version_string_test},
2146 {0, 0, 0}
2147 };
2148
2149 test_st async_tests[] ={
2150 {"add", 1, add_wrapper },
2151 {0, 0, 0}
2152 };
2153
2154 test_st string_tests[] ={
2155 {"string static with null", 0, string_static_null },
2156 {"string alloc with null", 0, string_alloc_null },
2157 {"string alloc with 1K", 0, string_alloc_with_size },
2158 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig },
2159 {"string append", 0, string_alloc_append },
2160 {"string append failure (too big)", 0, string_alloc_append_toobig },
2161 {0, 0, 0}
2162 };
2163
2164 test_st result_tests[] ={
2165 {"result static", 0, result_static},
2166 {"result alloc", 0, result_alloc},
2167 {0, 0, 0}
2168 };
2169
2170 test_st version_1_2_3[] ={
2171 {"append", 0, append_test },
2172 {"prepend", 0, prepend_test },
2173 {"cas", 0, cas_test },
2174 {"cas2", 0, cas2_test },
2175 {"append_binary", 0, append_binary_test },
2176 {0, 0, 0}
2177 };
2178
2179 test_st user_tests[] ={
2180 {"user_supplied_bug1", 0, user_supplied_bug1 },
2181 {"user_supplied_bug2", 0, user_supplied_bug2 },
2182 {"user_supplied_bug3", 0, user_supplied_bug3 },
2183 {"user_supplied_bug4", 0, user_supplied_bug4 },
2184 {"user_supplied_bug5", 1, user_supplied_bug5 },
2185 {"user_supplied_bug6", 1, user_supplied_bug6 },
2186 {"user_supplied_bug7", 1, user_supplied_bug7 },
2187 {"user_supplied_bug8", 1, user_supplied_bug8 },
2188 {"user_supplied_bug9", 1, user_supplied_bug9 },
2189 {"user_supplied_bug10", 1, user_supplied_bug10 },
2190 {"user_supplied_bug11", 1, user_supplied_bug11 },
2191 {0, 0, 0}
2192 };
2193
2194 test_st generate_tests[] ={
2195 {"generate_data", 1, generate_data },
2196 {"get_read", 0, get_read },
2197 {"delete_generate", 0, delete_generate },
2198 {"generate_buffer_data", 1, generate_buffer_data },
2199 {"delete_buffer", 0, delete_buffer_generate},
2200 {"generate_data", 1, generate_data },
2201 {"mget_read", 0, mget_read },
2202 {"mget_read_result", 0, mget_read_result },
2203 {"mget_read_function", 0, mget_read_function },
2204 {"cleanup", 1, cleanup_pairs },
2205 {0, 0, 0}
2206 };
2207
2208
2209 collection_st collection[] ={
2210 {"block", 0, 0, tests},
2211 {"nonblock", pre_nonblock, 0, tests},
2212 {"nodelay", pre_nodelay, 0, tests},
2213 {"md5", pre_md5, 0, tests},
2214 {"crc", pre_crc, 0, tests},
2215 {"hsieh", pre_hsieh, 0, tests},
2216 {"fnv1_64", pre_hash_fnv1_64, 0, tests},
2217 {"fnv1a_64", pre_hash_fnv1a_64, 0, tests},
2218 {"fnv1_32", pre_hash_fnv1_32, 0, tests},
2219 {"fnv1a_32", pre_hash_fnv1a_32, 0, tests},
2220 {"ketama", pre_hash_ketama, 0, tests},
2221 {"unix_socket", pre_unix_socket, 0, tests},
2222 {"unix_socket_nodelay", pre_nodelay, 0, tests},
2223 {"poll_timeout", poll_timeout, 0, tests},
2224 {"gets", enable_cas, 0, tests},
2225 {"consistent", enable_consistent, 0, tests},
2226 // {"udp", pre_udp, 0, tests},
2227 {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},
2228 {"string", 0, 0, string_tests},
2229 {"result", 0, 0, result_tests},
2230 {"async", pre_nonblock, 0, async_tests},
2231 {"user", 0, 0, user_tests},
2232 {"generate", 0, 0, generate_tests},
2233 {"generate_hsieh", pre_hsieh, 0, generate_tests},
2234 {"generate_hsieh_consistent", enable_consistent, 0, generate_tests},
2235 {"generate_md5", pre_md5, 0, generate_tests},
2236 {"generate_nonblock", pre_nonblock, 0, generate_tests},
2237 {0, 0, 0, 0}
2238 };
2239
2240 collection_st *gets_collections(void)
2241 {
2242 return collection;
2243 }