ctdb-tests: Add test templates for eventd protocol elements
authorAmitay Isaacs <amitay@gmail.com>
Fri, 4 Aug 2017 07:34:14 +0000 (17:34 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 30 Aug 2017 12:59:26 +0000 (14:59 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tests/src/protocol_event_test.c

index 027e09e6f9b804d245ecfc09f0c7487725daf196..df911eebd7998a6e08860b54948ddb8335a7faec 100644 (file)
  * 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;