ctdb-protocol: Add marshalling for struct ctdb_pid_srvid
[metze/samba/wip.git] / ctdb / tests / src / protocol_common.c
1 /*
2    protocol tests - common functions
3
4    Copyright (C) Amitay Isaacs  2015-2017
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "replace.h"
21 #include "system/network.h"
22
23 #include <assert.h>
24
25 #include "protocol/protocol_api.h"
26
27 #include "tests/src/protocol_common.h"
28
29 uint8_t BUFFER[1024*1024];
30
31 /*
32  * Functions to generation random data
33  */
34
35 int rand_int(int max)
36 {
37         return random() % max;
38 }
39
40 uint8_t rand8(void)
41 {
42         uint8_t val = rand_int(256) & 0xff;
43         return val;
44 }
45
46 uint16_t rand16(void)
47 {
48         uint16_t val = rand_int(0xffff) & 0xffff;
49         return val;
50 }
51
52 int32_t rand32i(void)
53 {
54         return INT_MIN + random();
55 }
56
57 uint32_t rand32(void)
58 {
59         return random();
60 }
61
62 uint64_t rand64(void)
63 {
64         uint64_t t = random();
65         t = (t << 32) | random();
66         return t;
67 }
68
69 double rand_double(void)
70 {
71         return 1.0 / rand64();
72 }
73
74 void fill_buffer(void *p, size_t len)
75 {
76         int i;
77         uint8_t *ptr = p;
78
79         for (i=0; i<len; i++) {
80                 ptr[i] = rand8();
81         }
82 }
83
84 void verify_buffer(void *p1, void *p2, size_t len)
85 {
86         if (len > 0) {
87                 assert(memcmp(p1, p2, len) == 0);
88         }
89 }
90
91 static void fill_string(char *p, size_t len)
92 {
93         int i;
94
95         for (i=0; i<len-1; i++) {
96                 p[i] = 'A' + rand_int(26);
97         }
98         p[len-1] = '\0';
99 }
100
101 static void verify_string(const char *p1, const char *p2)
102 {
103         assert(strlen(p1) == strlen(p2));
104         assert(strcmp(p1, p2) == 0);
105 }
106
107 void fill_ctdb_uint8(uint8_t *p)
108 {
109         *p = rand8();
110 }
111
112 void verify_ctdb_uint8(uint8_t *p1, uint8_t *p2)
113 {
114         assert(*p1 == *p2);
115 }
116
117 void fill_ctdb_uint16(uint16_t *p)
118 {
119         *p = rand16();
120 }
121
122 void verify_ctdb_uint16(uint16_t *p1, uint16_t *p2)
123 {
124         assert(*p1 == *p2);
125 }
126
127 void fill_ctdb_int32(int32_t *p)
128 {
129         *p = rand32i();
130 }
131
132 void verify_ctdb_int32(int32_t *p1, int32_t *p2)
133 {
134         assert(*p1 == *p2);
135 }
136
137 void fill_ctdb_uint32(uint32_t *p)
138 {
139         *p = rand32();
140 }
141
142 void verify_ctdb_uint32(uint32_t *p1, uint32_t *p2)
143 {
144         assert(*p1 == *p2);
145 }
146
147 void fill_ctdb_uint64(uint64_t *p)
148 {
149         *p = rand64();
150 }
151
152 void verify_ctdb_uint64(uint64_t *p1, uint64_t *p2)
153 {
154         assert(*p1 == *p2);
155 }
156
157 void fill_ctdb_double(double *p)
158 {
159         *p = rand_double();
160 }
161
162 void verify_ctdb_double(double *p1, double *p2)
163 {
164         assert(*p1 == *p2);
165 }
166
167 void fill_ctdb_bool(bool *p)
168 {
169         if (rand_int(2) == 0) {
170                 *p = true;
171         } else {
172                 *p = false;
173         }
174 }
175
176 void verify_ctdb_bool(bool *p1, bool *p2)
177 {
178         assert(*p1 == *p2);
179 }
180
181 void fill_ctdb_string(TALLOC_CTX *mem_ctx, const char **p)
182 {
183         char *str;
184         int len;
185
186         len = rand_int(1024) + 2;
187         str = talloc_size(mem_ctx, len+1);
188         assert(str != NULL);
189
190         fill_string(str, len);
191         *p = str;
192 }
193
194 void verify_ctdb_string(const char **p1, const char **p2)
195 {
196         if (*p1 == NULL || *p2 == NULL) {
197                 assert(*p1 == *p2);
198         } else {
199                 verify_string(*p1, *p2);
200         }
201 }
202
203 void fill_ctdb_stringn(TALLOC_CTX *mem_ctx, const char **p)
204 {
205         fill_ctdb_string(mem_ctx, p);
206 }
207
208 void verify_ctdb_stringn(const char **p1, const char **p2)
209 {
210         verify_ctdb_string(p1, p2);
211 }
212
213 void fill_ctdb_pid(pid_t *p)
214 {
215         *p = rand32();
216 }
217
218 void verify_ctdb_pid(pid_t *p1, pid_t *p2)
219 {
220         assert(*p1 == *p2);
221 }
222
223 void fill_ctdb_timeval(struct timeval *p)
224 {
225         p->tv_sec = rand32();
226         p->tv_usec = rand_int(1000000);
227 }
228
229 void verify_ctdb_timeval(struct timeval *p1, struct timeval *p2)
230 {
231         assert(p1->tv_sec == p2->tv_sec);
232         assert(p1->tv_usec == p2->tv_usec);
233 }
234
235 void fill_tdb_data_nonnull(TALLOC_CTX *mem_ctx, TDB_DATA *p)
236 {
237         p->dsize = rand_int(1024) + 1;
238         p->dptr = talloc_array(mem_ctx, uint8_t, p->dsize);
239         assert(p->dptr != NULL);
240         fill_buffer(p->dptr, p->dsize);
241 }
242
243 void fill_tdb_data(TALLOC_CTX *mem_ctx, TDB_DATA *p)
244 {
245         if (rand_int(5) == 0) {
246                 p->dsize = 0;
247                 p->dptr = NULL;
248         } else {
249                 fill_tdb_data_nonnull(mem_ctx, p);
250         }
251 }
252
253 void verify_tdb_data(TDB_DATA *p1, TDB_DATA *p2)
254 {
255         assert(p1->dsize == p2->dsize);
256         verify_buffer(p1->dptr, p2->dptr, p1->dsize);
257 }
258
259 void fill_ctdb_tdb_data(TALLOC_CTX *mem_ctx, TDB_DATA *p)
260 {
261         fill_tdb_data(mem_ctx, p);
262 }
263
264 void verify_ctdb_tdb_data(TDB_DATA *p1, TDB_DATA *p2)
265 {
266         verify_tdb_data(p1, p2);
267 }
268
269 void fill_ctdb_tdb_datan(TALLOC_CTX *mem_ctx, TDB_DATA *p)
270 {
271         fill_tdb_data(mem_ctx, p);
272 }
273
274 void verify_ctdb_tdb_datan(TDB_DATA *p1, TDB_DATA *p2)
275 {
276         verify_tdb_data(p1, p2);
277 }
278
279 void fill_ctdb_latency_counter(struct ctdb_latency_counter *p)
280 {
281         p->num = rand32i();
282         p->min = rand_double();
283         p->max = rand_double();
284         p->total = rand_double();
285 }
286
287 void verify_ctdb_latency_counter(struct ctdb_latency_counter *p1,
288                                  struct ctdb_latency_counter *p2)
289 {
290         assert(p1->num == p2->num);
291         assert(p1->min == p2->min);
292         assert(p1->max == p2->max);
293         assert(p1->total == p2->total);
294 }
295
296 void fill_ctdb_statistics(TALLOC_CTX *mem_ctx, struct ctdb_statistics *p)
297 {
298         int i;
299
300         p->num_clients = rand32();
301         p->frozen = rand32();
302         p->recovering = rand32();
303         p->client_packets_sent = rand32();
304         p->client_packets_recv = rand32();
305         p->node_packets_sent = rand32();
306         p->node_packets_recv = rand32();
307         p->keepalive_packets_sent = rand32();
308         p->keepalive_packets_recv = rand32();
309
310         p->node.req_call = rand32();
311         p->node.reply_call = rand32();
312         p->node.req_dmaster = rand32();
313         p->node.reply_dmaster = rand32();
314         p->node.reply_error = rand32();
315         p->node.req_message = rand32();
316         p->node.req_control = rand32();
317         p->node.reply_control = rand32();
318
319         p->client.req_call = rand32();
320         p->client.req_message = rand32();
321         p->client.req_control = rand32();
322
323         p->timeouts.call = rand32();
324         p->timeouts.control = rand32();
325         p->timeouts.traverse = rand32();
326
327         fill_ctdb_latency_counter(&p->reclock.ctdbd);
328         fill_ctdb_latency_counter(&p->reclock.recd);
329
330         p->locks.num_calls = rand32();
331         p->locks.num_current = rand32();
332         p->locks.num_pending = rand32();
333         p->locks.num_failed = rand32();
334         fill_ctdb_latency_counter(&p->locks.latency);
335         for (i=0; i<MAX_COUNT_BUCKETS; i++) {
336                 p->locks.buckets[i] = rand32();
337         }
338
339         p->total_calls = rand32();
340         p->pending_calls = rand32();
341         p->childwrite_calls = rand32();
342         p->pending_childwrite_calls = rand32();
343         p->memory_used = rand32();
344         p->__last_counter = rand32();
345         p->max_hop_count = rand32();
346         for (i=0; i<MAX_COUNT_BUCKETS; i++) {
347                 p->hop_count_bucket[i] = rand32();
348         }
349         fill_ctdb_latency_counter(&p->call_latency);
350         fill_ctdb_latency_counter(&p->childwrite_latency);
351         p->num_recoveries = rand32();
352         fill_ctdb_timeval(&p->statistics_start_time);
353         fill_ctdb_timeval(&p->statistics_current_time);
354         p->total_ro_delegations = rand32();
355         p->total_ro_revokes = rand32();
356 }
357
358 void verify_ctdb_statistics(struct ctdb_statistics *p1,
359                             struct ctdb_statistics *p2)
360 {
361         int i;
362
363         assert(p1->num_clients == p2->num_clients);
364         assert(p1->frozen == p2->frozen);
365         assert(p1->recovering == p2->recovering);
366         assert(p1->client_packets_sent == p2->client_packets_sent);
367         assert(p1->client_packets_recv == p2->client_packets_recv);
368         assert(p1->node_packets_sent == p2->node_packets_sent);
369         assert(p1->node_packets_recv == p2->node_packets_recv);
370         assert(p1->keepalive_packets_sent == p2->keepalive_packets_sent);
371         assert(p1->keepalive_packets_recv == p2->keepalive_packets_recv);
372
373         assert(p1->node.req_call == p2->node.req_call);
374         assert(p1->node.reply_call == p2->node.reply_call);
375         assert(p1->node.req_dmaster == p2->node.req_dmaster);
376         assert(p1->node.reply_dmaster == p2->node.reply_dmaster);
377         assert(p1->node.reply_error == p2->node.reply_error);
378         assert(p1->node.req_message == p2->node.req_message);
379         assert(p1->node.req_control == p2->node.req_control);
380         assert(p1->node.reply_control == p2->node.reply_control);
381
382         assert(p1->client.req_call == p2->client.req_call);
383         assert(p1->client.req_message == p2->client.req_message);
384         assert(p1->client.req_control == p2->client.req_control);
385
386         assert(p1->timeouts.call == p2->timeouts.call);
387         assert(p1->timeouts.control == p2->timeouts.control);
388         assert(p1->timeouts.traverse == p2->timeouts.traverse);
389
390         verify_ctdb_latency_counter(&p1->reclock.ctdbd, &p2->reclock.ctdbd);
391         verify_ctdb_latency_counter(&p1->reclock.recd, &p2->reclock.recd);
392
393         assert(p1->locks.num_calls == p2->locks.num_calls);
394         assert(p1->locks.num_current == p2->locks.num_current);
395         assert(p1->locks.num_pending == p2->locks.num_pending);
396         assert(p1->locks.num_failed == p2->locks.num_failed);
397         verify_ctdb_latency_counter(&p1->locks.latency, &p2->locks.latency);
398         for (i=0; i<MAX_COUNT_BUCKETS; i++) {
399                 assert(p1->locks.buckets[i] == p2->locks.buckets[i]);
400         }
401
402         assert(p1->total_calls == p2->total_calls);
403         assert(p1->pending_calls == p2->pending_calls);
404         assert(p1->childwrite_calls == p2->childwrite_calls);
405         assert(p1->pending_childwrite_calls == p2->pending_childwrite_calls);
406         assert(p1->memory_used == p2->memory_used);
407         assert(p1->__last_counter == p2->__last_counter);
408         assert(p1->max_hop_count == p2->max_hop_count);
409         for (i=0; i<MAX_COUNT_BUCKETS; i++) {
410                 assert(p1->hop_count_bucket[i] == p2->hop_count_bucket[i]);
411         }
412         verify_ctdb_latency_counter(&p1->call_latency, &p2->call_latency);
413         verify_ctdb_latency_counter(&p1->childwrite_latency,
414                                     &p2->childwrite_latency);
415         assert(p1->num_recoveries == p2->num_recoveries);
416         verify_ctdb_timeval(&p1->statistics_start_time,
417                             &p2->statistics_start_time);
418         verify_ctdb_timeval(&p1->statistics_current_time,
419                             &p2->statistics_current_time);
420         assert(p1->total_ro_delegations == p2->total_ro_delegations);
421         assert(p1->total_ro_revokes == p2->total_ro_revokes);
422 }
423
424 void fill_ctdb_vnn_map(TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *p)
425 {
426         int i;
427
428         p->generation = rand32();
429         p->size = rand_int(20);
430         if (p->size > 0) {
431                 p->map = talloc_array(mem_ctx, uint32_t, p->size);
432                 assert(p->map != NULL);
433
434                 for (i=0; i<p->size; i++) {
435                         p->map[i] = rand32();
436                 }
437         } else {
438                 p->map = NULL;
439         }
440 }
441
442 void verify_ctdb_vnn_map(struct ctdb_vnn_map *p1, struct ctdb_vnn_map *p2)
443 {
444         int i;
445
446         assert(p1->generation == p2->generation);
447         assert(p1->size == p2->size);
448         for (i=0; i<p1->size; i++) {
449                 assert(p1->map[i] == p2->map[i]);
450         }
451 }
452
453 void fill_ctdb_dbid(TALLOC_CTX *mem_ctx, struct ctdb_dbid *p)
454 {
455         p->db_id = rand32();
456         p->flags = rand8();
457 }
458
459 void verify_ctdb_dbid(struct ctdb_dbid *p1, struct ctdb_dbid *p2)
460 {
461         assert(p1->db_id == p2->db_id);
462         assert(p1->flags == p2->flags);
463 }
464
465 void fill_ctdb_dbid_map(TALLOC_CTX *mem_ctx, struct ctdb_dbid_map *p)
466 {
467         int i;
468
469         p->num = rand_int(40);
470         if (p->num > 0) {
471                 p->dbs = talloc_zero_array(mem_ctx, struct ctdb_dbid, p->num);
472                 assert(p->dbs != NULL);
473                 for (i=0; i<p->num; i++) {
474                         fill_ctdb_dbid(mem_ctx, &p->dbs[i]);
475                 }
476         } else {
477                 p->dbs = NULL;
478         }
479 }
480
481 void verify_ctdb_dbid_map(struct ctdb_dbid_map *p1, struct ctdb_dbid_map *p2)
482 {
483         int i;
484
485         assert(p1->num == p2->num);
486         for (i=0; i<p1->num; i++) {
487                 verify_ctdb_dbid(&p1->dbs[i], &p2->dbs[i]);
488         }
489 }
490
491 void fill_ctdb_pulldb(TALLOC_CTX *mem_ctx, struct ctdb_pulldb *p)
492 {
493         p->db_id = rand32();
494         p->lmaster = rand32();
495 }
496
497 void verify_ctdb_pulldb(struct ctdb_pulldb *p1, struct ctdb_pulldb *p2)
498 {
499         assert(p1->db_id == p2->db_id);
500         assert(p1->lmaster == p2->lmaster);
501 }
502
503 void fill_ctdb_pulldb_ext(TALLOC_CTX *mem_ctx, struct ctdb_pulldb_ext *p)
504 {
505         p->db_id = rand32();
506         p->lmaster = rand32();
507         p->srvid = rand64();
508 }
509
510 void verify_ctdb_pulldb_ext(struct ctdb_pulldb_ext *p1,
511                             struct ctdb_pulldb_ext *p2)
512 {
513         assert(p1->db_id == p2->db_id);
514         assert(p1->lmaster == p2->lmaster);
515         assert(p1->srvid == p2->srvid);
516 }
517
518 void fill_ctdb_ltdb_header(struct ctdb_ltdb_header *p)
519 {
520         p->rsn = rand64();
521         p->dmaster = rand32();
522         p->reserved1 = rand32();
523         p->flags = rand32();
524 }
525
526 void verify_ctdb_ltdb_header(struct ctdb_ltdb_header *p1,
527                              struct ctdb_ltdb_header *p2)
528 {
529         assert(p1->rsn == p2->rsn);
530         assert(p1->dmaster == p2->dmaster);
531         assert(p1->reserved1 == p2->reserved1);
532         assert(p1->flags == p2->flags);
533 }
534
535 void fill_ctdb_rec_data(TALLOC_CTX *mem_ctx, struct ctdb_rec_data *p)
536 {
537         p->reqid = rand32();
538         if (p->reqid % 5 == 0) {
539                 p->header = talloc(mem_ctx, struct ctdb_ltdb_header);
540                 assert(p->header != NULL);
541                 fill_ctdb_ltdb_header(p->header);
542         } else {
543                 p->header = NULL;
544         }
545         fill_tdb_data_nonnull(mem_ctx, &p->key);
546         fill_tdb_data(mem_ctx, &p->data);
547 }
548
549 void verify_ctdb_rec_data(struct ctdb_rec_data *p1, struct ctdb_rec_data *p2)
550 {
551         struct ctdb_ltdb_header header;
552
553         assert(p1->reqid == p2->reqid);
554         if (p1->header != NULL) {
555                 assert(ctdb_ltdb_header_extract(&p2->data, &header) == 0);
556                 verify_ctdb_ltdb_header(p1->header, &header);
557         }
558         verify_tdb_data(&p1->key, &p2->key);
559         verify_tdb_data(&p1->data, &p2->data);
560 }
561
562 void fill_ctdb_rec_buffer(TALLOC_CTX *mem_ctx, struct ctdb_rec_buffer *p)
563 {
564         struct ctdb_rec_data rec;
565         int ret, i;
566         int count;
567
568         p->db_id = rand32();
569         p->count = 0;
570         p->buf = NULL;
571         p->buflen = 0;
572
573         count = rand_int(100);
574         if (count > 0) {
575                 for (i=0; i<count; i++) {
576                         fill_ctdb_rec_data(mem_ctx, &rec);
577                         ret = ctdb_rec_buffer_add(mem_ctx, p, rec.reqid,
578                                                   rec.header,
579                                                   rec.key, rec.data);
580                         assert(ret == 0);
581                 }
582         }
583 }
584
585 void verify_ctdb_rec_buffer(struct ctdb_rec_buffer *p1,
586                             struct ctdb_rec_buffer *p2)
587 {
588         assert(p1->db_id == p2->db_id);
589         assert(p1->count == p2->count);
590         assert(p1->buflen == p2->buflen);
591         verify_buffer(p1->buf, p2->buf, p1->buflen);
592 }
593
594 void fill_ctdb_traverse_start(TALLOC_CTX *mem_ctx,
595                               struct ctdb_traverse_start *p)
596 {
597         p->db_id = rand32();
598         p->reqid = rand32();
599         p->srvid = rand64();
600 }
601
602 void verify_ctdb_traverse_start(struct ctdb_traverse_start *p1,
603                                 struct ctdb_traverse_start *p2)
604 {
605         assert(p1->db_id == p2->db_id);
606         assert(p1->reqid == p2->reqid);
607         assert(p1->srvid == p2->srvid);
608 }
609
610 void fill_ctdb_traverse_all(TALLOC_CTX *mem_ctx,
611                             struct ctdb_traverse_all *p)
612 {
613         p->db_id = rand32();
614         p->reqid = rand32();
615         p->pnn = rand32();
616         p->client_reqid = rand32();
617         p->srvid = rand64();
618 }
619
620 void verify_ctdb_traverse_all(struct ctdb_traverse_all *p1,
621                               struct ctdb_traverse_all *p2)
622 {
623         assert(p1->db_id == p2->db_id);
624         assert(p1->reqid == p2->reqid);
625         assert(p1->pnn == p2->pnn);
626         assert(p1->client_reqid == p2->client_reqid);
627         assert(p1->srvid == p2->srvid);
628 }
629
630 void fill_ctdb_traverse_start_ext(TALLOC_CTX *mem_ctx,
631                                   struct ctdb_traverse_start_ext *p)
632 {
633         p->db_id = rand32();
634         p->reqid = rand32();
635         p->srvid = rand64();
636         p->withemptyrecords = rand_int(2);
637 }
638
639 void verify_ctdb_traverse_start_ext(struct ctdb_traverse_start_ext *p1,
640                                     struct ctdb_traverse_start_ext *p2)
641 {
642         assert(p1->db_id == p2->db_id);
643         assert(p1->reqid == p2->reqid);
644         assert(p1->srvid == p2->srvid);
645         assert(p1->withemptyrecords == p2->withemptyrecords);
646 }
647
648 void fill_ctdb_traverse_all_ext(TALLOC_CTX *mem_ctx,
649                                 struct ctdb_traverse_all_ext *p)
650 {
651         p->db_id = rand32();
652         p->reqid = rand32();
653         p->pnn = rand32();
654         p->client_reqid = rand32();
655         p->srvid = rand64();
656         p->withemptyrecords = rand_int(2);
657 }
658
659 void verify_ctdb_traverse_all_ext(struct ctdb_traverse_all_ext *p1,
660                                   struct ctdb_traverse_all_ext *p2)
661 {
662         assert(p1->db_id == p2->db_id);
663         assert(p1->reqid == p2->reqid);
664         assert(p1->pnn == p2->pnn);
665         assert(p1->client_reqid == p2->client_reqid);
666         assert(p1->srvid == p2->srvid);
667         assert(p1->withemptyrecords == p2->withemptyrecords);
668 }
669
670 void fill_ctdb_sock_addr(TALLOC_CTX *mem_ctx, ctdb_sock_addr *p)
671 {
672         if (rand_int(2) == 0) {
673                 p->ip.sin_family = AF_INET;
674                 p->ip.sin_port = rand_int(65535);
675                 fill_buffer(&p->ip.sin_addr, sizeof(struct in_addr));
676         } else {
677                 p->ip6.sin6_family = AF_INET6;
678                 p->ip6.sin6_port = rand_int(65535);
679                 fill_buffer(&p->ip6.sin6_addr, sizeof(struct in6_addr));
680         }
681 }
682
683 void verify_ctdb_sock_addr(ctdb_sock_addr *p1, ctdb_sock_addr *p2)
684 {
685         assert(p1->sa.sa_family == p2->sa.sa_family);
686         if (p1->sa.sa_family == AF_INET) {
687                 assert(p1->ip.sin_port == p2->ip.sin_port);
688                 verify_buffer(&p1->ip.sin_addr, &p2->ip.sin_addr,
689                                    sizeof(struct in_addr));
690         } else {
691                 assert(p1->ip6.sin6_port == p2->ip6.sin6_port);
692                 verify_buffer(&p1->ip6.sin6_addr, &p2->ip6.sin6_addr,
693                                    sizeof(struct in6_addr));
694         }
695 }
696
697 void fill_ctdb_connection(TALLOC_CTX *mem_ctx, struct ctdb_connection *p)
698 {
699         fill_ctdb_sock_addr(mem_ctx, &p->src);
700         fill_ctdb_sock_addr(mem_ctx, &p->dst);
701 }
702
703 void verify_ctdb_connection(struct ctdb_connection *p1,
704                             struct ctdb_connection *p2)
705 {
706         verify_ctdb_sock_addr(&p1->src, &p2->src);
707         verify_ctdb_sock_addr(&p1->dst, &p2->dst);
708 }
709
710 void fill_ctdb_connection_list(TALLOC_CTX *mem_ctx,
711                                struct ctdb_connection_list *p)
712 {
713         uint32_t i;
714
715         p->num = rand_int(1000);
716         if (p->num > 0) {
717                 p->conn = talloc_array(mem_ctx, struct ctdb_connection, p->num);
718                 assert(p->conn != NULL);
719                 for (i=0; i<p->num; i++) {
720                         fill_ctdb_connection(mem_ctx, &p->conn[i]);
721                 }
722         } else {
723                 p->conn = NULL;
724         }
725 }
726
727 void verify_ctdb_connection_list(struct ctdb_connection_list *p1,
728                                  struct ctdb_connection_list *p2)
729 {
730         uint32_t i;
731
732         assert(p1->num == p2->num);
733         for (i=0; i<p1->num; i++) {
734                 verify_ctdb_connection(&p1->conn[i], &p2->conn[i]);
735         }
736 }
737
738 void fill_ctdb_tunable(TALLOC_CTX *mem_ctx, struct ctdb_tunable *p)
739 {
740         fill_ctdb_string(mem_ctx, &p->name);
741         p->value = rand32();
742 }
743
744 void verify_ctdb_tunable(struct ctdb_tunable *p1, struct ctdb_tunable *p2)
745 {
746         verify_ctdb_string(&p1->name, &p2->name);
747         assert(p1->value == p2->value);
748 }
749
750 void fill_ctdb_node_flag_change(TALLOC_CTX *mem_ctx,
751                                 struct ctdb_node_flag_change *p)
752 {
753         p->pnn = rand32();
754         p->new_flags = rand32();
755         p->old_flags = rand32();
756 }
757
758 void verify_ctdb_node_flag_change(struct ctdb_node_flag_change *p1,
759                                   struct ctdb_node_flag_change *p2)
760 {
761         assert(p1->pnn == p2->pnn);
762         assert(p1->new_flags == p2->new_flags);
763         assert(p1->old_flags == p2->old_flags);
764 }
765
766 void fill_ctdb_var_list(TALLOC_CTX *mem_ctx, struct ctdb_var_list *p)
767 {
768         int i;
769
770         p->count = rand_int(100) + 1;
771         p->var = talloc_array(mem_ctx, const char *, p->count);
772         for (i=0; i<p->count; i++) {
773                 fill_ctdb_string(p->var, &p->var[i]);
774         }
775 }
776
777 void verify_ctdb_var_list(struct ctdb_var_list *p1, struct ctdb_var_list *p2)
778 {
779         int i;
780
781         assert(p1->count == p2->count);
782         for (i=0; i<p1->count; i++) {
783                 verify_ctdb_string(&p1->var[i], &p2->var[i]);
784         }
785 }
786
787 void fill_ctdb_tunable_list(TALLOC_CTX *mem_ctx, struct ctdb_tunable_list *p)
788 {
789         p->max_redirect_count = rand32();
790         p->seqnum_interval = rand32();
791         p->control_timeout = rand32();
792         p->traverse_timeout = rand32();
793         p->keepalive_interval = rand32();
794         p->keepalive_limit = rand32();
795         p->recover_timeout = rand32();
796         p->recover_interval = rand32();
797         p->election_timeout = rand32();
798         p->takeover_timeout = rand32();
799         p->monitor_interval = rand32();
800         p->tickle_update_interval = rand32();
801         p->script_timeout = rand32();
802         p->monitor_timeout_count = rand32();
803         p->script_unhealthy_on_timeout = rand32();
804         p->recovery_grace_period = rand32();
805         p->recovery_ban_period = rand32();
806         p->database_hash_size = rand32();
807         p->database_max_dead = rand32();
808         p->rerecovery_timeout = rand32();
809         p->enable_bans = rand32();
810         p->deterministic_public_ips = rand32();
811         p->reclock_ping_period = rand32();
812         p->no_ip_failback = rand32();
813         p->disable_ip_failover = rand32();
814         p->verbose_memory_names = rand32();
815         p->recd_ping_timeout = rand32();
816         p->recd_ping_failcount = rand32();
817         p->log_latency_ms = rand32();
818         p->reclock_latency_ms = rand32();
819         p->recovery_drop_all_ips = rand32();
820         p->verify_recovery_lock = rand32();
821         p->vacuum_interval = rand32();
822         p->vacuum_max_run_time = rand32();
823         p->repack_limit = rand32();
824         p->vacuum_limit = rand32();
825         p->max_queue_depth_drop_msg = rand32();
826         p->allow_unhealthy_db_read = rand32();
827         p->stat_history_interval = rand32();
828         p->deferred_attach_timeout = rand32();
829         p->vacuum_fast_path_count = rand32();
830         p->lcp2_public_ip_assignment = rand32();
831         p->allow_client_db_attach = rand32();
832         p->recover_pdb_by_seqnum = rand32();
833         p->deferred_rebalance_on_node_add = rand32();
834         p->fetch_collapse = rand32();
835         p->hopcount_make_sticky = rand32();
836         p->sticky_duration = rand32();
837         p->sticky_pindown = rand32();
838         p->no_ip_takeover = rand32();
839         p->db_record_count_warn = rand32();
840         p->db_record_size_warn = rand32();
841         p->db_size_warn = rand32();
842         p->pulldb_preallocation_size = rand32();
843         p->no_ip_host_on_all_disabled = rand32();
844         p->samba3_hack = rand32();
845         p->mutex_enabled = rand32();
846         p->lock_processes_per_db = rand32();
847         p->rec_buffer_size_limit = rand32();
848         p->queue_buffer_size = rand32();
849         p->ip_alloc_algorithm = rand32();
850         p->allow_mixed_versions = rand32();
851 }
852
853 void verify_ctdb_tunable_list(struct ctdb_tunable_list *p1,
854                               struct ctdb_tunable_list *p2)
855 {
856         assert(p1->max_redirect_count == p2->max_redirect_count);
857         assert(p1->seqnum_interval == p2->seqnum_interval);
858         assert(p1->control_timeout == p2->control_timeout);
859         assert(p1->traverse_timeout == p2->traverse_timeout);
860         assert(p1->keepalive_interval == p2->keepalive_interval);
861         assert(p1->keepalive_limit == p2->keepalive_limit);
862         assert(p1->recover_timeout == p2->recover_timeout);
863         assert(p1->recover_interval == p2->recover_interval);
864         assert(p1->election_timeout == p2->election_timeout);
865         assert(p1->takeover_timeout == p2->takeover_timeout);
866         assert(p1->monitor_interval == p2->monitor_interval);
867         assert(p1->tickle_update_interval == p2->tickle_update_interval);
868         assert(p1->script_timeout == p2->script_timeout);
869         assert(p1->monitor_timeout_count == p2->monitor_timeout_count);
870         assert(p1->script_unhealthy_on_timeout == p2->script_unhealthy_on_timeout);
871         assert(p1->recovery_grace_period == p2->recovery_grace_period);
872         assert(p1->recovery_ban_period == p2->recovery_ban_period);
873         assert(p1->database_hash_size == p2->database_hash_size);
874         assert(p1->database_max_dead == p2->database_max_dead);
875         assert(p1->rerecovery_timeout == p2->rerecovery_timeout);
876         assert(p1->enable_bans == p2->enable_bans);
877         assert(p1->deterministic_public_ips == p2->deterministic_public_ips);
878         assert(p1->reclock_ping_period == p2->reclock_ping_period);
879         assert(p1->no_ip_failback == p2->no_ip_failback);
880         assert(p1->disable_ip_failover == p2->disable_ip_failover);
881         assert(p1->verbose_memory_names == p2->verbose_memory_names);
882         assert(p1->recd_ping_timeout == p2->recd_ping_timeout);
883         assert(p1->recd_ping_failcount == p2->recd_ping_failcount);
884         assert(p1->log_latency_ms == p2->log_latency_ms);
885         assert(p1->reclock_latency_ms == p2->reclock_latency_ms);
886         assert(p1->recovery_drop_all_ips == p2->recovery_drop_all_ips);
887         assert(p1->verify_recovery_lock == p2->verify_recovery_lock);
888         assert(p1->vacuum_interval == p2->vacuum_interval);
889         assert(p1->vacuum_max_run_time == p2->vacuum_max_run_time);
890         assert(p1->repack_limit == p2->repack_limit);
891         assert(p1->vacuum_limit == p2->vacuum_limit);
892         assert(p1->max_queue_depth_drop_msg == p2->max_queue_depth_drop_msg);
893         assert(p1->allow_unhealthy_db_read == p2->allow_unhealthy_db_read);
894         assert(p1->stat_history_interval == p2->stat_history_interval);
895         assert(p1->deferred_attach_timeout == p2->deferred_attach_timeout);
896         assert(p1->vacuum_fast_path_count == p2->vacuum_fast_path_count);
897         assert(p1->lcp2_public_ip_assignment == p2->lcp2_public_ip_assignment);
898         assert(p1->allow_client_db_attach == p2->allow_client_db_attach);
899         assert(p1->recover_pdb_by_seqnum == p2->recover_pdb_by_seqnum);
900         assert(p1->deferred_rebalance_on_node_add == p2->deferred_rebalance_on_node_add);
901         assert(p1->fetch_collapse == p2->fetch_collapse);
902         assert(p1->hopcount_make_sticky == p2->hopcount_make_sticky);
903         assert(p1->sticky_duration == p2->sticky_duration);
904         assert(p1->sticky_pindown == p2->sticky_pindown);
905         assert(p1->no_ip_takeover == p2->no_ip_takeover);
906         assert(p1->db_record_count_warn == p2->db_record_count_warn);
907         assert(p1->db_record_size_warn == p2->db_record_size_warn);
908         assert(p1->db_size_warn == p2->db_size_warn);
909         assert(p1->pulldb_preallocation_size == p2->pulldb_preallocation_size);
910         assert(p1->no_ip_host_on_all_disabled == p2->no_ip_host_on_all_disabled);
911         assert(p1->samba3_hack == p2->samba3_hack);
912         assert(p1->mutex_enabled == p2->mutex_enabled);
913         assert(p1->lock_processes_per_db == p2->lock_processes_per_db);
914         assert(p1->rec_buffer_size_limit == p2->rec_buffer_size_limit);
915         assert(p1->queue_buffer_size == p2->queue_buffer_size);
916         assert(p1->ip_alloc_algorithm == p2->ip_alloc_algorithm);
917         assert(p1->allow_mixed_versions == p2->allow_mixed_versions);
918 }
919
920 void fill_ctdb_tickle_list(TALLOC_CTX *mem_ctx, struct ctdb_tickle_list *p)
921 {
922         int i;
923
924         fill_ctdb_sock_addr(mem_ctx, &p->addr);
925         p->num = rand_int(1000);
926         if (p->num > 0) {
927                 p->conn = talloc_array(mem_ctx, struct ctdb_connection, p->num);
928                 assert(p->conn != NULL);
929                 for (i=0; i<p->num; i++) {
930                         fill_ctdb_connection(mem_ctx, &p->conn[i]);
931                 }
932         } else {
933                 p->conn = NULL;
934         }
935 }
936
937 void verify_ctdb_tickle_list(struct ctdb_tickle_list *p1,
938                              struct ctdb_tickle_list *p2)
939 {
940         int i;
941
942         verify_ctdb_sock_addr(&p1->addr, &p2->addr);
943         assert(p1->num == p2->num);
944         for (i=0; i<p1->num; i++) {
945                 verify_ctdb_connection(&p1->conn[i], &p2->conn[i]);
946         }
947 }
948
949 void fill_ctdb_addr_info(TALLOC_CTX *mem_ctx, struct ctdb_addr_info *p)
950 {
951         fill_ctdb_sock_addr(mem_ctx, &p->addr);
952         p->mask = rand_int(33);
953         if (rand_int(2) == 0) {
954                 p->iface = NULL;
955         } else {
956                 fill_ctdb_string(mem_ctx, &p->iface);
957         }
958 }
959
960 void verify_ctdb_addr_info(struct ctdb_addr_info *p1,
961                            struct ctdb_addr_info *p2)
962 {
963         verify_ctdb_sock_addr(&p1->addr, &p2->addr);
964         assert(p1->mask == p2->mask);
965         verify_ctdb_string(&p1->iface, &p2->iface);
966 }
967
968 void fill_ctdb_transdb(TALLOC_CTX *mem_ctx, struct ctdb_transdb *p)
969 {
970         p->db_id = rand32();
971         p->tid = rand32();
972 }
973
974 void verify_ctdb_transdb(struct ctdb_transdb *p1, struct ctdb_transdb *p2)
975 {
976         assert(p1->db_id == p2->db_id);
977         assert(p1->tid == p2->tid);
978 }
979
980 void fill_ctdb_uptime(TALLOC_CTX *mem_ctx, struct ctdb_uptime *p)
981 {
982         fill_ctdb_timeval(&p->current_time);
983         fill_ctdb_timeval(&p->ctdbd_start_time);
984         fill_ctdb_timeval(&p->last_recovery_started);
985         fill_ctdb_timeval(&p->last_recovery_finished);
986 }
987
988 void verify_ctdb_uptime(struct ctdb_uptime *p1, struct ctdb_uptime *p2)
989 {
990         verify_ctdb_timeval(&p1->current_time, &p2->current_time);
991         verify_ctdb_timeval(&p1->ctdbd_start_time, &p2->ctdbd_start_time);
992         verify_ctdb_timeval(&p1->last_recovery_started,
993                             &p2->last_recovery_started);
994         verify_ctdb_timeval(&p1->last_recovery_finished,
995                             &p2->last_recovery_finished);
996 }
997
998 void fill_ctdb_public_ip(TALLOC_CTX *mem_ctx, struct ctdb_public_ip *p)
999 {
1000         p->pnn = rand32();
1001         fill_ctdb_sock_addr(mem_ctx, &p->addr);
1002 }
1003
1004 void verify_ctdb_public_ip(struct ctdb_public_ip *p1,
1005                            struct ctdb_public_ip *p2)
1006 {
1007         assert(p1->pnn == p2->pnn);
1008         verify_ctdb_sock_addr(&p1->addr, &p2->addr);
1009 }
1010
1011 void fill_ctdb_public_ip_list(TALLOC_CTX *mem_ctx,
1012                               struct ctdb_public_ip_list *p)
1013 {
1014         int i;
1015
1016         p->num = rand_int(32);
1017         if (p->num > 0) {
1018                 p->ip = talloc_array(mem_ctx, struct ctdb_public_ip, p->num);
1019                 assert(p->ip != NULL);
1020                 for (i=0; i<p->num; i++) {
1021                         fill_ctdb_public_ip(mem_ctx, &p->ip[i]);
1022                 }
1023         } else {
1024                 p->ip = NULL;
1025         }
1026 }
1027
1028 void verify_ctdb_public_ip_list(struct ctdb_public_ip_list *p1,
1029                                 struct ctdb_public_ip_list *p2)
1030 {
1031         int i;
1032
1033         assert(p1->num == p2->num);
1034         for (i=0; i<p1->num; i++) {
1035                 verify_ctdb_public_ip(&p1->ip[i], &p2->ip[i]);
1036         }
1037 }
1038
1039 void fill_ctdb_node_and_flags(TALLOC_CTX *mem_ctx,
1040                               struct ctdb_node_and_flags *p)
1041 {
1042         p->pnn = rand32();
1043         p->flags = rand32();
1044         fill_ctdb_sock_addr(mem_ctx, &p->addr);
1045 }
1046
1047 void verify_ctdb_node_and_flags(struct ctdb_node_and_flags *p1,
1048                                 struct ctdb_node_and_flags *p2)
1049 {
1050         assert(p1->pnn == p2->pnn);
1051         assert(p1->flags == p2->flags);
1052         verify_ctdb_sock_addr(&p1->addr, &p2->addr);
1053 }
1054
1055 void fill_ctdb_node_map(TALLOC_CTX *mem_ctx, struct ctdb_node_map *p)
1056 {
1057         int i;
1058
1059         p->num = rand_int(32);
1060         if (p->num > 0) {
1061                 p->node = talloc_array(mem_ctx, struct ctdb_node_and_flags,
1062                                        p->num);
1063                 assert(p->node != NULL);
1064                 for (i=0; i<p->num; i++) {
1065                         fill_ctdb_node_and_flags(mem_ctx, &p->node[i]);
1066                 }
1067         } else {
1068                 p->node = NULL;
1069         }
1070 }
1071
1072 void verify_ctdb_node_map(struct ctdb_node_map *p1, struct ctdb_node_map *p2)
1073 {
1074         int i;
1075
1076         assert(p1->num == p2->num);
1077         for (i=0; i<p1->num; i++) {
1078                 verify_ctdb_node_and_flags(&p1->node[i], &p2->node[i]);
1079         }
1080 }
1081
1082 void fill_ctdb_script(TALLOC_CTX *mem_ctx, struct ctdb_script *p)
1083 {
1084         fill_string(p->name, MAX_SCRIPT_NAME+1);
1085         fill_ctdb_timeval(&p->start);
1086         fill_ctdb_timeval(&p->finished);
1087         p->status = rand32i();
1088         fill_string(p->output, MAX_SCRIPT_OUTPUT+1);
1089 }
1090
1091 void verify_ctdb_script(struct ctdb_script *p1, struct ctdb_script *p2)
1092 {
1093         verify_string(p1->name, p2->name);
1094         verify_ctdb_timeval(&p1->start, &p2->start);
1095         verify_ctdb_timeval(&p1->finished, &p2->finished);
1096         assert(p1->status == p2->status);
1097         verify_string(p1->output, p2->output);
1098 }
1099
1100 void fill_ctdb_script_list(TALLOC_CTX *mem_ctx, struct ctdb_script_list *p)
1101 {
1102         int i;
1103
1104         p->num_scripts = rand_int(32);
1105         if (p->num_scripts > 0) {
1106                 p->script = talloc_zero_array(mem_ctx, struct ctdb_script,
1107                                               p->num_scripts);
1108                 assert(p->script != NULL);
1109                 for (i=0; i<p->num_scripts; i++) {
1110                         fill_ctdb_script(mem_ctx, &p->script[i]);
1111                 }
1112         } else {
1113                 p->script = NULL;
1114         }
1115 }
1116
1117 void verify_ctdb_script_list(struct ctdb_script_list *p1,
1118                              struct ctdb_script_list *p2)
1119 {
1120         int i;
1121
1122         assert(p1->num_scripts == p2->num_scripts);
1123         for (i=0; i<p1->num_scripts; i++) {
1124                 verify_ctdb_script(&p1->script[i], &p2->script[i]);
1125         }
1126 }
1127
1128 void fill_ctdb_ban_state(TALLOC_CTX *mem_ctx, struct ctdb_ban_state *p)
1129 {
1130         p->pnn = rand32();
1131         p->time = rand32();
1132 }
1133
1134 void verify_ctdb_ban_state(struct ctdb_ban_state *p1,
1135                            struct ctdb_ban_state *p2)
1136 {
1137         assert(p1->pnn == p2->pnn);
1138         assert(p1->time == p2->time);
1139 }
1140
1141 void fill_ctdb_notify_data(TALLOC_CTX *mem_ctx, struct ctdb_notify_data *p)
1142 {
1143         p->srvid = rand64();
1144         fill_tdb_data(mem_ctx, &p->data);
1145 }
1146
1147 void verify_ctdb_notify_data(struct ctdb_notify_data *p1,
1148                              struct ctdb_notify_data *p2)
1149 {
1150         assert(p1->srvid == p2->srvid);
1151         verify_tdb_data(&p1->data, &p2->data);
1152 }
1153
1154 void fill_ctdb_iface(TALLOC_CTX *mem_ctx, struct ctdb_iface *p)
1155 {
1156         fill_string(p->name, CTDB_IFACE_SIZE+2);
1157         p->link_state = rand16();
1158         p->references = rand32();
1159 }
1160
1161 void verify_ctdb_iface(struct ctdb_iface *p1, struct ctdb_iface *p2)
1162 {
1163         verify_string(p1->name, p2->name);
1164         assert(p1->link_state == p2->link_state);
1165         assert(p1->references == p2->references);
1166 }
1167
1168 void fill_ctdb_iface_list(TALLOC_CTX *mem_ctx, struct ctdb_iface_list *p)
1169 {
1170         int i;
1171
1172         p->num = rand_int(32);
1173         if (p->num > 0) {
1174                 p->iface = talloc_array(mem_ctx, struct ctdb_iface, p->num);
1175                 assert(p->iface != NULL);
1176                 for (i=0; i<p->num; i++) {
1177                         fill_ctdb_iface(mem_ctx, &p->iface[i]);
1178                 }
1179         } else {
1180                 p->iface = NULL;
1181         }
1182 }
1183
1184 void verify_ctdb_iface_list(struct ctdb_iface_list *p1,
1185                             struct ctdb_iface_list *p2)
1186 {
1187         int i;
1188
1189         assert(p1->num == p2->num);
1190         for (i=0; i<p1->num; i++) {
1191                 verify_ctdb_iface(&p1->iface[i], &p2->iface[i]);
1192         }
1193 }
1194
1195 void fill_ctdb_public_ip_info(TALLOC_CTX *mem_ctx,
1196                               struct ctdb_public_ip_info *p)
1197 {
1198         fill_ctdb_public_ip(mem_ctx, &p->ip);
1199         p->active_idx = rand_int(32) + 1;
1200         p->ifaces = talloc(mem_ctx, struct ctdb_iface_list);
1201         assert(p->ifaces != NULL);
1202         fill_ctdb_iface_list(mem_ctx, p->ifaces);
1203 }
1204
1205 void verify_ctdb_public_ip_info(struct ctdb_public_ip_info *p1,
1206                                 struct ctdb_public_ip_info *p2)
1207 {
1208         verify_ctdb_public_ip(&p1->ip, &p2->ip);
1209         assert(p1->active_idx == p2->active_idx);
1210         verify_ctdb_iface_list(p1->ifaces, p2->ifaces);
1211 }
1212
1213 void fill_ctdb_statistics_list(TALLOC_CTX *mem_ctx,
1214                                struct ctdb_statistics_list *p)
1215 {
1216         int i;
1217
1218         p->num = rand_int(10);
1219         if (p->num > 0) {
1220                 p->stats = talloc_zero_array(mem_ctx, struct ctdb_statistics,
1221                                              p->num);
1222                 assert(p->stats != NULL);
1223
1224                 for (i=0; i<p->num; i++) {
1225                         fill_ctdb_statistics(mem_ctx, &p->stats[i]);
1226                 }
1227         } else {
1228                 p->stats = NULL;
1229         }
1230 }
1231
1232 void verify_ctdb_statistics_list(struct ctdb_statistics_list *p1,
1233                                  struct ctdb_statistics_list *p2)
1234 {
1235         int i;
1236
1237         assert(p1->num == p2->num);
1238         for (i=0; i<p1->num; i++) {
1239                 verify_ctdb_statistics(&p1->stats[i], &p2->stats[i]);
1240         }
1241 }
1242
1243 void fill_ctdb_key_data(TALLOC_CTX *mem_ctx, struct ctdb_key_data *p)
1244 {
1245         p->db_id = rand32();
1246         fill_ctdb_ltdb_header(&p->header);
1247         fill_tdb_data_nonnull(mem_ctx, &p->key);
1248 }
1249
1250 void verify_ctdb_key_data(struct ctdb_key_data *p1, struct ctdb_key_data *p2)
1251 {
1252         assert(p1->db_id == p2->db_id);
1253         verify_ctdb_ltdb_header(&p1->header, &p2->header);
1254         verify_tdb_data(&p1->key, &p2->key);
1255 }
1256
1257 void fill_ctdb_db_statistics(TALLOC_CTX *mem_ctx,
1258                              struct ctdb_db_statistics *p)
1259 {
1260         int i;
1261
1262         p->locks.num_calls = rand32();
1263         p->locks.num_current = rand32();
1264         p->locks.num_pending = rand32();
1265         p->locks.num_failed = rand32();
1266         fill_ctdb_latency_counter(&p->locks.latency);
1267         for (i=0; i<MAX_COUNT_BUCKETS; i++) {
1268                 p->locks.buckets[i] = rand32();
1269         }
1270
1271         fill_ctdb_latency_counter(&p->vacuum.latency);
1272
1273         p->db_ro_delegations = rand32();
1274         p->db_ro_revokes = rand32();
1275         for (i=0; i<MAX_COUNT_BUCKETS; i++) {
1276                 p->hop_count_bucket[i] = rand32();
1277         }
1278
1279         p->num_hot_keys = MAX_HOT_KEYS;
1280         for (i=0; i<p->num_hot_keys; i++) {
1281                 p->hot_keys[i].count = rand32();
1282                 fill_tdb_data(mem_ctx, &p->hot_keys[i].key);
1283         }
1284 }
1285
1286 void verify_ctdb_db_statistics(struct ctdb_db_statistics *p1,
1287                                struct ctdb_db_statistics *p2)
1288 {
1289         int i;
1290
1291         assert(p1->locks.num_calls == p2->locks.num_calls);
1292         assert(p1->locks.num_current == p2->locks.num_current);
1293         assert(p1->locks.num_pending == p2->locks.num_pending);
1294         assert(p1->locks.num_failed == p2->locks.num_failed);
1295         verify_ctdb_latency_counter(&p1->locks.latency, &p2->locks.latency);
1296         for (i=0; i<MAX_COUNT_BUCKETS; i++) {
1297                 assert(p1->locks.buckets[i] == p2->locks.buckets[i]);
1298         }
1299
1300         verify_ctdb_latency_counter(&p1->vacuum.latency, &p2->vacuum.latency);
1301
1302         assert(p1->db_ro_delegations == p2->db_ro_delegations);
1303         assert(p1->db_ro_revokes == p2->db_ro_revokes);
1304         for (i=0; i<MAX_COUNT_BUCKETS; i++) {
1305                 assert(p1->hop_count_bucket[i] == p2->hop_count_bucket[i]);
1306         }
1307
1308         assert(p1->num_hot_keys == p2->num_hot_keys);
1309         for (i=0; i<p1->num_hot_keys; i++) {
1310                 assert(p1->hot_keys[i].count == p2->hot_keys[i].count);
1311                 verify_tdb_data(&p1->hot_keys[i].key, &p2->hot_keys[i].key);
1312         }
1313 }
1314
1315 void fill_ctdb_pid_srvid(TALLOC_CTX *mem_ctx, struct ctdb_pid_srvid *p)
1316 {
1317         p->pid = rand32();
1318         p->srvid = rand64();
1319 }
1320
1321 void verify_ctdb_pid_srvid(struct ctdb_pid_srvid *p1,
1322                            struct ctdb_pid_srvid *p2)
1323 {
1324         assert(p1->pid == p2->pid);
1325         assert(p1->srvid == p2->srvid);
1326 }
1327
1328 void fill_ctdb_election_message(TALLOC_CTX *mem_ctx,
1329                                 struct ctdb_election_message *p)
1330 {
1331         p->num_connected = rand_int(32);
1332         fill_ctdb_timeval(&p->priority_time);
1333         p->pnn = rand_int(32);
1334         p->node_flags = rand32();
1335 }
1336
1337 void verify_ctdb_election_message(struct ctdb_election_message *p1,
1338                                   struct ctdb_election_message *p2)
1339 {
1340         assert(p1->num_connected == p2->num_connected);
1341         verify_ctdb_timeval(&p1->priority_time, &p2->priority_time);
1342         assert(p1->pnn == p2->pnn);
1343         assert(p1->node_flags == p2->node_flags);
1344 }
1345
1346 void fill_ctdb_srvid_message(TALLOC_CTX *mem_ctx,
1347                              struct ctdb_srvid_message *p)
1348 {
1349         p->pnn = rand_int(32);
1350         p->srvid = rand64();
1351 }
1352
1353 void verify_ctdb_srvid_message(struct ctdb_srvid_message *p1,
1354                                struct ctdb_srvid_message *p2)
1355 {
1356         assert(p1->pnn == p2->pnn);
1357         assert(p1->srvid == p2->srvid);
1358 }
1359
1360 void fill_ctdb_disable_message(TALLOC_CTX *mem_ctx,
1361                                struct ctdb_disable_message *p)
1362 {
1363         p->pnn = rand_int(32);
1364         p->srvid = rand64();
1365         p->timeout = rand32();
1366 }
1367
1368 void verify_ctdb_disable_message(struct ctdb_disable_message *p1,
1369                                  struct ctdb_disable_message *p2)
1370 {
1371         assert(p1->pnn == p2->pnn);
1372         assert(p1->srvid == p2->srvid);
1373         assert(p1->timeout == p2->timeout);
1374 }
1375
1376 void fill_ctdb_server_id(struct ctdb_server_id *p)
1377 {
1378         p->pid = rand64();
1379         p->task_id = rand32();
1380         p->vnn = rand_int(32);
1381         p->unique_id = rand64();
1382 }
1383
1384 void verify_ctdb_server_id(struct ctdb_server_id *p1,
1385                            struct ctdb_server_id *p2)
1386 {
1387         assert(p1->pid == p2->pid);
1388         assert(p1->task_id == p2->task_id);
1389         assert(p1->vnn == p2->vnn);
1390         assert(p1->unique_id == p2->unique_id);
1391 }
1392
1393 void fill_ctdb_g_lock(struct ctdb_g_lock *p)
1394 {
1395         p->type = rand_int(2);
1396         fill_ctdb_server_id(&p->sid);
1397 }
1398
1399 void verify_ctdb_g_lock(struct ctdb_g_lock *p1, struct ctdb_g_lock *p2)
1400 {
1401         assert(p1->type == p2->type);
1402         verify_ctdb_server_id(&p1->sid, &p2->sid);
1403 }
1404
1405 void fill_ctdb_g_lock_list(TALLOC_CTX *mem_ctx, struct ctdb_g_lock_list *p)
1406 {
1407         int i;
1408
1409         p->num = rand_int(20) + 1;
1410         p->lock = talloc_zero_array(mem_ctx, struct ctdb_g_lock, p->num);
1411         assert(p->lock != NULL);
1412         for (i=0; i<p->num; i++) {
1413                 fill_ctdb_g_lock(&p->lock[i]);
1414         }
1415 }
1416
1417 void verify_ctdb_g_lock_list(struct ctdb_g_lock_list *p1,
1418                              struct ctdb_g_lock_list *p2)
1419 {
1420         int i;
1421
1422         assert(p1->num == p2->num);
1423         for (i=0; i<p1->num; i++) {
1424                 verify_ctdb_g_lock(&p1->lock[i], &p2->lock[i]);
1425         }
1426 }
1427
1428 void fill_sock_packet_header(struct sock_packet_header *p)
1429 {
1430         p->length = rand32();
1431         p->reqid = rand32();
1432 }
1433
1434 void verify_sock_packet_header(struct sock_packet_header *p1,
1435                                struct sock_packet_header *p2)
1436 {
1437         assert(p1->length == p2->length);
1438         assert(p1->reqid == p2->reqid);
1439 }