net: simplify test helpers

This change consolidates test helpers that test platform capabilities.
testNetwork, testAddress and testListenArgs report whether given
ariguments are testable on the current platform configuration to
mitigate to receive weird test results.

Change-Id: Ie1ed568a1f9cc50f3155945ea01562904bc2c389
Reviewed-on: https://go-review.googlesource.com/8076
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/src/net/unix_test.go b/src/net/unix_test.go
index 55c5072..85d1ff4 100644
--- a/src/net/unix_test.go
+++ b/src/net/unix_test.go
@@ -17,9 +17,10 @@
 )
 
 func TestReadUnixgramWithUnnamedSocket(t *testing.T) {
-	if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
-		t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH)
+	if !testableNetwork("unixgram") {
+		t.Skip("unixgram test")
 	}
+
 	addr := testUnixAddr()
 	la, err := ResolveUnixAddr("unixgram", addr)
 	if err != nil {
@@ -67,8 +68,8 @@
 }
 
 func TestReadUnixgramWithZeroBytesBuffer(t *testing.T) {
-	if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
-		t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH)
+	if !testableNetwork("unixgram") {
+		t.Skip("unixgram test")
 	}
 	// issue 4352: Recvfrom failed with "address family not
 	// supported by protocol family" if zero-length buffer provided
@@ -149,6 +150,7 @@
 	if runtime.GOOS != "linux" {
 		t.Skip("skipping: autobind is linux only")
 	}
+
 	laddr := &UnixAddr{Name: "", Net: "unix"}
 	ln, err := ListenUnix("unix", laddr)
 	if err != nil {
@@ -158,9 +160,10 @@
 }
 
 func TestUnixgramWrite(t *testing.T) {
-	if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
-		t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH)
+	if !testableNetwork("unixgram") {
+		t.Skip("unixgram test")
 	}
+
 	addr := testUnixAddr()
 	laddr, err := ResolveUnixAddr("unixgram", addr)
 	if err != nil {
@@ -228,9 +231,10 @@
 }
 
 func TestUnixConnLocalAndRemoteNames(t *testing.T) {
-	if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
-		t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH)
+	if !testableNetwork("unix") {
+		t.Skip("unix test")
 	}
+
 	for _, laddr := range []string{"", testUnixAddr()} {
 		laddr := laddr
 		taddr := testUnixAddr()
@@ -290,9 +294,10 @@
 }
 
 func TestUnixgramConnLocalAndRemoteNames(t *testing.T) {
-	if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
-		t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH)
+	if !testableNetwork("unixgram") {
+		t.Skip("unixgram test")
 	}
+
 	for _, laddr := range []string{"", testUnixAddr()} {
 		laddr := laddr
 		taddr := testUnixAddr()