1
0
mirror of https://github.com/golang/go synced 2024-09-29 20:24:34 -06:00

net: retrieve if unix network is available only once for AIX

The previous version was executing "oslevel -s" everytime testableNetwork
was called with unix/unixgram network. The current version retrieves if
the network is possible only once at the beginning of the tests.

This is clearly faster:
ok      net     74.045s
ok      net     5.098s

Change-Id: I12549da27721f85c007cf17cab5cfdbfeb839cf6
Reviewed-on: https://go-review.googlesource.com/c/go/+/171717
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Clément Chigot 2019-04-11 16:26:38 +02:00 committed by Brad Fitzpatrick
parent 90458ec80e
commit 77fa11dffb

View File

@ -14,6 +14,23 @@ import (
"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 {
@ -38,15 +55,7 @@ func testableNetwork(network string) bool {
case "android", "nacl", "plan9", "windows":
return false
case "aix":
// Unix network isn't properly working on AIX 7.2 with Technical Level < 2
out, err := exec.Command("oslevel", "-s").Output()
if err != nil {
return false
}
if tl, err := strconv.Atoi(string(out[5:7])); err != nil || tl < 2 {
return false
}
return true
return unixEnabledOnAIX
}
// iOS does not support unix, unixgram.
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {