2 Sample test application.
11 #include "../lib/common.h"
13 long int timedif(struct timeval a
, struct timeval b
)
17 us
= a
.tv_usec
- b
.tv_usec
;
19 s
= a
.tv_sec
- b
.tv_sec
;
24 void init_test(memcached_st
*not_used
)
28 (void)memcached_create(&memc
);
29 memcached_free(&memc
);
32 void allocation_test(memcached_st
*not_used
)
35 memc
= memcached_create(NULL
);
40 void connection_test(memcached_st
*memc
)
44 rc
= memcached_server_add(memc
, "localhost", 0);
45 assert(rc
== MEMCACHED_SUCCESS
);
48 void error_test(memcached_st
*memc
)
52 for (rc
= MEMCACHED_SUCCESS
; rc
< MEMCACHED_MAXIMUM_RETURN
; rc
++)
54 printf("Error %d -> %s\n", rc
, memcached_strerror(memc
, rc
));
58 void set_test(memcached_st
*memc
)
62 char *value
= "when we sanitize";
64 rc
= memcached_set(memc
, key
, strlen(key
),
66 (time_t)0, (uint16_t)0);
67 assert(rc
== MEMCACHED_SUCCESS
);
70 void add_test(memcached_st
*memc
)
74 char *value
= "when we sanitize";
76 rc
= memcached_add(memc
, key
, strlen(key
),
78 (time_t)0, (uint16_t)0);
79 assert(rc
== MEMCACHED_NOTSTORED
);
82 void replace_test(memcached_st
*memc
)
86 char *value
= "when we sanitize";
88 rc
= memcached_replace(memc
, key
, strlen(key
),
90 (time_t)0, (uint16_t)0);
91 assert(rc
== MEMCACHED_SUCCESS
);
94 void delete_test(memcached_st
*memc
)
98 char *value
= "when we sanitize";
100 rc
= memcached_set(memc
, key
, strlen(key
),
101 value
, strlen(value
),
102 (time_t)0, (uint16_t)0);
103 assert(rc
== MEMCACHED_SUCCESS
);
105 rc
= memcached_delete(memc
, key
, strlen(key
), (time_t)0);
106 assert(rc
== MEMCACHED_SUCCESS
);
109 void flush_test(memcached_st
*memc
)
113 rc
= memcached_flush(memc
, 0);
114 assert(rc
== MEMCACHED_SUCCESS
);
117 void get_test(memcached_st
*memc
)
122 size_t string_length
;
125 string
= memcached_get(memc
, key
, strlen(key
),
126 &string_length
, &flags
, &rc
);
128 assert(rc
== MEMCACHED_NOTFOUND
);
129 assert(string_length
== 0);
133 void get_test2(memcached_st
*memc
)
137 char *value
= "when we sanitize";
139 size_t string_length
;
142 rc
= memcached_set(memc
, key
, strlen(key
),
143 value
, strlen(value
),
144 (time_t)0, (uint16_t)0);
145 assert(rc
== MEMCACHED_SUCCESS
);
147 string
= memcached_get(memc
, key
, strlen(key
),
148 &string_length
, &flags
, &rc
);
151 assert(rc
== MEMCACHED_SUCCESS
);
152 assert(string_length
== strlen(value
));
153 assert(!memcmp(string
, value
, string_length
));
158 void set_test2(memcached_st
*memc
)
162 char *value
= "train in the brain";
163 size_t value_length
= strlen(value
);
166 for (x
= 0; x
< 10; x
++)
168 rc
= memcached_set(memc
, key
, strlen(key
),
170 (time_t)0, (uint16_t)0);
171 assert(rc
== MEMCACHED_SUCCESS
);
175 void set_test3(memcached_st
*memc
)
180 size_t value_length
= 8191;
183 value
= (char*)malloc(value_length
);
186 for (x
= 0; x
< value_length
; x
++)
187 value
[x
] = (char) (x
% 127);
189 for (x
= 0; x
< 1; x
++)
191 rc
= memcached_set(memc
, key
, strlen(key
),
193 (time_t)0, (uint16_t)0);
194 assert(rc
== MEMCACHED_SUCCESS
);
200 void get_test3(memcached_st
*memc
)
205 size_t value_length
= 8191;
207 size_t string_length
;
211 value
= (char*)malloc(value_length
);
214 for (x
= 0; x
< value_length
; x
++)
215 value
[x
] = (char) (x
% 127);
217 rc
= memcached_set(memc
, key
, strlen(key
),
219 (time_t)0, (uint16_t)0);
220 assert(rc
== MEMCACHED_SUCCESS
);
222 string
= memcached_get(memc
, key
, strlen(key
),
223 &string_length
, &flags
, &rc
);
225 assert(rc
== MEMCACHED_SUCCESS
);
227 assert(string_length
== value_length
);
228 assert(!memcmp(string
, value
, string_length
));
234 void get_test4(memcached_st
*memc
)
239 size_t value_length
= 8191;
241 size_t string_length
;
245 value
= (char*)malloc(value_length
);
248 for (x
= 0; x
< value_length
; x
++)
249 value
[x
] = (char) (x
% 127);
251 rc
= memcached_set(memc
, key
, strlen(key
),
253 (time_t)0, (uint16_t)0);
254 assert(rc
== MEMCACHED_SUCCESS
);
256 for (x
= 0; x
< 10; x
++)
258 string
= memcached_get(memc
, key
, strlen(key
),
259 &string_length
, &flags
, &rc
);
261 assert(rc
== MEMCACHED_SUCCESS
);
263 assert(string_length
== value_length
);
264 assert(!memcmp(string
, value
, string_length
));
271 void stats_servername_test(memcached_st
*memc
)
274 memcached_stat_st stat
;
275 rc
= memcached_stat_servername(&stat
, NULL
,
277 MEMCACHED_DEFAULT_PORT
);
280 void increment_test(memcached_st
*memc
)
282 unsigned int new_number
;
287 rc
= memcached_set(memc
, key
, strlen(key
),
288 value
, strlen(value
),
289 (time_t)0, (uint16_t)0);
290 assert(rc
== MEMCACHED_SUCCESS
);
292 rc
= memcached_increment(memc
, key
, strlen(key
),
294 assert(rc
== MEMCACHED_SUCCESS
);
295 assert(new_number
== 1);
297 rc
= memcached_increment(memc
, key
, strlen(key
),
299 assert(rc
== MEMCACHED_SUCCESS
);
300 assert(new_number
== 2);
303 void decrement_test(memcached_st
*memc
)
305 unsigned int new_number
;
310 rc
= memcached_set(memc
, key
, strlen(key
),
311 value
, strlen(value
),
312 (time_t)0, (uint16_t)0);
313 assert(rc
== MEMCACHED_SUCCESS
);
315 rc
= memcached_decrement(memc
, key
, strlen(key
),
317 assert(rc
== MEMCACHED_SUCCESS
);
318 assert(new_number
== 2);
320 rc
= memcached_decrement(memc
, key
, strlen(key
),
322 assert(rc
== MEMCACHED_SUCCESS
);
323 assert(new_number
== 1);
326 void quit_test(memcached_st
*memc
)
330 char *value
= "sanford and sun";
332 rc
= memcached_set(memc
, key
, strlen(key
),
333 value
, strlen(value
),
334 (time_t)10, (uint16_t)3);
335 assert(rc
== MEMCACHED_SUCCESS
);
336 memcached_quit(memc
);
338 rc
= memcached_set(memc
, key
, strlen(key
),
339 value
, strlen(value
),
340 (time_t)50, (uint16_t)9);
341 assert(rc
== MEMCACHED_SUCCESS
);
344 void mget_test(memcached_st
*memc
)
347 char *keys
[]= {"fudge", "son", "food"};
348 size_t key_length
[]= {5, 3, 4};
352 char return_key
[MEMCACHED_MAX_KEY
];
353 size_t return_key_length
;
355 size_t return_value_length
;
357 /* We need to empty the server before continueing test */
358 rc
= memcached_flush(memc
, 0);
359 assert(rc
== MEMCACHED_SUCCESS
);
361 rc
= memcached_mget(memc
, keys
, key_length
, 3);
362 assert(rc
== MEMCACHED_SUCCESS
);
364 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
365 &return_value_length
, &flags
, &rc
)) != NULL
)
367 assert(return_value
);
369 assert(!return_value
);
370 assert(return_value_length
== 0);
371 assert(rc
== MEMCACHED_NOTFOUND
);
373 for (x
= 0; x
< 3; x
++)
375 rc
= memcached_set(memc
, keys
[x
], key_length
[x
],
376 keys
[x
], key_length
[x
],
377 (time_t)50, (uint16_t)9);
378 assert(rc
== MEMCACHED_SUCCESS
);
381 rc
= memcached_mget(memc
, keys
, key_length
, 3);
382 assert(rc
== MEMCACHED_SUCCESS
);
385 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
386 &return_value_length
, &flags
, &rc
)))
388 assert(return_value
);
389 assert(rc
== MEMCACHED_SUCCESS
);
390 assert(return_key_length
== return_value_length
);
391 assert(!memcmp(return_value
, return_key
, return_value_length
));
397 void get_stats_keys(memcached_st
*memc
)
401 memcached_stat_st stat
;
404 list
= memcached_stat_get_keys(memc
, &stat
, &rc
);
405 assert(rc
== MEMCACHED_SUCCESS
);
406 for (ptr
= list
; *ptr
; ptr
++)
407 printf("Found key %s\n", *ptr
);
413 void get_stats(memcached_st
*memc
)
419 memcached_stat_st
*stat
;
421 stat
= memcached_stat(memc
, NULL
, &rc
);
422 assert(rc
== MEMCACHED_SUCCESS
);
424 assert(rc
== MEMCACHED_SUCCESS
);
427 for (x
= 0; x
< memcached_server_count(memc
); x
++)
429 list
= memcached_stat_get_keys(memc
, &stat
[x
], &rc
);
430 assert(rc
== MEMCACHED_SUCCESS
);
431 for (ptr
= list
; *ptr
; ptr
++)
432 printf("Found key %s\n", *ptr
);
440 void add_host_test(memcached_st
*memc
)
443 memcached_server_st
*servers
;
445 char servername
[]= "0.example.com";
447 servers
= memcached_server_list_append(NULL
, servername
, 400, &rc
);
449 assert(1 == memcached_server_list_count(servers
));
451 for (x
= 2; x
< 20; x
++)
453 char buffer
[SMALL_STRING_LEN
];
455 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
456 servers
= memcached_server_list_append(servers
, buffer
, 401,
458 assert(rc
== MEMCACHED_SUCCESS
);
459 assert(x
== memcached_server_list_count(servers
));
462 rc
= memcached_server_push(memc
, servers
);
463 assert(rc
== MEMCACHED_SUCCESS
);
464 rc
= memcached_server_push(memc
, servers
);
465 assert(rc
== MEMCACHED_SUCCESS
);
467 memcached_server_list_free(servers
);
470 /* We don't test the behavior itself, we test the switches */
471 void behavior_test(memcached_st
*memc
)
473 unsigned long long value
;
476 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, &set
);
477 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
480 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, &set
);
481 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
484 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_MD5_HASHING
, &set
);
485 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_MD5_HASHING
);
490 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, &set
);
491 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
);
494 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, &set
);
495 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
);
498 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_MD5_HASHING
, &set
);
499 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_MD5_HASHING
);
502 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
505 value
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
509 /* Test case provided by Cal Haldenbrand */
510 void user_supplied_bug1(memcached_st
*memc
)
512 unsigned int setter
= 1;
515 unsigned long long total
= 0;
518 char randomstuff
[6 * 1024];
521 memset(randomstuff
, 0, 6 * 1024);
523 /* We just keep looking at the same values over and over */
526 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, &setter
);
527 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, &setter
);
531 for (x
= 0 ; total
< 20 * 1024576 ; x
++ )
535 size
= (rand() % ( 5 * 1024 ) ) + 400;
536 memset(randomstuff
, 0, 6 * 1024);
537 assert(size
< 6 * 1024); /* Being safe here */
539 for (j
= 0 ; j
< size
;j
++)
540 randomstuff
[j
] = (char) (rand() % 26) + 97;
543 sprintf(key
, "%d", x
);
544 rc
= memcached_set(memc
, key
, strlen(key
),
545 randomstuff
, strlen(randomstuff
), 10, 0);
546 /* If we fail, lets try again */
547 if (rc
!= MEMCACHED_SUCCESS
)
548 rc
= memcached_set(memc
, key
, strlen(key
),
549 randomstuff
, strlen(randomstuff
), 10, 0);
550 assert(rc
== MEMCACHED_SUCCESS
);
554 /* Test case provided by Cal Haldenbrand */
555 void user_supplied_bug2(memcached_st
*memc
)
560 unsigned long long total
;
563 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, &setter
);
564 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, &setter
);
566 setter
= 20 * 1024576;
567 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, &setter
);
568 setter
= 20 * 1024576;
569 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, &setter
);
570 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
571 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
574 for (x
= 0, errors
= 0, total
= 0 ; total
< 20 * 1024576 ; x
++)
576 memcached_return rc
= MEMCACHED_SUCCESS
;
577 char buffer
[SMALL_STRING_LEN
];
582 memset(buffer
, 0, SMALL_STRING_LEN
);
584 snprintf(buffer
, SMALL_STRING_LEN
, "%u", x
);
585 getval
= memcached_get(memc
, buffer
, strlen(buffer
),
586 &val_len
, &flags
, &rc
);
587 if (rc
!= MEMCACHED_SUCCESS
)
589 if (rc
== MEMCACHED_NOTFOUND
)
602 #define KEY_COUNT 2000 // * 1024576
603 void user_supplied_bug3(memcached_st
*memc
)
609 size_t key_lengths
[KEY_COUNT
];
612 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, &setter
);
613 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, &setter
);
615 setter
= 20 * 1024576;
616 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, &setter
);
617 setter
= 20 * 1024576;
618 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, &setter
);
619 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
620 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
623 keys
= (char **)malloc(sizeof(char *) * KEY_COUNT
);
625 memset(keys
, 0, (sizeof(char *) * KEY_COUNT
));
626 for (x
= 0; x
< KEY_COUNT
; x
++)
630 snprintf(buffer
, 30, "%u", x
);
631 keys
[x
]= strdup(buffer
);
632 key_lengths
[x
]= strlen(keys
[x
]);
635 rc
= memcached_mget(memc
, keys
, key_lengths
, KEY_COUNT
);
636 assert(rc
== MEMCACHED_SUCCESS
);
638 /* Turn this into a help function */
641 size_t return_key_length
;
643 size_t return_value_length
;
646 while ((return_value
= memcached_fetch(memc
, return_key
, &return_key_length
,
647 &return_value_length
, &flags
, &rc
)))
649 assert(return_value
);
650 assert(rc
== MEMCACHED_SUCCESS
);
655 for (x
= 0; x
< KEY_COUNT
; x
++)
660 void string_alloc_null(memcached_st
*memc
)
662 memcached_string_st
*string
;
664 string
= memcached_string_create(memc
, 0);
666 memcached_string_free(memc
, string
);
669 void string_alloc_with_size(memcached_st
*memc
)
671 memcached_string_st
*string
;
673 string
= memcached_string_create(memc
, 1024);
675 memcached_string_free(memc
, string
);
678 void string_alloc_with_size_toobig(memcached_st
*memc
)
680 memcached_string_st
*string
;
682 string
= memcached_string_create(memc
, 1024*100000000000);
683 assert(string
== NULL
);
686 void string_alloc_append(memcached_st
*memc
)
689 char buffer
[SMALL_STRING_LEN
];
690 memcached_string_st
*string
;
693 memset(buffer
, 6, SMALL_STRING_LEN
);
695 string
= memcached_string_create(memc
, 100);
698 for (x
= 0; x
< 1024; x
++)
701 rc
= memcached_string_append(memc
, string
, buffer
, SMALL_STRING_LEN
);
702 assert(rc
== MEMCACHED_SUCCESS
);
704 memcached_string_free(memc
, string
);
707 void string_alloc_append_toobig(memcached_st
*memc
)
711 char buffer
[SMALL_STRING_LEN
];
712 memcached_string_st
*string
;
715 memset(buffer
, 6, SMALL_STRING_LEN
);
717 string
= memcached_string_create(memc
, 100);
720 for (x
= 0; x
< 1024; x
++)
722 rc
= memcached_string_append(memc
, string
, buffer
, SMALL_STRING_LEN
);
723 assert(rc
== MEMCACHED_SUCCESS
);
725 rc
= memcached_string_append(memc
, string
, buffer
, 1024*100000000000);
726 assert(rc
== MEMCACHED_MEMORY_ALLOCATION_FAILURE
);
727 memcached_string_free(memc
, string
);
730 void add_host_test1(memcached_st
*memc
)
734 char servername
[]= "0.example.com";
735 memcached_server_st
*servers
;
737 servers
= memcached_server_list_append(NULL
, servername
, 400, &rc
);
739 assert(1 == memcached_server_list_count(servers
));
741 for (x
= 2; x
< 20; x
++)
743 char buffer
[SMALL_STRING_LEN
];
745 snprintf(buffer
, SMALL_STRING_LEN
, "%u.example.com", 400+x
);
746 servers
= memcached_server_list_append(servers
, buffer
, 401,
748 assert(rc
== MEMCACHED_SUCCESS
);
749 assert(x
== memcached_server_list_count(servers
));
752 rc
= memcached_server_push(memc
, servers
);
753 assert(rc
== MEMCACHED_SUCCESS
);
754 rc
= memcached_server_push(memc
, servers
);
755 assert(rc
== MEMCACHED_SUCCESS
);
757 memcached_server_list_free(servers
);
760 typedef struct test_st test_st
;
764 unsigned int requires_flush
;
765 void (*function
)(memcached_st
*memc
);
768 int main(int argc
, char *argv
[])
772 char *test_to_run
= NULL
;
773 char *wildcard
= NULL
;
774 memcached_server_st
*servers
;
777 test_to_run
= argv
[1];
782 if (!(server_list
= getenv("MEMCACHED_SERVERS")))
783 server_list
= "localhost";
785 printf("servers %s\n", server_list
);
788 servers
= memcached_servers_parse(server_list
);
791 for (x
= 0; x
< memcached_server_list_count(servers
); x
++)
793 printf("\t%s : %u\n", servers
[x
].hostname
, servers
[x
].port
);
794 assert(servers
[x
].stack_responses
== 0);
795 assert(servers
[x
].fd
== -1);
796 assert(servers
[x
].cursor_active
== 0);
801 /* Clean the server before beginning testing */
803 {"flush", 0, flush_test
},
804 {"init", 0, init_test
},
805 {"allocation", 0, allocation_test
},
806 {"error", 0, error_test
},
807 {"set", 0, set_test
},
808 {"set2", 0, set_test2
},
809 {"set3", 0, set_test3
},
810 {"add", 0, add_test
},
811 {"replace", 0, replace_test
},
812 {"delete", 1, delete_test
},
813 {"get", 1, get_test
},
814 {"get2", 0, get_test2
},
815 {"get3", 0, get_test3
},
816 {"get4", 0, get_test4
},
817 {"stats_servername", 0, stats_servername_test
},
818 {"increment", 0, increment_test
},
819 {"decrement", 0, decrement_test
},
820 {"quit", 0, quit_test
},
821 {"mget", 0, mget_test
},
822 {"get_stats", 0, get_stats
},
823 {"add_host_test", 0, add_host_test
},
824 {"get_stats_keys", 0, get_stats_keys
},
825 {"behavior_test", 0, get_stats_keys
},
829 test_st string_tests
[] ={
830 {"string alloc with null", 0, string_alloc_null
},
831 {"string alloc with 1K", 0, string_alloc_with_size
},
832 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig
},
833 {"string append", 0, string_alloc_append
},
834 {"string append failure (too big)", 0, string_alloc_append_toobig
},
838 test_st user_tests
[] ={
839 {"user_supplied_bug1", 0, user_supplied_bug1
},
840 {"user_supplied_bug2", 0, user_supplied_bug2
},
841 {"user_supplied_bug3", 0, user_supplied_bug3
},
845 if ((test_to_run
&& !strcmp(test_to_run
, "block")) || !test_to_run
)
847 fprintf(stderr
, "\nBlock tests\n\n");
848 for (x
= 0; tests
[x
].function_name
; x
++)
851 if (strcmp(wildcard
, tests
[x
].function_name
))
856 struct timeval start_time
, end_time
;
858 memc
= memcached_create(NULL
);
861 if (tests
[x
].requires_flush
)
862 memcached_flush(memc
, 0);
864 rc
= memcached_server_push(memc
, servers
);
865 assert(rc
== MEMCACHED_SUCCESS
);
868 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
870 assert(memc
->hosts
[loop
].stack_responses
== 0);
871 assert(memc
->hosts
[loop
].fd
== -1);
872 assert(memc
->hosts
[loop
].cursor_active
== 0);
875 fprintf(stderr
, "Testing %s", tests
[x
].function_name
);
876 gettimeofday(&start_time
, NULL
);
877 tests
[x
].function(memc
);
878 gettimeofday(&end_time
, NULL
);
879 long int load_time
= timedif(end_time
, start_time
);
880 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
883 memcached_free(memc
);
887 if ((test_to_run
&& !strcmp(test_to_run
, "nonblock")) || !test_to_run
)
889 fprintf(stderr
, "\nNonblock tests\n\n");
890 for (x
= 0; tests
[x
].function_name
; x
++)
893 if (strcmp(wildcard
, tests
[x
].function_name
))
898 struct timeval start_time
, end_time
;
900 memc
= memcached_create(NULL
);
903 if (tests
[x
].requires_flush
)
904 memcached_flush(memc
, 0);
906 rc
= memcached_server_push(memc
, servers
);
907 assert(rc
== MEMCACHED_SUCCESS
);
909 fprintf(stderr
, "Testing %s", tests
[x
].function_name
);
910 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, NULL
);
911 gettimeofday(&start_time
, NULL
);
912 tests
[x
].function(memc
);
913 gettimeofday(&end_time
, NULL
);
914 long int load_time
= timedif(end_time
, start_time
);
915 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
918 memcached_free(memc
);
922 if ((test_to_run
&& !strcmp(test_to_run
, "nodelay")) || !test_to_run
)
924 fprintf(stderr
, "\nTCP Nodelay tests\n\n");
925 for (x
= 0; tests
[x
].function_name
; x
++)
928 if (strcmp(wildcard
, tests
[x
].function_name
))
933 struct timeval start_time
, end_time
;
935 memc
= memcached_create(NULL
);
938 if (tests
[x
].requires_flush
)
939 memcached_flush(memc
, 0);
941 rc
= memcached_server_push(memc
, servers
);
942 assert(rc
== MEMCACHED_SUCCESS
);
944 fprintf(stderr
, "Testing %s", tests
[x
].function_name
);
945 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, NULL
);
946 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, NULL
);
947 gettimeofday(&start_time
, NULL
);
948 tests
[x
].function(memc
);
949 gettimeofday(&end_time
, NULL
);
950 long int load_time
= timedif(end_time
, start_time
);
951 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
954 memcached_free(memc
);
958 if ((test_to_run
&& !strcmp(test_to_run
, "md5")) || !test_to_run
)
960 fprintf(stderr
, "\nMD5 Hashing\n\n");
961 for (x
= 0; tests
[x
].function_name
; x
++)
964 if (strcmp(wildcard
, tests
[x
].function_name
))
969 struct timeval start_time
, end_time
;
971 memc
= memcached_create(NULL
);
974 if (tests
[x
].requires_flush
)
975 memcached_flush(memc
, 0);
977 rc
= memcached_server_push(memc
, servers
);
978 assert(rc
== MEMCACHED_SUCCESS
);
980 fprintf(stderr
, "Testing %s", tests
[x
].function_name
);
981 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_MD5_HASHING
, NULL
);
982 gettimeofday(&start_time
, NULL
);
983 tests
[x
].function(memc
);
984 gettimeofday(&end_time
, NULL
);
985 long int load_time
= timedif(end_time
, start_time
);
986 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
989 memcached_free(memc
);
993 if ((test_to_run
&& !strcmp(test_to_run
, "string")) || !test_to_run
)
995 fprintf(stderr
, "\nString tests (internal API)\n\n");
996 for (x
= 0; string_tests
[x
].function_name
; x
++)
999 if (strcmp(wildcard
, string_tests
[x
].function_name
))
1003 memcached_return rc
;
1004 struct timeval start_time
, end_time
;
1006 memc
= memcached_create(NULL
);
1009 if (tests
[x
].requires_flush
)
1010 memcached_flush(memc
, 0);
1012 rc
= memcached_server_push(memc
, servers
);
1013 assert(rc
== MEMCACHED_SUCCESS
);
1015 fprintf(stderr
, "Testing %s", string_tests
[x
].function_name
);
1016 gettimeofday(&start_time
, NULL
);
1017 string_tests
[x
].function(memc
);
1018 gettimeofday(&end_time
, NULL
);
1019 long int load_time
= timedif(end_time
, start_time
);
1020 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
1023 memcached_free(memc
);
1027 if ((test_to_run
&& !strcmp(test_to_run
, "user")) || !test_to_run
)
1029 fprintf(stderr
, "\nUser Supplied tests\n\n");
1030 for (x
= 0; user_tests
[x
].function_name
; x
++)
1033 if (strcmp(wildcard
, user_tests
[x
].function_name
))
1037 memcached_return rc
;
1038 struct timeval start_time
, end_time
;
1040 memc
= memcached_create(NULL
);
1043 if (tests
[x
].requires_flush
)
1044 memcached_flush(memc
, 0);
1046 rc
= memcached_server_push(memc
, servers
);
1047 assert(rc
== MEMCACHED_SUCCESS
);
1049 fprintf(stderr
, "Testing %s", user_tests
[x
].function_name
);
1050 gettimeofday(&start_time
, NULL
);
1051 user_tests
[x
].function(memc
);
1052 gettimeofday(&end_time
, NULL
);
1053 long int load_time
= timedif(end_time
, start_time
);
1054 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
1057 memcached_free(memc
);
1061 /* Clean up whatever we might have left */
1064 memc
= memcached_create(NULL
);
1067 memcached_free(memc
);
1070 fprintf(stderr
, "All tests completed successfully\n\n");
1072 memcached_server_list_free(servers
);