]> granicus.if.org Git - strace/commitdiff
tests: replace net-yy.test with net-yy-inet.test
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 26 Jan 2016 22:03:22 +0000 (22:03 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 3 Feb 2016 12:42:01 +0000 (12:42 +0000)
Unlike the former test that was based on match_awk,
the new one uses match_diff and does more rigorous testing.

* tests/net-yy-inet.c: New file.
* tests/net-yy-inet.test: New test.
* tests/net-yy.test: Remove.
* tests/net-yy-accept.awk: Remove.
* tests/net-yy-connect.awk: Remove.
* tests/inet-accept-connect-send-recv.c: Remove.
* tests/.gitignore: Replace inet-accept-connect-send-recv
with net-yy-inet.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(TESTS): Replace net-yy.test with net-yy-inet.test.
(EXTRA_DIST): Remove net-yy-accept.awk and net-yy-connect.awk.

tests/.gitignore
tests/Makefile.am
tests/inet-accept-connect-send-recv.c [deleted file]
tests/net-yy-accept.awk [deleted file]
tests/net-yy-connect.awk [deleted file]
tests/net-yy-inet.c [new file with mode: 0644]
tests/net-yy-inet.test [moved from tests/net-yy.test with 67% similarity]

index ad61dc4ab76a05af0896a184896656a54518ba87..ffd6356daeddacb4da5ee95dc6c571379b734e25 100644 (file)
@@ -33,7 +33,6 @@ getdents
 getdents64
 getrandom
 getxxid
-inet-accept-connect-send-recv
 inet-cmsg
 ioctl
 ip_mreq
@@ -58,6 +57,7 @@ mmsg
 mq
 nanosleep
 net-accept-connect
+net-yy-inet
 net-yy-unix
 netlink_inet_diag
 netlink_unix_diag
index fa88481938ff4ef578fec8cd68f102e8bd37da8b..af8f7c96063feb6de549d484a91a648da6367f48 100644 (file)
@@ -82,7 +82,6 @@ check_PROGRAMS = \
        getdents64 \
        getrandom \
        getxxid \
-       inet-accept-connect-send-recv \
        inet-cmsg \
        ioctl \
        ip_mreq \
@@ -105,6 +104,7 @@ check_PROGRAMS = \
        mq \
        nanosleep \
        net-accept-connect \
+       net-yy-inet \
        net-yy-unix \
        netlink_inet_diag \
        netlink_unix_diag \
@@ -246,7 +246,7 @@ TESTS = \
        mq.test \
        nanosleep.test \
        net-fd.test \
-       net-yy.test \
+       net-yy-inet.test \
        net-yy-unix.test \
        net.test \
        newfstatat.test \
@@ -343,8 +343,6 @@ EXTRA_DIST = init.sh run.sh match.awk \
             mq.expected \
             net.expected \
             net-fd.expected \
-            net-yy-accept.awk \
-            net-yy-connect.awk \
             oldselect.expected \
             pipe.expected \
             ppoll.expected \
diff --git a/tests/inet-accept-connect-send-recv.c b/tests/inet-accept-connect-send-recv.c
deleted file mode 100644 (file)
index 334aeb7..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests.h"
-#include <assert.h>
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-int main(void)
-{
-       static const char data[] = "data";
-       const size_t size = sizeof(data) - 1;
-       struct sockaddr_in addr;
-       socklen_t len = sizeof(addr);
-       pid_t pid;
-
-       memset(&addr, 0, sizeof(addr));
-       addr.sin_family = AF_INET;
-       addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-
-       close(0);
-       close(1);
-
-       if (socket(PF_INET, SOCK_STREAM, 0))
-               perror_msg_and_skip("socket");
-       if (bind(0, (struct sockaddr *) &addr, len))
-               perror_msg_and_skip("bind");
-       if (listen(0, 5))
-               perror_msg_and_skip("listen");
-
-       memset(&addr, 0, sizeof(addr));
-       assert(getsockname(0, (struct sockaddr *) &addr, &len) == 0);
-
-       pid = fork();
-       if (pid < 0)
-               perror_msg_and_fail("fork");
-
-       if (pid) {
-               char buf[sizeof(data)];
-               int status;
-
-               assert(accept(0, (struct sockaddr *) &addr, &len) == 1);
-               assert(close(0) == 0);
-               assert(recv(1, buf, sizeof(buf), MSG_WAITALL) == (int) size);
-               assert(waitpid(pid, &status, 0) == pid);
-               assert(status == 0);
-               assert(close(1) == 0);
-       } else {
-               assert(close(0) == 0);
-               assert(socket(PF_INET, SOCK_STREAM, 0) == 0);
-               assert(connect(0, (struct sockaddr *) &addr, len) == 0);
-               assert(send(0, data, size, MSG_DONTROUTE) == (int) size);
-               assert(close(0) == 0);
-       }
-
-       return 0;
-}
diff --git a/tests/net-yy-accept.awk b/tests/net-yy-accept.awk
deleted file mode 100644 (file)
index fed3e30..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/bin/gawk
-#
-# Copyright (c) 2014 Masatake YAMATO <yamato@redhat.com>
-# Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. The name of the author may not be used to endorse or promote products
-#    derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-BEGIN {
-  lines = 9
-  fail = 0
-
-  r_i = "[1-9][0-9]*"
-  r_port = "[1-9][0-9][0-9][0-9]+"
-  r_localhost = "127\\.0\\.0\\.1"
-  r_socket = "^socket\\(PF_INET, SOCK_STREAM, IPPROTO_IP\\) += 0<TCP:\\[(" r_i ")\\]>$"
-  r_getsockname = "^getsockname\\(0<TCP:\\[" r_localhost ":(" r_port ")\\]>, \\{sa_family=AF_INET, sin_port=htons\\((" r_port ")\\), sin_addr=inet_addr\\(\"" r_localhost "\"\\)\\}, \\[" r_i "\\]\\) += 0$"
-}
-
-NR == 1 {
-  if (match($0, r_socket, a)) {
-    inode = a[1]
-    r_bind = "^bind\\(0<TCP:\\[" inode "\\]>, \\{sa_family=AF_INET, sin_port=htons\\(0\\), sin_addr=inet_addr\\(\"" r_localhost "\"\\)\\}, " r_i "\\) += 0$"
-    r_listen = "^listen\\(0<TCP:\\[" inode "\\]>, 5\\) += 0$"
-    next
-  }
-}
-
-NR == 2 {if (r_bind != "" && match($0, r_bind)) next}
-
-NR == 3 {if (r_listen != "" && match($0, r_listen)) next}
-
-NR == 4 {
-  if (match($0, r_getsockname, a) && a[1] == a[2]) {
-    port_l = a[1]
-    r_accept = "^accept\\(0<TCP:\\[" r_localhost ":" port_l "\\]>, \\{sa_family=AF_INET, sin_port=htons\\((" r_port ")\\), sin_addr=inet_addr\\(\"" r_localhost "\"\\)\\}, \\[" r_i "\\]\\) += 1<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":(" r_port ")\\]>$"
-    r_close0 = "^close\\(0<TCP:\\[" r_localhost ":" port_l "\\]>) += 0$"
-    next
-  }
-}
-
-NR == 5 {
-  if (r_accept != "" && match($0, r_accept, a) && a[1] == a[2]) {
-    port_r = a[1]
-    r_recv = "^recv\\(1<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>, \"data\", 5, MSG_WAITALL\\) += 4$"
-    r_recvfrom = "^recvfrom\\(1<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>, \"data\", 5, MSG_WAITALL, NULL, NULL\\) += 4$"
-    r_close1 = "^close\\(1<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>) += 0$"
-    next
-  }
-}
-
-NR == 6 {if (r_close0 != "" && match($0, r_close0)) next}
-
-NR == 7 {if (r_recv != "" && (match($0, r_recv) || match($0, r_recvfrom))) next}
-
-NR == 8 {if (r_close1 != "" && match($0, r_close1)) next}
-
-NR == lines && $0 == "+++ exited with 0 +++" {next}
-
-{
-  print "Line " NR " does not match: " $0
-  fail=1
-}
-
-END {
-  if (NR != lines) {
-    print "Expected " lines " lines, found " NR " line(s)."
-    print ""
-    exit 1
-  }
-  if (fail) {
-    print ""
-    exit 1
-  }
-}
diff --git a/tests/net-yy-connect.awk b/tests/net-yy-connect.awk
deleted file mode 100644 (file)
index f4dcf91..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/bin/gawk
-#
-# Copyright (c) 2014 Masatake YAMATO <yamato@redhat.com>
-# Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. The name of the author may not be used to endorse or promote products
-#    derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-BEGIN {
-  lines = 5
-  fail = 0
-
-  r_i = "[1-9][0-9]*"
-  r_port = "[1-9][0-9][0-9][0-9]+"
-  r_localhost = "127\\.0\\.0\\.1"
-  r_socket = "^socket\\(PF_INET, SOCK_STREAM, IPPROTO_IP\\) += 0<TCP:\\[(" r_i ")\\]>$"
-}
-
-NR == 1 {
-  if (match($0, r_socket, a)) {
-    inode = a[1]
-    r_connect = "^connect\\(0<TCP:\\[" inode "\\]>, \\{sa_family=AF_INET, sin_port=htons\\((" r_port ")\\), sin_addr=inet_addr\\(\"" r_localhost "\"\\)\\}, " r_i ") += 0$"
-    next
-  }
-}
-
-NR == 2 {
-  if (r_connect != "" && match($0, r_connect, a)) {
-    port_r = a[1]
-    r_send = "^send\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE\\) += 4$"
-    r_sendto = "^sendto\\(0<TCP:\\[" r_localhost ":(" r_port ")->" r_localhost ":" port_r "\\]>, \"data\", 4, MSG_DONTROUTE, NULL, 0\\) += 4$"
-    next
-  }
-}
-
-NR == 3 {
-  if (r_send != "" && (match($0, r_send, a) || match($0, r_sendto, a))) {
-    port_l = a[1]
-    r_close = "^close\\(0<TCP:\\[" r_localhost ":" port_l "->" r_localhost ":" port_r "\\]>\\) += 0$"
-    next
-  }
-}
-
-NR == 4 {if (r_close != "" && match($0, r_close)) next}
-
-NR == lines && $0 == "+++ exited with 0 +++" {next}
-
-{
-  print "Line " NR " does not match: " $0
-  fail=1
-}
-
-END {
-  if (NR != lines) {
-    print "Expected " lines " lines, found " NR " line(s)."
-    print ""
-    exit 1
-  }
-  if (fail) {
-    print ""
-    exit 1
-  }
-}
diff --git a/tests/net-yy-inet.c b/tests/net-yy-inet.c
new file mode 100644 (file)
index 0000000..c6842b4
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * This file is part of net-yy-inet strace test.
+ *
+ * Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include <assert.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+
+int
+main(void)
+{
+       const struct sockaddr_in addr = {
+               .sin_family = AF_INET,
+               .sin_addr.s_addr = htonl(INADDR_LOOPBACK)
+       };
+       struct sockaddr * const listen_sa = tail_memdup(&addr, sizeof(addr));
+       socklen_t * const len = tail_alloc(sizeof(socklen_t));
+       *len = sizeof(addr);
+
+       const int listen_fd = socket(PF_INET, SOCK_STREAM, 0);
+       if (listen_fd < 0)
+               perror_msg_and_skip("socket");
+       const unsigned long listen_inode = inode_of_sockfd(listen_fd);
+       printf("socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = %d<TCP:[%lu]>\n",
+              listen_fd, listen_inode);
+
+       if (bind(listen_fd, listen_sa, *len))
+               perror_msg_and_skip("bind");
+       printf("bind(%d<TCP:[%lu]>, {sa_family=AF_INET, sin_port=htons(0)"
+              ", sin_addr=inet_addr(\"127.0.0.1\")}, %u) = 0\n",
+              listen_fd, listen_inode, (unsigned) *len);
+
+       if (listen(listen_fd, 1))
+               perror_msg_and_skip("listen");
+       printf("listen(%d<TCP:[%lu]>, 1) = 0\n", listen_fd, listen_inode);
+
+       memset(listen_sa, 0, sizeof(addr));
+       *len = sizeof(addr);
+       if (getsockname(listen_fd, listen_sa, len))
+               perror_msg_and_fail("getsockname");
+       const unsigned int listen_port =
+               ntohs(((struct sockaddr_in *) listen_sa) -> sin_port);
+       printf("getsockname(%d<TCP:[127.0.0.1:%u]>, {sa_family=AF_INET"
+              ", sin_port=htons(%u), sin_addr=inet_addr(\"127.0.0.1\")}"
+              ", [%u]) = 0\n",
+              listen_fd, listen_port, listen_port, (unsigned) *len);
+
+       unsigned int * const optval = tail_alloc(sizeof(unsigned int));
+       *len = sizeof(*optval);
+       if (getsockopt(listen_fd, SOL_TCP, TCP_MAXSEG, optval, len))
+               perror_msg_and_fail("getsockopt");
+       printf("getsockopt(%d<TCP:[127.0.0.1:%u]>, SOL_TCP, TCP_MAXSEG"
+              ", [%u], [%u]) = 0\n",
+              listen_fd, listen_port, *optval, (unsigned) *len);
+
+       const int connect_fd = socket(PF_INET, SOCK_STREAM, 0);
+       if (connect_fd < 0)
+               perror_msg_and_fail("socket");
+       const unsigned long connect_inode = inode_of_sockfd(connect_fd);
+       printf("socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = %d<TCP:[%lu]>\n",
+              connect_fd, connect_inode);
+
+       *len = sizeof(addr);
+       if (connect(connect_fd, listen_sa, *len))
+               perror_msg_and_fail("connect");
+       printf("connect(%d<TCP:[%lu]>, {sa_family=AF_INET, sin_port=htons(%u)"
+              ", sin_addr=inet_addr(\"127.0.0.1\")}, %u) = 0\n",
+              connect_fd, connect_inode, listen_port, (unsigned) *len);
+
+       struct sockaddr * const accept_sa = tail_alloc(sizeof(addr));
+       memset(accept_sa, 0, sizeof(addr));
+       *len = sizeof(addr);
+       const int accept_fd = accept(listen_fd, accept_sa, len);
+       if (accept_fd < 0)
+               perror_msg_and_fail("accept");
+       const unsigned int connect_port =
+               ntohs(((struct sockaddr_in *) accept_sa) -> sin_port);
+       printf("accept(%d<TCP:[127.0.0.1:%u]>, {sa_family=AF_INET"
+              ", sin_port=htons(%u), sin_addr=inet_addr(\"127.0.0.1\")}"
+              ", [%u]) = %d<TCP:[127.0.0.1:%u->127.0.0.1:%u]>\n",
+              listen_fd, listen_port, connect_port, (unsigned) *len,
+              accept_fd, listen_port, connect_port);
+
+       memset(accept_sa, 0, sizeof(addr));
+       *len = sizeof(addr);
+       if (getpeername(accept_fd, accept_sa, len))
+               perror_msg_and_fail("getpeername");
+       printf("getpeername(%d<TCP:[127.0.0.1:%u->127.0.0.1:%u]>"
+              ", {sa_family=AF_INET, sin_port=htons(%u)"
+              ", sin_addr=inet_addr(\"127.0.0.1\")}, [%u]) = 0\n",
+              accept_fd, listen_port, connect_port, connect_port,
+              (unsigned) *len);
+
+       memset(listen_sa, 0, sizeof(addr));
+       *len = sizeof(addr);
+       if (getpeername(connect_fd, listen_sa, len))
+               perror_msg_and_fail("getpeername");
+       printf("getpeername(%d<TCP:[127.0.0.1:%u->127.0.0.1:%u]>"
+              ", {sa_family=AF_INET, sin_port=htons(%u)"
+              ", sin_addr=inet_addr(\"127.0.0.1\")}, [%u]) = 0\n",
+              connect_fd, connect_port, listen_port, listen_port,
+              (unsigned) *len);
+
+       *len = sizeof(*optval);
+       if (setsockopt(connect_fd, SOL_TCP, TCP_MAXSEG, optval, *len))
+               perror_msg_and_fail("setsockopt");
+       printf("setsockopt(%d<TCP:[127.0.0.1:%u->127.0.0.1:%u]>"
+              ", SOL_TCP, TCP_MAXSEG, [%u], %u) = 0\n",
+              connect_fd, connect_port, listen_port, *optval,
+              (unsigned) *len);
+
+       char text[] = "text";
+       assert(sendto(connect_fd, text, sizeof(text) - 1,
+              MSG_DONTROUTE | MSG_DONTWAIT, NULL, 0) == sizeof(text) - 1);
+       printf("sendto(%d<TCP:[127.0.0.1:%u->127.0.0.1:%u]>, \"%s\", %u"
+              ", MSG_DONTROUTE|MSG_DONTWAIT, NULL, 0) = %u\n",
+              connect_fd, connect_port, listen_port, text,
+              (unsigned) sizeof(text) - 1, (unsigned) sizeof(text) - 1);
+
+       assert(close(connect_fd) == 0);
+       printf("close(%d<TCP:[127.0.0.1:%u->127.0.0.1:%u]>) = 0\n",
+              connect_fd, connect_port, listen_port);
+
+       assert(recvfrom(accept_fd, text, sizeof(text) - 1, MSG_WAITALL,
+                       NULL, NULL) == sizeof(text) - 1);
+       printf("recvfrom(%d<TCP:[127.0.0.1:%u->127.0.0.1:%u]>, \"%s\", %u"
+              ", MSG_WAITALL, NULL, NULL) = %u\n",
+              accept_fd, listen_port, connect_port, text,
+              (unsigned) sizeof(text) - 1, (unsigned) sizeof(text) - 1);
+
+       assert(close(accept_fd) == 0);
+       printf("close(%d<TCP:[127.0.0.1:%u->127.0.0.1:%u]>) = 0\n",
+              accept_fd, listen_port, connect_port);
+
+       assert(close(listen_fd) == 0);
+       printf("close(%d<TCP:[127.0.0.1:%u]>) = 0\n",
+              listen_fd, listen_port);
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
similarity index 67%
rename from tests/net-yy.test
rename to tests/net-yy-inet.test
index 8316cacf966699ed172823879f85efef111436a8..9a7c96e0cc5f4a30bdc43684413348860abf03a6 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # Check decoding of ip:port pairs associated with socket descriptors
 #
-# Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
+# Copyright (c) 2014-2016 Dmitry V. Levin <ldv@altlinux.org>
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
        framework_skip_ '/proc/self/fd/ is not available'
 
 check_prog sed
-
 run_prog ./netlink_inet_diag
-run_prog ./inet-accept-connect-send-recv
-run_strace_merge -yy -eclose,network $args
-
-child="$(sed -rn '/SIGCHLD/ s/^.*, si_pid=([1-9][0-9]*), .*/\1/p' "$LOG")"
-[ -n "$child" ] ||
-       dump_log_and_fail_with 'failed to find pid of child process'
-
-rm -f "$LOG"-*
-sed -rn "/^$child"' /!d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' "$LOG" > "$LOG"-connect &&
-sed -rn "/^$child"' /d; /SIGCHLD/d; / socket\(/,$ s/^[0-9]+ +[^ ]+ (.+)/\1/p' "$LOG" > "$LOG"-accept ||
-       dump_log_and_fail_with 'failed to separate logs'
 
-match_awk "$LOG-connect" "$srcdir"/net-yy-connect.awk "$STRACE $args connect output mismatch"
-match_awk "$LOG-accept" "$srcdir"/net-yy-accept.awk "$STRACE $args accept output mismatch"
+addr="${ME_%.test}-local-stream"
+run_prog "./${ME_%.test}" $addr > /dev/null
 
-rm -f "$LOG"-connect "$LOG"-accept
+OUT="$LOG.out"
+EXP="$LOG.exp"
+run_strace -a22 -yy -eclose,network $args > "$EXP"
+# Filter out close() calls made by ld.so and libc.
+sed -n '/socket/,$p' < "$LOG" > "$OUT"
 
-exit 0
+match_diff "$OUT" "$EXP"
+rm -f "$EXP" "$OUT"