mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Merge pull request #11030 from milantracy:rand
PiperOrigin-RevId: 688287238
This commit is contained in:
@@ -25,6 +25,7 @@ go_test(
|
||||
library = ":aio",
|
||||
deps = [
|
||||
"//pkg/bitmap",
|
||||
"//pkg/rand",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
+1
-1
@@ -17,12 +17,12 @@ package aio
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/bitmap"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
)
|
||||
|
||||
func TestRead(t *testing.T) {
|
||||
|
||||
@@ -62,6 +62,7 @@ go_test(
|
||||
],
|
||||
library = ":buffer",
|
||||
deps = [
|
||||
"//pkg/rand",
|
||||
"//pkg/state",
|
||||
"//pkg/tcpip/checksum",
|
||||
"@com_github_google_go_cmp//cmp:go_default_library",
|
||||
|
||||
@@ -19,11 +19,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
"gvisor.dev/gvisor/pkg/state"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/checksum"
|
||||
)
|
||||
|
||||
@@ -16,10 +16,10 @@ package buffer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
)
|
||||
|
||||
func TestNewView(t *testing.T) {
|
||||
|
||||
@@ -125,6 +125,7 @@ go_test(
|
||||
library = ":lisafs",
|
||||
deps = [
|
||||
"//pkg/marshal",
|
||||
"//pkg/rand",
|
||||
"//pkg/sync",
|
||||
"//pkg/unet",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
|
||||
@@ -16,12 +16,12 @@ package lisafs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/marshal"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/unet"
|
||||
)
|
||||
|
||||
@@ -14,6 +14,7 @@ go_library(
|
||||
"//pkg/abi/linux",
|
||||
"//pkg/context",
|
||||
"//pkg/lisafs",
|
||||
"//pkg/rand",
|
||||
"//pkg/refs",
|
||||
"//pkg/unet",
|
||||
"@com_github_syndtr_gocapability//capability:go_default_library",
|
||||
|
||||
@@ -19,7 +19,6 @@ package testsuite
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -29,6 +28,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/context"
|
||||
"gvisor.dev/gvisor/pkg/lisafs"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
"gvisor.dev/gvisor/pkg/refs"
|
||||
"gvisor.dev/gvisor/pkg/unet"
|
||||
)
|
||||
|
||||
@@ -87,6 +87,7 @@ go_test(
|
||||
deps = [
|
||||
"//pkg/fd",
|
||||
"//pkg/p9",
|
||||
"//pkg/rand",
|
||||
"//pkg/sync",
|
||||
"@com_github_golang_mock//gomock:go_default_library",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/fd"
|
||||
"gvisor.dev/gvisor/pkg/p9"
|
||||
gvisorrand "gvisor.dev/gvisor/pkg/rand"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
)
|
||||
|
||||
@@ -2192,7 +2193,7 @@ func TestReadWriteConcurrent(t *testing.T) {
|
||||
|
||||
// Initialize random data for each instance.
|
||||
for i := 0; i < instances; i++ {
|
||||
if _, err := rand.Read(dataSets[i][:]); err != nil {
|
||||
if _, err := gvisorrand.Read(dataSets[i][:]); err != nil {
|
||||
t.Fatalf("error initializing dataSet#%d, got %v", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/atomicbitops",
|
||||
"//pkg/buffer",
|
||||
"//pkg/rand",
|
||||
"//pkg/sync",
|
||||
"//pkg/waiter",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
|
||||
@@ -42,6 +42,7 @@ go_test(
|
||||
library = ":fdbased",
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/rand",
|
||||
"//pkg/refs",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/header",
|
||||
|
||||
@@ -20,7 +20,6 @@ package fdbased
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"slices"
|
||||
"testing"
|
||||
@@ -30,6 +29,7 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
"gvisor.dev/gvisor/pkg/refs"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
|
||||
@@ -19,6 +19,7 @@ go_library(
|
||||
],
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/rand",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/checker",
|
||||
"//pkg/tcpip/header",
|
||||
|
||||
@@ -18,11 +18,11 @@ package testutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/checker"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
|
||||
+1
-1
@@ -35,7 +35,6 @@ import (
|
||||
"io"
|
||||
"math"
|
||||
"math/bits"
|
||||
"math/rand"
|
||||
"net"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -43,6 +42,7 @@ import (
|
||||
"time"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/atomicbitops"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
)
|
||||
|
||||
@@ -16,6 +16,7 @@ go_library(
|
||||
],
|
||||
visibility = ["//:sandbox"],
|
||||
deps = [
|
||||
"//pkg/rand",
|
||||
"//pkg/sentry/watchdog",
|
||||
"//pkg/sync",
|
||||
"//runsc/config",
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -40,6 +39,7 @@ import (
|
||||
"github.com/cenkalti/backoff"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/rand"
|
||||
"gvisor.dev/gvisor/pkg/sentry/watchdog"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/runsc/config"
|
||||
@@ -352,28 +352,13 @@ func writeSpec(dir string, spec *specs.Spec) error {
|
||||
return os.WriteFile(filepath.Join(dir, "config.json"), b, 0755)
|
||||
}
|
||||
|
||||
// idRandomSrc is a pseudo random generator used to in RandomID.
|
||||
var idRandomSrc = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
// idRandomSrcMtx is the mutex protecting idRandomSrc.Read from being used
|
||||
// concurrently in different goroutines.
|
||||
var idRandomSrcMtx sync.Mutex
|
||||
|
||||
// RandomID returns 20 random bytes following the given prefix.
|
||||
func RandomID(prefix string) string {
|
||||
// Read 20 random bytes.
|
||||
b := make([]byte, 20)
|
||||
// Rand.Read is not safe for concurrent use. Packetimpact tests can be run in
|
||||
// parallel now, so we have to protect the Read with a mutex. Otherwise we'll
|
||||
// run into name conflicts.
|
||||
// https://golang.org/pkg/math/rand/#Rand.Read
|
||||
idRandomSrcMtx.Lock()
|
||||
// "[Read] always returns len(p) and a nil error." --godoc
|
||||
if _, err := idRandomSrc.Read(b); err != nil {
|
||||
idRandomSrcMtx.Unlock()
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic("rand.Read failed: " + err.Error())
|
||||
}
|
||||
idRandomSrcMtx.Unlock()
|
||||
if prefix != "" {
|
||||
prefix = prefix + "-"
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ go_binary(
|
||||
],
|
||||
visibility = ["//:sandbox"],
|
||||
deps = [
|
||||
"//pkg/rand",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/adapters/gonet",
|
||||
"//pkg/tcpip/link/fdbased",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user