Add notes to relevant tests.

These were out-of-band notes that can help provide additional context
and simplify automated imports.

PiperOrigin-RevId: 293525915
This commit is contained in:
Adin Scannell
2020-02-05 22:46:35 -08:00
committed by gVisor bot
parent f3d9560703
commit 1b6a12a768
43 changed files with 318 additions and 113 deletions
-1
View File
@@ -46,7 +46,6 @@ var (
//
// TODO(b/67298402): Support non-cumulative metrics.
// TODO(b/67298427): Support metric fields.
//
type Uint64Metric struct {
// value is the actual value of the metric. It must be accessed
// atomically.
+4
View File
@@ -114,6 +114,10 @@ func newX86FPStateSlice() []byte {
size, align := cpuid.HostFeatureSet().ExtendedStateSize()
capacity := size
// Always use at least 4096 bytes.
//
// For the KVM platform, this state is a fixed 4096 bytes, so make sure
// that the underlying array is at _least_ that size otherwise we will
// corrupt random memory. This is not a pleasant thing to debug.
if capacity < 4096 {
capacity = 4096
}
+1 -1
View File
@@ -55,7 +55,7 @@ type SignalContext64 struct {
Trapno uint64
Oldmask linux.SignalSet
Cr2 uint64
// Pointer to a struct _fpstate.
// Pointer to a struct _fpstate. See b/33003106#comment8.
Fpstate uint64
Reserved [8]uint64
}
+1
View File
@@ -177,6 +177,7 @@ func TestReaddirRevalidation(t *testing.T) {
// TestReaddirOverlayFrozen tests that calling Readdir on an overlay file with
// a frozen dirent tree does not make Readdir calls to the underlying files.
// This is a regression test for b/114808269.
func TestReaddirOverlayFrozen(t *testing.T) {
ctx := contexttest.Context(t)
+4
View File
@@ -11,6 +11,8 @@ inconsistency, please file a bug.
The following files are implemented:
<!-- mdformat off(don't wrap the table) -->
| File /proc/ | Content |
| :------------------------ | :---------------------------------------------------- |
| [cpuinfo](#cpuinfo) | Info about the CPU |
@@ -22,6 +24,8 @@ The following files are implemented:
| [uptime](#uptime) | Wall clock since boot, combined idle time of all cpus |
| [version](#version) | Kernel version |
<!-- mdformat on -->
### cpuinfo
```bash
+1
View File
@@ -91,6 +91,7 @@ go_library(
"fs_context.go",
"ipc_namespace.go",
"kernel.go",
"kernel_opts.go",
"kernel_state.go",
"pending_signals.go",
"pending_signals_list.go",
+3
View File
@@ -235,6 +235,9 @@ type Kernel struct {
// events. This is initialized lazily on the first unimplemented
// syscall.
unimplementedSyscallEmitter eventchannel.Emitter `state:"nosave"`
// SpecialOpts contains special kernel options.
SpecialOpts
}
// InitKernelArgs holds arguments to Init.
+20
View File
@@ -0,0 +1,20 @@
// Copyright 2020 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package kernel
// SpecialOpts contains non-standard options for the kernel.
//
// +stateify savable
type SpecialOpts struct{}
+1
View File
@@ -10,6 +10,7 @@ go_library(
"save_restore.go",
"socket.go",
"socket_unsafe.go",
"sockopt_impl.go",
"stack.go",
],
visibility = ["//pkg/sentry:internal"],
+3 -2
View File
@@ -285,7 +285,7 @@ func (s *socketOperations) GetSockOpt(t *kernel.Task, level int, name int, outPt
}
// Whitelist options and constrain option length.
var optlen int
optlen := getSockOptLen(t, level, name)
switch level {
case linux.SOL_IP:
switch name {
@@ -330,7 +330,7 @@ func (s *socketOperations) GetSockOpt(t *kernel.Task, level int, name int, outPt
// SetSockOpt implements socket.Socket.SetSockOpt.
func (s *socketOperations) SetSockOpt(t *kernel.Task, level int, name int, opt []byte) *syserr.Error {
// Whitelist options and constrain option length.
var optlen int
optlen := setSockOptLen(t, level, name)
switch level {
case linux.SOL_IP:
switch name {
@@ -353,6 +353,7 @@ func (s *socketOperations) SetSockOpt(t *kernel.Task, level int, name int, opt [
optlen = sizeofInt32
}
}
if optlen == 0 {
// Pretend to accept socket options we don't understand. This seems
// dangerous, but it's what netstack does...
@@ -0,0 +1,27 @@
// Copyright 2020 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package hostinet
import (
"gvisor.dev/gvisor/pkg/sentry/kernel"
)
func getSockOptLen(t *kernel.Task, level, name int) int {
return 0 // No custom options.
}
func setSockOptLen(t *kernel.Task, level, name int) int {
return 0 // No custom options.
}
+3
View File
@@ -2166,6 +2166,9 @@ func (e *endpoint) listen(backlog int) *tcpip.Error {
e.isRegistered = true
e.setEndpointState(StateListen)
// The channel may be non-nil when we're restoring the endpoint, and it
// may be pre-populated with some previously accepted (but not Accepted)
// endpoints.
if e.acceptedChan == nil {
e.acceptedChan = make(chan *endpoint, backlog)
}
+1
View File
@@ -8,6 +8,7 @@ go_library(
"config.go",
"config_amd64.go",
"config_arm64.go",
"config_profile.go",
"extra_filters.go",
"extra_filters_msan.go",
"extra_filters_race.go",
-13
View File
@@ -536,16 +536,3 @@ func controlServerFilters(fd int) seccomp.SyscallRules {
},
}
}
// profileFilters returns extra syscalls made by runtime/pprof package.
func profileFilters() seccomp.SyscallRules {
return seccomp.SyscallRules{
syscall.SYS_OPENAT: []seccomp.Rule{
{
seccomp.AllowAny{},
seccomp.AllowAny{},
seccomp.AllowValue(syscall.O_RDONLY | syscall.O_LARGEFILE | syscall.O_CLOEXEC),
},
},
}
}
+34
View File
@@ -0,0 +1,34 @@
// Copyright 2020 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package filter
import (
"syscall"
"gvisor.dev/gvisor/pkg/seccomp"
)
// profileFilters returns extra syscalls made by runtime/pprof package.
func profileFilters() seccomp.SyscallRules {
return seccomp.SyscallRules{
syscall.SYS_OPENAT: []seccomp.Rule{
{
seccomp.AllowAny{},
seccomp.AllowAny{},
seccomp.AllowValue(syscall.O_RDONLY | syscall.O_LARGEFILE | syscall.O_CLOEXEC),
},
},
}
}
+4 -1
View File
@@ -196,7 +196,10 @@ func TestJobControlSignalExec(t *testing.T) {
defer ptyMaster.Close()
defer ptySlave.Close()
// Exec bash and attach a terminal.
// Exec bash and attach a terminal. Note that occasionally /bin/sh
// may be a different shell or have a different configuration (such
// as disabling interactive mode and job control). Since we want to
// explicitly test interactive mode, use /bin/bash. See b/116981926.
execArgs := &control.ExecArgs{
Filename: "/bin/bash",
// Don't let bash execute from profile or rc files, otherwise
+5 -6
View File
@@ -143,8 +143,11 @@ func PrepareFiles(names ...string) (string, error) {
return "", fmt.Errorf("os.Chmod(%q, 0777) failed: %v", dir, err)
}
for _, name := range names {
src := getLocalPath(name)
dst := path.Join(dir, name)
src, err := testutil.FindFile(name)
if err != nil {
return "", fmt.Errorf("testutil.Preparefiles(%q) failed: %v", name, err)
}
dst := path.Join(dir, path.Base(name))
if err := testutil.Copy(src, dst); err != nil {
return "", fmt.Errorf("testutil.Copy(%q, %q) failed: %v", src, dst, err)
}
@@ -152,10 +155,6 @@ func PrepareFiles(names ...string) (string, error) {
return dir, nil
}
func getLocalPath(file string) string {
return path.Join(".", file)
}
// do executes docker command.
func do(args ...string) (string, error) {
log.Printf("Running: docker %s\n", args)
+4 -1
View File
@@ -5,7 +5,10 @@ package(licenses = ["notice"])
go_library(
name = "testutil",
testonly = 1,
srcs = ["testutil.go"],
srcs = [
"testutil.go",
"testutil_runfiles.go",
],
visibility = ["//:sandbox"],
deps = [
"//pkg/log",
-54
View File
@@ -79,60 +79,6 @@ func ConfigureExePath() error {
return nil
}
// FindFile searchs for a file inside the test run environment. It returns the
// full path to the file. It fails if none or more than one file is found.
func FindFile(path string) (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}
// The test root is demarcated by a path element called "__main__". Search for
// it backwards from the working directory.
root := wd
for {
dir, name := filepath.Split(root)
if name == "__main__" {
break
}
if len(dir) == 0 {
return "", fmt.Errorf("directory __main__ not found in %q", wd)
}
// Remove ending slash to loop around.
root = dir[:len(dir)-1]
}
// Annoyingly, bazel adds the build type to the directory path for go
// binaries, but not for c++ binaries. We use two different patterns to
// to find our file.
patterns := []string{
// Try the obvious path first.
filepath.Join(root, path),
// If it was a go binary, use a wildcard to match the build
// type. The pattern is: /test-path/__main__/directories/*/file.
filepath.Join(root, filepath.Dir(path), "*", filepath.Base(path)),
}
for _, p := range patterns {
matches, err := filepath.Glob(p)
if err != nil {
// "The only possible returned error is ErrBadPattern,
// when pattern is malformed." -godoc
return "", fmt.Errorf("error globbing %q: %v", p, err)
}
switch len(matches) {
case 0:
// Try the next pattern.
case 1:
// We found it.
return matches[0], nil
default:
return "", fmt.Errorf("more than one match found for %q: %s", path, matches)
}
}
return "", fmt.Errorf("file %q not found", path)
}
// TestConfig returns the default configuration to use in tests. Note that
// 'RootDir' must be set by caller if required.
func TestConfig() *boot.Config {
+75
View File
@@ -0,0 +1,75 @@
// Copyright 2018 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package testutil
import (
"fmt"
"os"
"path/filepath"
)
// FindFile searchs for a file inside the test run environment. It returns the
// full path to the file. It fails if none or more than one file is found.
func FindFile(path string) (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
}
// The test root is demarcated by a path element called "__main__". Search for
// it backwards from the working directory.
root := wd
for {
dir, name := filepath.Split(root)
if name == "__main__" {
break
}
if len(dir) == 0 {
return "", fmt.Errorf("directory __main__ not found in %q", wd)
}
// Remove ending slash to loop around.
root = dir[:len(dir)-1]
}
// Annoyingly, bazel adds the build type to the directory path for go
// binaries, but not for c++ binaries. We use two different patterns to
// to find our file.
patterns := []string{
// Try the obvious path first.
filepath.Join(root, path),
// If it was a go binary, use a wildcard to match the build
// type. The pattern is: /test-path/__main__/directories/*/file.
filepath.Join(root, filepath.Dir(path), "*", filepath.Base(path)),
}
for _, p := range patterns {
matches, err := filepath.Glob(p)
if err != nil {
// "The only possible returned error is ErrBadPattern,
// when pattern is malformed." -godoc
return "", fmt.Errorf("error globbing %q: %v", p, err)
}
switch len(matches) {
case 0:
// Try the next pattern.
case 1:
// We found it.
return matches[0], nil
default:
return "", fmt.Errorf("more than one match found for %q: %s", path, matches)
}
}
return "", fmt.Errorf("file %q not found", path)
}

Some files were not shown because too many files have changed in this diff Show More