mirror of https://github.com/golang/go.git
net: re-enable raw socket tests on windows
Since CL 38bf89161a72 raw socket tests are not executed on windows builders. This change re-enable them again. It will attempt to run raw socket tests only if user is permitted to create raw socket by OS. Fixes #6392 R=golang-dev CC=golang-dev, mikioh.mikioh, rsc https://golang.org/cl/13422044
This commit is contained in:
parent
0f3ea75020
commit
b80ef1ab48
|
|
@ -125,3 +125,7 @@ func setReadBuffer(fd *netFD, bytes int) error {
|
|||
func setWriteBuffer(fd *netFD, bytes int) error {
|
||||
return syscall.EPLAN9
|
||||
}
|
||||
|
||||
func skipRawSocketTests() (skip bool, skipmsg string, err error) {
|
||||
return true, "skipping test on plan9", nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -473,3 +473,10 @@ func (fd *netFD) dup() (f *os.File, err error) {
|
|||
func closesocket(s int) error {
|
||||
return syscall.Close(s)
|
||||
}
|
||||
|
||||
func skipRawSocketTests() (skip bool, skipmsg string, err error) {
|
||||
if os.Getuid() != 0 {
|
||||
return true, "skipping test; must be root", nil
|
||||
}
|
||||
return false, "", nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -568,6 +568,25 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (*netFD, error) {
|
|||
return netfd, nil
|
||||
}
|
||||
|
||||
func skipRawSocketTests() (skip bool, skipmsg string, err error) {
|
||||
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
|
||||
// Note: To use a socket of type SOCK_RAW requires administrative privileges.
|
||||
// Users running Winsock applications that use raw sockets must be a member of
|
||||
// the Administrators group on the local computer, otherwise raw socket calls
|
||||
// will fail with an error code of WSAEACCES. On Windows Vista and later, access
|
||||
// for raw sockets is enforced at socket creation. In earlier versions of Windows,
|
||||
// access for raw sockets is enforced during other socket operations.
|
||||
s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, 0)
|
||||
if err == syscall.WSAEACCES {
|
||||
return true, "skipping test; no access to raw socket allowed", nil
|
||||
}
|
||||
if err != nil {
|
||||
return true, "", err
|
||||
}
|
||||
defer syscall.Closesocket(s)
|
||||
return false, "", nil
|
||||
}
|
||||
|
||||
// Unimplemented functions.
|
||||
|
||||
func (fd *netFD) dup() (*os.File, error) {
|
||||
|
|
|
|||
|
|
@ -59,6 +59,14 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
func skipRawSocketTest(t *testing.T) (skip bool, skipmsg string) {
|
||||
skip, skipmsg, err := skipRawSocketTests()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return skip, skipmsg
|
||||
}
|
||||
|
||||
func TestResolveIPAddr(t *testing.T) {
|
||||
for _, tt := range resolveIPAddrTests {
|
||||
addr, err := ResolveIPAddr(tt.net, tt.litAddrOrName)
|
||||
|
|
@ -80,17 +88,8 @@ var icmpEchoTests = []struct {
|
|||
}
|
||||
|
||||
func TestConnICMPEcho(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "plan9":
|
||||
t.Skipf("skipping test on %q", runtime.GOOS)
|
||||
case "windows":
|
||||
if testing.Short() || !*testExternal {
|
||||
t.Skipf("skipping test on %q to avoid network firewall", runtime.GOOS)
|
||||
}
|
||||
default:
|
||||
if os.Getuid() != 0 {
|
||||
t.Skip("skipping test; must be root")
|
||||
}
|
||||
if skip, skipmsg := skipRawSocketTest(t); skip {
|
||||
t.Skip(skipmsg)
|
||||
}
|
||||
|
||||
for i, tt := range icmpEchoTests {
|
||||
|
|
@ -157,17 +156,8 @@ func TestConnICMPEcho(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPacketConnICMPEcho(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "plan9":
|
||||
t.Skipf("skipping test on %q", runtime.GOOS)
|
||||
case "windows":
|
||||
if testing.Short() || !*testExternal {
|
||||
t.Skipf("skipping test on %q to avoid network firewall", runtime.GOOS)
|
||||
}
|
||||
default:
|
||||
if os.Getuid() != 0 {
|
||||
t.Skip("skipping test; must be root")
|
||||
}
|
||||
if skip, skipmsg := skipRawSocketTest(t); skip {
|
||||
t.Skip(skipmsg)
|
||||
}
|
||||
|
||||
for i, tt := range icmpEchoTests {
|
||||
|
|
|
|||
|
|
@ -25,10 +25,6 @@ var ipv4MulticastListenerTests = []struct {
|
|||
// port.
|
||||
func TestIPv4MulticastListener(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
if testing.Short() || !*testExternal {
|
||||
t.Skipf("skipping test on %q to avoid network firewall", runtime.GOOS)
|
||||
}
|
||||
case "plan9":
|
||||
t.Skipf("skipping test on %q", runtime.GOOS)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,20 +26,9 @@ func packetConnTestData(t *testing.T, net string, i int) ([]byte, func()) {
|
|||
case "udp":
|
||||
return []byte("UDP PACKETCONN TEST"), nil
|
||||
case "ip":
|
||||
switch runtime.GOOS {
|
||||
case "plan9":
|
||||
if skip, skipmsg := skipRawSocketTest(t); skip {
|
||||
return nil, func() {
|
||||
t.Logf("skipping %q test on %q", net, runtime.GOOS)
|
||||
}
|
||||
case "windows":
|
||||
if testing.Short() || !*testExternal {
|
||||
t.Skipf("skipping test on %q to avoid network firewall", runtime.GOOS)
|
||||
}
|
||||
default:
|
||||
if os.Getuid() != 0 {
|
||||
return nil, func() {
|
||||
t.Logf("skipping %q test; must be root", net)
|
||||
}
|
||||
t.Logf(skipmsg)
|
||||
}
|
||||
}
|
||||
b, err := (&icmpMessage{
|
||||
|
|
|
|||
|
|
@ -173,17 +173,8 @@ func TestUDPConnSpecificMethods(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIPConnSpecificMethods(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "plan9":
|
||||
t.Skipf("skipping test on %q", runtime.GOOS)
|
||||
case "windows":
|
||||
if testing.Short() || !*testExternal {
|
||||
t.Skipf("skipping test on %q to avoid network firewall", runtime.GOOS)
|
||||
}
|
||||
default:
|
||||
if os.Getuid() != 0 {
|
||||
t.Skipf("skipping test; must be root")
|
||||
}
|
||||
if skip, skipmsg := skipRawSocketTest(t); skip {
|
||||
t.Skip(skipmsg)
|
||||
}
|
||||
|
||||
la, err := ResolveIPAddr("ip4", "127.0.0.1")
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ const (
|
|||
ERROR_OPERATION_ABORTED Errno = 995
|
||||
ERROR_IO_PENDING Errno = 997
|
||||
ERROR_NOT_FOUND Errno = 1168
|
||||
WSAEACCES Errno = 10013
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
Loading…
Reference in New Issue