summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-08-14 16:28:16 +1000
committerMartin Schwenke <martins@samba.org>2017-08-30 14:59:22 +0200
commit82b7ec031d2a2896065f97c2b1041008903c5e06 (patch)
treeea781585fc620cc944de634214e56a52a9aaa0fa
parentfc3f6147189c7c4a5fa2c7ee75c9aef18c0e1a73 (diff)
downloadsamba-82b7ec031d2a2896065f97c2b1041008903c5e06.tar.gz
ctdb-tests: Add compatibility test for protocol data types
This patch prepares for testing old and new marshalling codes for various data types to ensure backward compatibility. Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
-rwxr-xr-xctdb/tests/cunit/protocol_test_012.sh9
-rw-r--r--ctdb/tests/src/protocol_types_compat_test.c104
-rw-r--r--ctdb/wscript1
3 files changed, 114 insertions, 0 deletions
diff --git a/ctdb/tests/cunit/protocol_test_012.sh b/ctdb/tests/cunit/protocol_test_012.sh
new file mode 100755
index 00000000000..6137ac5773b
--- /dev/null
+++ b/ctdb/tests/cunit/protocol_test_012.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+ok_null
+
+for i in $(seq 1 1000) ; do
+ unit_test protocol_types_compat_test $i
+done
diff --git a/ctdb/tests/src/protocol_types_compat_test.c b/ctdb/tests/src/protocol_types_compat_test.c
new file mode 100644
index 00000000000..c7d96655e33
--- /dev/null
+++ b/ctdb/tests/src/protocol_types_compat_test.c
@@ -0,0 +1,104 @@
+/*
+ protocol types backward compatibility test
+
+ Copyright (C) Amitay Isaacs 2015
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "system/filesys.h"
+
+#include <assert.h>
+
+#include "protocol/protocol_basic.c"
+#include "protocol/protocol_types.c"
+
+#include "tests/src/protocol_common.h"
+
+#define COMPAT_TEST_FUNC(NAME) test_ ##NAME## _compat
+#define OLD_LEN_FUNC(NAME) NAME## _len_old
+#define OLD_PUSH_FUNC(NAME) NAME## _push_old
+#define OLD_PULL_FUNC(NAME) NAME## _pull_old
+
+#define COMPAT_TYPE1_TEST(TYPE, NAME) \
+static void COMPAT_TEST_FUNC(NAME)(void) \
+{ \
+ TALLOC_CTX *mem_ctx; \
+ uint8_t *buf1, *buf2; \
+ TYPE p = { 0 }, p1, p2; \
+ size_t buflen1, buflen2, np = 0; \
+ int ret; \
+\
+ mem_ctx = talloc_new(NULL); \
+ assert(mem_ctx != NULL); \
+ FILL_FUNC(NAME)(&p); \
+ buflen1 = LEN_FUNC(NAME)(&p); \
+ buflen2 = OLD_LEN_FUNC(NAME)(&p); \
+ assert(buflen1 == buflen2); \
+ buf1 = talloc_zero_size(mem_ctx, buflen1); \
+ assert(buf1 != NULL); \
+ buf2 = talloc_zero_size(mem_ctx, buflen2); \
+ assert(buf2 != NULL); \
+ PUSH_FUNC(NAME)(&p, buf1, &np); \
+ OLD_PUSH_FUNC(NAME)(&p, buf2); \
+ assert(memcmp(buf1, buf2, buflen1) == 0); \
+ ret = PULL_FUNC(NAME)(buf1, buflen1, &p1, &np); \
+ assert(ret == 0); \
+ ret = OLD_PULL_FUNC(NAME)(buf2, buflen2, &p2); \
+ VERIFY_FUNC(NAME)(&p1, &p2); \
+ talloc_free(mem_ctx); \
+}
+
+#define COMPAT_TYPE3_TEST(TYPE, NAME) \
+static void COMPAT_TEST_FUNC(NAME)(void) \
+{ \
+ TALLOC_CTX *mem_ctx; \
+ uint8_t *buf1, *buf2; \
+ TYPE *p, *p1, *p2; \
+ size_t buflen1, buflen2, np = 0; \
+ int ret; \
+\
+ mem_ctx = talloc_new(NULL); \
+ assert(mem_ctx != NULL); \
+ p = talloc_zero(mem_ctx, TYPE); \
+ assert(p != NULL); \
+ FILL_FUNC(NAME)(p, p); \
+ buflen1 = LEN_FUNC(NAME)(p); \
+ buflen2 = OLD_LEN_FUNC(NAME)(p); \
+ assert(buflen1 == buflen2); \
+ buf1 = talloc_zero_size(mem_ctx, buflen1); \
+ assert(buf1 != NULL); \
+ buf2 = talloc_zero_size(mem_ctx, buflen2); \
+ assert(buf2 != NULL); \
+ PUSH_FUNC(NAME)(p, buf1, &np); \
+ OLD_PUSH_FUNC(NAME)(p, buf2); \
+ assert(memcmp(buf1, buf2, buflen1) == 0); \
+ ret = PULL_FUNC(NAME)(buf1, buflen1, mem_ctx, &p1, &np); \
+ assert(ret == 0); \
+ ret = OLD_PULL_FUNC(NAME)(buf2, buflen2, mem_ctx, &p2); \
+ VERIFY_FUNC(NAME)(p1, p2); \
+ talloc_free(mem_ctx); \
+}
+
+
+int main(int argc, char *argv[])
+{
+ if (argc == 2) {
+ int seed = atoi(argv[1]);
+ srandom(seed);
+ }
+
+ return 0;
+}
diff --git a/ctdb/wscript b/ctdb/wscript
index c23e840f4e7..071fcb56956 100644
--- a/ctdb/wscript
+++ b/ctdb/wscript
@@ -780,6 +780,7 @@ def build(bld):
'protocol_ctdb_test',
'protocol_event_test',
'protocol_util_test',
+ 'protocol_types_compat_test',
]
for target in ctdb_protocol_tests: