diff options
author | Amitay Isaacs <amitay@gmail.com> | 2017-08-04 17:34:14 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2017-08-30 14:59:26 +0200 |
commit | 9d892aeb49705b2b72b2763b088d8a371387a3ae (patch) | |
tree | 2ea5fd747d514f200e14080110bf9f12f8a4cafc /ctdb/tests | |
parent | b9b0c6831531409f7046e0c848ece10748be5c70 (diff) | |
download | samba-9d892aeb49705b2b72b2763b088d8a371387a3ae.tar.gz |
ctdb-tests: Add test templates for eventd protocol elements
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/tests')
-rw-r--r-- | ctdb/tests/src/protocol_event_test.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ctdb/tests/src/protocol_event_test.c b/ctdb/tests/src/protocol_event_test.c index 027e09e6f9b..df911eebd79 100644 --- a/ctdb/tests/src/protocol_event_test.c +++ b/ctdb/tests/src/protocol_event_test.c @@ -33,6 +33,65 @@ * Functions to test eventd protocol marshalling */ +/* for ctdb_event_request_data, ctdb_event_reply_data */ +#define PROTOCOL_EVENT1_TEST(TYPE, NAME) \ +static void TEST_FUNC(NAME)(uint32_t command) \ +{ \ + TALLOC_CTX *mem_ctx; \ + TYPE c1, c2; \ + uint8_t *buf; \ + size_t buflen, np; \ + int ret; \ +\ + printf("%s %u\n", #NAME, command); \ + fflush(stdout); \ + mem_ctx = talloc_new(NULL); \ + assert(mem_ctx != NULL); \ + FILL_FUNC(NAME)(mem_ctx, &c1, command); \ + buflen = LEN_FUNC(NAME)(&c1); \ + buf = talloc_size(mem_ctx, buflen); \ + assert(buf != NULL); \ + np = 0; \ + PUSH_FUNC(NAME)(&c1, buf, &np); \ + assert(np == buflen); \ + np = 0; \ + ret = PULL_FUNC(NAME)(buf, buflen, mem_ctx, &c2, &np); \ + assert(ret == 0); \ + assert(np == buflen); \ + VERIFY_FUNC(NAME)(&c1, &c2); \ + talloc_free(mem_ctx); \ +} + +#define PROTOCOL_EVENT2_TEST(TYPE, NAME) \ +static void TEST_FUNC(NAME)(uint32_t command) \ +{ \ + TALLOC_CTX *mem_ctx; \ + TYPE c1, c2; \ + uint8_t *buf; \ + size_t buflen, len; \ + int ret; \ +\ + printf("%s %u\n", #NAME, command); \ + fflush(stdout); \ + mem_ctx = talloc_new(NULL); \ + assert(mem_ctx != NULL); \ + FILL_FUNC(NAME)(mem_ctx, &c1, command); \ + buflen = LEN_FUNC(NAME)(&c1); \ + buf = talloc_size(mem_ctx, buflen); \ + assert(buf != NULL); \ + len = 0; \ + ret = PUSH_FUNC(NAME)(&c1, buf, &len); \ + assert(ret == EMSGSIZE); \ + assert(len == buflen); \ + ret = PUSH_FUNC(NAME)(&c1, buf, &buflen); \ + assert(ret == 0); \ + ret = PULL_FUNC(NAME)(buf, buflen, mem_ctx, &c2); \ + assert(ret == 0); \ + assert(c2.header.length == buflen); \ + VERIFY_FUNC(NAME)(&c1, &c2); \ + talloc_free(mem_ctx); \ +} + static void test_ctdb_event_header(void) { TALLOC_CTX *mem_ctx; |