tests: add a test for basic network syscalls

* tests/.gitignore: Add net-accept-connect, *.o and *.log.*.
* tests/Makefile.am (AM_CFLAGS): New variable.
(check_PROGRAMS): Add net-accept-connect.
(TESTS): Add net.
* tests/net-accept-connect.c: New file.
* tests/net: New file.
diff --git a/tests/.gitignore b/tests/.gitignore
index 7e563b8..947455d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,2 +1,5 @@
+net-accept-connect
 *.log
+*.log.*
+*.o
 *.trs
diff --git a/tests/Makefile.am b/tests/Makefile.am
index aaf103a..a7f584d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,10 @@
 # Automake input for strace tests.
 
-TESTS = ptrace_setoptions strace-f qual_syscall stat
+AM_CFLAGS = $(WARN_CFLAGS)
+
+check_PROGRAMS = net-accept-connect
+
+TESTS = ptrace_setoptions strace-f qual_syscall stat net
 
 EXTRA_DIST = init.sh $(TESTS)
 
diff --git a/tests/net b/tests/net
new file mode 100755
index 0000000..3fb10ba
--- /dev/null
+++ b/tests/net
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+# Check how network syscalls are traced.
+
+. "${srcdir=.}/init.sh"
+
+check_strace
+check_timeout
+check_prog grep
+check_prog rm
+
+rm -f check.log.*
+
+$TIMEOUT ./net-accept-connect ||
+	fail_ 'net-accept-connect failed'
+
+args='-tt -ff -o check.log -enetwork ./net-accept-connect'
+$TIMEOUT $STRACE $args ||
+	fail_ "strace $args failed"
+
+"$srcdir"/../strace-log-merge check.log > check.log || {
+	cat check.log
+	fail_ 'strace-log-merge failed'
+}
+
+rm -f check.log.*
+
+grep_log()
+{
+	local syscall="$1"; shift
+	local prefix='[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +'
+
+	LC_ALL=C grep -E -x "$prefix$syscall$@" check.log > /dev/null || {
+		cat check.log
+		fail_ "strace -enetwork failed to trace \"$syscall\" properly"
+	}
+}
+
+grep_log socket '\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\) += 0'
+grep_log socket '\(PF_(LOCAL|UNIX|FILE), SOCK_STREAM, 0\) += 1'
+grep_log bind '\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="local-stream"\}, 110\) += 0'
+grep_log listen '\(0, 5\) += 0'
+grep_log getsockname '\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="local-stream"\}, \[15\]\) += 0'
+grep_log accept '\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), NULL\}, \[2\]\) += 1'
+grep_log connect '\(1, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="local-stream"\}, 110\) += 0'
+
+exit 0
diff --git a/tests/net-accept-connect.c b/tests/net-accept-connect.c
new file mode 100644
index 0000000..9d296f7
--- /dev/null
+++ b/tests/net-accept-connect.c
@@ -0,0 +1,48 @@
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#define SUN_PATH "local-stream"
+int main(void)
+{
+	struct sockaddr_un addr = {
+		.sun_family = AF_UNIX,
+		.sun_path = SUN_PATH
+	};
+	socklen_t len = sizeof addr;
+
+	unlink(SUN_PATH);
+	close(0);
+	close(1);
+
+	assert(socket(PF_LOCAL, SOCK_STREAM, 0) == 0);
+	assert(bind(0, (struct sockaddr *) &addr, len) == 0);
+	assert(listen(0, 5) == 0);
+
+	memset(&addr, 0, sizeof addr);
+	assert(getsockname(0, (struct sockaddr *) &addr, &len) == 0);
+
+	pid_t pid = fork();
+	assert(pid >= 0);
+
+	if (pid) {
+		assert(accept(0, (struct sockaddr *) &addr, &len) == 1);
+		assert(close(0) == 0);
+		int status;
+		assert(waitpid(pid, &status, 0) == pid);
+		assert(status == 0);
+		assert(close(1) == 0);
+	} else {
+		assert(socket(PF_LOCAL, SOCK_STREAM, 0) == 1);
+		assert(close(0) == 0);
+		assert(connect(1, (struct sockaddr *) &addr, sizeof addr) == 0);
+		assert(close(1) == 0);
+		return 0;
+	}
+
+	unlink(SUN_PATH);
+	return 0;
+}