mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
ctdb-tests: Use built-in hexdump() in system socket tests
Better compatibility, since od output isn't consistent on FreeBSD. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Tue Mar 10 09:17:12 UTC 2020 on sn-devel-184
This commit is contained in:
parent
602694522f
commit
9f9dcfb6c3
@ -2,29 +2,9 @@
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
out_file="${CTDB_TEST_TMP_DIR}/packet.out"
|
||||
|
||||
remove_file ()
|
||||
{
|
||||
rm -f "$out_file"
|
||||
}
|
||||
|
||||
test_cleanup remove_file
|
||||
|
||||
d=$(dirname "$out_file")
|
||||
mkdir -p "$d"
|
||||
|
||||
########################################
|
||||
|
||||
tcp_run ()
|
||||
{
|
||||
$VALGRIND system_socket_test tcp "$@" >"$out_file" || exit $?
|
||||
od -A x -t x1 "$out_file"
|
||||
}
|
||||
|
||||
tcp_test ()
|
||||
{
|
||||
unit_test_notrace tcp_run "$@"
|
||||
unit_test system_socket_test tcp "$@"
|
||||
}
|
||||
|
||||
ok <<EOF
|
||||
|
@ -2,35 +2,11 @@
|
||||
|
||||
. "${TEST_SCRIPTS_DIR}/unit.sh"
|
||||
|
||||
out_file="${CTDB_TEST_TMP_DIR}/packet.out"
|
||||
|
||||
remove_file ()
|
||||
{
|
||||
rm -f "$out_file"
|
||||
}
|
||||
|
||||
test_cleanup remove_file
|
||||
|
||||
d=$(dirname "$out_file")
|
||||
mkdir -p "$d"
|
||||
|
||||
########################################
|
||||
|
||||
arp_run ()
|
||||
{
|
||||
$VALGRIND system_socket_test arp "$@" >"$out_file" || exit $?
|
||||
od -A x -t x1 "$out_file"
|
||||
}
|
||||
ctdb_test_check_supported_OS "Linux"
|
||||
|
||||
arp_test ()
|
||||
{
|
||||
os=$(uname)
|
||||
if [ "$os" = "Linux" ] ; then
|
||||
unit_test_notrace arp_run "$@"
|
||||
else
|
||||
ok "PACKETSOCKET not supported"
|
||||
unit_test system_socket_test arp "$@"
|
||||
fi
|
||||
unit_test system_socket_test arp "$@"
|
||||
}
|
||||
|
||||
ok <<EOF
|
||||
|
@ -36,6 +36,23 @@
|
||||
|
||||
#include "protocol/protocol_util.h"
|
||||
|
||||
static void hexdump(uint8_t *buf, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (i % 16 == 0) {
|
||||
if (i != 0) {
|
||||
printf("\n");
|
||||
}
|
||||
printf("%06zx", i);
|
||||
}
|
||||
printf(" %02x", buf[i]);
|
||||
}
|
||||
|
||||
printf("\n%06zx\n", i);
|
||||
}
|
||||
|
||||
static void test_types(void)
|
||||
{
|
||||
/*
|
||||
@ -59,7 +76,6 @@ static void test_arp(const char *addr_str, const char *hwaddr_str, bool reply)
|
||||
uint8_t buf[512];
|
||||
size_t buflen = sizeof(buf);
|
||||
size_t len;
|
||||
ssize_t num_written;
|
||||
int ret;
|
||||
|
||||
ret = ctdb_sock_addr_from_string(addr_str, &addr, false);
|
||||
@ -81,8 +97,7 @@ static void test_arp(const char *addr_str, const char *hwaddr_str, bool reply)
|
||||
|
||||
assert(ret == 0);
|
||||
|
||||
num_written = write(STDOUT_FILENO, buf, len);
|
||||
assert(num_written != -1 && (size_t)num_written == len);
|
||||
hexdump(buf, len);
|
||||
}
|
||||
|
||||
#else /* HAVE_PACKETSOCKET */
|
||||
@ -106,7 +121,6 @@ static void test_tcp(const char *src_str,
|
||||
uint8_t buf[512];
|
||||
struct ether_header *eth;
|
||||
size_t expected_len, len;
|
||||
ssize_t num_written;
|
||||
char src_str_out[64], dst_str_out[64];
|
||||
uint32_t seq_out, ack_out;
|
||||
int rst_out = 0;
|
||||
@ -159,10 +173,7 @@ static void test_tcp(const char *src_str,
|
||||
assert(ret == 0);
|
||||
assert(len == expected_len);
|
||||
|
||||
num_written = write(STDOUT_FILENO,
|
||||
buf + sizeof(struct ether_header),
|
||||
len);
|
||||
assert(num_written != -1 && (size_t)num_written == len);
|
||||
hexdump(buf + sizeof(struct ether_header), len);
|
||||
|
||||
switch (ntohs(eth->ether_type)) {
|
||||
case ETHERTYPE_IP:
|
||||
|
Loading…
Reference in New Issue
Block a user