mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix sniffer_test by embedding the run_sniffer binary in it.
This works around file path resolution issues. PiperOrigin-RevId: 663985469
This commit is contained in:
committed by
gVisor bot
parent
6199fc8395
commit
043ce9c5d2
@@ -308,7 +308,7 @@ gpu-all-tests: gpu-images gpu-smoke-tests $(RUNTIME_BIN)
|
||||
@$(call sudo,test/gpu:imagegen_test,--runtime=$(RUNTIME) -test.v $(ARGS))
|
||||
@$(call sudo,test/gpu:sr_test,--runtime=$(RUNTIME) -test.v $(ARGS))
|
||||
@$(call sudo,test/gpu:nccl_test,--runtime=$(RUNTIME) -test.v $(ARGS))
|
||||
@$(call test,--test_env=RUNTIME=$(RUNTIME) test/gpu:sniffer_test)
|
||||
@$(call sudo,test/gpu:sniffer_test,--runtime=$(RUNTIME) -test.v $(ARGS))
|
||||
.PHONY: gpu-all-tests
|
||||
|
||||
cos-gpu-all-tests: gpu-images cos-gpu-smoke-tests $(RUNTIME_BIN)
|
||||
@@ -318,7 +318,7 @@ cos-gpu-all-tests: gpu-images cos-gpu-smoke-tests $(RUNTIME_BIN)
|
||||
@$(call sudo,test/gpu:imagegen_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
|
||||
@$(call sudo,test/gpu:sr_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
|
||||
@$(call sudo,test/gpu:nccl_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
|
||||
@$(call test,--test_env=RUNTIME=$(RUNTIME) --test_arg="--cos-gpu" test/gpu:sniffer_test)
|
||||
@$(call sudo,test/gpu:sniffer_test,--runtime=$(RUNTIME) -test.v --cos-gpu $(ARGS))
|
||||
.PHONY: cos-gpu-all-tests
|
||||
|
||||
portforward-tests: load-basic_redis load-basic_nginx $(RUNTIME_BIN)
|
||||
|
||||
+13
-3
@@ -103,11 +103,22 @@ go_test(
|
||||
deps = ["//test/gpu/stablediffusion"],
|
||||
)
|
||||
|
||||
# We copy the `run_sniffer` binary here because `go:embed` can only embed
|
||||
# from the current directory or subdirectories, not parents of it.
|
||||
genrule(
|
||||
name = "run_sniffer_copy",
|
||||
srcs = [
|
||||
"//tools/ioctl_sniffer:run_sniffer",
|
||||
],
|
||||
outs = ["run_sniffer_copy"],
|
||||
cmd = "cat < $(SRCS) > $@",
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "sniffer_test",
|
||||
srcs = ["sniffer_test.go"],
|
||||
data = [
|
||||
"//tools/ioctl_sniffer:run_sniffer",
|
||||
embedsrcs = [
|
||||
":run_sniffer_copy", # keep
|
||||
],
|
||||
tags = [
|
||||
"manual",
|
||||
@@ -117,7 +128,6 @@ go_test(
|
||||
visibility = ["//:sandbox"],
|
||||
deps = [
|
||||
"//pkg/test/dockerutil",
|
||||
"//pkg/test/testutil",
|
||||
"@com_github_docker_docker//api/types/mount:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -18,25 +18,48 @@ package sniffer_test
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"gvisor.dev/gvisor/pkg/test/dockerutil"
|
||||
"gvisor.dev/gvisor/pkg/test/testutil"
|
||||
|
||||
// Needed for go:embed
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
const maxDuration = 1 * time.Minute
|
||||
|
||||
//go:embed run_sniffer_copy
|
||||
var runSnifferBinary []byte
|
||||
|
||||
// RunCommand runs the given command via the sniffer, with the -enforce_compatibility flag.
|
||||
//
|
||||
// It's run in a docker container, with the cuda-tests image.
|
||||
func runCUDATestsCommand(t *testing.T, cmd ...string) (string, error) {
|
||||
// Find the sniffer binary
|
||||
cliPath, err := testutil.FindFile("tools/ioctl_sniffer/run_sniffer")
|
||||
// Extract the sniffer binary to a temporary location.
|
||||
runSniffer, err := os.CreateTemp("/tmp", "run_sniffer.*")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to find run_sniffer: %v", err)
|
||||
t.Fatalf("Failed to create temporary file: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := runSniffer.Close(); err != nil {
|
||||
t.Fatalf("Failed to close temporary file: %v", err)
|
||||
}
|
||||
if err := os.Remove(runSniffer.Name()); err != nil {
|
||||
t.Fatalf("Failed to unlink temporary file: %v", err)
|
||||
}
|
||||
}()
|
||||
if _, err := runSniffer.Write(runSnifferBinary); err != nil {
|
||||
t.Fatalf("Failed to write to temporary file: %v", err)
|
||||
}
|
||||
if err := runSniffer.Sync(); err != nil {
|
||||
t.Fatalf("Failed to sync temporary file: %v", err)
|
||||
}
|
||||
if err := runSniffer.Chmod(0o555); err != nil {
|
||||
t.Fatalf("Failed to chmod temporary file: %v", err)
|
||||
}
|
||||
|
||||
// Set up our docker container
|
||||
@@ -51,7 +74,7 @@ func runCUDATestsCommand(t *testing.T, cmd ...string) (string, error) {
|
||||
opts.Image = "gpu/cuda-tests"
|
||||
opts.Mounts = append(opts.Mounts, mount.Mount{
|
||||
Type: mount.TypeBind,
|
||||
Source: cliPath,
|
||||
Source: runSniffer.Name(),
|
||||
Target: "/run_sniffer",
|
||||
ReadOnly: false,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user