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