net: TestInterfaceHardwareAddrWithWmic fails #23153
Comments
Thanks for spotting this! @alexbrainman which version of Windows is this machine on? Can you run Trying to track down the mapping between wmic parameters and |
I have VirtualBox installed. Alex |
Change https://golang.org/cl/84696 mentions this issue: |
Is this just a bug/kludge in the Microsoft? On my system the interface is called "Local Area Connection 14" and ipconfig shows a "mac address" of 00..0e. Which is just another way to say 14... |
I do not know how this things were decided by Microsoft? @mattn can you, please, run net.TestInterfaceHardwareAddrWithWmic on current tip. That code got changed recently, and I am worried about interface names that have non-English characters in it. I remember that test broke for you in the past. Thank you. Alex |
@alexbrainman wmic command seems not list with names if the interface is down. Anyone, could you please try this? diff --git a/src/net/net_windows_test.go b/src/net/net_windows_test.go
index ab09cdb28a..5c227d81b4 100644
--- a/src/net/net_windows_test.go
+++ b/src/net/net_windows_test.go
@@ -523,6 +523,10 @@ func TestInterfaceHardwareAddrWithWmic(t *testing.T) {
// no MAC address for loopback interfaces
continue
}
+ if ifi.Flags&FlagUp == 0 {
+ // interface is not up
+ continue
+ }
goMacToName[ifi.HardwareAddr.String()] = ifi.Name
}
On my environment, some of NIC name have multi-byte strings. So tests always fail. (Yes, this is known issue) |
Ah, I misreaded. Sorry. Enabled flag can be used.
Yes, As you mentioned about non-english interface names, I still have problem. |
@alexbrainman Good news. wmic command output UTF-16 when the output is a file. It return DBCS when output is a pipe. So writing file should work. Could you please add runWmic? diff --git a/src/net/net_windows_test.go b/src/net/net_windows_test.go
index ab09cdb28a..ed02ae7e62 100644
--- a/src/net/net_windows_test.go
+++ b/src/net/net_windows_test.go
@@ -18,6 +18,7 @@ import (
"syscall"
"testing"
"time"
+ "unsafe"
)
func toErrno(err error) (syscall.Errno, bool) {
@@ -512,6 +513,29 @@ func contains(needle string, haystack []string) bool {
return false
}
+func runWmic(args ...string) ([]byte, error) {
+ f, err := ioutil.TempFile("", "wmic")
+ if err != nil {
+ return nil, err
+ }
+ defer os.Remove(f.Name())
+ cmd := exec.Command(args[0], args[1:]...)
+ cmd.Stdout = f
+ err = cmd.Run()
+ f.Close()
+ if err != nil {
+ return nil, err
+ }
+ b, err := ioutil.ReadFile(f.Name())
+ if err != nil {
+ return nil, err
+ }
+ if len(b) >= 3 && b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF {
+ b = b[3:]
+ }
+ return []byte(syscall.UTF16ToString(*(*[]uint16)(unsafe.Pointer(&b)))), nil
+}
+
func TestInterfaceHardwareAddrWithWmic(t *testing.T) {
ift, err := Interfaces()
if err != nil {
@@ -523,6 +547,10 @@ func TestInterfaceHardwareAddrWithWmic(t *testing.T) {
// no MAC address for loopback interfaces
continue
}
+ if ifi.Flags&FlagUp == 0 {
+ // interface is not up
+ continue
+ }
goMacToName[ifi.HardwareAddr.String()] = ifi.Name
}
@@ -533,7 +561,7 @@ func TestInterfaceHardwareAddrWithWmic(t *testing.T) {
//SERVER-2008R2-V,42:01:0A:F0:00:18,Local Area Connection
//SERVER-2008R2-V,42:01:0A:F0:00:18,Duplicate Adapter
//SERVER-2008R2-V,20:41:53:59:4E:FF,
- out, err := exec.Command("wmic", "nic", "get", "MACAddress,NetConnectionID", "/format:csv").CombinedOutput()
+ out, err := runWmic("wmic", "nic", "get", "MACAddress,NetConnectionID", "/format:csv")
if err != nil {
t.Fatal(err)
} |
Thank you for confirming. Sorry about the break. I will let @johnsonj decide what to do about CL 84696, and then we need to fix your problem with non-English names. I suggest you create new issue for non-English names, so we don't forget to fix it before go1.10 is released. Thank you. Alex |
Change https://golang.org/cl/85315 mentions this issue: |
this solution as it stands doesn't work with non-english device names (#23191 (which has a fix)) and names some devices differently (#23153) probably due to the fact that this test previously only ran on Server 2008. Re-opens #20073 Change-Id: I5c36774ddd85ac07620b4015372d564acbb169ad Reviewed-on: https://go-review.googlesource.com/85315 Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Change https://golang.org/cl/84935 mentions this issue: |
I'm not quite sure what is happening with this issue. It says that there is a test failure, but it seems that the test was reverted. What is left to do here? Thanks. |
TestInterfaceHardwareAddrWithWmic is removed now, so this issue can be closed. We still have issue #20073 opened - TestInterfaceHardwareAddrWithWmic was added to fix #20073. Thank you. Alex |
Thanks. |
What version of Go are you using (
go version
)?go version devel +98443ecd0a Fri Dec 15 21:57:27 2017 +0000 windows/amd64
Does this issue reproduce with the latest release?
Yes, it does.
What operating system and processor architecture are you using (
go env
)?set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Alex\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\users\alex\dev
set GORACE=
set GOROOT=c:\users\alex\dev\go
set GOTMPDIR=
set GOTOOLDIR=c:\users\alex\dev\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Alex\AppData\Local\Temp\go-build981970258=/tmp/go-build -gno-record-gcc-switches
What did you do?
I run
go test -run=TestInterfaceHardwareAddrWithWmic net
command.What did you expect to see?
What did you see instead?
Alex
The text was updated successfully, but these errors were encountered: