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