]> Cypherpunks repositories - gostls13.git/commitdiff
net: run unix socket stream tests on Windows
authorqmuntal <quimmuntal@gmail.com>
Wed, 26 Mar 2025 13:14:38 +0000 (14:14 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Wed, 26 Mar 2025 20:22:29 +0000 (13:22 -0700)
The net package supports Unix domain sockets on Windows, but most of
the tests related to them are skipped.

This CL unskip the SOCK_STREAM tests. SOCK_DGRAM probablye can also
make to work, but that will come in a follow-up CL.

Change-Id: If9506a8af57e9bfe58bd7b48a98fc39335627a61
Reviewed-on: https://go-review.googlesource.com/c/go/+/660915
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/net/platform_plan9_test.go [new file with mode: 0644]
src/net/platform_test.go
src/net/platform_unix_test.go [new file with mode: 0644]
src/net/platform_windows_test.go [new file with mode: 0644]
src/net/rawconn_windows_test.go
src/net/unixsock_test.go

diff --git a/src/net/platform_plan9_test.go b/src/net/platform_plan9_test.go
new file mode 100644 (file)
index 0000000..e1ca0aa
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package net
+
+func supportsUnixSocket() bool {
+       return false
+}
index 709d4a3eb7b7a789577361cb3047343ecd53046f..f8317104d03ed1dbab75762c9d898af2996c7d8f 100644 (file)
@@ -7,30 +7,11 @@ package net
 import (
        "internal/testenv"
        "os"
-       "os/exec"
        "runtime"
-       "strconv"
        "strings"
        "testing"
 )
 
-var unixEnabledOnAIX bool
-
-func init() {
-       if runtime.GOOS == "aix" {
-               // Unix network isn't properly working on AIX 7.2 with
-               // Technical Level < 2.
-               // The information is retrieved only once in this init()
-               // instead of everytime testableNetwork is called.
-               out, _ := exec.Command("oslevel", "-s").Output()
-               if len(out) >= len("7200-XX-ZZ-YYMM") { // AIX 7.2, Tech Level XX, Service Pack ZZ, date YYMM
-                       aixVer := string(out[:4])
-                       tl, _ := strconv.Atoi(string(out[5:7]))
-                       unixEnabledOnAIX = aixVer > "7200" || (aixVer == "7200" && tl >= 2)
-               }
-       }
-}
-
 // testableNetwork reports whether network is testable on the current
 // platform configuration.
 func testableNetwork(network string) bool {
@@ -46,13 +27,15 @@ func testableNetwork(network string) bool {
                                return false
                        }
                }
-       case "unix", "unixgram":
+       case "unixgram":
                switch runtime.GOOS {
-               case "android", "ios", "plan9", "windows":
+               case "windows":
                        return false
-               case "aix":
-                       return unixEnabledOnAIX
+               default:
+                       return supportsUnixSocket()
                }
+       case "unix":
+               return supportsUnixSocket()
        case "unixpacket":
                switch runtime.GOOS {
                case "aix", "android", "darwin", "ios", "plan9", "windows":
diff --git a/src/net/platform_unix_test.go b/src/net/platform_unix_test.go
new file mode 100644 (file)
index 0000000..b6b3a55
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build unix || js || wasip1
+
+package net
+
+import (
+       "os/exec"
+       "runtime"
+       "strconv"
+)
+
+var unixEnabledOnAIX bool
+
+func init() {
+       if runtime.GOOS == "aix" {
+               // Unix network isn't properly working on AIX 7.2 with
+               // Technical Level < 2.
+               // The information is retrieved only once in this init()
+               // instead of everytime testableNetwork is called.
+               out, _ := exec.Command("oslevel", "-s").Output()
+               if len(out) >= len("7200-XX-ZZ-YYMM") { // AIX 7.2, Tech Level XX, Service Pack ZZ, date YYMM
+                       aixVer := string(out[:4])
+                       tl, _ := strconv.Atoi(string(out[5:7]))
+                       unixEnabledOnAIX = aixVer > "7200" || (aixVer == "7200" && tl >= 2)
+               }
+       }
+}
+
+func supportsUnixSocket() bool {
+       switch runtime.GOOS {
+       case "android", "ios":
+               return false
+       case "aix":
+               return unixEnabledOnAIX
+       }
+       return true
+}
diff --git a/src/net/platform_windows_test.go b/src/net/platform_windows_test.go
new file mode 100644 (file)
index 0000000..ec2c861
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package net
+
+import "internal/syscall/windows"
+
+func supportsUnixSocket() bool {
+       return windows.SupportUnixSocket()
+}
index 5febf08f774b1892491ff8dbc0e80725021a1c0f..ebfec3499a2fdd9e0c7eff7ee511b402a3a9589b 100644 (file)
@@ -95,6 +95,11 @@ func controlOnConnSetup(network string, address string, c syscall.RawConn) error
        switch network {
        case "tcp", "udp", "ip":
                return errors.New("ambiguous network: " + network)
+       case "unix", "unixpacket", "unixgram":
+               fn = func(s uintptr) {
+                       const SO_ERROR = 0x1007
+                       _, operr = syscall.GetsockoptInt(syscall.Handle(s), syscall.SOL_SOCKET, SO_ERROR)
+               }
        default:
                switch network[len(network)-1] {
                case '4':
index 6906ecc0466a9d784eb431cbe76c0189e330063a..1bbe53db10db2fbc10e9587d9812e07fab704704 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build !plan9 && !windows
+//go:build !plan9
 
 package net
 
@@ -282,7 +282,7 @@ func TestUnixConnLocalAndRemoteNames(t *testing.T) {
                }
 
                switch runtime.GOOS {
-               case "android", "linux":
+               case "android", "linux", "windows":
                        if laddr == "" {
                                laddr = "@" // autobind feature
                        }
@@ -398,6 +398,9 @@ func TestUnixUnlink(t *testing.T) {
 
        // FileListener should not.
        t.Run("FileListener", func(t *testing.T) {
+               if runtime.GOOS == "windows" {
+                       t.Skip("skipping: FileListener not implemented on windows")
+               }
                l := listen(t)
                f, _ := l.File()
                l1, _ := FileListener(f)
@@ -445,6 +448,9 @@ func TestUnixUnlink(t *testing.T) {
        })
 
        t.Run("FileListener/SetUnlinkOnClose(true)", func(t *testing.T) {
+               if runtime.GOOS == "windows" {
+                       t.Skip("skipping: FileListener not implemented on windows")
+               }
                l := listen(t)
                f, _ := l.File()
                l1, _ := FileListener(f)
@@ -458,6 +464,9 @@ func TestUnixUnlink(t *testing.T) {
        })
 
        t.Run("FileListener/SetUnlinkOnClose(false)", func(t *testing.T) {
+               if runtime.GOOS == "windows" {
+                       t.Skip("skipping: FileListener not implemented on windows")
+               }
                l := listen(t)
                f, _ := l.File()
                l1, _ := FileListener(f)