summaryrefslogtreecommitdiff
path: root/ctdb/tests/src
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2018-08-11 18:32:17 +1000
committerAmitay Isaacs <amitay@samba.org>2018-08-30 04:48:57 +0200
commit0927b382265191a756f131e7c81ac687d85353eb (patch)
treee77770ad37b85c4f542952ac0ccaf69264898b5e /ctdb/tests/src
parent7c361f4866ca9a2989d214cf132df56a78a8c638 (diff)
downloadsamba-0927b382265191a756f131e7c81ac687d85353eb.tar.gz
ctdb-tests: Add basic test to sanity check types in socket marshalling
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/tests/src')
-rw-r--r--ctdb/tests/src/system_socket_test.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/ctdb/tests/src/system_socket_test.c b/ctdb/tests/src/system_socket_test.c
new file mode 100644
index 00000000000..61dfa3970c1
--- /dev/null
+++ b/ctdb/tests/src/system_socket_test.c
@@ -0,0 +1,63 @@
+/*
+ Raw socket (un) marshalling tests
+
+ Copyright (C) Martin Schwenke 2018
+
+ 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 <assert.h>
+
+#include "common/system_socket.c"
+
+#include "protocol/protocol_util.h"
+
+static void test_types(void)
+{
+ /*
+ * We use this struct in the code but don't pack it due to
+ * portability concerns. It should have no padding.
+ */
+ struct {
+ struct ip ip;
+ struct tcphdr tcp;
+ } ip4pkt;
+
+ assert(sizeof(ip4pkt) == sizeof(struct ip) + sizeof(struct tcphdr));
+}
+
+static void usage(const char *prog)
+{
+ fprintf(stderr, "usage: %s <cmd> [<arg> ...]\n", prog);
+ fprintf(stderr, " commands:\n");
+ fprintf(stderr, " types\n");
+
+ exit(1);
+}
+
+int main(int argc, char **argv)
+{
+
+ if (argc < 2) {
+ usage(argv[0]);
+ }
+
+ if (strcmp(argv[1], "types") == 0) {
+ test_types();
+ } else {
+ usage(argv[0]);
+ }
+
+ return 0;
+}