summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/host/socket_test.go
diff options
context:
space:
mode:
authorAyush Ranjan <ayushranjan@google.com>2021-03-03 10:23:55 -0800
committergVisor bot <gvisor-bot@google.com>2021-03-03 10:25:58 -0800
commita9441aea2780da8c93da1c73da860219f98438de (patch)
tree8b12915756f5bfb926218214cd7bc0b3281605fd /pkg/sentry/fs/host/socket_test.go
parentb8a5420f49a2afd622ec08b5019e1bf537f7da82 (diff)
[op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys. Note that syscall is still used in the following places: - pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities are not yet available in golang.org/x/sys. - syscall.Stat_t is still used in some places because os.FileInfo.Sys() still returns it and not unix.Stat_t. Updates #214 PiperOrigin-RevId: 360701387
Diffstat (limited to 'pkg/sentry/fs/host/socket_test.go')
-rw-r--r--pkg/sentry/fs/host/socket_test.go30
1 files changed, 15 insertions, 15 deletions
diff --git a/pkg/sentry/fs/host/socket_test.go b/pkg/sentry/fs/host/socket_test.go
index 9d58ea448..f7014b6b1 100644
--- a/pkg/sentry/fs/host/socket_test.go
+++ b/pkg/sentry/fs/host/socket_test.go
@@ -16,9 +16,9 @@ package host
import (
"reflect"
- "syscall"
"testing"
+ "golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/fd"
"gvisor.dev/gvisor/pkg/fdnotifier"
"gvisor.dev/gvisor/pkg/sentry/contexttest"
@@ -40,7 +40,7 @@ var (
)
func getFl(fd int) (uint32, error) {
- fl, _, err := syscall.RawSyscall(syscall.SYS_FCNTL, uintptr(fd), syscall.F_GETFL, 0)
+ fl, _, err := unix.RawSyscall(unix.SYS_FCNTL, uintptr(fd), unix.F_GETFL, 0)
if err == 0 {
return uint32(fl), nil
}
@@ -49,7 +49,7 @@ func getFl(fd int) (uint32, error) {
func TestSocketIsBlocking(t *testing.T) {
// Using socketpair here because it's already connected.
- pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
+ pair, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0)
if err != nil {
t.Fatalf("host socket creation failed: %v", err)
}
@@ -58,13 +58,13 @@ func TestSocketIsBlocking(t *testing.T) {
if err != nil {
t.Fatalf("getFl: fcntl(%v, GETFL) => %v", pair[0], err)
}
- if fl&syscall.O_NONBLOCK == syscall.O_NONBLOCK {
+ if fl&unix.O_NONBLOCK == unix.O_NONBLOCK {
t.Fatalf("Expected socket %v to be blocking", pair[0])
}
if fl, err = getFl(pair[1]); err != nil {
t.Fatalf("getFl: fcntl(%v, GETFL) => %v", pair[1], err)
}
- if fl&syscall.O_NONBLOCK == syscall.O_NONBLOCK {
+ if fl&unix.O_NONBLOCK == unix.O_NONBLOCK {
t.Fatalf("Expected socket %v to be blocking", pair[1])
}
ctx := contexttest.Context(t)
@@ -77,20 +77,20 @@ func TestSocketIsBlocking(t *testing.T) {
if fl, err = getFl(pair[0]); err != nil {
t.Fatalf("getFl: fcntl(%v, GETFL) => %v", pair[0], err)
}
- if fl&syscall.O_NONBLOCK != syscall.O_NONBLOCK {
+ if fl&unix.O_NONBLOCK != unix.O_NONBLOCK {
t.Errorf("Expected socket %v to have become non-blocking", pair[0])
}
if fl, err = getFl(pair[1]); err != nil {
t.Fatalf("getFl: fcntl(%v, GETFL) => %v", pair[1], err)
}
- if fl&syscall.O_NONBLOCK == syscall.O_NONBLOCK {
+ if fl&unix.O_NONBLOCK == unix.O_NONBLOCK {
t.Errorf("Did not expect socket %v to become non-blocking", pair[1])
}
}
func TestSocketWritev(t *testing.T) {
// Using socketpair here because it's already connected.
- pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
+ pair, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0)
if err != nil {
t.Fatalf("host socket creation failed: %v", err)
}
@@ -113,7 +113,7 @@ func TestSocketWritev(t *testing.T) {
func TestSocketWritevLen0(t *testing.T) {
// Using socketpair here because it's already connected.
- pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
+ pair, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0)
if err != nil {
t.Fatalf("host socket creation failed: %v", err)
}
@@ -135,7 +135,7 @@ func TestSocketWritevLen0(t *testing.T) {
func TestSocketSendMsgLen0(t *testing.T) {
// Using socketpair here because it's already connected.
- pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
+ pair, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0)
if err != nil {
t.Fatalf("host socket creation failed: %v", err)
}
@@ -158,9 +158,9 @@ func TestSocketSendMsgLen0(t *testing.T) {
}
func TestListen(t *testing.T) {
- pair, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
+ pair, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM, 0)
if err != nil {
- t.Fatalf("syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0) => %v", err)
+ t.Fatalf("unix.Socket(unix.AF_UNIX, unix.SOCK_STREAM, 0) => %v", err)
}
ctx := contexttest.Context(t)
sfile1, err := newSocket(ctx, pair[0], false)
@@ -186,9 +186,9 @@ func TestListen(t *testing.T) {
}
// Create a Unix socket, do not bind it.
- sock, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
+ sock, err := unix.Socket(unix.AF_UNIX, unix.SOCK_STREAM, 0)
if err != nil {
- t.Fatalf("syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0) => %v", err)
+ t.Fatalf("unix.Socket(unix.AF_UNIX, unix.SOCK_STREAM, 0) => %v", err)
}
sfile3, err := newSocket(ctx, sock, false)
if err != nil {
@@ -236,7 +236,7 @@ func TestQueuedSize(t *testing.T) {
}
func TestRelease(t *testing.T) {
- f, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, 0)
+ f, err := unix.Socket(unix.AF_UNIX, unix.SOCK_STREAM|unix.SOCK_NONBLOCK|unix.SOCK_CLOEXEC, 0)
if err != nil {
t.Fatal("Creating socket:", err)
}