Merge lp:~mordred/libmemcached/fix-valgrind-race-condition into lp:~tangent-org/libmemcached/trunk

Proposed by Monty Taylor
Status: Merged
Merged at revision: 866
Proposed branch: lp:~mordred/libmemcached/fix-valgrind-race-condition
Merge into: lp:~tangent-org/libmemcached/trunk
Diff against target: 1075 lines (+295/-243)
26 files modified
ChangeLog (+3/-0)
clients/execute.c (+3/-5)
clients/execute.h (+3/-0)
clients/generator.c (+1/-1)
clients/memcat.c (+2/-1)
clients/memcp.c (+3/-2)
clients/memdump.c (+2/-1)
clients/memerror.c (+1/-1)
clients/memflush.c (+1/-1)
clients/memrm.c (+1/-1)
clients/memstat.c (+1/-1)
clients/utilities.c (+1/-1)
clients/utilities.h (+1/-0)
libmemcached/connect.c (+134/-88)
libmemcached/delete.c (+1/-1)
libmemcached/include.am (+2/-1)
libmemcached/io.c (+22/-17)
libmemcached/util/version.c (+6/-6)
libmemcached/util/version.h (+2/-2)
tests/atomsmasher.c (+5/-9)
tests/hashkit_functions.c (+2/-0)
tests/include.am (+1/-0)
tests/mem_functions.c (+89/-96)
tests/mem_udp.c (+3/-8)
tests/start.c (+2/-0)
tests/test.c (+3/-0)
To merge this branch: bzr merge lp:~mordred/libmemcached/fix-valgrind-race-condition
Reviewer Review Type Date Requested Status
Brian Aker Pending
Review via email: mp+28776@code.launchpad.net

Description of the change

Fixed the build race condition around dtrace.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2010-06-11 01:43:08 +0000
3+++ ChangeLog 2010-06-29 17:06:27 +0000
4@@ -1,6 +1,9 @@
5 0.41
6 * Added --file for memcat.
7 * Added limemcached_ping() to libmemcached_util
8+ * Bugfix for some cases where connect would have issues with timeout.
9+ * Wrong value for errno given as error on an IO failure inside of poll.
10+ * Bug fix for issue where multiple interfaces with bad DNS were not being caught.
11
12 0.40 Thu Apr 22 19:01:25 PDT 2010
13 * Placed retry logic in for busted resolvers
14
15=== modified file 'clients/execute.c'
16--- clients/execute.c 2010-01-16 01:50:37 +0000
17+++ clients/execute.c 2010-06-29 17:06:27 +0000
18@@ -14,8 +14,7 @@
19 Return the number of rows set.
20 */
21
22-#include "libmemcached/common.h"
23-
24+#include "config.h"
25 #include "execute.h"
26
27 unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of)
28@@ -108,12 +107,11 @@
29 rc= memcached_mget_execute(memc, keys, key_length,
30 (size_t)number_of, callbacks, &retrieved, 1);
31
32- likely (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND ||
33+ if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND ||
34 rc == MEMCACHED_BUFFERED || rc == MEMCACHED_END)
35 {
36 rc= memcached_fetch_execute(memc, callbacks, (void *)&retrieved, 1);
37- unlikely (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTFOUND &&
38- rc != MEMCACHED_END)
39+ if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTFOUND && rc != MEMCACHED_END)
40 {
41 fprintf(stderr, "Failed to execute mget: %s\n",
42 memcached_strerror(memc, rc));
43
44=== modified file 'clients/execute.h'
45--- clients/execute.h 2009-12-16 19:03:49 +0000
46+++ clients/execute.h 2010-06-29 17:06:27 +0000
47@@ -11,6 +11,9 @@
48
49 #ifndef CLIENTS_EXECUTE_H
50 #define CLIENTS_EXECUTE_H
51+
52+#include <stdio.h>
53+
54 #include "libmemcached/memcached.h"
55 #include "generator.h"
56
57
58=== modified file 'clients/generator.c'
59--- clients/generator.c 2010-04-22 00:49:09 +0000
60+++ clients/generator.c 2010-06-29 17:06:27 +0000
61@@ -9,7 +9,7 @@
62 *
63 */
64
65-#include "libmemcached/common.h"
66+#include "config.h"
67
68 #include <stdio.h>
69 #include <stdlib.h>
70
71=== modified file 'clients/memcat.c'
72--- clients/memcat.c 2010-06-08 19:05:16 +0000
73+++ clients/memcat.c 2010-06-29 17:06:27 +0000
74@@ -9,7 +9,8 @@
75 *
76 */
77
78-#include "libmemcached/common.h"
79+#include "config.h"
80+
81 #include <stdio.h>
82 #include <inttypes.h>
83 #include <string.h>
84
85=== modified file 'clients/memcp.c'
86--- clients/memcp.c 2010-03-03 10:50:13 +0000
87+++ clients/memcp.c 2010-06-29 17:06:27 +0000
88@@ -9,7 +9,8 @@
89 *
90 */
91
92-#include "libmemcached/common.h"
93+#include "config.h"
94+
95 #include <stdio.h>
96 #include <stdlib.h>
97 #include <inttypes.h>
98@@ -54,7 +55,7 @@
99
100 /* Check for various possible errors */
101
102- if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
103+ if ((errno == ERANGE && (val == INTMAX_MAX || val == INTMAX_MIN))
104 || (errno != 0 && val == 0))
105 {
106 *error= true;
107
108=== modified file 'clients/memdump.c'
109--- clients/memdump.c 2010-03-03 10:50:13 +0000
110+++ clients/memdump.c 2010-06-29 17:06:27 +0000
111@@ -9,7 +9,8 @@
112 *
113 */
114
115-#include "libmemcached/common.h"
116+#include "config.h"
117+
118 #include <stdio.h>
119 #include <stdlib.h>
120 #include <inttypes.h>
121
122=== modified file 'clients/memerror.c'
123--- clients/memerror.c 2010-01-14 21:37:53 +0000
124+++ clients/memerror.c 2010-06-29 17:06:27 +0000
125@@ -8,8 +8,8 @@
126 * Summary:
127 *
128 */
129+#include "config.h"
130
131-#include "libmemcached/common.h"
132 #include <stdio.h>
133 #include <inttypes.h>
134 #include <string.h>
135
136=== modified file 'clients/memflush.c'
137--- clients/memflush.c 2010-03-03 10:50:13 +0000
138+++ clients/memflush.c 2010-06-29 17:06:27 +0000
139@@ -8,8 +8,8 @@
140 * Summary:
141 *
142 */
143+#include "config.h"
144
145-#include "libmemcached/common.h"
146 #include <stdio.h>
147 #include <unistd.h>
148 #include <string.h>
149
150=== modified file 'clients/memrm.c'
151--- clients/memrm.c 2010-03-03 10:50:13 +0000
152+++ clients/memrm.c 2010-06-29 17:06:27 +0000
153@@ -8,8 +8,8 @@
154 * Summary:
155 *
156 */
157+#include "config.h"
158
159-#include "libmemcached/common.h"
160 #include <stdio.h>
161 #include <unistd.h>
162 #include <getopt.h>
163
164=== modified file 'clients/memstat.c'
165--- clients/memstat.c 2010-03-10 00:45:36 +0000
166+++ clients/memstat.c 2010-06-29 17:06:27 +0000
167@@ -11,8 +11,8 @@
168 * Brian Aker
169 * Toru Maesaka
170 */
171+#include "config.h"
172
173-#include "libmemcached/common.h"
174 #include <stdio.h>
175 #include <sys/types.h>
176 #include <sys/stat.h>
177
178=== modified file 'clients/utilities.c'
179--- clients/utilities.c 2010-05-24 09:08:06 +0000
180+++ clients/utilities.c 2010-06-29 17:06:27 +0000
181@@ -8,8 +8,8 @@
182 * Summary:
183 *
184 */
185+#include "config.h"
186
187-#include "libmemcached/common.h"
188 #include <stdio.h>
189 #include <ctype.h>
190 #include <string.h>
191
192=== modified file 'clients/utilities.h'
193--- clients/utilities.h 2010-03-03 10:50:13 +0000
194+++ clients/utilities.h 2010-06-29 17:06:27 +0000
195@@ -11,6 +11,7 @@
196
197 #include <getopt.h>
198 #include <libmemcached/memcached.h>
199+#include "libmemcached/watchpoint.h"
200 #include "client_options.h"
201
202 #if TIME_WITH_SYS_TIME
203
204=== modified file 'libmemcached/connect.c'
205--- libmemcached/connect.c 2010-06-13 21:04:20 +0000
206+++ libmemcached/connect.c 2010-06-29 17:06:27 +0000
207@@ -1,9 +1,96 @@
208+/* LibMemcached
209+ * Copyright (C) 2006-2010 Brian Aker
210+ * All rights reserved.
211+ *
212+ * Use and distribution licensed under the BSD license. See
213+ * the COPYING file in the parent directory for full text.
214+ *
215+ * Summary: Server IO, Not public!
216+ *
217+ */
218+
219 #include "common.h"
220 #include <netdb.h>
221 #include <poll.h>
222 #include <sys/time.h>
223 #include <time.h>
224
225+static memcached_return_t connect_poll(memcached_server_st *ptr)
226+{
227+ struct pollfd fds[1];
228+ fds[0].fd = ptr->fd;
229+ fds[0].events = POLLOUT;
230+
231+ int timeout= ptr->root->connect_timeout;
232+ if (ptr->root->flags.no_block == true)
233+ timeout= -1;
234+
235+ int error;
236+ size_t loop_max= 5;
237+
238+ while (--loop_max) // Should only loop on cases of ERESTART or EINTR
239+ {
240+ error= poll(fds, 1, timeout);
241+
242+ switch (error)
243+ {
244+ case 1:
245+ {
246+ int err;
247+ socklen_t len= sizeof (err);
248+ (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
249+
250+ // We check the value to see what happened wth the socket.
251+ if (err == 0)
252+ {
253+ return MEMCACHED_SUCCESS;
254+ }
255+ else
256+ {
257+ ptr->cached_errno= errno;
258+
259+ return MEMCACHED_ERRNO;
260+ }
261+ }
262+ case 0:
263+ return MEMCACHED_TIMEOUT;
264+ default: // A real error occurred and we need to completely bail
265+ WATCHPOINT_ERRNO(errno);
266+ switch (errno)
267+ {
268+#ifdef TARGET_OS_LINUX
269+ case ERESTART:
270+#endif
271+ case EINTR:
272+ continue;
273+ default:
274+ if (fds[0].revents & POLLERR)
275+ {
276+ int err;
277+ socklen_t len= sizeof (err);
278+ (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
279+ ptr->cached_errno= (err == 0) ? errno : err;
280+ }
281+ else
282+ {
283+ ptr->cached_errno= errno;
284+ }
285+
286+ (void)close(ptr->fd);
287+ ptr->fd= -1;
288+
289+ return MEMCACHED_ERRNO;
290+ }
291+ }
292+ WATCHPOINT_ASSERT(0); // Programming error
293+ }
294+
295+ // This should only be possible from ERESTART or EINTR;
296+ ptr->cached_errno= errno;
297+
298+ return MEMCACHED_ERRNO;
299+}
300+
301 static memcached_return_t set_hostinfo(memcached_server_st *server)
302 {
303 struct addrinfo *ai;
304@@ -265,6 +352,8 @@
305
306 static memcached_return_t network_connect(memcached_server_st *ptr)
307 {
308+ bool timeout_error_occured= false;
309+
310 if (ptr->fd == -1)
311 {
312 struct addrinfo *use;
313@@ -305,93 +394,39 @@
314 (void)set_socket_options(ptr);
315
316 /* connect to server */
317- if ((connect(ptr->fd, use->ai_addr, use->ai_addrlen) == -1))
318- {
319- ptr->cached_errno= errno;
320- if (errno == EINPROGRESS || /* nonblocking mode - first return, */
321- errno == EALREADY) /* nonblocking mode - subsequent returns */
322- {
323- struct pollfd fds[1];
324- fds[0].fd = ptr->fd;
325- fds[0].events = POLLOUT;
326-
327- int timeout= ptr->root->connect_timeout;
328- if (ptr->root->flags.no_block == true)
329- timeout= -1;
330-
331- size_t loop_max= 5;
332- while (--loop_max)
333- {
334- int error= poll(fds, 1, timeout);
335-
336- switch (error)
337- {
338- case 1:
339- loop_max= 1;
340- break;
341- case 0:
342- if (loop_max==1)
343- return MEMCACHED_TIMEOUT;
344- continue;
345- // A real error occurred and we need to completely bail
346- default:
347- WATCHPOINT_ERRNO(errno);
348- switch (errno)
349- {
350-#ifdef TARGET_OS_LINUX
351- case ERESTART:
352-#endif
353- case EINTR:
354- continue;
355- default:
356- if (fds[0].revents & POLLERR)
357- {
358- int err;
359- socklen_t len= sizeof (err);
360- (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
361- ptr->cached_errno= (err == 0) ? errno : err;
362- }
363-
364- (void)close(ptr->fd);
365- ptr->fd= -1;
366-
367- break;
368- }
369- }
370- }
371- }
372- else if (errno == EISCONN) /* we are connected :-) */
373- {
374- break;
375- }
376- else if (errno != EINTR)
377- {
378- (void)close(ptr->fd);
379- ptr->fd= -1;
380- break;
381- }
382- }
383-
384-#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
385- if (ptr->fd != -1 && ptr->root->sasl && ptr->root->sasl->callbacks)
386- {
387- memcached_return rc= memcached_sasl_authenticate_connection(ptr);
388- if (rc != MEMCACHED_SUCCESS)
389- {
390- (void)close(ptr->fd);
391- ptr->fd= -1;
392-
393- return rc;
394- }
395- }
396-#endif
397-
398-
399- if (ptr->fd != -1)
400- {
401- return MEMCACHED_SUCCESS;
402- }
403- use = use->ai_next;
404+ if ((connect(ptr->fd, use->ai_addr, use->ai_addrlen) > -1))
405+ {
406+ break; // Success
407+ }
408+
409+ /* An error occurred */
410+ ptr->cached_errno= errno;
411+ if (errno == EINPROGRESS || /* nonblocking mode - first return, */
412+ errno == EALREADY) /* nonblocking mode - subsequent returns */
413+ {
414+ memcached_return_t rc;
415+ rc= connect_poll(ptr);
416+
417+ if (rc == MEMCACHED_TIMEOUT)
418+ timeout_error_occured= true;
419+
420+ if (rc == MEMCACHED_SUCCESS)
421+ break;
422+ }
423+ else if (errno == EISCONN) /* we are connected :-) */
424+ {
425+ break;
426+ }
427+ else if (errno == EINTR) // Special case, we retry ai_addr
428+ {
429+ (void)close(ptr->fd);
430+ ptr->fd= -1;
431+ continue;
432+ }
433+
434+ (void)close(ptr->fd);
435+ ptr->fd= -1;
436+ use= use->ai_next;
437 }
438 }
439
440@@ -408,7 +443,7 @@
441 ptr->next_retry= next_time.tv_sec + ptr->root->retry_timeout;
442 }
443
444- if (ptr->cached_errno == 0)
445+ if (timeout_error_occured)
446 return MEMCACHED_TIMEOUT;
447
448 return MEMCACHED_ERRNO; /* The last error should be from connect() */
449@@ -481,6 +516,17 @@
450 case MEMCACHED_CONNECTION_UDP:
451 case MEMCACHED_CONNECTION_TCP:
452 rc= network_connect(ptr);
453+#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
454+ if (ptr->fd != -1 && ptr->root->sasl && ptr->root->sasl->callbacks)
455+ {
456+ rc= memcached_sasl_authenticate_connection(ptr);
457+ if (rc != MEMCACHED_SUCCESS)
458+ {
459+ (void)close(ptr->fd);
460+ ptr->fd= -1;
461+ }
462+ }
463+#endif
464 break;
465 case MEMCACHED_CONNECTION_UNIX_SOCKET:
466 rc= unix_socket_connect(ptr);
467
468=== modified file 'libmemcached/delete.c'
469--- libmemcached/delete.c 2010-04-02 19:55:21 +0000
470+++ libmemcached/delete.c 2010-06-29 17:06:27 +0000
471@@ -45,7 +45,7 @@
472
473 if (ptr->flags.binary_protocol)
474 {
475- likely (!expiration)
476+ likely (! expiration)
477 {
478 rc= binary_delete(ptr, server_key, key, key_length, to_write);
479 }
480
481=== modified file 'libmemcached/include.am'
482--- libmemcached/include.am 2010-06-15 06:31:25 +0000
483+++ libmemcached/include.am 2010-06-29 17:06:27 +0000
484@@ -158,6 +158,7 @@
485 if DTRACE_NEEDS_OBJECTS
486 libmemcached_libmemcached_la_SOURCES += libmemcached/libmemcached_probes.d
487 libmemcached_libmemcached_la_DEPENDENCIES += libmemcached/libmemcached_probes.o
488+CLEANFILES+= libmemcached/libmemcached_probes.o
489 endif
490
491 SUFFIXES+= .d
492@@ -165,7 +166,7 @@
493 libmemcached/dtrace_probes.h: libmemcached/libmemcached_probes.d
494 $(DTRACE) $(DTRACEFLAGS) -h -o libmemcached/dtrace_probes.h -s ${top_srcdir}/libmemcached/libmemcached_probes.d
495
496-libmemcached/libmemcached_probes.o: libmemcached/libmemcached_probes.d ${libmemcached_libmemcached_OBJECTS} config.h
497+libmemcached/libmemcached_probes.o: libmemcached/libmemcached_probes.d ${libmemcached_libmemcached_la_OBJECTS} config.h
498
499 .d.o:
500 $(DTRACE) $(DTRACEFLAGS) -o libmemcached/libmemcached_probes.o -G -s ${top_srcdir}/libmemcached/libmemcached_probes.d `grep '^pic_object' ${top_builddir}/libmemcached/*.lo | cut -f 2 -d\' | sed "s/^/${top_builddir}\//"`
501
502=== modified file 'libmemcached/io.c'
503--- libmemcached/io.c 2010-04-22 22:51:37 +0000
504+++ libmemcached/io.c 2010-06-29 17:06:27 +0000
505@@ -62,45 +62,50 @@
506 timeout= -1;
507
508 size_t loop_max= 5;
509- while (--loop_max)
510+ while (--loop_max) // While loop is for ERESTART or EINTR
511 {
512 error= poll(&fds, 1, timeout);
513
514 switch (error)
515 {
516- case 1:
517+ case 1: // Success!
518 WATCHPOINT_IF_LABELED_NUMBER(read_or_write && loop_max < 4, "read() times we had to loop, decremented down from 5", loop_max);
519 WATCHPOINT_IF_LABELED_NUMBER(!read_or_write && loop_max < 4, "write() times we had to loop, decremented down from 5", loop_max);
520
521 return MEMCACHED_SUCCESS;
522- case 0:
523+ case 0: // Timeout occured, we let the while() loop do its thing.
524 return MEMCACHED_TIMEOUT;
525 default:
526 WATCHPOINT_ERRNO(errno);
527+ switch (errno)
528 {
529- switch (errno)
530- {
531 #ifdef TARGET_OS_LINUX
532- case ERESTART:
533+ case ERESTART:
534 #endif
535- case EINTR:
536- continue;
537- default:
538- ptr->cached_errno= error;
539- memcached_quit_server(ptr, true);
540+ case EINTR:
541+ break;
542+ default:
543+ if (fds.revents & POLLERR)
544+ {
545+ int err;
546+ socklen_t len= sizeof (err);
547+ (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
548+ ptr->cached_errno= (err == 0) ? errno : err;
549+ }
550+ else
551+ {
552+ ptr->cached_errno= errno;
553+ }
554+ memcached_quit_server(ptr, true);
555
556- return MEMCACHED_FAILURE;
557- }
558+ return MEMCACHED_FAILURE;
559 }
560 }
561 }
562
563- if (loop_max == 0 && error == 0)
564- return MEMCACHED_TIMEOUT;
565-
566 /* Imposssible for anything other then -1 */
567 WATCHPOINT_ASSERT(error == -1);
568- ptr->cached_errno= error;
569+ ptr->cached_errno= errno;
570 memcached_quit_server(ptr, true);
571
572 return MEMCACHED_FAILURE;
573
574=== modified file 'libmemcached/util/version.c'
575--- libmemcached/util/version.c 2010-06-15 06:31:25 +0000
576+++ libmemcached/util/version.c 2010-06-29 17:06:27 +0000
577@@ -16,8 +16,8 @@
578 struct local_context
579 {
580 uint8_t major_version;
581+ uint8_t minor_version;
582 uint8_t micro_version;
583- uint8_t minor_version;
584
585 bool truth;
586 };
587@@ -30,8 +30,8 @@
588 struct local_context *check= (struct local_context *)context;
589
590 if (instance->major_version >= check->major_version &&
591- instance->micro_version >= check->micro_version &&
592- instance->minor_version >= check->minor_version)
593+ instance->minor_version >= check->minor_version &&
594+ instance->micro_version >= check->micro_version )
595 {
596 return MEMCACHED_SUCCESS;
597 }
598@@ -43,13 +43,13 @@
599
600 bool libmemcached_util_version_check(memcached_st *memc,
601 uint8_t major_version,
602- uint8_t micro_version,
603- uint8_t minor_version)
604+ uint8_t minor_version,
605+ uint8_t micro_version)
606 {
607 memcached_server_fn callbacks[1];
608 memcached_version(memc);
609
610- struct local_context check= { .major_version= major_version, .micro_version= micro_version, .minor_version= minor_version, .truth= true };
611+ struct local_context check= { .major_version= major_version, .minor_version= minor_version, .micro_version= micro_version, .truth= true };
612
613 callbacks[0]= check_server_version;
614 memcached_server_cursor(memc, callbacks, (void *)&check, 1);
615
616=== modified file 'libmemcached/util/version.h'
617--- libmemcached/util/version.h 2010-06-15 06:31:25 +0000
618+++ libmemcached/util/version.h 2010-06-29 17:06:27 +0000
619@@ -19,8 +19,8 @@
620 LIBMEMCACHED_API
621 bool libmemcached_util_version_check(memcached_st *memc,
622 uint8_t major_version,
623- uint8_t micro_version,
624- uint8_t minor_version);
625+ uint8_t minor_version,
626+ uint8_t micro_version);
627
628 #ifdef __cplusplus
629 }
630
631=== modified file 'tests/atomsmasher.c'
632--- tests/atomsmasher.c 2010-01-15 21:49:15 +0000
633+++ tests/atomsmasher.c 2010-06-29 17:06:27 +0000
634@@ -12,10 +12,14 @@
635 /*
636 Sample test application.
637 */
638-#include "libmemcached/common.h"
639+#include "config.h"
640+
641+#include "libmemcached/memcached.h"
642+#include "libmemcached/watchpoint.h"
643
644 #include <stdio.h>
645 #include <stdlib.h>
646+#include <stdint.h>
647 #include <string.h>
648 #include <sys/time.h>
649 #include <sys/types.h>
650@@ -26,14 +30,6 @@
651 #include "../clients/generator.h"
652 #include "../clients/execute.h"
653
654-#ifndef INT64_MAX
655-#define INT64_MAX LONG_MAX
656-#endif
657-#ifndef INT32_MAX
658-#define INT32_MAX INT_MAX
659-#endif
660-
661-
662 #include "test.h"
663
664 /* Number of items generated for tests */
665
666=== modified file 'tests/hashkit_functions.c'
667--- tests/hashkit_functions.c 2010-04-11 17:56:46 +0000
668+++ tests/hashkit_functions.c 2010-06-29 17:06:27 +0000
669@@ -6,6 +6,8 @@
670 * the COPYING file in the parent directory for full text.
671 */
672
673+#include "config.h"
674+
675 #include <assert.h>
676 #include <stdio.h>
677 #include <stdlib.h>
678
679=== modified file 'tests/include.am'
680--- tests/include.am 2010-06-13 16:43:30 +0000
681+++ tests/include.am 2010-06-29 17:06:27 +0000
682@@ -41,6 +41,7 @@
683 tests_testapp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING)
684 tests_testapp_SOURCES= tests/mem_functions.c
685 tests_testapp_DEPENDENCIES= \
686+ $(BUILT_SOURCES) \
687 clients/libgenexec.la \
688 tests/libserver.la \
689 tests/libtest.la \
690
691=== modified file 'tests/mem_functions.c'
692--- tests/mem_functions.c 2010-06-15 06:31:25 +0000
693+++ tests/mem_functions.c 2010-06-29 17:06:27 +0000
694@@ -10,10 +10,11 @@
695 Sample test application.
696 */
697
698-#include "libmemcached/common.h"
699+#include "config.h"
700
701 #include <assert.h>
702 #include <stdio.h>
703+#include <stdint.h>
704 #include <stdlib.h>
705 #include <string.h>
706 #include <sys/time.h>
707@@ -22,20 +23,18 @@
708 #include <signal.h>
709 #include <unistd.h>
710 #include <time.h>
711+
712+#include "libmemcached/common.h"
713+
714 #include "server.h"
715 #include "clients/generator.h"
716 #include "clients/execute.h"
717
718-#ifndef INT64_MAX
719-#define INT64_MAX LONG_MAX
720-#endif
721-#ifndef INT32_MAX
722-#define INT32_MAX INT_MAX
723-#endif
724-
725+#define SMALL_STRING_LEN 1024
726
727 #include "test.h"
728
729+
730 #ifdef HAVE_LIBMEMCACHEDUTIL
731 #include <pthread.h>
732 #include "libmemcached/memcached_util.h"
733@@ -682,7 +681,6 @@
734 */
735 static test_return_t add_wrapper(memcached_st *memc)
736 {
737- unsigned int x;
738 unsigned int max= 10000;
739 #ifdef __sun
740 max= 10;
741@@ -691,7 +689,7 @@
742 max= 10;
743 #endif
744
745- for (x= 0; x < max; x++)
746+ for (uint32_t x= 0; x < max; x++)
747 add_test(memc);
748
749 return TEST_SUCCESS;
750@@ -3599,7 +3597,7 @@
751 // will not toggle protocol on an connection.
752 memcached_version(memc_clone);
753
754- if (libmemcached_util_version_check(memc_clone, 1, 2, 0))
755+ if (libmemcached_util_version_check(memc_clone, 1, 3, 0))
756 {
757 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
758 rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
759@@ -3724,23 +3722,14 @@
760 static test_return_t pre_binary(memcached_st *memc)
761 {
762 memcached_return_t rc= MEMCACHED_FAILURE;
763- memcached_st *memc_clone;
764-
765- memc_clone= memcached_clone(NULL, memc);
766- test_true(memc_clone);
767- // The memcached_version needs to be done on a clone, because the server
768- // will not toggle protocol on an connection.
769- memcached_version(memc_clone);
770-
771- if (libmemcached_util_version_check(memc_clone, 1, 2, 0))
772+
773+ if (libmemcached_util_version_check(memc, 1, 3, 0))
774 {
775 rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
776 test_true(rc == MEMCACHED_SUCCESS);
777 test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1);
778 }
779
780- memcached_free(memc_clone);
781-
782 return rc == MEMCACHED_SUCCESS ? TEST_SUCCESS : TEST_SKIPPED;
783 }
784
785@@ -4432,24 +4421,24 @@
786 memcached_version(memc);
787
788 // We only use one binary when we test, so this should be just fine.
789- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version, instance->minor_version);
790- test_true(if_successful == true);
791-
792- if (instance->minor_version > 0)
793- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version, instance->minor_version -1);
794- else if (instance->micro_version > 0)
795- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version - 1, instance->minor_version);
796- else if (instance->major_version > 0)
797- if_successful= libmemcached_util_version_check(memc, instance->major_version -1, instance->micro_version, instance->minor_version);
798-
799- test_true(if_successful == true);
800-
801- if (instance->minor_version > 0)
802- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version, instance->minor_version +1);
803- else if (instance->micro_version > 0)
804- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version +1, instance->minor_version);
805- else if (instance->major_version > 0)
806- if_successful= libmemcached_util_version_check(memc, instance->major_version +1, instance->micro_version, instance->minor_version);
807+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version, instance->micro_version);
808+ test_true(if_successful == true);
809+
810+ if (instance->micro_version > 0)
811+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version, instance->micro_version -1);
812+ else if (instance->minor_version > 0)
813+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version - 1, instance->micro_version);
814+ else if (instance->major_version > 0)
815+ if_successful= libmemcached_util_version_check(memc, instance->major_version -1, instance->minor_version, instance->micro_version);
816+
817+ test_true(if_successful == true);
818+
819+ if (instance->micro_version > 0)
820+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version, instance->micro_version +1);
821+ else if (instance->minor_version > 0)
822+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version +1, instance->micro_version);
823+ else if (instance->major_version > 0)
824+ if_successful= libmemcached_util_version_check(memc, instance->major_version +1, instance->minor_version, instance->micro_version);
825
826 test_true(if_successful == false);
827
828@@ -5018,7 +5007,7 @@
829 We are testing the error condition when we connect to a server via memcached_get()
830 but find that the server is not available.
831 */
832-static test_return_t memcached_get_MEMCACHED_SOME_ERRORS(memcached_st *memc)
833+static test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *memc)
834 {
835 (void)memc;
836 memcached_st *tl_memc_h;
837@@ -5032,7 +5021,7 @@
838
839 // Create a handle.
840 tl_memc_h= memcached_create(NULL);
841- servers= memcached_servers_parse("localhost:9898"); // This server should not exist
842+ servers= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
843 memcached_server_push(tl_memc_h, servers);
844 memcached_server_list_free(servers);
845
846@@ -5046,7 +5035,7 @@
847 }
848
849 test_true(len == 0);
850- test_true(rc == MEMCACHED_SOME_ERRORS);
851+ test_true(rc == MEMCACHED_ERRNO);
852
853 return TEST_SUCCESS;
854 }
855@@ -5083,7 +5072,7 @@
856 We are testing the error condition when we connect to a server via memcached_get_by_key()
857 but find that the server is not available.
858 */
859-static test_return_t memcached_get_by_key_MEMCACHED_SOME_ERRORS(memcached_st *memc)
860+static test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *memc)
861 {
862 (void)memc;
863 memcached_st *tl_memc_h;
864@@ -5097,7 +5086,7 @@
865
866 // Create a handle.
867 tl_memc_h= memcached_create(NULL);
868- servers= memcached_servers_parse("localhost:9898"); // This server should not exist
869+ servers= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
870 memcached_server_push(tl_memc_h, servers);
871 memcached_server_list_free(servers);
872
873@@ -5111,7 +5100,7 @@
874 }
875
876 test_true(len == 0);
877- test_true(rc == MEMCACHED_SOME_ERRORS);
878+ test_true(rc == MEMCACHED_ERRNO);
879
880 return TEST_SUCCESS;
881 }
882@@ -5575,54 +5564,58 @@
883
884 static test_return_t regression_bug_463297(memcached_st *memc)
885 {
886- memcached_st *memc_clone= memcached_clone(NULL, memc);
887- test_true(memc_clone != NULL);
888- test_true(memcached_version(memc_clone) == MEMCACHED_SUCCESS);
889-
890-
891- if (libmemcached_util_version_check(memc_clone, 1, 1, 2))
892+ memcached_st *memc_clone= memcached_clone(NULL, memc);
893+ test_true(memc_clone != NULL);
894+ test_true(memcached_version(memc_clone) == MEMCACHED_SUCCESS);
895+
896+ memcached_server_instance_st instance=
897+ memcached_server_instance_by_position(memc_clone, 0);
898+
899+ if (instance->major_version > 1 ||
900+ (instance->major_version == 1 &&
901+ instance->minor_version > 2))
902 {
903- /* Binary protocol doesn't support deferred delete */
904- memcached_st *bin_clone= memcached_clone(NULL, memc);
905- test_true(bin_clone != NULL);
906- test_true(memcached_behavior_set(bin_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1) == MEMCACHED_SUCCESS);
907- test_true(memcached_delete(bin_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
908- memcached_free(bin_clone);
909-
910- memcached_quit(memc_clone);
911-
912- /* If we know the server version, deferred delete should fail
913- * with invalid arguments */
914- test_true(memcached_delete(memc_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
915-
916- /* If we don't know the server version, we should get a protocol error */
917- memcached_return_t rc= memcached_delete(memc, "foo", 3, 1);
918-
919- /* but there is a bug in some of the memcached servers (1.4) that treats
920- * the counter as noreply so it doesn't send the proper error message
921- */
922- test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
923-
924- /* And buffered mode should be disabled and we should get protocol error */
925- test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1) == MEMCACHED_SUCCESS);
926- rc= memcached_delete(memc, "foo", 3, 1);
927- test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
928-
929- /* Same goes for noreply... */
930- test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1) == MEMCACHED_SUCCESS);
931- rc= memcached_delete(memc, "foo", 3, 1);
932- test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
933-
934- /* but a normal request should go through (and be buffered) */
935- test_true((rc= memcached_delete(memc, "foo", 3, 0)) == MEMCACHED_BUFFERED);
936- test_true(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS);
937-
938- test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0) == MEMCACHED_SUCCESS);
939- /* unbuffered noreply should be success */
940- test_true(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_SUCCESS);
941- /* unbuffered with reply should be not found... */
942- test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0) == MEMCACHED_SUCCESS);
943- test_true(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_NOTFOUND);
944+ /* Binary protocol doesn't support deferred delete */
945+ memcached_st *bin_clone= memcached_clone(NULL, memc);
946+ test_true(bin_clone != NULL);
947+ test_true(memcached_behavior_set(bin_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1) == MEMCACHED_SUCCESS);
948+ test_true(memcached_delete(bin_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
949+ memcached_free(bin_clone);
950+
951+ memcached_quit(memc_clone);
952+
953+ /* If we know the server version, deferred delete should fail
954+ * with invalid arguments */
955+ test_true(memcached_delete(memc_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
956+
957+ /* If we don't know the server version, we should get a protocol error */
958+ memcached_return_t rc= memcached_delete(memc, "foo", 3, 1);
959+
960+ /* but there is a bug in some of the memcached servers (1.4) that treats
961+ * the counter as noreply so it doesn't send the proper error message
962+ */
963+ test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
964+
965+ /* And buffered mode should be disabled and we should get protocol error */
966+ test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1) == MEMCACHED_SUCCESS);
967+ rc= memcached_delete(memc, "foo", 3, 1);
968+ test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
969+
970+ /* Same goes for noreply... */
971+ test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1) == MEMCACHED_SUCCESS);
972+ rc= memcached_delete(memc, "foo", 3, 1);
973+ test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
974+
975+ /* but a normal request should go through (and be buffered) */
976+ test_true((rc= memcached_delete(memc, "foo", 3, 0)) == MEMCACHED_BUFFERED);
977+ test_true(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS);
978+
979+ test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0) == MEMCACHED_SUCCESS);
980+ /* unbuffered noreply should be success */
981+ test_true(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_SUCCESS);
982+ /* unbuffered with reply should be not found... */
983+ test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0) == MEMCACHED_SUCCESS);
984+ test_true(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_NOTFOUND);
985 }
986
987 memcached_free(memc_clone);
988@@ -6080,6 +6073,7 @@
989
990 /* Clean the server before beginning testing */
991 test_st tests[] ={
992+ {"util_version", 1, (test_callback_fn)util_version_test },
993 {"flush", 0, (test_callback_fn)flush_test },
994 {"init", 0, (test_callback_fn)init_test },
995 {"allocation", 0, (test_callback_fn)allocation_test },
996@@ -6135,7 +6129,6 @@
997 #ifdef HAVE_LIBMEMCACHEDUTIL
998 {"connectionpool", 1, (test_callback_fn)connection_pool_test },
999 {"ping", 1, (test_callback_fn)ping_test },
1000- {"util_version", 1, (test_callback_fn)util_version_test },
1001 #endif
1002 {"test_get_last_disconnect", 1, (test_callback_fn)test_get_last_disconnect},
1003 {"verbosity", 1, (test_callback_fn)test_verbosity},
1004@@ -6332,9 +6325,9 @@
1005 };
1006
1007 test_st error_conditions[] ={
1008- {"memcached_get_MEMCACHED_SOME_ERRORS", 0, (test_callback_fn)memcached_get_MEMCACHED_SOME_ERRORS },
1009+ {"memcached_get_MEMCACHED_ERRNO", 0, (test_callback_fn)memcached_get_MEMCACHED_ERRNO },
1010 {"memcached_get_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_MEMCACHED_NOTFOUND },
1011- {"memcached_get_by_key_MEMCACHED_SOME_ERRORS", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_SOME_ERRORS },
1012+ {"memcached_get_by_key_MEMCACHED_ERRNO", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_ERRNO },
1013 {"memcached_get_by_key_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_NOTFOUND },
1014 {0, 0, (test_callback_fn)0}
1015 };
1016
1017=== modified file 'tests/mem_udp.c'
1018--- tests/mem_udp.c 2010-02-18 06:22:15 +0000
1019+++ tests/mem_udp.c 2010-06-29 17:06:27 +0000
1020@@ -10,10 +10,13 @@
1021 Sample test application.
1022 */
1023
1024+#include "config.h"
1025+
1026 #include "libmemcached/common.h"
1027
1028 #include <assert.h>
1029 #include <stdio.h>
1030+#include <stdint.h>
1031 #include <stdlib.h>
1032 #include <string.h>
1033 #include <sys/time.h>
1034@@ -25,14 +28,6 @@
1035
1036 #include "server.h"
1037
1038-#ifndef INT64_MAX
1039-#define INT64_MAX LONG_MAX
1040-#endif
1041-#ifndef INT32_MAX
1042-#define INT32_MAX INT_MAX
1043-#endif
1044-
1045-
1046 #include "test.h"
1047
1048 #define SERVERS_TO_CREATE 5
1049
1050=== modified file 'tests/start.c'
1051--- tests/start.c 2009-12-16 19:03:49 +0000
1052+++ tests/start.c 2010-06-29 17:06:27 +0000
1053@@ -9,6 +9,8 @@
1054 *
1055 */
1056
1057+#include "config.h"
1058+
1059 #include <stdio.h>
1060 #include <string.h>
1061 #include "server.h"
1062
1063=== modified file 'tests/test.c'
1064--- tests/test.c 2010-04-22 00:49:09 +0000
1065+++ tests/test.c 2010-06-29 17:06:27 +0000
1066@@ -9,6 +9,9 @@
1067 /*
1068 Sample test application.
1069 */
1070+
1071+#include "config.h"
1072+
1073 #include <assert.h>
1074 #include <stdlib.h>
1075 #include <string.h>

Subscribers

People subscribed via source and target branches

to all changes: