]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Add basic test to sanity check types in socket marshalling
authorMartin Schwenke <martin@meltin.net>
Sat, 11 Aug 2018 08:32:17 +0000 (18:32 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 30 Aug 2018 02:48:57 +0000 (04:48 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/cunit/system_socket_test_001.sh [new file with mode: 0755]
ctdb/tests/src/system_socket_test.c [new file with mode: 0644]
ctdb/wscript

diff --git a/ctdb/tests/cunit/system_socket_test_001.sh b/ctdb/tests/cunit/system_socket_test_001.sh
new file mode 100755 (executable)
index 0000000..389cec6
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+. "${TEST_SCRIPTS_DIR}/unit.sh"
+
+ok_null
+unit_test system_socket_test types
diff --git a/ctdb/tests/src/system_socket_test.c b/ctdb/tests/src/system_socket_test.c
new file mode 100644 (file)
index 0000000..61dfa39
--- /dev/null
@@ -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;
+}
index 323da8cf12a3c2b9913ee72c9246433d9e49b2d6..43baee6f68bb8d7e07ab8bf77711416cb57fad38 100644 (file)
@@ -915,6 +915,11 @@ def build(bld):
                      deps='talloc tevent tdb ctdb-protocol',
                      install_path='${CTDB_TEST_LIBEXECDIR}')
 
+    bld.SAMBA_BINARY('system_socket_test',
+                     source='tests/src/system_socket_test.c',
+                     deps='talloc ctdb-protocol-util',
+                     install_path='${CTDB_TEST_LIBEXECDIR}')
+
     bld.SAMBA_BINARY('porting_tests',
                      source='tests/src/porting_tests.c',
                      deps='samba-util ctdb-system popt',