mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net: enable unixpacket test on available platforms
DragonFlyBSD, FreeBSD 9 and beyond, NetBSD 6 and beyond, and Solaris (illumos) support AF_UNIX+SOCK_SEQPACKET socket. LGTM=dave R=golang-codereviews, dave CC=golang-codereviews https://golang.org/cl/83390043
This commit is contained in:
parent
67a5181045
commit
e88e7ed6ba
3 changed files with 56 additions and 53 deletions
|
|
@ -16,11 +16,11 @@ import (
|
||||||
|
|
||||||
var connTests = []struct {
|
var connTests = []struct {
|
||||||
net string
|
net string
|
||||||
addr func() string
|
addr string
|
||||||
}{
|
}{
|
||||||
{"tcp", func() string { return "127.0.0.1:0" }},
|
{"tcp", "127.0.0.1:0"},
|
||||||
{"unix", testUnixAddr},
|
{"unix", testUnixAddr()},
|
||||||
{"unixpacket", testUnixAddr},
|
{"unixpacket", testUnixAddr()},
|
||||||
}
|
}
|
||||||
|
|
||||||
// someTimeout is used just to test that net.Conn implementations
|
// someTimeout is used just to test that net.Conn implementations
|
||||||
|
|
@ -31,18 +31,21 @@ const someTimeout = 10 * time.Second
|
||||||
func TestConnAndListener(t *testing.T) {
|
func TestConnAndListener(t *testing.T) {
|
||||||
for _, tt := range connTests {
|
for _, tt := range connTests {
|
||||||
switch tt.net {
|
switch tt.net {
|
||||||
case "unix", "unixpacket":
|
case "unix":
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "plan9", "windows", "nacl":
|
case "nacl", "plan9", "windows":
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if tt.net == "unixpacket" && runtime.GOOS != "linux" {
|
case "unixpacket":
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin", "nacl", "openbsd", "plan9", "windows":
|
||||||
|
continue
|
||||||
|
case "freebsd": // FreeBSD 8 doesn't support unixpacket
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := tt.addr()
|
ln, err := Listen(tt.net, tt.addr)
|
||||||
ln, err := Listen(tt.net, addr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Listen failed: %v", err)
|
t.Fatalf("Listen failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +55,7 @@ func TestConnAndListener(t *testing.T) {
|
||||||
case "unix", "unixpacket":
|
case "unix", "unixpacket":
|
||||||
os.Remove(addr)
|
os.Remove(addr)
|
||||||
}
|
}
|
||||||
}(ln, tt.net, addr)
|
}(ln, tt.net, tt.addr)
|
||||||
if ln.Addr().Network() != tt.net {
|
if ln.Addr().Network() != tt.net {
|
||||||
t.Fatalf("got %v; expected %v", ln.Addr().Network(), tt.net)
|
t.Fatalf("got %v; expected %v", ln.Addr().Network(), tt.net)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// also uses /tmp directory in case it is prohibited to create UNIX
|
// also uses /tmp directory in case it is prohibited to create UNIX
|
||||||
// sockets in TMPDIR.
|
// sockets in TMPDIR.
|
||||||
func testUnixAddr() string {
|
func testUnixAddr() string {
|
||||||
f, err := ioutil.TempFile("/tmp", "nettest")
|
f, err := ioutil.TempFile("", "nettest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,11 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func skipServerTest(net, unixsotype, addr string, ipv6, ipv4map, linuxonly bool) bool {
|
func skipServerTest(net, unixsotype, addr string, ipv6, ipv4map, linuxOnly bool) bool {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
case "plan9", "windows":
|
case "plan9", "windows":
|
||||||
|
|
@ -23,7 +22,7 @@ func skipServerTest(net, unixsotype, addr string, ipv6, ipv4map, linuxonly bool)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if net == unixsotype && linuxonly {
|
if net == unixsotype && linuxOnly {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,21 +41,15 @@ func skipServerTest(net, unixsotype, addr string, ipv6, ipv4map, linuxonly bool)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func tempfile(filename string) string {
|
|
||||||
// use /tmp in case it is prohibited to create
|
|
||||||
// UNIX sockets in TMPDIR
|
|
||||||
return "/tmp/" + filename + "." + strconv.Itoa(os.Getpid())
|
|
||||||
}
|
|
||||||
|
|
||||||
var streamConnServerTests = []struct {
|
var streamConnServerTests = []struct {
|
||||||
snet string // server side
|
snet string // server side
|
||||||
saddr string
|
saddr string
|
||||||
cnet string // client side
|
cnet string // client side
|
||||||
caddr string
|
caddr string
|
||||||
ipv6 bool // test with underlying AF_INET6 socket
|
ipv6 bool // test with underlying AF_INET6 socket
|
||||||
ipv4map bool // test with IPv6 IPv4-mapping functionality
|
ipv4map bool // test with IPv6 IPv4-mapping functionality
|
||||||
empty bool // test with empty data
|
empty bool // test with empty data
|
||||||
linux bool // test with abstract unix domain socket, a Linux-ism
|
linuxOnly bool // test with abstract unix domain socket, a Linux-ism
|
||||||
}{
|
}{
|
||||||
{snet: "tcp", saddr: "", cnet: "tcp", caddr: "127.0.0.1"},
|
{snet: "tcp", saddr: "", cnet: "tcp", caddr: "127.0.0.1"},
|
||||||
{snet: "tcp", saddr: "0.0.0.0", cnet: "tcp", caddr: "127.0.0.1"},
|
{snet: "tcp", saddr: "0.0.0.0", cnet: "tcp", caddr: "127.0.0.1"},
|
||||||
|
|
@ -93,13 +86,13 @@ var streamConnServerTests = []struct {
|
||||||
|
|
||||||
{snet: "tcp6", saddr: "[::1]", cnet: "tcp6", caddr: "[::1]", ipv6: true},
|
{snet: "tcp6", saddr: "[::1]", cnet: "tcp6", caddr: "[::1]", ipv6: true},
|
||||||
|
|
||||||
{snet: "unix", saddr: tempfile("gotest1.net"), cnet: "unix", caddr: tempfile("gotest1.net.local")},
|
{snet: "unix", saddr: testUnixAddr(), cnet: "unix", caddr: testUnixAddr()},
|
||||||
{snet: "unix", saddr: "@gotest2/net", cnet: "unix", caddr: "@gotest2/net.local", linux: true},
|
{snet: "unix", saddr: "@gotest2/net", cnet: "unix", caddr: "@gotest2/net.local", linuxOnly: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStreamConnServer(t *testing.T) {
|
func TestStreamConnServer(t *testing.T) {
|
||||||
for _, tt := range streamConnServerTests {
|
for _, tt := range streamConnServerTests {
|
||||||
if skipServerTest(tt.snet, "unix", tt.saddr, tt.ipv6, tt.ipv4map, tt.linux) {
|
if skipServerTest(tt.snet, "unix", tt.saddr, tt.ipv6, tt.ipv4map, tt.linuxOnly) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,21 +130,28 @@ func TestStreamConnServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var seqpacketConnServerTests = []struct {
|
var seqpacketConnServerTests = []struct {
|
||||||
net string
|
net string
|
||||||
saddr string // server address
|
saddr string // server address
|
||||||
caddr string // client address
|
caddr string // client address
|
||||||
empty bool // test with empty data
|
empty bool // test with empty data
|
||||||
|
linuxOnly bool // test with abstract unix domain socket, a Linux-ism
|
||||||
}{
|
}{
|
||||||
{net: "unixpacket", saddr: tempfile("/gotest3.net"), caddr: tempfile("gotest3.net.local")},
|
{net: "unixpacket", saddr: testUnixAddr(), caddr: testUnixAddr()},
|
||||||
{net: "unixpacket", saddr: "@gotest4/net", caddr: "@gotest4/net.local"},
|
{net: "unixpacket", saddr: "@gotest4/net", caddr: "@gotest4/net.local", linuxOnly: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSeqpacketConnServer(t *testing.T) {
|
func TestSeqpacketConnServer(t *testing.T) {
|
||||||
if runtime.GOOS != "linux" {
|
switch runtime.GOOS {
|
||||||
|
case "darwin", "nacl", "openbsd", "plan9", "windows":
|
||||||
|
fallthrough
|
||||||
|
case "freebsd": // FreeBSD 8 doesn't support unixpacket
|
||||||
t.Skipf("skipping test on %q", runtime.GOOS)
|
t.Skipf("skipping test on %q", runtime.GOOS)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range seqpacketConnServerTests {
|
for _, tt := range seqpacketConnServerTests {
|
||||||
|
if runtime.GOOS != "linux" && tt.linuxOnly {
|
||||||
|
continue
|
||||||
|
}
|
||||||
listening := make(chan string)
|
listening := make(chan string)
|
||||||
done := make(chan int)
|
done := make(chan int)
|
||||||
switch tt.net {
|
switch tt.net {
|
||||||
|
|
@ -248,15 +248,15 @@ func runStreamConnClient(t *testing.T, net, taddr string, isEmpty bool) {
|
||||||
var testDatagram = flag.Bool("datagram", false, "whether to test udp and unixgram")
|
var testDatagram = flag.Bool("datagram", false, "whether to test udp and unixgram")
|
||||||
|
|
||||||
var datagramPacketConnServerTests = []struct {
|
var datagramPacketConnServerTests = []struct {
|
||||||
snet string // server side
|
snet string // server side
|
||||||
saddr string
|
saddr string
|
||||||
cnet string // client side
|
cnet string // client side
|
||||||
caddr string
|
caddr string
|
||||||
ipv6 bool // test with underlying AF_INET6 socket
|
ipv6 bool // test with underlying AF_INET6 socket
|
||||||
ipv4map bool // test with IPv6 IPv4-mapping functionality
|
ipv4map bool // test with IPv6 IPv4-mapping functionality
|
||||||
dial bool // test with Dial or DialUnix
|
dial bool // test with Dial or DialUnix
|
||||||
empty bool // test with empty data
|
empty bool // test with empty data
|
||||||
linux bool // test with abstract unix domain socket, a Linux-ism
|
linuxOnly bool // test with abstract unix domain socket, a Linux-ism
|
||||||
}{
|
}{
|
||||||
{snet: "udp", saddr: "", cnet: "udp", caddr: "127.0.0.1"},
|
{snet: "udp", saddr: "", cnet: "udp", caddr: "127.0.0.1"},
|
||||||
{snet: "udp", saddr: "0.0.0.0", cnet: "udp", caddr: "127.0.0.1"},
|
{snet: "udp", saddr: "0.0.0.0", cnet: "udp", caddr: "127.0.0.1"},
|
||||||
|
|
@ -301,12 +301,12 @@ var datagramPacketConnServerTests = []struct {
|
||||||
{snet: "udp", saddr: "[::1]", cnet: "udp", caddr: "[::1]", ipv6: true, empty: true},
|
{snet: "udp", saddr: "[::1]", cnet: "udp", caddr: "[::1]", ipv6: true, empty: true},
|
||||||
{snet: "udp", saddr: "[::1]", cnet: "udp", caddr: "[::1]", ipv6: true, dial: true, empty: true},
|
{snet: "udp", saddr: "[::1]", cnet: "udp", caddr: "[::1]", ipv6: true, dial: true, empty: true},
|
||||||
|
|
||||||
{snet: "unixgram", saddr: tempfile("gotest5.net"), cnet: "unixgram", caddr: tempfile("gotest5.net.local")},
|
{snet: "unixgram", saddr: testUnixAddr(), cnet: "unixgram", caddr: testUnixAddr()},
|
||||||
{snet: "unixgram", saddr: tempfile("gotest5.net"), cnet: "unixgram", caddr: tempfile("gotest5.net.local"), dial: true},
|
{snet: "unixgram", saddr: testUnixAddr(), cnet: "unixgram", caddr: testUnixAddr(), dial: true},
|
||||||
{snet: "unixgram", saddr: tempfile("gotest5.net"), cnet: "unixgram", caddr: tempfile("gotest5.net.local"), empty: true},
|
{snet: "unixgram", saddr: testUnixAddr(), cnet: "unixgram", caddr: testUnixAddr(), empty: true},
|
||||||
{snet: "unixgram", saddr: tempfile("gotest5.net"), cnet: "unixgram", caddr: tempfile("gotest5.net.local"), dial: true, empty: true},
|
{snet: "unixgram", saddr: testUnixAddr(), cnet: "unixgram", caddr: testUnixAddr(), dial: true, empty: true},
|
||||||
|
|
||||||
{snet: "unixgram", saddr: "@gotest6/net", cnet: "unixgram", caddr: "@gotest6/net.local", linux: true},
|
{snet: "unixgram", saddr: "@gotest6/net", cnet: "unixgram", caddr: "@gotest6/net.local", linuxOnly: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDatagramPacketConnServer(t *testing.T) {
|
func TestDatagramPacketConnServer(t *testing.T) {
|
||||||
|
|
@ -315,7 +315,7 @@ func TestDatagramPacketConnServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range datagramPacketConnServerTests {
|
for _, tt := range datagramPacketConnServerTests {
|
||||||
if skipServerTest(tt.snet, "unixgram", tt.saddr, tt.ipv6, tt.ipv4map, tt.linux) {
|
if skipServerTest(tt.snet, "unixgram", tt.saddr, tt.ipv6, tt.ipv4map, tt.linuxOnly) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue