From: Martin Schwenke Date: Sat, 11 Aug 2018 08:32:17 +0000 (+1000) Subject: ctdb-tests: Add basic test to sanity check types in socket marshalling X-Git-Tag: tdb-1.3.17~1980 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0927b382265191a756f131e7c81ac687d85353eb;p=thirdparty%2Fsamba.git ctdb-tests: Add basic test to sanity check types in socket marshalling Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/tests/cunit/system_socket_test_001.sh b/ctdb/tests/cunit/system_socket_test_001.sh new file mode 100755 index 00000000000..389cec6ac8c --- /dev/null +++ b/ctdb/tests/cunit/system_socket_test_001.sh @@ -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 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 . +*/ + +#include + +#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 [ ...]\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; +} diff --git a/ctdb/wscript b/ctdb/wscript index 323da8cf12a..43baee6f68b 100644 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -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',