Source file
src/internal/syscall/unix/kernel_version_solaris_test.go
1
2
3
4
5
6
7 package unix_test
8
9 import (
10 "internal/syscall/unix"
11 "runtime"
12 "syscall"
13 "testing"
14 )
15
16 func TestSupportSockNonblockCloexec(t *testing.T) {
17
18 s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, 0)
19 if err == nil {
20 syscall.Close(s)
21 }
22 wantSock := err != syscall.EPROTONOSUPPORT && err != syscall.EINVAL
23 gotSock := unix.SupportSockNonblockCloexec()
24 if wantSock != gotSock {
25 t.Fatalf("SupportSockNonblockCloexec, got %t; want %t", gotSock, wantSock)
26 }
27
28
29 for {
30 _, _, err = syscall.Accept4(0, syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC)
31 if err != syscall.EINTR {
32 break
33 }
34 }
35 wantAccept4 := err != syscall.ENOSYS
36 gotAccept4 := unix.SupportAccept4()
37 if wantAccept4 != gotAccept4 {
38 t.Fatalf("SupportAccept4, got %t; want %t", gotAccept4, wantAccept4)
39 }
40
41
42 major, minor := unix.KernelVersion()
43 t.Logf("Kernel version: %d.%d", major, minor)
44 if runtime.GOOS == "illumos" {
45 if gotSock && gotAccept4 && (major < 5 || (major == 5 && minor < 11)) {
46 t.Fatalf("SupportSockNonblockCloexec and SupportAccept4 are true, but kernel version is older than 5.11, SunOS version: %d.%d", major, minor)
47 }
48 if !gotSock && !gotAccept4 && (major > 5 || (major == 5 && minor >= 11)) {
49 t.Errorf("SupportSockNonblockCloexec and SupportAccept4 are false, but kernel version is 5.11 or newer, SunOS version: %d.%d", major, minor)
50 }
51 } else {
52 if gotSock && gotAccept4 && (major < 11 || (major == 11 && minor < 4)) {
53 t.Fatalf("SupportSockNonblockCloexec and SupportAccept4 are true, but kernel version is older than 11.4, Solaris version: %d.%d", major, minor)
54 }
55 if !gotSock && !gotAccept4 && (major > 11 || (major == 11 && minor >= 4)) {
56 t.Errorf("SupportSockNonblockCloexec and SupportAccept4 are false, but kernel version is 11.4 or newer, Solaris version: %d.%d", major, minor)
57 }
58 }
59 }
60
View as plain text