ctdb-protocol: Fix marshalling for ctdb_script
[vlendec/samba-autobuild/.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_tunable(TALLOC_CTX *mem_ctx, struct ctdb_tunable *p)
711 {
712         fill_ctdb_string(mem_ctx, &p->name);
713         p->value = rand32();
714 }
715
716 void verify_ctdb_tunable(struct ctdb_tunable *p1, struct ctdb_tunable *p2)
717 {
718         verify_ctdb_string(&p1->name, &p2->name);
719         assert(p1->value == p2->value);
720 }
721
722 void fill_ctdb_node_flag_change(TALLOC_CTX *mem_ctx,
723                                 struct ctdb_node_flag_change *p)
724 {
725         p->pnn = rand32();
726         p->new_flags = rand32();
727         p->old_flags = rand32();
728 }
729
730 void verify_ctdb_node_flag_change(struct ctdb_node_flag_change *p1,
731                                   struct ctdb_node_flag_change *p2)
732 {
733         assert(p1->pnn == p2->pnn);
734         assert(p1->new_flags == p2->new_flags);
735         assert(p1->old_flags == p2->old_flags);
736 }
737
738 void fill_ctdb_var_list(TALLOC_CTX *mem_ctx, struct ctdb_var_list *p)
739 {
740         int i;
741
742         p->count = rand_int(100) + 1;
743         p->var = talloc_array(mem_ctx, const char *, p->count);
744         for (i=0; i<p->count; i++) {
745                 fill_ctdb_string(p->var, &p->var[i]);
746         }
747 }
748
749 void verify_ctdb_var_list(struct ctdb_var_list *p1, struct ctdb_var_list *p2)
750 {
751         int i;
752
753         assert(p1->count == p2->count);
754         for (i=0; i<p1->count; i++) {
755                 verify_ctdb_string(&p1->var[i], &p2->var[i]);
756         }
757 }
758
759 void fill_ctdb_tunable_list(TALLOC_CTX *mem_ctx, struct ctdb_tunable_list *p)
760 {
761         p->max_redirect_count = rand32();
762         p->seqnum_interval = rand32();
763         p->control_timeout = rand32();
764         p->traverse_timeout = rand32();
765         p->keepalive_interval = rand32();
766         p->keepalive_limit = rand32();
767         p->recover_timeout = rand32();
768         p->recover_interval = rand32();
769         p->election_timeout = rand32();
770         p->takeover_timeout = rand32();
771         p->monitor_interval = rand32();
772         p->tickle_update_interval = rand32();
773         p->script_timeout = rand32();
774         p->monitor_timeout_count = rand32();
775         p->script_unhealthy_on_timeout = rand32();
776         p->recovery_grace_period = rand32();
777         p->recovery_ban_period = rand32();
778         p->database_hash_size = rand32();
779         p->database_max_dead = rand32();
780         p->rerecovery_timeout = rand32();
781         p->enable_bans = rand32();
782         p->deterministic_public_ips = rand32();
783         p->reclock_ping_period = rand32();
784         p->no_ip_failback = rand32();
785         p->disable_ip_failover = rand32();
786         p->verbose_memory_names = rand32();
787         p->recd_ping_timeout = rand32();
788         p->recd_ping_failcount = rand32();
789         p->log_latency_ms = rand32();
790         p->reclock_latency_ms = rand32();
791         p->recovery_drop_all_ips = rand32();
792         p->verify_recovery_lock = rand32();
793         p->vacuum_interval = rand32();
794         p->vacuum_max_run_time = rand32();
795         p->repack_limit = rand32();
796         p->vacuum_limit = rand32();
797         p->max_queue_depth_drop_msg = rand32();
798         p->allow_unhealthy_db_read = rand32();
799         p->stat_history_interval = rand32();
800         p->deferred_attach_timeout = rand32();
801         p->vacuum_fast_path_count = rand32();
802         p->lcp2_public_ip_assignment = rand32();
803         p->allow_client_db_attach = rand32();
804         p->recover_pdb_by_seqnum = rand32();
805         p->deferred_rebalance_on_node_add = rand32();
806         p->fetch_collapse = rand32();
807         p->hopcount_make_sticky = rand32();
808         p->sticky_duration = rand32();
809         p->sticky_pindown = rand32();
810         p->no_ip_takeover = rand32();
811         p->db_record_count_warn = rand32();
812         p->db_record_size_warn = rand32();
813         p->db_size_warn = rand32();
814         p->pulldb_preallocation_size = rand32();
815         p->no_ip_host_on_all_disabled = rand32();
816         p->samba3_hack = rand32();
817         p->mutex_enabled = rand32();
818         p->lock_processes_per_db = rand32();
819         p->rec_buffer_size_limit = rand32();
820         p->queue_buffer_size = rand32();
821         p->ip_alloc_algorithm = rand32();
822         p->allow_mixed_versions = rand32();
823 }
824
825 void verify_ctdb_tunable_list(struct ctdb_tunable_list *p1,
826                               struct ctdb_tunable_list *p2)
827 {
828         assert(p1->max_redirect_count == p2->max_redirect_count);
829         assert(p1->seqnum_interval == p2->seqnum_interval);
830         assert(p1->control_timeout == p2->control_timeout);
831         assert(p1->traverse_timeout == p2->traverse_timeout);
832         assert(p1->keepalive_interval == p2->keepalive_interval);
833         assert(p1->keepalive_limit == p2->keepalive_limit);
834         assert(p1->recover_timeout == p2->recover_timeout);
835         assert(p1->recover_interval == p2->recover_interval);
836         assert(p1->election_timeout == p2->election_timeout);
837         assert(p1->takeover_timeout == p2->takeover_timeout);
838         assert(p1->monitor_interval == p2->monitor_interval);
839         assert(p1->tickle_update_interval == p2->tickle_update_interval);
840         assert(p1->script_timeout == p2->script_timeout);
841         assert(p1->monitor_timeout_count == p2->monitor_timeout_count);
842         assert(p1->script_unhealthy_on_timeout == p2->script_unhealthy_on_timeout);
843         assert(p1->recovery_grace_period == p2->recovery_grace_period);
844         assert(p1->recovery_ban_period == p2->recovery_ban_period);
845         assert(p1->database_hash_size == p2->database_hash_size);
846         assert(p1->database_max_dead == p2->database_max_dead);
847         assert(p1->rerecovery_timeout == p2->rerecovery_timeout);
848         assert(p1->enable_bans == p2->enable_bans);
849         assert(p1->deterministic_public_ips == p2->deterministic_public_ips);
850         assert(p1->reclock_ping_period == p2->reclock_ping_period);
851         assert(p1->no_ip_failback == p2->no_ip_failback);
852         assert(p1->disable_ip_failover == p2->disable_ip_failover);
853         assert(p1->verbose_memory_names == p2->verbose_memory_names);
854         assert(p1->recd_ping_timeout == p2->recd_ping_timeout);
855         assert(p1->recd_ping_failcount == p2->recd_ping_failcount);
856         assert(p1->log_latency_ms == p2->log_latency_ms);
857         assert(p1->reclock_latency_ms == p2->reclock_latency_ms);
858         assert(p1->recovery_drop_all_ips == p2->recovery_drop_all_ips);
859         assert(p1->verify_recovery_lock == p2->verify_recovery_lock);
860         assert(p1->vacuum_interval == p2->vacuum_interval);
861         assert(p1->vacuum_max_run_time == p2->vacuum_max_run_time);
862         assert(p1->repack_limit == p2->repack_limit);
863         assert(p1->vacuum_limit == p2->vacuum_limit);
864         assert(p1->max_queue_depth_drop_msg == p2->max_queue_depth_drop_msg);
865         assert(p1->allow_unhealthy_db_read == p2->allow_unhealthy_db_read);
866         assert(p1->stat_history_interval == p2->stat_history_interval);
867         assert(p1->deferred_attach_timeout == p2->deferred_attach_timeout);
868         assert(p1->vacuum_fast_path_count == p2->vacuum_fast_path_count);
869         assert(p1->lcp2_public_ip_assignment == p2->lcp2_public_ip_assignment);
870         assert(p1->allow_client_db_attach == p2->allow_client_db_attach);
871         assert(p1->recover_pdb_by_seqnum == p2->recover_pdb_by_seqnum);
872         assert(p1->deferred_rebalance_on_node_add == p2->deferred_rebalance_on_node_add);
873         assert(p1->fetch_collapse == p2->fetch_collapse);
874         assert(p1->hopcount_make_sticky == p2->hopcount_make_sticky);
875         assert(p1->sticky_duration == p2->sticky_duration);
876         assert(p1->sticky_pindown == p2->sticky_pindown);
877         assert(p1->no_ip_takeover == p2->no_ip_takeover);
878         assert(p1->db_record_count_warn == p2->db_record_count_warn);
879         assert(p1->db_record_size_warn == p2->db_record_size_warn);
880         assert(p1->db_size_warn == p2->db_size_warn);
881         assert(p1->pulldb_preallocation_size == p2->pulldb_preallocation_size);
882         assert(p1->no_ip_host_on_all_disabled == p2->no_ip_host_on_all_disabled);
883         assert(p1->samba3_hack == p2->samba3_hack);
884         assert(p1->mutex_enabled == p2->mutex_enabled);
885         assert(p1->lock_processes_per_db == p2->lock_processes_per_db);
886         assert(p1->rec_buffer_size_limit == p2->rec_buffer_size_limit);
887         assert(p1->queue_buffer_size == p2->queue_buffer_size);
888         assert(p1->ip_alloc_algorithm == p2->ip_alloc_algorithm);
889         assert(p1->allow_mixed_versions == p2->allow_mixed_versions);
890 }
891
892 void fill_ctdb_tickle_list(TALLOC_CTX *mem_ctx, struct ctdb_tickle_list *p)
893 {
894         int i;
895
896         fill_ctdb_sock_addr(mem_ctx, &p->addr);
897         p->num = rand_int(1000);
898         if (p->num > 0) {
899                 p->conn = talloc_array(mem_ctx, struct ctdb_connection, p->num);
900                 assert(p->conn != NULL);
901                 for (i=0; i<p->num; i++) {
902                         fill_ctdb_connection(mem_ctx, &p->conn[i]);
903                 }
904         } else {
905                 p->conn = NULL;
906         }
907 }
908
909 void verify_ctdb_tickle_list(struct ctdb_tickle_list *p1,
910                              struct ctdb_tickle_list *p2)
911 {
912         int i;
913
914         verify_ctdb_sock_addr(&p1->addr, &p2->addr);
915         assert(p1->num == p2->num);
916         for (i=0; i<p1->num; i++) {
917                 verify_ctdb_connection(&p1->conn[i], &p2->conn[i]);
918         }
919 }
920
921 void fill_ctdb_addr_info(TALLOC_CTX *mem_ctx, struct ctdb_addr_info *p)
922 {
923         fill_ctdb_sock_addr(mem_ctx, &p->addr);
924         p->mask = rand_int(33);
925         if (rand_int(2) == 0) {
926                 p->iface = NULL;
927         } else {
928                 fill_ctdb_string(mem_ctx, &p->iface);
929         }
930 }
931
932 void verify_ctdb_addr_info(struct ctdb_addr_info *p1,
933                            struct ctdb_addr_info *p2)
934 {
935         verify_ctdb_sock_addr(&p1->addr, &p2->addr);
936         assert(p1->mask == p2->mask);
937         verify_ctdb_string(&p1->iface, &p2->iface);
938 }
939
940 void fill_ctdb_transdb(TALLOC_CTX *mem_ctx, struct ctdb_transdb *p)
941 {
942         p->db_id = rand32();
943         p->tid = rand32();
944 }
945
946 void verify_ctdb_transdb(struct ctdb_transdb *p1, struct ctdb_transdb *p2)
947 {
948         assert(p1->db_id == p2->db_id);
949         assert(p1->tid == p2->tid);
950 }
951
952 void fill_ctdb_uptime(TALLOC_CTX *mem_ctx, struct ctdb_uptime *p)
953 {
954         fill_ctdb_timeval(&p->current_time);
955         fill_ctdb_timeval(&p->ctdbd_start_time);
956         fill_ctdb_timeval(&p->last_recovery_started);
957         fill_ctdb_timeval(&p->last_recovery_finished);
958 }
959
960 void verify_ctdb_uptime(struct ctdb_uptime *p1, struct ctdb_uptime *p2)
961 {
962         verify_ctdb_timeval(&p1->current_time, &p2->current_time);
963         verify_ctdb_timeval(&p1->ctdbd_start_time, &p2->ctdbd_start_time);
964         verify_ctdb_timeval(&p1->last_recovery_started,
965                             &p2->last_recovery_started);
966         verify_ctdb_timeval(&p1->last_recovery_finished,
967                             &p2->last_recovery_finished);
968 }
969
970 void fill_ctdb_public_ip(TALLOC_CTX *mem_ctx, struct ctdb_public_ip *p)
971 {
972         p->pnn = rand32();
973         fill_ctdb_sock_addr(mem_ctx, &p->addr);
974 }
975
976 void verify_ctdb_public_ip(struct ctdb_public_ip *p1,
977                            struct ctdb_public_ip *p2)
978 {
979         assert(p1->pnn == p2->pnn);
980         verify_ctdb_sock_addr(&p1->addr, &p2->addr);
981 }
982
983 void fill_ctdb_public_ip_list(TALLOC_CTX *mem_ctx,
984                               struct ctdb_public_ip_list *p)
985 {
986         int i;
987
988         p->num = rand_int(32);
989         if (p->num > 0) {
990                 p->ip = talloc_array(mem_ctx, struct ctdb_public_ip, p->num);
991                 assert(p->ip != NULL);
992                 for (i=0; i<p->num; i++) {
993                         fill_ctdb_public_ip(mem_ctx, &p->ip[i]);
994                 }
995         } else {
996                 p->ip = NULL;
997         }
998 }
999
1000 void verify_ctdb_public_ip_list(struct ctdb_public_ip_list *p1,
1001                                 struct ctdb_public_ip_list *p2)
1002 {
1003         int i;
1004
1005         assert(p1->num == p2->num);
1006         for (i=0; i<p1->num; i++) {
1007                 verify_ctdb_public_ip(&p1->ip[i], &p2->ip[i]);
1008         }
1009 }
1010
1011 void fill_ctdb_node_and_flags(TALLOC_CTX *mem_ctx,
1012                               struct ctdb_node_and_flags *p)
1013 {
1014         p->pnn = rand32();
1015         p->flags = rand32();
1016         fill_ctdb_sock_addr(mem_ctx, &p->addr);
1017 }
1018
1019 void verify_ctdb_node_and_flags(struct ctdb_node_and_flags *p1,
1020                                 struct ctdb_node_and_flags *p2)
1021 {
1022         assert(p1->pnn == p2->pnn);
1023         assert(p1->flags == p2->flags);
1024         verify_ctdb_sock_addr(&p1->addr, &p2->addr);
1025 }
1026
1027 void fill_ctdb_node_map(TALLOC_CTX *mem_ctx, struct ctdb_node_map *p)
1028 {
1029         int i;
1030
1031         p->num = rand_int(32);
1032         if (p->num > 0) {
1033                 p->node = talloc_array(mem_ctx, struct ctdb_node_and_flags,
1034                                        p->num);
1035                 assert(p->node != NULL);
1036                 for (i=0; i<p->num; i++) {
1037                         fill_ctdb_node_and_flags(mem_ctx, &p->node[i]);
1038                 }
1039         } else {
1040                 p->node = NULL;
1041         }
1042 }
1043
1044 void verify_ctdb_node_map(struct ctdb_node_map *p1, struct ctdb_node_map *p2)
1045 {
1046         int i;
1047
1048         assert(p1->num == p2->num);
1049         for (i=0; i<p1->num; i++) {
1050                 verify_ctdb_node_and_flags(&p1->node[i], &p2->node[i]);
1051         }
1052 }
1053
1054 void fill_ctdb_script(TALLOC_CTX *mem_ctx, struct ctdb_script *p)
1055 {
1056         fill_string(p->name, MAX_SCRIPT_NAME+1);
1057         fill_ctdb_timeval(&p->start);
1058         fill_ctdb_timeval(&p->finished);
1059         p->status = rand32i();
1060         fill_string(p->output, MAX_SCRIPT_OUTPUT+1);
1061 }
1062
1063 void verify_ctdb_script(struct ctdb_script *p1, struct ctdb_script *p2)
1064 {
1065         verify_string(p1->name, p2->name);
1066         verify_ctdb_timeval(&p1->start, &p2->start);
1067         verify_ctdb_timeval(&p1->finished, &p2->finished);
1068         assert(p1->status == p2->status);
1069         verify_string(p1->output, p2->output);
1070 }
1071
1072 void fill_ctdb_script_list(TALLOC_CTX *mem_ctx, struct ctdb_script_list *p)
1073 {
1074         int i;
1075
1076         p->num_scripts = rand_int(32);
1077         if (p->num_scripts > 0) {
1078                 p->script = talloc_array(mem_ctx, struct ctdb_script,
1079                                          p->num_scripts);
1080                 assert(p->script != NULL);
1081                 for (i=0; i<p->num_scripts; i++) {
1082                         fill_ctdb_script(mem_ctx, &p->script[i]);
1083                 }
1084         } else {
1085                 p->script = NULL;
1086         }
1087 }
1088
1089 void verify_ctdb_script_list(struct ctdb_script_list *p1,
1090                              struct ctdb_script_list *p2)
1091 {
1092         int i;
1093
1094         assert(p1->num_scripts == p2->num_scripts);
1095         for (i=0; i<p1->num_scripts; i++) {
1096                 verify_ctdb_script(&p1->script[i], &p2->script[i]);
1097         }
1098 }
1099
1100 void fill_ctdb_ban_state(TALLOC_CTX *mem_ctx, struct ctdb_ban_state *p)
1101 {
1102         p->pnn = rand32();
1103         p->time = rand32();
1104 }
1105
1106 void verify_ctdb_ban_state(struct ctdb_ban_state *p1,
1107                            struct ctdb_ban_state *p2)
1108 {
1109         assert(p1->pnn == p2->pnn);
1110         assert(p1->time == p2->time);
1111 }
1112
1113 void fill_ctdb_notify_data(TALLOC_CTX *mem_ctx, struct ctdb_notify_data *p)
1114 {
1115         p->srvid = rand64();
1116         fill_tdb_data(mem_ctx, &p->data);
1117 }
1118
1119 void verify_ctdb_notify_data(struct ctdb_notify_data *p1,
1120                              struct ctdb_notify_data *p2)
1121 {
1122         assert(p1->srvid == p2->srvid);
1123         verify_tdb_data(&p1->data, &p2->data);
1124 }
1125
1126 void fill_ctdb_iface(TALLOC_CTX *mem_ctx, struct ctdb_iface *p)
1127 {
1128         fill_buffer(p, sizeof(struct ctdb_iface));
1129 }
1130
1131 void verify_ctdb_iface(struct ctdb_iface *p1, struct ctdb_iface *p2)
1132 {
1133         verify_buffer(p1, p2, sizeof(struct ctdb_iface));
1134 }
1135
1136 void fill_ctdb_iface_list(TALLOC_CTX *mem_ctx, struct ctdb_iface_list *p)
1137 {
1138         int i;
1139
1140         p->num = rand_int(32);
1141         if (p->num > 0) {
1142                 p->iface = talloc_array(mem_ctx, struct ctdb_iface, p->num);
1143                 assert(p->iface != NULL);
1144                 for (i=0; i<p->num; i++) {
1145                         fill_ctdb_iface(mem_ctx, &p->iface[i]);
1146                 }
1147         } else {
1148                 p->iface = NULL;
1149         }
1150 }
1151
1152 void verify_ctdb_iface_list(struct ctdb_iface_list *p1,
1153                             struct ctdb_iface_list *p2)
1154 {
1155         int i;
1156
1157         assert(p1->num == p2->num);
1158         for (i=0; i<p1->num; i++) {
1159                 verify_ctdb_iface(&p1->iface[i], &p2->iface[i]);
1160         }
1161 }
1162
1163 void fill_ctdb_public_ip_info(TALLOC_CTX *mem_ctx,
1164                               struct ctdb_public_ip_info *p)
1165 {
1166         fill_ctdb_public_ip(mem_ctx, &p->ip);
1167         p->active_idx = rand_int(32) + 1;
1168         p->ifaces = talloc(mem_ctx, struct ctdb_iface_list);
1169         assert(p->ifaces != NULL);
1170         fill_ctdb_iface_list(mem_ctx, p->ifaces);
1171 }
1172
1173 void verify_ctdb_public_ip_info(struct ctdb_public_ip_info *p1,
1174                                 struct ctdb_public_ip_info *p2)
1175 {
1176         verify_ctdb_public_ip(&p1->ip, &p2->ip);
1177         assert(p1->active_idx == p2->active_idx);
1178         verify_ctdb_iface_list(p1->ifaces, p2->ifaces);
1179 }
1180
1181 void fill_ctdb_statistics_list(TALLOC_CTX *mem_ctx,
1182                                struct ctdb_statistics_list *p)
1183 {
1184         int i;
1185
1186         p->num = rand_int(10);
1187         if (p->num > 0) {
1188                 p->stats = talloc_array(mem_ctx, struct ctdb_statistics,
1189                                         p->num);
1190                 assert(p->stats != NULL);
1191
1192                 for (i=0; i<p->num; i++) {
1193                         fill_ctdb_statistics(mem_ctx, &p->stats[i]);
1194                 }
1195         } else {
1196                 p->stats = NULL;
1197         }
1198 }
1199
1200 void verify_ctdb_statistics_list(struct ctdb_statistics_list *p1,
1201                                  struct ctdb_statistics_list *p2)
1202 {
1203         int i;
1204
1205         assert(p1->num == p2->num);
1206         for (i=0; i<p1->num; i++) {
1207                 verify_ctdb_statistics(&p1->stats[i], &p2->stats[i]);
1208         }
1209 }
1210
1211 void fill_ctdb_key_data(TALLOC_CTX *mem_ctx, struct ctdb_key_data *p)
1212 {
1213         p->db_id = rand32();
1214         fill_ctdb_ltdb_header(&p->header);
1215         fill_tdb_data_nonnull(mem_ctx, &p->key);
1216 }
1217
1218 void verify_ctdb_key_data(struct ctdb_key_data *p1, struct ctdb_key_data *p2)
1219 {
1220         assert(p1->db_id == p2->db_id);
1221         verify_ctdb_ltdb_header(&p1->header, &p2->header);
1222         verify_tdb_data(&p1->key, &p2->key);
1223 }
1224
1225 void fill_ctdb_db_statistics(TALLOC_CTX *mem_ctx,
1226                              struct ctdb_db_statistics *p)
1227 {
1228         int i;
1229
1230         fill_buffer(p, offsetof(struct ctdb_db_statistics, num_hot_keys));
1231         p->num_hot_keys = 10;
1232         for (i=0; i<p->num_hot_keys; i++) {
1233                 p->hot_keys[i].count = rand32();
1234                 fill_tdb_data(mem_ctx, &p->hot_keys[i].key);
1235         }
1236 }
1237
1238 void verify_ctdb_db_statistics(struct ctdb_db_statistics *p1,
1239                                struct ctdb_db_statistics *p2)
1240 {
1241         int i;
1242
1243         verify_buffer(p1, p2, offsetof(struct ctdb_db_statistics,
1244                                             num_hot_keys));
1245         assert(p1->num_hot_keys == p2->num_hot_keys);
1246         for (i=0; i<p1->num_hot_keys; i++) {
1247                 assert(p1->hot_keys[i].count == p2->hot_keys[i].count);
1248                 verify_tdb_data(&p1->hot_keys[i].key, &p2->hot_keys[i].key);
1249         }
1250 }
1251
1252 void fill_ctdb_election_message(TALLOC_CTX *mem_ctx,
1253                                 struct ctdb_election_message *p)
1254 {
1255         p->num_connected = rand_int(32);
1256         fill_buffer(&p->priority_time, sizeof(struct timeval));
1257         p->pnn = rand_int(32);
1258         p->node_flags = rand32();
1259 }
1260
1261 void verify_ctdb_election_message(struct ctdb_election_message *p1,
1262                                   struct ctdb_election_message *p2)
1263 {
1264         assert(p1->num_connected == p2->num_connected);
1265         verify_buffer(p1, p2, sizeof(struct timeval));
1266         assert(p1->pnn == p2->pnn);
1267         assert(p1->node_flags == p2->node_flags);
1268 }
1269
1270 void fill_ctdb_srvid_message(TALLOC_CTX *mem_ctx,
1271                              struct ctdb_srvid_message *p)
1272 {
1273         p->pnn = rand_int(32);
1274         p->srvid = rand64();
1275 }
1276
1277 void verify_ctdb_srvid_message(struct ctdb_srvid_message *p1,
1278                                struct ctdb_srvid_message *p2)
1279 {
1280         assert(p1->pnn == p2->pnn);
1281         assert(p1->srvid == p2->srvid);
1282 }
1283
1284 void fill_ctdb_disable_message(TALLOC_CTX *mem_ctx,
1285                                struct ctdb_disable_message *p)
1286 {
1287         p->pnn = rand_int(32);
1288         p->srvid = rand64();
1289         p->timeout = rand32();
1290 }
1291
1292 void verify_ctdb_disable_message(struct ctdb_disable_message *p1,
1293                                  struct ctdb_disable_message *p2)
1294 {
1295         assert(p1->pnn == p2->pnn);
1296         assert(p1->srvid == p2->srvid);
1297         assert(p1->timeout == p2->timeout);
1298 }
1299
1300 void fill_ctdb_server_id(TALLOC_CTX *mem_ctx, struct ctdb_server_id *p)
1301 {
1302         p->pid = rand64();
1303         p->task_id = rand32();
1304         p->vnn = rand_int(32);
1305         p->unique_id = rand64();
1306 }
1307
1308 void verify_ctdb_server_id(struct ctdb_server_id *p1,
1309                            struct ctdb_server_id *p2)
1310 {
1311         assert(p1->pid == p2->pid);
1312         assert(p1->task_id == p2->task_id);
1313         assert(p1->vnn == p2->vnn);
1314         assert(p1->unique_id == p2->unique_id);
1315 }
1316
1317 void fill_ctdb_g_lock(TALLOC_CTX *mem_ctx, struct ctdb_g_lock *p)
1318 {
1319         p->type = rand_int(2);
1320         fill_ctdb_server_id(mem_ctx, &p->sid);
1321 }
1322
1323 void verify_ctdb_g_lock(struct ctdb_g_lock *p1, struct ctdb_g_lock *p2)
1324 {
1325         assert(p1->type == p2->type);
1326         verify_ctdb_server_id(&p1->sid, &p2->sid);
1327 }
1328
1329 void fill_ctdb_g_lock_list(TALLOC_CTX *mem_ctx, struct ctdb_g_lock_list *p)
1330 {
1331         int i;
1332
1333         p->num = rand_int(20) + 1;
1334         p->lock = talloc_array(mem_ctx, struct ctdb_g_lock, p->num);
1335         assert(p->lock != NULL);
1336         for (i=0; i<p->num; i++) {
1337                 fill_ctdb_g_lock(mem_ctx, &p->lock[i]);
1338         }
1339 }
1340
1341 void verify_ctdb_g_lock_list(struct ctdb_g_lock_list *p1,
1342                              struct ctdb_g_lock_list *p2)
1343 {
1344         int i;
1345
1346         assert(p1->num == p2->num);
1347         for (i=0; i<p1->num; i++) {
1348                 verify_ctdb_g_lock(&p1->lock[i], &p2->lock[i]);
1349         }
1350 }