1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

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>
This commit is contained in:
Martin Schwenke 2018-08-11 18:32:17 +10:00 committed by Amitay Isaacs
parent 7c361f4866
commit 0927b38226
3 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,6 @@
#!/bin/sh
. "${TEST_SCRIPTS_DIR}/unit.sh"
ok_null
unit_test system_socket_test types

View File

@ -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;
}

View 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',