diff options
Diffstat (limited to 'ctdb/tests/src')
-rw-r--r-- | ctdb/tests/src/protocol_common_ctdb.c | 14 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_common_ctdb.h | 5 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_ctdb_compat_test.c | 69 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_ctdb_test.c | 6 |
4 files changed, 94 insertions, 0 deletions
diff --git a/ctdb/tests/src/protocol_common_ctdb.c b/ctdb/tests/src/protocol_common_ctdb.c index be9e2560cc6..26b1ad65d80 100644 --- a/ctdb/tests/src/protocol_common_ctdb.c +++ b/ctdb/tests/src/protocol_common_ctdb.c @@ -1948,3 +1948,17 @@ void verify_ctdb_req_message_data(struct ctdb_req_message_data *c, assert(c->srvid == c2->srvid); verify_tdb_data(&c->data, &c2->data); } + +void fill_ctdb_req_keepalive(TALLOC_CTX *mem_ctx, + struct ctdb_req_keepalive *c) +{ + c->version = rand32(); + c->uptime = rand32(); +} + +void verify_ctdb_req_keepalive(struct ctdb_req_keepalive *c, + struct ctdb_req_keepalive *c2) +{ + assert(c->version == c2->version); + assert(c->uptime == c2->uptime); +} diff --git a/ctdb/tests/src/protocol_common_ctdb.h b/ctdb/tests/src/protocol_common_ctdb.h index f5bd16a8ef7..cf22418b623 100644 --- a/ctdb/tests/src/protocol_common_ctdb.h +++ b/ctdb/tests/src/protocol_common_ctdb.h @@ -89,4 +89,9 @@ void fill_ctdb_req_message_data(TALLOC_CTX *mem_ctx, void verify_ctdb_req_message_data(struct ctdb_req_message_data *c, struct ctdb_req_message_data *c2); +void fill_ctdb_req_keepalive(TALLOC_CTX *mem_ctx, + struct ctdb_req_keepalive *c); +void verify_ctdb_req_keepalive(struct ctdb_req_keepalive *c, + struct ctdb_req_keepalive *c2); + #endif /* __CTDB_PROTOCOL_COMMON_CTDB_H__ */ diff --git a/ctdb/tests/src/protocol_ctdb_compat_test.c b/ctdb/tests/src/protocol_ctdb_compat_test.c index 896c82e67d6..8357283d372 100644 --- a/ctdb/tests/src/protocol_ctdb_compat_test.c +++ b/ctdb/tests/src/protocol_ctdb_compat_test.c @@ -28,6 +28,7 @@ #include "protocol/protocol_call.c" #include "protocol/protocol_control.c" #include "protocol/protocol_message.c" +#include "protocol/protocol_keepalive.c" #include "tests/src/protocol_common.h" #include "tests/src/protocol_common_ctdb.h" @@ -1042,6 +1043,70 @@ static int ctdb_req_message_data_pull_old(uint8_t *buf, size_t buflen, return 0; } +struct ctdb_req_keepalive_wire { + struct ctdb_req_header hdr; + uint32_t version; + uint32_t uptime; +}; + +static size_t ctdb_req_keepalive_len_old(struct ctdb_req_header *h, + struct ctdb_req_keepalive *c) +{ + return sizeof(struct ctdb_req_keepalive_wire); +} + +static int ctdb_req_keepalive_push_old(struct ctdb_req_header *h, + struct ctdb_req_keepalive *c, + uint8_t *buf, size_t *buflen) +{ + struct ctdb_req_keepalive_wire *wire = + (struct ctdb_req_keepalive_wire *)buf; + size_t length; + + length = ctdb_req_keepalive_len_old(h, c); + if (*buflen < length) { + *buflen = length; + return EMSGSIZE; + } + + h->length = *buflen; + ctdb_req_header_push_old(h, (uint8_t *)&wire->hdr); + + wire->version = c->version; + wire->uptime = c->uptime; + + return 0; +} + +static int ctdb_req_keepalive_pull_old(uint8_t *buf, size_t buflen, + struct ctdb_req_header *h, + TALLOC_CTX *mem_ctx, + struct ctdb_req_keepalive *c) +{ + struct ctdb_req_keepalive_wire *wire = + (struct ctdb_req_keepalive_wire *)buf; + size_t length; + int ret; + + length = sizeof(struct ctdb_req_keepalive_wire); + if (buflen < length) { + return EMSGSIZE; + } + + if (h != NULL) { + ret = ctdb_req_header_pull_old((uint8_t *)&wire->hdr, buflen, + h); + if (ret != 0) { + return ret; + } + } + + c->version = wire->version; + c->uptime = wire->uptime; + + return 0; +} + COMPAT_CTDB1_TEST(struct ctdb_req_header, ctdb_req_header); @@ -1057,6 +1122,8 @@ COMPAT_CTDB6_TEST(struct ctdb_reply_control, ctdb_reply_control, CTDB_REPLY_CONT COMPAT_CTDB7_TEST(struct ctdb_req_message, ctdb_req_message, CTDB_REQ_MESSAGE); COMPAT_CTDB4_TEST(struct ctdb_req_message_data, ctdb_req_message_data, CTDB_REQ_MESSAGE); +COMPAT_CTDB4_TEST(struct ctdb_req_keepalive, ctdb_req_keepalive, CTDB_REQ_KEEPALIVE); + #define NUM_CONTROLS 151 int main(int argc, char *argv[]) @@ -1110,5 +1177,7 @@ int main(int argc, char *argv[]) } COMPAT_TEST_FUNC(ctdb_req_message_data)(); + COMPAT_TEST_FUNC(ctdb_req_keepalive)(); + return 0; } diff --git a/ctdb/tests/src/protocol_ctdb_test.c b/ctdb/tests/src/protocol_ctdb_test.c index e563b31812b..450f5c2aef4 100644 --- a/ctdb/tests/src/protocol_ctdb_test.c +++ b/ctdb/tests/src/protocol_ctdb_test.c @@ -25,6 +25,7 @@ #include "protocol/protocol_call.c" #include "protocol/protocol_control.c" #include "protocol/protocol_message.c" +#include "protocol/protocol_keepalive.c" #include "protocol/protocol_packet.c" #include "tests/src/protocol_common.h" @@ -305,6 +306,9 @@ PROTOCOL_CTDB7_TEST(struct ctdb_req_message, ctdb_req_message, PROTOCOL_CTDB4_TEST(struct ctdb_req_message_data, ctdb_req_message_data, CTDB_REQ_MESSAGE); +PROTOCOL_CTDB4_TEST(struct ctdb_req_keepalive, ctdb_req_keepalive, + CTDB_REQ_KEEPALIVE); + int main(int argc, char *argv[]) { uint32_t opcode; @@ -366,5 +370,7 @@ int main(int argc, char *argv[]) } TEST_FUNC(ctdb_req_message_data)(); + TEST_FUNC(ctdb_req_keepalive)(); + return 0; } |