]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Use built-in hexdump() in system socket tests
authorMartin Schwenke <martin@meltin.net>
Wed, 4 Mar 2020 03:38:15 +0000 (14:38 +1100)
committerAmitay Isaacs <amitay@samba.org>
Tue, 10 Mar 2020 09:17:12 +0000 (09:17 +0000)
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

ctdb/tests/UNIT/cunit/system_socket_test_002.sh
ctdb/tests/UNIT/cunit/system_socket_test_003.sh
ctdb/tests/src/system_socket_test.c

index e22f2484b08772c9a8f3dcb34c85bb766704fbfe..8bea074bd8d874942ee08d8ce8cccb3397511a56 100755 (executable)
@@ -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
index df8bf5f602c939037663a82652e983cea355d8d6..0b265eabdfad46343b2dcbd16ed1d68b14062373 100755 (executable)
@@ -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
index da962f00a2cc7f1c80ca6c56c780b9779518f64c..a6fe85476514dcdff128a864e50552dcc5e73655 100644 (file)
 
 #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: