2 protocol tests - common functions
4 Copyright (C) Amitay Isaacs 2015-2017
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.
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.
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/>.
21 #include "system/network.h"
25 #include "protocol/protocol_api.h"
27 #include "tests/src/protocol_common.h"
29 uint8_t BUFFER[1024*1024];
32 * Functions to generation random data
37 return random() % max;
42 uint8_t val = rand_int(256) & 0xff;
48 uint16_t val = rand_int(0xffff) & 0xffff;
54 return INT_MIN + random();
64 uint64_t t = random();
65 t = (t << 32) | random();
69 double rand_double(void)
71 return 1.0 / rand64();
74 void fill_buffer(void *p, size_t len)
79 for (i=0; i<len; i++) {
84 void verify_buffer(void *p1, void *p2, size_t len)
87 assert(memcmp(p1, p2, len) == 0);
91 static void fill_string(char *p, size_t len)
95 for (i=0; i<len-1; i++) {
96 p[i] = 'A' + rand_int(26);
101 static void verify_string(const char *p1, const char *p2)
103 assert(strlen(p1) == strlen(p2));
104 assert(strcmp(p1, p2) == 0);
107 void fill_ctdb_uint8(uint8_t *p)
112 void verify_ctdb_uint8(uint8_t *p1, uint8_t *p2)
117 void fill_ctdb_uint16(uint16_t *p)
122 void verify_ctdb_uint16(uint16_t *p1, uint16_t *p2)
127 void fill_ctdb_int32(int32_t *p)
132 void verify_ctdb_int32(int32_t *p1, int32_t *p2)
137 void fill_ctdb_uint32(uint32_t *p)
142 void verify_ctdb_uint32(uint32_t *p1, uint32_t *p2)
147 void fill_ctdb_uint64(uint64_t *p)
152 void verify_ctdb_uint64(uint64_t *p1, uint64_t *p2)
157 void fill_ctdb_double(double *p)
162 void verify_ctdb_double(double *p1, double *p2)
167 void fill_ctdb_bool(bool *p)
169 if (rand_int(2) == 0) {
176 void verify_ctdb_bool(bool *p1, bool *p2)
181 void fill_ctdb_string(TALLOC_CTX *mem_ctx, const char **p)
186 len = rand_int(1024) + 2;
187 str = talloc_size(mem_ctx, len+1);
190 fill_string(str, len);
194 void verify_ctdb_string(const char **p1, const char **p2)
196 if (*p1 == NULL || *p2 == NULL) {
199 verify_string(*p1, *p2);
203 void fill_ctdb_stringn(TALLOC_CTX *mem_ctx, const char **p)
205 fill_ctdb_string(mem_ctx, p);
208 void verify_ctdb_stringn(const char **p1, const char **p2)
210 verify_ctdb_string(p1, p2);
213 void fill_ctdb_pid(pid_t *p)
218 void verify_ctdb_pid(pid_t *p1, pid_t *p2)
223 void fill_ctdb_timeval(struct timeval *p)
225 p->tv_sec = rand32();
226 p->tv_usec = rand_int(1000000);
229 void verify_ctdb_timeval(struct timeval *p1, struct timeval *p2)
231 assert(p1->tv_sec == p2->tv_sec);
232 assert(p1->tv_usec == p2->tv_usec);
235 void fill_tdb_data_nonnull(TALLOC_CTX *mem_ctx, TDB_DATA *p)
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);
243 void fill_tdb_data(TALLOC_CTX *mem_ctx, TDB_DATA *p)
245 if (rand_int(5) == 0) {
249 fill_tdb_data_nonnull(mem_ctx, p);
253 void verify_tdb_data(TDB_DATA *p1, TDB_DATA *p2)
255 assert(p1->dsize == p2->dsize);
256 verify_buffer(p1->dptr, p2->dptr, p1->dsize);
259 void fill_ctdb_tdb_data(TALLOC_CTX *mem_ctx, TDB_DATA *p)
261 fill_tdb_data(mem_ctx, p);
264 void verify_ctdb_tdb_data(TDB_DATA *p1, TDB_DATA *p2)
266 verify_tdb_data(p1, p2);
269 void fill_ctdb_tdb_datan(TALLOC_CTX *mem_ctx, TDB_DATA *p)
271 fill_tdb_data(mem_ctx, p);
274 void verify_ctdb_tdb_datan(TDB_DATA *p1, TDB_DATA *p2)
276 verify_tdb_data(p1, p2);
279 void fill_ctdb_latency_counter(struct ctdb_latency_counter *p)
282 p->min = rand_double();
283 p->max = rand_double();
284 p->total = rand_double();
287 void verify_ctdb_latency_counter(struct ctdb_latency_counter *p1,
288 struct ctdb_latency_counter *p2)
290 assert(p1->num == p2->num);
291 assert(p1->min == p2->min);
292 assert(p1->max == p2->max);
293 assert(p1->total == p2->total);
296 void fill_ctdb_statistics(TALLOC_CTX *mem_ctx, struct ctdb_statistics *p)
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();
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();
319 p->client.req_call = rand32();
320 p->client.req_message = rand32();
321 p->client.req_control = rand32();
323 p->timeouts.call = rand32();
324 p->timeouts.control = rand32();
325 p->timeouts.traverse = rand32();
327 fill_ctdb_latency_counter(&p->reclock.ctdbd);
328 fill_ctdb_latency_counter(&p->reclock.recd);
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();
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();
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();
358 void verify_ctdb_statistics(struct ctdb_statistics *p1,
359 struct ctdb_statistics *p2)
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);
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);
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);
386 assert(p1->timeouts.call == p2->timeouts.call);
387 assert(p1->timeouts.control == p2->timeouts.control);
388 assert(p1->timeouts.traverse == p2->timeouts.traverse);
390 verify_ctdb_latency_counter(&p1->reclock.ctdbd, &p2->reclock.ctdbd);
391 verify_ctdb_latency_counter(&p1->reclock.recd, &p2->reclock.recd);
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]);
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]);
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);
424 void fill_ctdb_vnn_map(TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *p)
428 p->generation = rand32();
429 p->size = rand_int(20);
431 p->map = talloc_array(mem_ctx, uint32_t, p->size);
432 assert(p->map != NULL);
434 for (i=0; i<p->size; i++) {
435 p->map[i] = rand32();
442 void verify_ctdb_vnn_map(struct ctdb_vnn_map *p1, struct ctdb_vnn_map *p2)
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]);
453 void fill_ctdb_dbid(TALLOC_CTX *mem_ctx, struct ctdb_dbid *p)
459 void verify_ctdb_dbid(struct ctdb_dbid *p1, struct ctdb_dbid *p2)
461 assert(p1->db_id == p2->db_id);
462 assert(p1->flags == p2->flags);
465 void fill_ctdb_dbid_map(TALLOC_CTX *mem_ctx, struct ctdb_dbid_map *p)
469 p->num = rand_int(40);
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]);
481 void verify_ctdb_dbid_map(struct ctdb_dbid_map *p1, struct ctdb_dbid_map *p2)
485 assert(p1->num == p2->num);
486 for (i=0; i<p1->num; i++) {
487 verify_ctdb_dbid(&p1->dbs[i], &p2->dbs[i]);
491 void fill_ctdb_pulldb(TALLOC_CTX *mem_ctx, struct ctdb_pulldb *p)
494 p->lmaster = rand32();
497 void verify_ctdb_pulldb(struct ctdb_pulldb *p1, struct ctdb_pulldb *p2)
499 assert(p1->db_id == p2->db_id);
500 assert(p1->lmaster == p2->lmaster);
503 void fill_ctdb_pulldb_ext(TALLOC_CTX *mem_ctx, struct ctdb_pulldb_ext *p)
506 p->lmaster = rand32();
510 void verify_ctdb_pulldb_ext(struct ctdb_pulldb_ext *p1,
511 struct ctdb_pulldb_ext *p2)
513 assert(p1->db_id == p2->db_id);
514 assert(p1->lmaster == p2->lmaster);
515 assert(p1->srvid == p2->srvid);
518 void fill_ctdb_ltdb_header(struct ctdb_ltdb_header *p)
521 p->dmaster = rand32();
522 p->reserved1 = rand32();
526 void verify_ctdb_ltdb_header(struct ctdb_ltdb_header *p1,
527 struct ctdb_ltdb_header *p2)
529 assert(p1->rsn == p2->rsn);
530 assert(p1->dmaster == p2->dmaster);
531 assert(p1->reserved1 == p2->reserved1);
532 assert(p1->flags == p2->flags);
535 void fill_ctdb_rec_data(TALLOC_CTX *mem_ctx, struct ctdb_rec_data *p)
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);
545 fill_tdb_data_nonnull(mem_ctx, &p->key);
546 fill_tdb_data(mem_ctx, &p->data);
549 void verify_ctdb_rec_data(struct ctdb_rec_data *p1, struct ctdb_rec_data *p2)
551 struct ctdb_ltdb_header header;
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);
558 verify_tdb_data(&p1->key, &p2->key);
559 verify_tdb_data(&p1->data, &p2->data);
562 void fill_ctdb_rec_buffer(TALLOC_CTX *mem_ctx, struct ctdb_rec_buffer *p)
564 struct ctdb_rec_data rec;
573 count = rand_int(100);
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,
585 void verify_ctdb_rec_buffer(struct ctdb_rec_buffer *p1,
586 struct ctdb_rec_buffer *p2)
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);
594 void fill_ctdb_traverse_start(TALLOC_CTX *mem_ctx,
595 struct ctdb_traverse_start *p)
602 void verify_ctdb_traverse_start(struct ctdb_traverse_start *p1,
603 struct ctdb_traverse_start *p2)
605 assert(p1->db_id == p2->db_id);
606 assert(p1->reqid == p2->reqid);
607 assert(p1->srvid == p2->srvid);
610 void fill_ctdb_traverse_all(TALLOC_CTX *mem_ctx,
611 struct ctdb_traverse_all *p)
616 p->client_reqid = rand32();
620 void verify_ctdb_traverse_all(struct ctdb_traverse_all *p1,
621 struct ctdb_traverse_all *p2)
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);
630 void fill_ctdb_traverse_start_ext(TALLOC_CTX *mem_ctx,
631 struct ctdb_traverse_start_ext *p)
636 p->withemptyrecords = rand_int(2);
639 void verify_ctdb_traverse_start_ext(struct ctdb_traverse_start_ext *p1,
640 struct ctdb_traverse_start_ext *p2)
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);
648 void fill_ctdb_traverse_all_ext(TALLOC_CTX *mem_ctx,
649 struct ctdb_traverse_all_ext *p)
654 p->client_reqid = rand32();
656 p->withemptyrecords = rand_int(2);
659 void verify_ctdb_traverse_all_ext(struct ctdb_traverse_all_ext *p1,
660 struct ctdb_traverse_all_ext *p2)
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);
670 void fill_ctdb_sock_addr(TALLOC_CTX *mem_ctx, ctdb_sock_addr *p)
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));
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));
683 void verify_ctdb_sock_addr(ctdb_sock_addr *p1, ctdb_sock_addr *p2)
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));
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));
697 void fill_ctdb_connection(TALLOC_CTX *mem_ctx, struct ctdb_connection *p)
699 fill_ctdb_sock_addr(mem_ctx, &p->src);
700 fill_ctdb_sock_addr(mem_ctx, &p->dst);
703 void verify_ctdb_connection(struct ctdb_connection *p1,
704 struct ctdb_connection *p2)
706 verify_ctdb_sock_addr(&p1->src, &p2->src);
707 verify_ctdb_sock_addr(&p1->dst, &p2->dst);
710 void fill_ctdb_connection_list(TALLOC_CTX *mem_ctx,
711 struct ctdb_connection_list *p)
715 p->num = rand_int(1000);
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]);
727 void verify_ctdb_connection_list(struct ctdb_connection_list *p1,
728 struct ctdb_connection_list *p2)
732 assert(p1->num == p2->num);
733 for (i=0; i<p1->num; i++) {
734 verify_ctdb_connection(&p1->conn[i], &p2->conn[i]);
738 void fill_ctdb_tunable(TALLOC_CTX *mem_ctx, struct ctdb_tunable *p)
740 fill_ctdb_string(mem_ctx, &p->name);
744 void verify_ctdb_tunable(struct ctdb_tunable *p1, struct ctdb_tunable *p2)
746 verify_ctdb_string(&p1->name, &p2->name);
747 assert(p1->value == p2->value);
750 void fill_ctdb_node_flag_change(TALLOC_CTX *mem_ctx,
751 struct ctdb_node_flag_change *p)
754 p->new_flags = rand32();
755 p->old_flags = rand32();
758 void verify_ctdb_node_flag_change(struct ctdb_node_flag_change *p1,
759 struct ctdb_node_flag_change *p2)
761 assert(p1->pnn == p2->pnn);
762 assert(p1->new_flags == p2->new_flags);
763 assert(p1->old_flags == p2->old_flags);
766 void fill_ctdb_var_list(TALLOC_CTX *mem_ctx, struct ctdb_var_list *p)
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]);
777 void verify_ctdb_var_list(struct ctdb_var_list *p1, struct ctdb_var_list *p2)
781 assert(p1->count == p2->count);
782 for (i=0; i<p1->count; i++) {
783 verify_ctdb_string(&p1->var[i], &p2->var[i]);
787 void fill_ctdb_tunable_list(TALLOC_CTX *mem_ctx, struct ctdb_tunable_list *p)
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();
853 void verify_ctdb_tunable_list(struct ctdb_tunable_list *p1,
854 struct ctdb_tunable_list *p2)
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);
920 void fill_ctdb_tickle_list(TALLOC_CTX *mem_ctx, struct ctdb_tickle_list *p)
924 fill_ctdb_sock_addr(mem_ctx, &p->addr);
925 p->num = rand_int(1000);
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]);
937 void verify_ctdb_tickle_list(struct ctdb_tickle_list *p1,
938 struct ctdb_tickle_list *p2)
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]);
949 void fill_ctdb_addr_info(TALLOC_CTX *mem_ctx, struct ctdb_addr_info *p)
951 fill_ctdb_sock_addr(mem_ctx, &p->addr);
952 p->mask = rand_int(33);
953 if (rand_int(2) == 0) {
956 fill_ctdb_string(mem_ctx, &p->iface);
960 void verify_ctdb_addr_info(struct ctdb_addr_info *p1,
961 struct ctdb_addr_info *p2)
963 verify_ctdb_sock_addr(&p1->addr, &p2->addr);
964 assert(p1->mask == p2->mask);
965 verify_ctdb_string(&p1->iface, &p2->iface);
968 void fill_ctdb_transdb(TALLOC_CTX *mem_ctx, struct ctdb_transdb *p)
974 void verify_ctdb_transdb(struct ctdb_transdb *p1, struct ctdb_transdb *p2)
976 assert(p1->db_id == p2->db_id);
977 assert(p1->tid == p2->tid);
980 void fill_ctdb_uptime(TALLOC_CTX *mem_ctx, struct ctdb_uptime *p)
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);
988 void verify_ctdb_uptime(struct ctdb_uptime *p1, struct ctdb_uptime *p2)
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);
998 void fill_ctdb_public_ip(TALLOC_CTX *mem_ctx, struct ctdb_public_ip *p)
1001 fill_ctdb_sock_addr(mem_ctx, &p->addr);
1004 void verify_ctdb_public_ip(struct ctdb_public_ip *p1,
1005 struct ctdb_public_ip *p2)
1007 assert(p1->pnn == p2->pnn);
1008 verify_ctdb_sock_addr(&p1->addr, &p2->addr);
1011 void fill_ctdb_public_ip_list(TALLOC_CTX *mem_ctx,
1012 struct ctdb_public_ip_list *p)
1016 p->num = rand_int(32);
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]);
1028 void verify_ctdb_public_ip_list(struct ctdb_public_ip_list *p1,
1029 struct ctdb_public_ip_list *p2)
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]);
1039 void fill_ctdb_node_and_flags(TALLOC_CTX *mem_ctx,
1040 struct ctdb_node_and_flags *p)
1043 p->flags = rand32();
1044 fill_ctdb_sock_addr(mem_ctx, &p->addr);
1047 void verify_ctdb_node_and_flags(struct ctdb_node_and_flags *p1,
1048 struct ctdb_node_and_flags *p2)
1050 assert(p1->pnn == p2->pnn);
1051 assert(p1->flags == p2->flags);
1052 verify_ctdb_sock_addr(&p1->addr, &p2->addr);
1055 void fill_ctdb_node_map(TALLOC_CTX *mem_ctx, struct ctdb_node_map *p)
1059 p->num = rand_int(32);
1061 p->node = talloc_array(mem_ctx, struct ctdb_node_and_flags,
1063 assert(p->node != NULL);
1064 for (i=0; i<p->num; i++) {
1065 fill_ctdb_node_and_flags(mem_ctx, &p->node[i]);
1072 void verify_ctdb_node_map(struct ctdb_node_map *p1, struct ctdb_node_map *p2)
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]);
1082 void fill_ctdb_script(TALLOC_CTX *mem_ctx, struct ctdb_script *p)
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);
1091 void verify_ctdb_script(struct ctdb_script *p1, struct ctdb_script *p2)
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);
1100 void fill_ctdb_script_list(TALLOC_CTX *mem_ctx, struct ctdb_script_list *p)
1104 p->num_scripts = rand_int(32);
1105 if (p->num_scripts > 0) {
1106 p->script = talloc_zero_array(mem_ctx, struct ctdb_script,
1108 assert(p->script != NULL);
1109 for (i=0; i<p->num_scripts; i++) {
1110 fill_ctdb_script(mem_ctx, &p->script[i]);
1117 void verify_ctdb_script_list(struct ctdb_script_list *p1,
1118 struct ctdb_script_list *p2)
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]);
1128 void fill_ctdb_ban_state(TALLOC_CTX *mem_ctx, struct ctdb_ban_state *p)
1134 void verify_ctdb_ban_state(struct ctdb_ban_state *p1,
1135 struct ctdb_ban_state *p2)
1137 assert(p1->pnn == p2->pnn);
1138 assert(p1->time == p2->time);
1141 void fill_ctdb_notify_data(TALLOC_CTX *mem_ctx, struct ctdb_notify_data *p)
1143 p->srvid = rand64();
1144 fill_tdb_data(mem_ctx, &p->data);
1147 void verify_ctdb_notify_data(struct ctdb_notify_data *p1,
1148 struct ctdb_notify_data *p2)
1150 assert(p1->srvid == p2->srvid);
1151 verify_tdb_data(&p1->data, &p2->data);
1154 void fill_ctdb_iface(TALLOC_CTX *mem_ctx, struct ctdb_iface *p)
1156 fill_string(p->name, CTDB_IFACE_SIZE+2);
1157 p->link_state = rand16();
1158 p->references = rand32();
1161 void verify_ctdb_iface(struct ctdb_iface *p1, struct ctdb_iface *p2)
1163 verify_string(p1->name, p2->name);
1164 assert(p1->link_state == p2->link_state);
1165 assert(p1->references == p2->references);
1168 void fill_ctdb_iface_list(TALLOC_CTX *mem_ctx, struct ctdb_iface_list *p)
1172 p->num = rand_int(32);
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]);
1184 void verify_ctdb_iface_list(struct ctdb_iface_list *p1,
1185 struct ctdb_iface_list *p2)
1189 assert(p1->num == p2->num);
1190 for (i=0; i<p1->num; i++) {
1191 verify_ctdb_iface(&p1->iface[i], &p2->iface[i]);
1195 void fill_ctdb_public_ip_info(TALLOC_CTX *mem_ctx,
1196 struct ctdb_public_ip_info *p)
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);
1205 void verify_ctdb_public_ip_info(struct ctdb_public_ip_info *p1,
1206 struct ctdb_public_ip_info *p2)
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);
1213 void fill_ctdb_statistics_list(TALLOC_CTX *mem_ctx,
1214 struct ctdb_statistics_list *p)
1218 p->num = rand_int(10);
1220 p->stats = talloc_zero_array(mem_ctx, struct ctdb_statistics,
1222 assert(p->stats != NULL);
1224 for (i=0; i<p->num; i++) {
1225 fill_ctdb_statistics(mem_ctx, &p->stats[i]);
1232 void verify_ctdb_statistics_list(struct ctdb_statistics_list *p1,
1233 struct ctdb_statistics_list *p2)
1237 assert(p1->num == p2->num);
1238 for (i=0; i<p1->num; i++) {
1239 verify_ctdb_statistics(&p1->stats[i], &p2->stats[i]);
1243 void fill_ctdb_key_data(TALLOC_CTX *mem_ctx, struct ctdb_key_data *p)
1245 p->db_id = rand32();
1246 fill_ctdb_ltdb_header(&p->header);
1247 fill_tdb_data_nonnull(mem_ctx, &p->key);
1250 void verify_ctdb_key_data(struct ctdb_key_data *p1, struct ctdb_key_data *p2)
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);
1257 void fill_ctdb_db_statistics(TALLOC_CTX *mem_ctx,
1258 struct ctdb_db_statistics *p)
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();
1271 fill_ctdb_latency_counter(&p->vacuum.latency);
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();
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);
1286 void verify_ctdb_db_statistics(struct ctdb_db_statistics *p1,
1287 struct ctdb_db_statistics *p2)
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]);
1300 verify_ctdb_latency_counter(&p1->vacuum.latency, &p2->vacuum.latency);
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]);
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);
1315 void fill_ctdb_pid_srvid(TALLOC_CTX *mem_ctx, struct ctdb_pid_srvid *p)
1318 p->srvid = rand64();
1321 void verify_ctdb_pid_srvid(struct ctdb_pid_srvid *p1,
1322 struct ctdb_pid_srvid *p2)
1324 assert(p1->pid == p2->pid);
1325 assert(p1->srvid == p2->srvid);
1328 void fill_ctdb_election_message(TALLOC_CTX *mem_ctx,
1329 struct ctdb_election_message *p)
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();
1337 void verify_ctdb_election_message(struct ctdb_election_message *p1,
1338 struct ctdb_election_message *p2)
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);
1346 void fill_ctdb_srvid_message(TALLOC_CTX *mem_ctx,
1347 struct ctdb_srvid_message *p)
1349 p->pnn = rand_int(32);
1350 p->srvid = rand64();
1353 void verify_ctdb_srvid_message(struct ctdb_srvid_message *p1,
1354 struct ctdb_srvid_message *p2)
1356 assert(p1->pnn == p2->pnn);
1357 assert(p1->srvid == p2->srvid);
1360 void fill_ctdb_disable_message(TALLOC_CTX *mem_ctx,
1361 struct ctdb_disable_message *p)
1363 p->pnn = rand_int(32);
1364 p->srvid = rand64();
1365 p->timeout = rand32();
1368 void verify_ctdb_disable_message(struct ctdb_disable_message *p1,
1369 struct ctdb_disable_message *p2)
1371 assert(p1->pnn == p2->pnn);
1372 assert(p1->srvid == p2->srvid);
1373 assert(p1->timeout == p2->timeout);
1376 void fill_ctdb_server_id(struct ctdb_server_id *p)
1379 p->task_id = rand32();
1380 p->vnn = rand_int(32);
1381 p->unique_id = rand64();
1384 void verify_ctdb_server_id(struct ctdb_server_id *p1,
1385 struct ctdb_server_id *p2)
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);
1393 void fill_ctdb_g_lock(struct ctdb_g_lock *p)
1395 p->type = rand_int(2);
1396 fill_ctdb_server_id(&p->sid);
1399 void verify_ctdb_g_lock(struct ctdb_g_lock *p1, struct ctdb_g_lock *p2)
1401 assert(p1->type == p2->type);
1402 verify_ctdb_server_id(&p1->sid, &p2->sid);
1405 void fill_ctdb_g_lock_list(TALLOC_CTX *mem_ctx, struct ctdb_g_lock_list *p)
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]);
1417 void verify_ctdb_g_lock_list(struct ctdb_g_lock_list *p1,
1418 struct ctdb_g_lock_list *p2)
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]);
1428 void fill_sock_packet_header(struct sock_packet_header *p)
1430 p->length = rand32();
1431 p->reqid = rand32();
1434 void verify_sock_packet_header(struct sock_packet_header *p1,
1435 struct sock_packet_header *p2)
1437 assert(p1->length == p2->length);
1438 assert(p1->reqid == p2->reqid);