Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: TestInterfaceHardwareAddrWithWmic fails #23153

Closed
alexbrainman opened this issue Dec 15, 2017 · 16 comments

Comments

Projects
None yet
7 participants
@alexbrainman
Copy link
Member

commented Dec 15, 2017

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?

PASS

What did you see instead?

--- FAIL: TestInterfaceHardwareAddrWithWmic (0.31s)
        net_windows_test.go:560: go interface count (3, map[0a:00:27:00:00:06:VirtualBox Host-Only Network #2 44:8a:5b:e8:97:a9:Ethernet 00:00:00:00:00:00:00:e0:Teredo Tunneling Pseudo-Interface]) differs from wmic count (2, map[44:8a:5b:e8:97:a9:[Ethernet] 0a:00:27:00:00:06:[VirtualBox Host-Only Network #2]])
        net_windows_test.go:572: go found interface (name: Teredo Tunneling Pseudo-Interface, mac: 00:00:00:00:00:00:00:e0) not found by wmic (map[44:8a:5b:e8:97:a9:[Ethernet] 0a:00:27:00:00:06:[VirtualBox Host-Only Network #2]])
FAIL
FAIL    net     0.638s

Alex

@odeke-em odeke-em added the OS-Windows label Dec 16, 2017

@odeke-em

This comment has been minimized.

Copy link
Member

commented Dec 16, 2017

@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented Dec 16, 2017

Thank you @odeke-em but leaving for @johnsonj because he touched that test last. :-)
I will try to investigate this when I have time. I am also happy to test CLs on my computer any time.

Alex

@johnsonj

This comment has been minimized.

Copy link
Member

commented Dec 18, 2017

Thanks for spotting this!

@alexbrainman which version of Windows is this machine on? Can you run wmic nic get MACAddress,NetConnectionID,Name,Description,AdapterType,PhysicalAdapter,SystemName /format:csv

Trying to track down the mapping between wmic parameters and net.Interfaces()

msdn reference

@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented Dec 18, 2017

@alexbrainman which version of Windows is this machine on?

C:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows 10 Enterprise
OS Version:                10.0.16299 N/A Build 16299

Can you run wmic nic get MACAddress,NetConnectionID,Name,Description,AdapterType,PhysicalAdapter,SystemName /format:csv

C:\>wmic nic get MACAddress,NetConnectionID,Name,Description,AdapterType,PhysicalAdapter,SystemName /format:csv

Node,AdapterType,Description,MACAddress,Name,NetConnectionID,PhysicalAdapter,SystemName
SHARIK,,Microsoft Kernel Debug Network Adapter,,Microsoft Kernel Debug Network Adapter,,FALSE,SHARIK
SHARIK,Ethernet 802.3,Realtek PCIe GBE Family Controller,44:8A:5B:E8:97:A9,Realtek PCIe GBE Family Controller,Ethernet,TRUE,SHARIK
SHARIK,Tunnel,Microsoft Teredo Tunneling Adapter,,Teredo Tunneling Pseudo-Interface,,FALSE,SHARIK
SHARIK,,WAN Miniport (SSTP),,WAN Miniport (SSTP),,FALSE,SHARIK
SHARIK,,WAN Miniport (IKEv2),,WAN Miniport (IKEv2),,FALSE,SHARIK
SHARIK,,WAN Miniport (L2TP),,WAN Miniport (L2TP),,FALSE,SHARIK
SHARIK,,WAN Miniport (PPTP),,WAN Miniport (PPTP),,FALSE,SHARIK
SHARIK,,WAN Miniport (PPPOE),,WAN Miniport (PPPOE),,FALSE,SHARIK
SHARIK,Ethernet 802.3,WAN Miniport (IP),DA:A5:20:52:41:53,WAN Miniport (IP),,FALSE,SHARIK
SHARIK,Ethernet 802.3,WAN Miniport (IPv6),E0:78:20:52:41:53,WAN Miniport (IPv6),,FALSE,SHARIK
SHARIK,Ethernet 802.3,WAN Miniport (Network Monitor),E4:3C:20:52:41:53,WAN Miniport (Network Monitor),,FALSE,SHARIK
SHARIK,Ethernet 802.3,VirtualBox Host-Only Ethernet Adapter,0A:00:27:00:00:06,VirtualBox Host-Only Ethernet Adapter #2,VirtualBox Host-Only Network #2,TRUE,SHARIK

I have VirtualBox installed.

Alex

@gopherbot

This comment has been minimized.

Copy link

commented Dec 19, 2017

Change https://golang.org/cl/84696 mentions this issue: net: use NetEnabled for TestInterfaceHardwareAddrWithWmic

@as

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2017

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...

@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented Dec 19, 2017

Is this just a bug/kludge in the Microsoft?

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

@mattn

This comment has been minimized.

Copy link
Member

commented Dec 19, 2017

@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)

@mattn

This comment has been minimized.

Copy link
Member

commented Dec 19, 2017

Ah, I misreaded. Sorry. Enabled flag can be used.

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.

Yes, As you mentioned about non-english interface names, I still have problem.

@mattn

This comment has been minimized.

Copy link
Member

commented Dec 19, 2017

@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)
 	}
@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented Dec 20, 2017

As you mentioned about non-english interface names, I still have problem.

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

@gopherbot

This comment has been minimized.

Copy link

commented Dec 22, 2017

Change https://golang.org/cl/85315 mentions this issue: Revert "net: enable TestInterfaceHardwareAddrWithGetmac on all windows versions"

gopherbot pushed a commit that referenced this issue Dec 25, 2017

net: revert CL 82975
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>
@gopherbot

This comment has been minimized.

Copy link

commented Dec 25, 2017

Change https://golang.org/cl/84935 mentions this issue: net: redirect output out of wmic command to file on Windows

@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Go1.11 Mar 29, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2018

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.

@alexbrainman

This comment has been minimized.

Copy link
Member Author

commented Mar 29, 2018

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?

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2018

Thanks.

@golang golang locked and limited conversation to collaborators Mar 29, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.