mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add rudimentary UDS test to lisafs
PiperOrigin-RevId: 483732841
This commit is contained in:
committed by
gVisor bot
parent
84767a8f23
commit
7e3bd4db0f
@@ -77,6 +77,7 @@ var localFSTests = map[string]TestFunc{
|
||||
"Walk": testWalk,
|
||||
"Rename": testRename,
|
||||
"Mknod": testMknod,
|
||||
"UDS": testUDS,
|
||||
"Getdents": testGetdents,
|
||||
}
|
||||
|
||||
@@ -200,6 +201,14 @@ func mknod(ctx context.Context, t *testing.T, dir lisafs.ClientFD, name string)
|
||||
return dir.Client().NewFD(nodeIno.ControlFD), nodeIno.Stat
|
||||
}
|
||||
|
||||
func bind(ctx context.Context, t *testing.T, dir lisafs.ClientFD, name string, sockType linux.SockType) (lisafs.ClientFD, *lisafs.ClientBoundSocketFD, linux.Statx) {
|
||||
nodeIno, socket, err := dir.BindAt(ctx, sockType, name, 0777, lisafs.UID(unix.Getuid()), lisafs.GID(unix.Getgid()))
|
||||
if err != nil {
|
||||
t.Fatalf("bind failed: %v", err)
|
||||
}
|
||||
return dir.Client().NewFD(nodeIno.ControlFD), socket, nodeIno.Stat
|
||||
}
|
||||
|
||||
func walk(ctx context.Context, t *testing.T, dir lisafs.ClientFD, names []string) []lisafs.Inode {
|
||||
_, inodes, err := dir.WalkMultiple(ctx, names)
|
||||
if err != nil {
|
||||
@@ -563,10 +572,22 @@ func testRename(ctx context.Context, t *testing.T, tester Tester, root lisafs.Cl
|
||||
}
|
||||
|
||||
func testMknod(ctx context.Context, t *testing.T, tester Tester, root lisafs.ClientFD) {
|
||||
name := "namedPipe"
|
||||
name := "regular-file"
|
||||
pipeFile, pipeStat := mknod(ctx, t, root, name)
|
||||
defer closeFD(ctx, t, pipeFile)
|
||||
|
||||
if got := pipeStat.Mode & unix.S_IFMT; got != unix.S_IFREG {
|
||||
t.Errorf("socket file mode is incorrect: want %#x, got %#x", unix.S_IFSOCK, got)
|
||||
}
|
||||
if tester.SetUserGroupIDSupported() {
|
||||
if want := unix.Getuid(); int(pipeStat.UID) != want {
|
||||
t.Errorf("socket file uid is incorrect: want %d, got %d", want, pipeStat.UID)
|
||||
}
|
||||
if want := unix.Getgid(); int(pipeStat.GID) != want {
|
||||
t.Errorf("socket file gid is incorrect: want %d, got %d", want, pipeStat.GID)
|
||||
}
|
||||
}
|
||||
|
||||
var stat linux.Statx
|
||||
statTo(ctx, t, pipeFile, &stat)
|
||||
|
||||
@@ -581,6 +602,40 @@ func testMknod(ctx context.Context, t *testing.T, tester Tester, root lisafs.Cli
|
||||
}
|
||||
}
|
||||
|
||||
func testUDS(ctx context.Context, t *testing.T, tester Tester, root lisafs.ClientFD) {
|
||||
const name = "sock"
|
||||
file, socket, stat := bind(ctx, t, root, name, unix.SOCK_STREAM)
|
||||
defer closeFD(ctx, t, file)
|
||||
defer socket.Close(ctx)
|
||||
|
||||
if got := stat.Mode & unix.S_IFMT; got != unix.S_IFSOCK {
|
||||
t.Errorf("socket file mode is incorrect: want %#x, got %#x", unix.S_IFSOCK, got)
|
||||
}
|
||||
if tester.SetUserGroupIDSupported() {
|
||||
if want := unix.Getuid(); int(stat.UID) != want {
|
||||
t.Errorf("socket file uid is incorrect: want %d, got %d", want, stat.UID)
|
||||
}
|
||||
if want := unix.Getgid(); int(stat.GID) != want {
|
||||
t.Errorf("socket file gid is incorrect: want %d, got %d", want, stat.GID)
|
||||
}
|
||||
}
|
||||
|
||||
var got linux.Statx
|
||||
statTo(ctx, t, file, &got)
|
||||
if stat.Mode != got.Mode {
|
||||
t.Errorf("UDS mode is incorrect: want %d, got %d", stat.Mode, got.Mode)
|
||||
}
|
||||
if stat.UID != got.UID {
|
||||
t.Errorf("mknod UID is incorrect: want %d, got %d", stat.UID, got.UID)
|
||||
}
|
||||
if stat.GID != got.GID {
|
||||
t.Errorf("mknod GID is incorrect: want %d, got %d", stat.GID, got.GID)
|
||||
}
|
||||
|
||||
// TODO(b/194709873): Once listen and accept are implemented, test connecting
|
||||
// and accepting a connection using sockF.
|
||||
}
|
||||
|
||||
func testGetdents(ctx context.Context, t *testing.T, tester Tester, root lisafs.ClientFD) {
|
||||
tempDir, _ := mkdir(ctx, t, root, "tempDir")
|
||||
defer closeFD(ctx, t, tempDir)
|
||||
|
||||
@@ -53,5 +53,6 @@ go_test(
|
||||
"//pkg/lisafs",
|
||||
"//pkg/lisafs/testsuite",
|
||||
"//pkg/log",
|
||||
"//runsc/config",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/lisafs"
|
||||
"gvisor.dev/gvisor/pkg/lisafs/testsuite"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/runsc/config"
|
||||
"gvisor.dev/gvisor/runsc/fsgofer"
|
||||
)
|
||||
|
||||
@@ -38,7 +39,7 @@ type tester struct{}
|
||||
|
||||
// NewServer implements testsuite.Tester.NewServer.
|
||||
func (tester) NewServer(t *testing.T) *lisafs.Server {
|
||||
return &fsgofer.NewLisafsServer(fsgofer.Config{}).Server
|
||||
return &fsgofer.NewLisafsServer(fsgofer.Config{HostUDS: config.HostUDSCreate}).Server
|
||||
}
|
||||
|
||||
// LinkSupported implements testsuite.Tester.LinkSupported.
|
||||
|
||||
Reference in New Issue
Block a user