Fixed bug found by Evan Weaver where increment was not returning propper error
[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(memcached_st *memc)
893 {
894 const char *version_string;
895
896 version_string= memcached_lib_version();
897
898 assert(!strcmp(version_string, LIBMEMCACHED_VERSION_STRING));
899
900 return 0;
901 }
902
903 uint8_t get_stats(memcached_st *memc)
904 {
905 unsigned int x;
906 char **list;
907 char **ptr;
908 memcached_return rc;
909 memcached_stat_st *stat;
910
911 stat= memcached_stat(memc, NULL, &rc);
912 assert(rc == MEMCACHED_SUCCESS);
913
914 assert(rc == MEMCACHED_SUCCESS);
915 assert(stat);
916
917 for (x= 0; x < memcached_server_count(memc); x++)
918 {
919 list= memcached_stat_get_keys(memc, stat+x, &rc);
920 assert(rc == MEMCACHED_SUCCESS);
921 for (ptr= list; *ptr; ptr++);
922
923 free(list);
924 }
925
926 memcached_stat_free(NULL, stat);
927
928 return 0;
929 }
930
931 uint8_t add_host_test(memcached_st *memc)
932 {
933 unsigned int x;
934 memcached_server_st *servers;
935 memcached_return rc;
936 char servername[]= "0.example.com";
937
938 servers= memcached_server_list_append(NULL, servername, 400, &rc);
939 assert(servers);
940 assert(1 == memcached_server_list_count(servers));
941
942 for (x= 2; x < 20; x++)
943 {
944 char buffer[SMALL_STRING_LEN];
945
946 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
947 servers= memcached_server_list_append(servers, buffer, 401,
948 &rc);
949 assert(rc == MEMCACHED_SUCCESS);
950 assert(x == memcached_server_list_count(servers));
951 }
952
953 rc= memcached_server_push(memc, servers);
954 assert(rc == MEMCACHED_SUCCESS);
955 rc= memcached_server_push(memc, servers);
956 assert(rc == MEMCACHED_SUCCESS);
957
958 memcached_server_list_free(servers);
959
960 return 0;
961 }
962
963 memcached_return clone_test_callback(memcached_st *parent, memcached_st *clone)
964 {
965 return MEMCACHED_SUCCESS;
966 }
967
968 memcached_return cleanup_test_callback(memcached_st *ptr)
969 {
970 return MEMCACHED_SUCCESS;
971 }
972
973 uint8_t callback_test(memcached_st *memc)
974 {
975 /* Test User Data */
976 {
977 int x= 5;
978 int *test_ptr;
979 memcached_return rc;
980
981 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_USER_DATA, &x);
982 assert(rc == MEMCACHED_SUCCESS);
983 test_ptr= (int *)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
984 assert(*test_ptr == x);
985 }
986
987 /* Test Clone Callback */
988 {
989 memcached_clone_func temp_function;
990 memcached_return rc;
991
992 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, clone_test_callback);
993 assert(rc == MEMCACHED_SUCCESS);
994 temp_function= (memcached_clone_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
995 assert(temp_function == clone_test_callback);
996 }
997
998 /* Test Cleanup Callback */
999 {
1000 memcached_cleanup_func temp_function;
1001 memcached_return rc;
1002
1003 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, cleanup_test_callback);
1004 assert(rc == MEMCACHED_SUCCESS);
1005 temp_function= (memcached_cleanup_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
1006 assert(temp_function == cleanup_test_callback);
1007 }
1008
1009 return 0;
1010 }
1011
1012 /* We don't test the behavior itself, we test the switches */
1013 uint8_t behavior_test(memcached_st *memc)
1014 {
1015 unsigned long long value;
1016 unsigned int set= 1;
1017
1018 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
1019 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
1020 assert(value == 1);
1021
1022 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
1023 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
1024 assert(value == 1);
1025
1026 set= MEMCACHED_HASH_MD5;
1027 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
1028 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1029 assert(value == MEMCACHED_HASH_MD5);
1030
1031 set= 0;
1032
1033 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
1034 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
1035 assert(value == 0);
1036
1037 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
1038 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
1039 assert(value == 0);
1040
1041 set= MEMCACHED_HASH_DEFAULT;
1042 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
1043 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1044 assert(value == MEMCACHED_HASH_DEFAULT);
1045
1046 set= MEMCACHED_HASH_CRC;
1047 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
1048 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
1049 assert(value == MEMCACHED_HASH_CRC);
1050
1051 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1052 assert(value > 0);
1053
1054 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1055 assert(value > 0);
1056
1057 return 0;
1058 }
1059
1060 /* Test case provided by Cal Haldenbrand */
1061 uint8_t user_supplied_bug1(memcached_st *memc)
1062 {
1063 unsigned int setter= 1;
1064 unsigned int x;
1065
1066 unsigned long long total= 0;
1067 int size= 0;
1068 char key[10];
1069 char randomstuff[6 * 1024];
1070 memcached_return rc;
1071
1072 memset(randomstuff, 0, 6 * 1024);
1073
1074 /* We just keep looking at the same values over and over */
1075 srandom(10);
1076
1077 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
1078 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
1079
1080
1081 /* add key */
1082 for (x= 0 ; total < 20 * 1024576 ; x++ )
1083 {
1084 unsigned int j= 0;
1085
1086 size= (rand() % ( 5 * 1024 ) ) + 400;
1087 memset(randomstuff, 0, 6 * 1024);
1088 assert(size < 6 * 1024); /* Being safe here */
1089
1090 for (j= 0 ; j < size ;j++)
1091 randomstuff[j] = (char) (rand() % 26) + 97;
1092
1093 total += size;
1094 sprintf(key, "%d", x);
1095 rc = memcached_set(memc, key, strlen(key),
1096 randomstuff, strlen(randomstuff), 10, 0);
1097 /* If we fail, lets try again */
1098 if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED)
1099 rc = memcached_set(memc, key, strlen(key),
1100 randomstuff, strlen(randomstuff), 10, 0);
1101 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
1102 }
1103
1104 return 0;
1105 }
1106
1107 /* Test case provided by Cal Haldenbrand */
1108 uint8_t user_supplied_bug2(memcached_st *memc)
1109 {
1110 int errors;
1111 unsigned int setter;
1112 unsigned int x;
1113 unsigned long long total;
1114
1115 setter= 1;
1116 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
1117 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
1118 #ifdef NOT_YET
1119 setter = 20 * 1024576;
1120 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, &setter);
1121 setter = 20 * 1024576;
1122 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter);
1123 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1124 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1125
1126 for (x= 0, errors= 0, total= 0 ; total < 20 * 1024576 ; x++)
1127 #endif
1128
1129 for (x= 0, errors= 0, total= 0 ; total < 24576 ; x++)
1130 {
1131 memcached_return rc= MEMCACHED_SUCCESS;
1132 char buffer[SMALL_STRING_LEN];
1133 uint32_t flags= 0;
1134 size_t val_len= 0;
1135 char *getval;
1136
1137 memset(buffer, 0, SMALL_STRING_LEN);
1138
1139 snprintf(buffer, SMALL_STRING_LEN, "%u", x);
1140 getval= memcached_get(memc, buffer, strlen(buffer),
1141 &val_len, &flags, &rc);
1142 if (rc != MEMCACHED_SUCCESS)
1143 {
1144 if (rc == MEMCACHED_NOTFOUND)
1145 errors++;
1146 else
1147 assert(0);
1148
1149 continue;
1150 }
1151 total+= val_len;
1152 errors= 0;
1153 free(getval);
1154 }
1155
1156 return 0;
1157 }
1158
1159 /* Do a large mget() over all the keys we think exist */
1160 #define KEY_COUNT 3000 // * 1024576
1161 uint8_t user_supplied_bug3(memcached_st *memc)
1162 {
1163 memcached_return rc;
1164 unsigned int setter;
1165 unsigned int x;
1166 char **keys;
1167 size_t key_lengths[KEY_COUNT];
1168
1169 setter= 1;
1170 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
1171 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
1172 #ifdef NOT_YET
1173 setter = 20 * 1024576;
1174 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, &setter);
1175 setter = 20 * 1024576;
1176 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter);
1177 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
1178 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
1179 #endif
1180
1181 keys= (char **)malloc(sizeof(char *) * KEY_COUNT);
1182 assert(keys);
1183 memset(keys, 0, (sizeof(char *) * KEY_COUNT));
1184 for (x= 0; x < KEY_COUNT; x++)
1185 {
1186 char buffer[30];
1187
1188 snprintf(buffer, 30, "%u", x);
1189 keys[x]= strdup(buffer);
1190 key_lengths[x]= strlen(keys[x]);
1191 }
1192
1193 rc= memcached_mget(memc, keys, key_lengths, KEY_COUNT);
1194 assert(rc == MEMCACHED_SUCCESS);
1195
1196 /* Turn this into a help function */
1197 {
1198 char return_key[MEMCACHED_MAX_KEY];
1199 size_t return_key_length;
1200 char *return_value;
1201 size_t return_value_length;
1202 uint32_t flags;
1203
1204 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1205 &return_value_length, &flags, &rc)))
1206 {
1207 assert(return_value);
1208 assert(rc == MEMCACHED_SUCCESS);
1209 free(return_value);
1210 }
1211 }
1212
1213 for (x= 0; x < KEY_COUNT; x++)
1214 free(keys[x]);
1215 free(keys);
1216
1217 return 0;
1218 }
1219
1220 /* Make sure we behave properly if server list has no values */
1221 uint8_t user_supplied_bug4(memcached_st *memc)
1222 {
1223 memcached_return rc;
1224 char *keys[]= {"fudge", "son", "food"};
1225 size_t key_length[]= {5, 3, 4};
1226 unsigned int x;
1227 uint32_t flags;
1228 char return_key[MEMCACHED_MAX_KEY];
1229 size_t return_key_length;
1230 char *return_value;
1231 size_t return_value_length;
1232
1233 /* Here we free everything before running a bunch of mget tests */
1234 {
1235 memcached_server_list_free(memc->hosts);
1236 memc->hosts= NULL;
1237 memc->number_of_hosts= 0;
1238 }
1239
1240
1241 /* We need to empty the server before continueing test */
1242 rc= memcached_flush(memc, 0);
1243 assert(rc == MEMCACHED_NO_SERVERS);
1244
1245 rc= memcached_mget(memc, keys, key_length, 3);
1246 assert(rc == MEMCACHED_NO_SERVERS);
1247
1248 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1249 &return_value_length, &flags, &rc)) != NULL)
1250 {
1251 assert(return_value);
1252 }
1253 assert(!return_value);
1254 assert(return_value_length == 0);
1255 assert(rc == MEMCACHED_NO_SERVERS);
1256
1257 for (x= 0; x < 3; x++)
1258 {
1259 rc= memcached_set(memc, keys[x], key_length[x],
1260 keys[x], key_length[x],
1261 (time_t)50, (uint32_t)9);
1262 assert(rc == MEMCACHED_NO_SERVERS);
1263 }
1264
1265 rc= memcached_mget(memc, keys, key_length, 3);
1266 assert(rc == MEMCACHED_NO_SERVERS);
1267
1268 x= 0;
1269 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1270 &return_value_length, &flags, &rc)))
1271 {
1272 assert(return_value);
1273 assert(rc == MEMCACHED_SUCCESS);
1274 assert(return_key_length == return_value_length);
1275 assert(!memcmp(return_value, return_key, return_value_length));
1276 free(return_value);
1277 x++;
1278 }
1279
1280 return 0;
1281 }
1282
1283 #define VALUE_SIZE_BUG5 1048064
1284 uint8_t user_supplied_bug5(memcached_st *memc)
1285 {
1286 memcached_return rc;
1287 char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1288 size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1289 char return_key[MEMCACHED_MAX_KEY];
1290 size_t return_key_length;
1291 char *value;
1292 size_t value_length;
1293 uint32_t flags;
1294 unsigned int count;
1295 unsigned int x;
1296 char insert_data[VALUE_SIZE_BUG5];
1297
1298 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1299 insert_data[x]= rand();
1300
1301 memcached_flush(memc, 0);
1302 value= memcached_get(memc, keys[0], key_length[0],
1303 &value_length, &flags, &rc);
1304 assert(value == NULL);
1305 rc= memcached_mget(memc, keys, key_length, 4);
1306
1307 count= 0;
1308 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1309 &value_length, &flags, &rc)))
1310 count++;
1311 assert(count == 0);
1312
1313 for (x= 0; x < 4; x++)
1314 {
1315 rc= memcached_set(memc, keys[x], key_length[x],
1316 insert_data, VALUE_SIZE_BUG5,
1317 (time_t)0, (uint32_t)0);
1318 assert(rc == MEMCACHED_SUCCESS);
1319 }
1320
1321 for (x= 0; x < 10; x++)
1322 {
1323 value= memcached_get(memc, keys[0], key_length[0],
1324 &value_length, &flags, &rc);
1325 assert(value);
1326 free(value);
1327
1328 rc= memcached_mget(memc, keys, key_length, 4);
1329 count= 0;
1330 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1331 &value_length, &flags, &rc)))
1332 {
1333 count++;
1334 free(value);
1335 }
1336 assert(count == 4);
1337 }
1338
1339 return 0;
1340 }
1341
1342 uint8_t user_supplied_bug6(memcached_st *memc)
1343 {
1344 memcached_return rc;
1345 char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1346 size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1347 char return_key[MEMCACHED_MAX_KEY];
1348 size_t return_key_length;
1349 char *value;
1350 size_t value_length;
1351 uint32_t flags;
1352 unsigned int count;
1353 unsigned int x;
1354 char insert_data[VALUE_SIZE_BUG5];
1355
1356 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1357 insert_data[x]= rand();
1358
1359 memcached_flush(memc, 0);
1360 value= memcached_get(memc, keys[0], key_length[0],
1361 &value_length, &flags, &rc);
1362 assert(value == NULL);
1363 assert(rc == MEMCACHED_NOTFOUND);
1364 rc= memcached_mget(memc, keys, key_length, 4);
1365 assert(rc == MEMCACHED_SUCCESS);
1366
1367 count= 0;
1368 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1369 &value_length, &flags, &rc)))
1370 count++;
1371 assert(count == 0);
1372 assert(rc == MEMCACHED_END);
1373
1374 for (x= 0; x < 4; x++)
1375 {
1376 rc= memcached_set(memc, keys[x], key_length[x],
1377 insert_data, VALUE_SIZE_BUG5,
1378 (time_t)0, (uint32_t)0);
1379 assert(rc == MEMCACHED_SUCCESS);
1380 }
1381
1382 for (x= 0; x < 2; x++)
1383 {
1384 value= memcached_get(memc, keys[0], key_length[0],
1385 &value_length, &flags, &rc);
1386 assert(value);
1387 free(value);
1388
1389 rc= memcached_mget(memc, keys, key_length, 4);
1390 assert(rc == MEMCACHED_SUCCESS);
1391 count= 3;
1392 /* We test for purge of partial complete fetches */
1393 for (count= 3; count; count--)
1394 {
1395 value= memcached_fetch(memc, return_key, &return_key_length,
1396 &value_length, &flags, &rc);
1397 assert(rc == MEMCACHED_SUCCESS);
1398 assert(!(memcmp(value, insert_data, value_length)));
1399 assert(value_length);
1400 free(value);
1401 }
1402 }
1403
1404 return 0;
1405 }
1406
1407 uint8_t user_supplied_bug8(memcached_st *memc)
1408 {
1409 memcached_return rc;
1410 memcached_st *mine;
1411 memcached_st *clone;
1412
1413 memcached_server_st *servers;
1414 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";
1415
1416 servers= memcached_servers_parse(server_list);
1417 assert(servers);
1418
1419 mine= memcached_create(NULL);
1420 rc= memcached_server_push(mine, servers);
1421 assert(rc == MEMCACHED_SUCCESS);
1422 memcached_server_list_free(servers);
1423
1424 assert(mine);
1425 clone= memcached_clone(NULL, mine);
1426
1427 memcached_quit(mine);
1428 memcached_quit(clone);
1429
1430
1431 memcached_free(mine);
1432 memcached_free(clone);
1433
1434 return 0;
1435 }
1436
1437 /* Test flag store/retrieve */
1438 uint8_t user_supplied_bug7(memcached_st *memc)
1439 {
1440 memcached_return rc;
1441 char *keys= "036790384900";
1442 size_t key_length= strlen("036790384900");
1443 char return_key[MEMCACHED_MAX_KEY];
1444 size_t return_key_length;
1445 char *value;
1446 size_t value_length;
1447 uint32_t flags;
1448 unsigned int x;
1449 char insert_data[VALUE_SIZE_BUG5];
1450
1451 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1452 insert_data[x]= rand();
1453
1454 memcached_flush(memc, 0);
1455
1456 flags= 245;
1457 rc= memcached_set(memc, keys, key_length,
1458 insert_data, VALUE_SIZE_BUG5,
1459 (time_t)0, flags);
1460 assert(rc == MEMCACHED_SUCCESS);
1461
1462 flags= 0;
1463 value= memcached_get(memc, keys, key_length,
1464 &value_length, &flags, &rc);
1465 assert(flags == 245);
1466 assert(value);
1467 free(value);
1468
1469 rc= memcached_mget(memc, &keys, &key_length, 1);
1470
1471 flags= 0;
1472 value= memcached_fetch(memc, return_key, &return_key_length,
1473 &value_length, &flags, &rc);
1474 assert(flags == 245);
1475 assert(value);
1476 free(value);
1477
1478
1479 return 0;
1480 }
1481
1482 uint8_t user_supplied_bug9(memcached_st *memc)
1483 {
1484 memcached_return rc;
1485 char *keys[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
1486 size_t key_length[3];
1487 unsigned int x;
1488 uint32_t flags;
1489 unsigned count= 0;
1490
1491 char return_key[MEMCACHED_MAX_KEY];
1492 size_t return_key_length;
1493 char *return_value;
1494 size_t return_value_length;
1495
1496
1497 key_length[0]= strlen("UDATA:edevil@sapo.pt");
1498 key_length[1]= strlen("fudge&*@#");
1499 key_length[2]= strlen("for^#@&$not");
1500
1501
1502 for (x= 0; x < 3; x++)
1503 {
1504 rc= memcached_set(memc, keys[x], key_length[x],
1505 keys[x], key_length[x],
1506 (time_t)50, (uint32_t)9);
1507 assert(rc == MEMCACHED_SUCCESS);
1508 }
1509
1510 rc= memcached_mget(memc, keys, key_length, 3);
1511 assert(rc == MEMCACHED_SUCCESS);
1512
1513 /* We need to empty the server before continueing test */
1514 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1515 &return_value_length, &flags, &rc)) != NULL)
1516 {
1517 assert(return_value);
1518 free(return_value);
1519 count++;
1520 }
1521 assert(count == 3);
1522
1523 return 0;
1524 }
1525
1526 /* We are testing with aggressive timeout to get failures */
1527 uint8_t user_supplied_bug10(memcached_st *memc)
1528 {
1529 char *key= "foo";
1530 char *value;
1531 size_t value_length= 512;
1532 unsigned int x;
1533 int key_len= 3;
1534 memcached_return rc;
1535 unsigned int set= 1;
1536 memcached_st *mclone= memcached_clone(NULL, memc);
1537 int32_t timeout;
1538
1539 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
1540 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
1541 timeout= 2;
1542 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout);
1543
1544 value = (char*)malloc(value_length * sizeof(char));
1545
1546 for (x= 0; x < value_length; x++)
1547 value[x]= (char) (x % 127);
1548
1549 for (x= 1; x <= 100000; ++x)
1550 {
1551 rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
1552
1553 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE || rc == MEMCACHED_BUFFERED);
1554
1555 if (rc == MEMCACHED_WRITE_FAILURE)
1556 x--;
1557 }
1558
1559 free(value);
1560 memcached_free(mclone);
1561
1562 return 0;
1563 }
1564
1565 /*
1566 We are looking failures in the async protocol
1567 */
1568 uint8_t user_supplied_bug11(memcached_st *memc)
1569 {
1570 char *key= "foo";
1571 char *value;
1572 size_t value_length= 512;
1573 unsigned int x;
1574 int key_len= 3;
1575 memcached_return rc;
1576 unsigned int set= 1;
1577 int32_t timeout;
1578 memcached_st *mclone= memcached_clone(NULL, memc);
1579
1580 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
1581 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
1582 timeout= -1;
1583 memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout);
1584
1585 timeout= (int32_t)memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
1586
1587 assert(timeout == -1);
1588
1589 value = (char*)malloc(value_length * sizeof(char));
1590
1591 for (x= 0; x < value_length; x++)
1592 value[x]= (char) (x % 127);
1593
1594 for (x= 1; x <= 100000; ++x)
1595 {
1596 rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
1597 }
1598
1599 free(value);
1600 memcached_free(mclone);
1601
1602 return 0;
1603 }
1604
1605 /*
1606 Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
1607 */
1608 uint8_t user_supplied_bug12(memcached_st *memc)
1609 {
1610 memcached_return rc;
1611 uint32_t flags;
1612 size_t value_length;
1613 char *value;
1614 uint64_t number_value;
1615
1616 value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
1617 &value_length, &flags, &rc);
1618 assert(value == NULL);
1619 assert(rc == MEMCACHED_NOTFOUND);
1620
1621 rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
1622 1, &number_value);
1623
1624 assert(value == NULL);
1625 assert(rc == MEMCACHED_NOTFOUND);
1626
1627 rc= memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
1628
1629 value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
1630 &value_length, &flags, &rc);
1631 assert(value);
1632 assert(rc == MEMCACHED_SUCCESS);
1633
1634 rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
1635 1, &number_value);
1636 assert(number_value == 2);
1637 assert(rc == MEMCACHED_SUCCESS);
1638
1639 return 0;
1640 }
1641
1642 uint8_t result_static(memcached_st *memc)
1643 {
1644 memcached_result_st result;
1645 memcached_result_st *result_ptr;
1646
1647 result_ptr= memcached_result_create(memc, &result);
1648 assert(result.is_allocated == MEMCACHED_NOT_ALLOCATED);
1649 assert(result_ptr);
1650 memcached_result_free(&result);
1651
1652 return 0;
1653 }
1654
1655 uint8_t result_alloc(memcached_st *memc)
1656 {
1657 memcached_result_st *result;
1658
1659 result= memcached_result_create(memc, NULL);
1660 assert(result);
1661 memcached_result_free(result);
1662
1663 return 0;
1664 }
1665
1666 uint8_t string_static_null(memcached_st *memc)
1667 {
1668 memcached_string_st string;
1669 memcached_string_st *string_ptr;
1670
1671 string_ptr= memcached_string_create(memc, &string, 0);
1672 assert(string.is_allocated == MEMCACHED_NOT_ALLOCATED);
1673 assert(string_ptr);
1674 memcached_string_free(&string);
1675
1676 return 0;
1677 }
1678
1679 uint8_t string_alloc_null(memcached_st *memc)
1680 {
1681 memcached_string_st *string;
1682
1683 string= memcached_string_create(memc, NULL, 0);
1684 assert(string);
1685 memcached_string_free(string);
1686
1687 return 0;
1688 }
1689
1690 uint8_t string_alloc_with_size(memcached_st *memc)
1691 {
1692 memcached_string_st *string;
1693
1694 string= memcached_string_create(memc, NULL, 1024);
1695 assert(string);
1696 memcached_string_free(string);
1697
1698 return 0;
1699 }
1700
1701 uint8_t string_alloc_with_size_toobig(memcached_st *memc)
1702 {
1703 memcached_string_st *string;
1704
1705 string= memcached_string_create(memc, NULL, INT64_MAX);
1706 assert(string == NULL);
1707
1708 return 0;
1709 }
1710
1711 uint8_t string_alloc_append(memcached_st *memc)
1712 {
1713 unsigned int x;
1714 char buffer[SMALL_STRING_LEN];
1715 memcached_string_st *string;
1716
1717 /* Ring the bell! */
1718 memset(buffer, 6, SMALL_STRING_LEN);
1719
1720 string= memcached_string_create(memc, NULL, 100);
1721 assert(string);
1722
1723 for (x= 0; x < 1024; x++)
1724 {
1725 memcached_return rc;
1726 rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
1727 assert(rc == MEMCACHED_SUCCESS);
1728 }
1729 memcached_string_free(string);
1730
1731 return 0;
1732 }
1733
1734 uint8_t string_alloc_append_toobig(memcached_st *memc)
1735 {
1736 memcached_return rc;
1737 unsigned int x;
1738 char buffer[SMALL_STRING_LEN];
1739 memcached_string_st *string;
1740
1741 /* Ring the bell! */
1742 memset(buffer, 6, SMALL_STRING_LEN);
1743
1744 string= memcached_string_create(memc, NULL, 100);
1745 assert(string);
1746
1747 for (x= 0; x < 1024; x++)
1748 {
1749 rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
1750 assert(rc == MEMCACHED_SUCCESS);
1751 }
1752 rc= memcached_string_append(string, buffer, INT64_MAX);
1753 assert(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE);
1754 memcached_string_free(string);
1755
1756 return 0;
1757 }
1758
1759 uint8_t cleanup_pairs(memcached_st *memc)
1760 {
1761 pairs_free(global_pairs);
1762
1763 return 0;
1764 }
1765
1766 uint8_t generate_data(memcached_st *memc)
1767 {
1768 unsigned long long x;
1769 global_pairs= pairs_generate(GLOBAL_COUNT);
1770 execute_set(memc, global_pairs, GLOBAL_COUNT);
1771
1772 for (x= 0; x < GLOBAL_COUNT; x++)
1773 {
1774 global_keys[x]= global_pairs[x].key;
1775 global_keys_length[x]= global_pairs[x].key_length;
1776 }
1777
1778 return 0;
1779 }
1780
1781 uint8_t generate_buffer_data(memcached_st *memc)
1782 {
1783 int latch= 0;
1784
1785 latch= 1;
1786 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch);
1787 generate_data(memc);
1788
1789 return 0;
1790 }
1791
1792 #ifdef NOT_DONE
1793 uint8_t mset_data(memcached_st *memc)
1794 {
1795 unsigned long long x;
1796 global_pairs= pairs_generate(GLOBAL_COUNT);
1797
1798 (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
1799
1800 for (x= 0; x < GLOBAL_COUNT; x++)
1801 {
1802 global_keys[x]= global_pairs[x].key;
1803 global_keys_length[x]= global_pairs[x].key_length;
1804 }
1805
1806 return 0;
1807 }
1808 #endif
1809
1810 uint8_t get_read(memcached_st *memc)
1811 {
1812 unsigned int x;
1813 memcached_return rc;
1814
1815 {
1816 char *return_value;
1817 size_t return_value_length;
1818 uint32_t flags;
1819
1820 for (x= 0; x < GLOBAL_COUNT; x++)
1821 {
1822 return_value= memcached_get(memc, global_keys[x], global_keys_length[x],
1823 &return_value_length, &flags, &rc);
1824 /*
1825 assert(return_value);
1826 assert(rc == MEMCACHED_SUCCESS);
1827 */
1828 if (rc == MEMCACHED_SUCCESS && return_value)
1829 free(return_value);
1830 }
1831 }
1832
1833 return 0;
1834 }
1835
1836 uint8_t mget_read(memcached_st *memc)
1837 {
1838 memcached_return rc;
1839
1840 rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
1841 assert(rc == MEMCACHED_SUCCESS);
1842 /* Turn this into a help function */
1843 {
1844 char return_key[MEMCACHED_MAX_KEY];
1845 size_t return_key_length;
1846 char *return_value;
1847 size_t return_value_length;
1848 uint32_t flags;
1849
1850 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1851 &return_value_length, &flags, &rc)))
1852 {
1853 assert(return_value);
1854 assert(rc == MEMCACHED_SUCCESS);
1855 free(return_value);
1856 }
1857 }
1858
1859 return 0;
1860 }
1861
1862 uint8_t mget_read_result(memcached_st *memc)
1863 {
1864 memcached_return rc;
1865
1866 rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
1867 assert(rc == MEMCACHED_SUCCESS);
1868 /* Turn this into a help function */
1869 {
1870 memcached_result_st results_obj;
1871 memcached_result_st *results;
1872
1873 results= memcached_result_create(memc, &results_obj);
1874
1875 while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
1876 {
1877 assert(results);
1878 assert(rc == MEMCACHED_SUCCESS);
1879 }
1880
1881 memcached_result_free(&results_obj);
1882 }
1883
1884 return 0;
1885 }
1886
1887 uint8_t mget_read_function(memcached_st *memc)
1888 {
1889 memcached_return rc;
1890 unsigned int counter;
1891 unsigned int (*callbacks[1])(memcached_st *, memcached_result_st *, void *);
1892
1893 rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
1894 assert(rc == MEMCACHED_SUCCESS);
1895
1896 callbacks[0]= &callback_counter;
1897 counter= 0;
1898 rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
1899
1900 return 0;
1901 }
1902
1903 uint8_t delete_generate(memcached_st *memc)
1904 {
1905 unsigned int x;
1906
1907 for (x= 0; x < GLOBAL_COUNT; x++)
1908 {
1909 (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
1910 }
1911
1912 return 0;
1913 }
1914
1915 uint8_t delete_buffer_generate(memcached_st *memc)
1916 {
1917 int latch= 0;
1918 unsigned int x;
1919
1920 latch= 1;
1921 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch);
1922
1923 for (x= 0; x < GLOBAL_COUNT; x++)
1924 {
1925 (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
1926 }
1927
1928 return 0;
1929 }
1930
1931 uint8_t free_data(memcached_st *memc)
1932 {
1933 pairs_free(global_pairs);
1934
1935 return 0;
1936 }
1937
1938 uint8_t add_host_test1(memcached_st *memc)
1939 {
1940 unsigned int x;
1941 memcached_return rc;
1942 char servername[]= "0.example.com";
1943 memcached_server_st *servers;
1944
1945 servers= memcached_server_list_append(NULL, servername, 400, &rc);
1946 assert(servers);
1947 assert(1 == memcached_server_list_count(servers));
1948
1949 for (x= 2; x < 20; x++)
1950 {
1951 char buffer[SMALL_STRING_LEN];
1952
1953 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
1954 servers= memcached_server_list_append(servers, buffer, 401,
1955 &rc);
1956 assert(rc == MEMCACHED_SUCCESS);
1957 assert(x == memcached_server_list_count(servers));
1958 }
1959
1960 rc= memcached_server_push(memc, servers);
1961 assert(rc == MEMCACHED_SUCCESS);
1962 rc= memcached_server_push(memc, servers);
1963 assert(rc == MEMCACHED_SUCCESS);
1964
1965 memcached_server_list_free(servers);
1966
1967 return 0;
1968 }
1969
1970 memcached_return pre_nonblock(memcached_st *memc)
1971 {
1972 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
1973
1974 return MEMCACHED_SUCCESS;
1975 }
1976
1977 memcached_return pre_md5(memcached_st *memc)
1978 {
1979 memcached_hash value= MEMCACHED_HASH_MD5;
1980 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1981
1982 return MEMCACHED_SUCCESS;
1983 }
1984
1985 memcached_return pre_crc(memcached_st *memc)
1986 {
1987 memcached_hash value= MEMCACHED_HASH_CRC;
1988 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1989
1990 return MEMCACHED_SUCCESS;
1991 }
1992
1993 memcached_return pre_hsieh(memcached_st *memc)
1994 {
1995 memcached_hash value= MEMCACHED_HASH_HSIEH;
1996 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1997
1998 return MEMCACHED_SUCCESS;
1999 }
2000
2001 memcached_return pre_hash_fnv1_64(memcached_st *memc)
2002 {
2003 memcached_hash value= MEMCACHED_HASH_FNV1_64;
2004 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
2005
2006 return MEMCACHED_SUCCESS;
2007 }
2008
2009 memcached_return pre_hash_fnv1a_64(memcached_st *memc)
2010 {
2011 memcached_hash value= MEMCACHED_HASH_FNV1A_64;
2012 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
2013
2014 return MEMCACHED_SUCCESS;
2015 }
2016
2017 memcached_return pre_hash_fnv1_32(memcached_st *memc)
2018 {
2019 memcached_hash value= MEMCACHED_HASH_FNV1_32;
2020 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
2021
2022 return MEMCACHED_SUCCESS;
2023 }
2024
2025 memcached_return pre_hash_fnv1a_32(memcached_st *memc)
2026 {
2027 memcached_hash value= MEMCACHED_HASH_FNV1A_32;
2028 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
2029
2030 return MEMCACHED_SUCCESS;
2031 }
2032
2033 memcached_return pre_hash_ketama(memcached_st *memc)
2034 {
2035 memcached_hash value= MEMCACHED_HASH_KETAMA;
2036 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
2037
2038 return MEMCACHED_SUCCESS;
2039 }
2040 void my_free(memcached_st *ptr, void *mem)
2041 {
2042 free(mem);
2043 }
2044
2045 void *my_malloc(memcached_st *ptr, const size_t size)
2046 {
2047 return malloc(size);
2048 }
2049
2050 void *my_realloc(memcached_st *ptr, void *mem, const size_t size)
2051 {
2052 return realloc(mem, size);
2053 }
2054
2055 memcached_return set_memory_alloc(memcached_st *memc)
2056 {
2057 {
2058 memcached_malloc_function test_ptr;
2059 memcached_return rc;
2060
2061 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &my_malloc);
2062 assert(rc == MEMCACHED_SUCCESS);
2063 test_ptr= (memcached_malloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
2064 assert(test_ptr == (memcached_malloc_function)my_malloc);
2065 }
2066
2067 {
2068 memcached_realloc_function test_ptr;
2069 memcached_return rc;
2070
2071 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &my_realloc);
2072 assert(rc == MEMCACHED_SUCCESS);
2073 test_ptr= (memcached_realloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
2074 assert(test_ptr == my_realloc);
2075 }
2076
2077 {
2078 memcached_free_function test_ptr;
2079 memcached_return rc;
2080
2081 rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, my_free);
2082 assert(rc == MEMCACHED_SUCCESS);
2083 test_ptr= (memcached_free_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
2084 assert(test_ptr == my_free);
2085 }
2086
2087 return MEMCACHED_SUCCESS;
2088 }
2089
2090 memcached_return enable_consistent(memcached_st *memc)
2091 {
2092 memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT;
2093 memcached_hash hash;
2094 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, &value);
2095 pre_hsieh(memc);
2096
2097 value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
2098 assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
2099
2100 hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
2101 assert(hash == MEMCACHED_HASH_HSIEH);
2102
2103
2104 return MEMCACHED_SUCCESS;
2105 }
2106
2107 memcached_return enable_cas(memcached_st *memc)
2108 {
2109 unsigned int set= 1;
2110
2111 memcached_version(memc);
2112
2113 if (memc->hosts[0].major_version >= 1 &&
2114 memc->hosts[0].minor_version >= 2 &&
2115 memc->hosts[0].micro_version >= 4)
2116 {
2117 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, &set);
2118
2119 return MEMCACHED_SUCCESS;
2120 }
2121
2122 return MEMCACHED_FAILURE;
2123 }
2124
2125 memcached_return check_for_1_2_3(memcached_st *memc)
2126 {
2127 memcached_version(memc);
2128
2129 if (memc->hosts[0].major_version >= 1 &&
2130 memc->hosts[0].minor_version >= 2 &&
2131 memc->hosts[0].micro_version >= 4)
2132 return MEMCACHED_SUCCESS;
2133
2134 return MEMCACHED_FAILURE;
2135 }
2136
2137 memcached_return pre_unix_socket(memcached_st *memc)
2138 {
2139 memcached_return rc;
2140 struct stat buf;
2141
2142 memcached_server_list_free(memc->hosts);
2143 memc->hosts= NULL;
2144 memc->number_of_hosts= 0;
2145
2146 if (stat("/tmp/memcached.socket", &buf))
2147 return MEMCACHED_FAILURE;
2148
2149 rc= memcached_server_add_unix_socket(memc, "/tmp/memcached.socket");
2150
2151 return rc;
2152 }
2153
2154 memcached_return pre_udp(memcached_st *memc)
2155 {
2156 memcached_return rc;
2157
2158 memcached_server_list_free(memc->hosts);
2159 memc->hosts= NULL;
2160 memc->number_of_hosts= 0;
2161
2162 if (0)
2163 return MEMCACHED_FAILURE;
2164
2165 rc= memcached_server_add_udp(memc, "localhost", MEMCACHED_DEFAULT_PORT);
2166
2167 return rc;
2168 }
2169
2170 memcached_return pre_nodelay(memcached_st *memc)
2171 {
2172 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
2173 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL);
2174
2175 return MEMCACHED_SUCCESS;
2176 }
2177
2178 memcached_return poll_timeout(memcached_st *memc)
2179 {
2180 int32_t timeout;
2181
2182 timeout= 100;
2183
2184 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout);
2185
2186 timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
2187
2188 assert(timeout == 100);
2189
2190 return MEMCACHED_SUCCESS;
2191 }
2192
2193
2194 /* Clean the server before beginning testing */
2195 test_st tests[] ={
2196 {"flush", 0, flush_test },
2197 {"init", 0, init_test },
2198 {"allocation", 0, allocation_test },
2199 {"server_list_null_test", 0, server_list_null_test},
2200 {"clone_test", 0, clone_test },
2201 {"error", 0, error_test },
2202 {"set", 0, set_test },
2203 {"set2", 0, set_test2 },
2204 {"set3", 0, set_test3 },
2205 {"add", 1, add_test },
2206 {"replace", 0, replace_test },
2207 {"delete", 1, delete_test },
2208 {"get", 1, get_test },
2209 {"get2", 0, get_test2 },
2210 {"get3", 0, get_test3 },
2211 {"get4", 0, get_test4 },
2212 {"stats_servername", 0, stats_servername_test },
2213 {"increment", 0, increment_test },
2214 {"decrement", 0, decrement_test },
2215 {"quit", 0, quit_test },
2216 {"mget", 1, mget_test },
2217 {"mget_result", 1, mget_result_test },
2218 {"mget_result_alloc", 1, mget_result_alloc_test },
2219 {"mget_result_function", 1, mget_result_function },
2220 {"get_stats", 0, get_stats },
2221 {"add_host_test", 0, add_host_test },
2222 {"get_stats_keys", 0, get_stats_keys },
2223 {"behavior_test", 0, get_stats_keys },
2224 {"callback_test", 0, get_stats_keys },
2225 {"version_string_test", 0, version_string_test},
2226 {0, 0, 0}
2227 };
2228
2229 test_st async_tests[] ={
2230 {"add", 1, add_wrapper },
2231 {0, 0, 0}
2232 };
2233
2234 test_st string_tests[] ={
2235 {"string static with null", 0, string_static_null },
2236 {"string alloc with null", 0, string_alloc_null },
2237 {"string alloc with 1K", 0, string_alloc_with_size },
2238 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig },
2239 {"string append", 0, string_alloc_append },
2240 {"string append failure (too big)", 0, string_alloc_append_toobig },
2241 {0, 0, 0}
2242 };
2243
2244 test_st result_tests[] ={
2245 {"result static", 0, result_static},
2246 {"result alloc", 0, result_alloc},
2247 {0, 0, 0}
2248 };
2249
2250 test_st version_1_2_3[] ={
2251 {"append", 0, append_test },
2252 {"prepend", 0, prepend_test },
2253 {"cas", 0, cas_test },
2254 {"cas2", 0, cas2_test },
2255 {"append_binary", 0, append_binary_test },
2256 {0, 0, 0}
2257 };
2258
2259 test_st user_tests[] ={
2260 {"user_supplied_bug1", 0, user_supplied_bug1 },
2261 {"user_supplied_bug2", 0, user_supplied_bug2 },
2262 {"user_supplied_bug3", 0, user_supplied_bug3 },
2263 {"user_supplied_bug4", 0, user_supplied_bug4 },
2264 {"user_supplied_bug5", 1, user_supplied_bug5 },
2265 {"user_supplied_bug6", 1, user_supplied_bug6 },
2266 {"user_supplied_bug7", 1, user_supplied_bug7 },
2267 {"user_supplied_bug8", 1, user_supplied_bug8 },
2268 {"user_supplied_bug9", 1, user_supplied_bug9 },
2269 {"user_supplied_bug10", 1, user_supplied_bug10 },
2270 {"user_supplied_bug11", 1, user_supplied_bug11 },
2271 {"user_supplied_bug12", 1, user_supplied_bug12 },
2272 {0, 0, 0}
2273 };
2274
2275 test_st generate_tests[] ={
2276 {"generate_data", 1, generate_data },
2277 {"get_read", 0, get_read },
2278 {"delete_generate", 0, delete_generate },
2279 {"generate_buffer_data", 1, generate_buffer_data },
2280 {"delete_buffer", 0, delete_buffer_generate},
2281 {"generate_data", 1, generate_data },
2282 {"mget_read", 0, mget_read },
2283 {"mget_read_result", 0, mget_read_result },
2284 {"mget_read_function", 0, mget_read_function },
2285 {"cleanup", 1, cleanup_pairs },
2286 {0, 0, 0}
2287 };
2288
2289
2290 collection_st collection[] ={
2291 {"block", 0, 0, tests},
2292 {"nonblock", pre_nonblock, 0, tests},
2293 {"nodelay", pre_nodelay, 0, tests},
2294 {"md5", pre_md5, 0, tests},
2295 {"crc", pre_crc, 0, tests},
2296 {"hsieh", pre_hsieh, 0, tests},
2297 {"fnv1_64", pre_hash_fnv1_64, 0, tests},
2298 {"fnv1a_64", pre_hash_fnv1a_64, 0, tests},
2299 {"fnv1_32", pre_hash_fnv1_32, 0, tests},
2300 {"fnv1a_32", pre_hash_fnv1a_32, 0, tests},
2301 {"ketama", pre_hash_ketama, 0, tests},
2302 {"unix_socket", pre_unix_socket, 0, tests},
2303 {"unix_socket_nodelay", pre_nodelay, 0, tests},
2304 {"poll_timeout", poll_timeout, 0, tests},
2305 {"gets", enable_cas, 0, tests},
2306 {"consistent", enable_consistent, 0, tests},
2307 {"memory_allocators", set_memory_alloc, 0, tests},
2308 // {"udp", pre_udp, 0, tests},
2309 {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},
2310 {"string", 0, 0, string_tests},
2311 {"result", 0, 0, result_tests},
2312 {"async", pre_nonblock, 0, async_tests},
2313 {"user", 0, 0, user_tests},
2314 {"generate", 0, 0, generate_tests},
2315 {"generate_hsieh", pre_hsieh, 0, generate_tests},
2316 {"generate_hsieh_consistent", enable_consistent, 0, generate_tests},
2317 {"generate_md5", pre_md5, 0, generate_tests},
2318 {"generate_nonblock", pre_nonblock, 0, generate_tests},
2319 {0, 0, 0, 0}
2320 };
2321
2322 collection_st *gets_collections(void)
2323 {
2324 return collection;
2325 }