From 9cc22a7f1fbabfc1b82d198d2ac6d1ec7771e47f Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Tue, 29 Mar 2016 12:24:18 +1100 Subject: [PATCH] net: skip TestInterfacesWithNetsh if "netsh help" contains no English words Fixes #14859 Change-Id: I262d634ee22498ec9855d273afdd409149765294 Reviewed-on: https://go-review.googlesource.com/21195 Reviewed-by: Brad Fitzpatrick Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot --- src/net/net_windows_test.go | 40 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/net/net_windows_test.go b/src/net/net_windows_test.go index 12846426635..38edbc29ab6 100644 --- a/src/net/net_windows_test.go +++ b/src/net/net_windows_test.go @@ -178,18 +178,6 @@ func isWindowsXP(t *testing.T) bool { return major < 6 } -var ( - modkernel32 = syscall.NewLazyDLL("kernel32.dll") - procGetACP = modkernel32.NewProc("GetACP") -) - -func isEnglishOS(t *testing.T) bool { - const windows_1252 = 1252 // ANSI Latin 1; Western European (Windows) - r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0) - acp := uint32(r0) - return acp == windows_1252 -} - func runCmd(args ...string) ([]byte, error) { removeUTF8BOM := func(b []byte) []byte { if len(b) >= 3 && b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF { @@ -226,6 +214,14 @@ func runCmd(args ...string) ([]byte, error) { return removeUTF8BOM(out), nil } +func netshSpeaksEnglish(t *testing.T) bool { + out, err := runCmd("netsh", "help") + if err != nil { + t.Fatal(err) + } + return bytes.Contains(out, []byte("The following commands are available:")) +} + func netshInterfaceIPShowInterface(ipver string, ifaces map[string]bool) error { out, err := runCmd("netsh", "interface", ipver, "show", "interface", "level=verbose") if err != nil { @@ -273,8 +269,8 @@ func TestInterfacesWithNetsh(t *testing.T) { if isWindowsXP(t) { t.Skip("Windows XP netsh command does not provide required functionality") } - if !isEnglishOS(t) { - t.Skip("English version of OS required for this test") + if !netshSpeaksEnglish(t) { + t.Skip("English version of netsh required for this test") } toString := func(name string, isup bool) string { @@ -447,8 +443,8 @@ func TestInterfaceAddrsWithNetsh(t *testing.T) { if isWindowsXP(t) { t.Skip("Windows XP netsh command does not provide required functionality") } - if !isEnglishOS(t) { - t.Skip("English version of OS required for this test") + if !netshSpeaksEnglish(t) { + t.Skip("English version of netsh required for this test") } outIPV4, err := runCmd("netsh", "interface", "ipv4", "show", "address") @@ -507,12 +503,20 @@ func TestInterfaceAddrsWithNetsh(t *testing.T) { } } +func getmacSpeaksEnglish(t *testing.T) bool { + out, err := runCmd("getmac", "/?") + if err != nil { + t.Fatal(err) + } + return bytes.Contains(out, []byte("network adapters on a system")) +} + func TestInterfaceHardwareAddrWithGetmac(t *testing.T) { if isWindowsXP(t) { t.Skip("Windows XP does not have powershell command") } - if !isEnglishOS(t) { - t.Skip("English version of OS required for this test") + if !getmacSpeaksEnglish(t) { + t.Skip("English version of getmac required for this test") } ift, err := Interfaces()