Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jan 1, 2025
1 parent 2890f2a commit 2404201
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 33 deletions.
7 changes: 3 additions & 4 deletions pkg/abi/nvgpu/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,11 @@ const (
NV2080_CTRL_CMD_BUS_GET_C2C_INFO = 0x2080182b
)


// +marshal
type NV2080_CTRL_BUS_GET_INFO_PARAMS struct {
BusInfoListSize uint32 `nvproxy:"same"`
_ uint32
BusInfoList P64
BusInfoListSize uint32
_ uint32
BusInfoList P64
}

// From src/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080ce.h:
Expand Down
4 changes: 2 additions & 2 deletions pkg/sentry/devices/nvproxy/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,8 @@ func ctrlBusGetInfo(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54_PARAMETERS
if _, err := ctrlParams.CopyIn(fi.t, addrFromP64(ioctlParams.Params)); err != nil {
return 0, err
}
busInfoBuf := make([]byte, ctrlParams.BusInfoListSize * nvgpu.CtrlXxxInfoSize)

busInfoBuf := make([]byte, ctrlParams.BusInfoListSize*nvgpu.CtrlXxxInfoSize)

return ctrlBusGetInfoInvoke(fi, ioctlParams, &ctrlParams, busInfoBuf)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sentry/devices/nvproxy/frontend_unsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func ctrlBusGetInfoInvoke(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54_PARA
}

func ctrlClientSystemGetBuildVersionInvoke(fi *frontendIoctlState, ioctlParams *nvgpu.NVOS54_PARAMETERS, ctrlParams *nvgpu.NV0000_CTRL_SYSTEM_GET_BUILD_VERSION_PARAMS, driverVersionBuf, versionBuf, titleBuf *byte) (uintptr, error) {
// *Buf arguments don't need runtime.KeepAlive() since our caller
// *Buf arguments don't need runtime.KeepAlive() since our caller
// ctrlClientSystemGetBuildVersion() copies them out, keeping them alive
// during this function.
origPDriverVersionBuffer := ctrlParams.PDriverVersionBuffer
Expand Down
4 changes: 2 additions & 2 deletions pkg/sentry/devices/nvproxy/seccomp_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func frontendIoctlFilters(enabledCaps nvconf.DriverCaps) []seccomp.SyscallRule {
{seccomp.EqualTo(frontendIoctlCmd(nvgpu.NV_ESC_RM_MAP_MEMORY, nvgpu.SizeofIoctlNVOS33ParametersWithFD)), compUtil},
{seccomp.EqualTo(frontendIoctlCmd(nvgpu.NV_ESC_RM_UNMAP_MEMORY, nvgpu.SizeofNVOS34Parameters)), compUtil},
{seccomp.EqualTo(frontendIoctlCmd(nvgpu.NV_ESC_RM_ALLOC_CONTEXT_DMA2, nvgpu.SizeofNVOS39Parameters)), nvconf.CapGraphics},
{seccomp.EqualTo(frontendIoctlCmd(nvgpu.NV_ESC_RM_MAP_MEMORY_DMA, nvgpu.SizeofNVOS46Parameters)), nvconf.CapGraphics|nvconf.CapVideo},
{seccomp.MaskedEqual(notIocSizeMask, frontendIoctlCmd(nvgpu.NV_ESC_RM_UNMAP_MEMORY_DMA, 0)), nvconf.CapGraphics|nvconf.CapVideo},
{seccomp.EqualTo(frontendIoctlCmd(nvgpu.NV_ESC_RM_MAP_MEMORY_DMA, nvgpu.SizeofNVOS46Parameters)), nvconf.CapGraphics | nvconf.CapVideo},
{seccomp.MaskedEqual(notIocSizeMask, frontendIoctlCmd(nvgpu.NV_ESC_RM_UNMAP_MEMORY_DMA, 0)), nvconf.CapGraphics | nvconf.CapVideo},
{seccomp.EqualTo(frontendIoctlCmd(nvgpu.NV_ESC_RM_UPDATE_DEVICE_MAPPING_INFO, nvgpu.SizeofNVOS56Parameters)), compUtil},
} {
if feIoctl.caps&enabledCaps != 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sentry/devices/nvproxy/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func Init() {
nvgpu.NV2080_CTRL_CMD_GPU_GET_INFOROM_IMAGE_VERSION: simpleDriverStruct("NV2080_CTRL_GPU_GET_INFOROM_IMAGE_VERSION_PARAMS"),
nvgpu.NV2080_CTRL_CMD_GPU_QUERY_INFOROM_ECC_SUPPORT: nil, // No params.
nvgpu.NV2080_CTRL_CMD_GPU_GET_ENCODER_CAPACITY: simpleDriverStruct("NV2080_CTRL_GPU_GET_ENCODER_CAPACITY_PARAMS"),
nvgpu.NV2080_CTRL_CMD_GPU_GET_ENGINES_V2: simpleDriverStruct("NV2080_CTRL_GPU_GET_ENGINES_V2_PARAMS"),
nvgpu.NV2080_CTRL_CMD_GPU_GET_ENGINES_V2: simpleDriverStruct("NV2080_CTRL_GPU_GET_ENGINES_V2_PARAMS"),
nvgpu.NV2080_CTRL_CMD_GPU_GET_ACTIVE_PARTITION_IDS: simpleDriverStruct("NV2080_CTRL_GPU_GET_ACTIVE_PARTITION_IDS_PARAMS"),
nvgpu.NV2080_CTRL_CMD_GPU_GET_PIDS: simpleDriverStruct("NV2080_CTRL_GPU_GET_PIDS_PARAMS"),
nvgpu.NV2080_CTRL_CMD_GPU_GET_PID_INFO: simpleDriverStruct("NV2080_CTRL_GPU_GET_PID_INFO_PARAMS"),
Expand Down
26 changes: 3 additions & 23 deletions test/gpu/ffmpeg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,9 @@ import (
// TestFffmpegEncodeGPU runs ffmpeg in a GPU container using NVENC.
func TestFffmpegEncodeGPU(t *testing.T) {
ctx := context.Background()
isGVisor, err := dockerutil.IsGVisorRuntime(ctx, t)
if err != nil {
t.Fatalf("Failed to determine if runtime is gVisor: %v", err)
}
if isGVisor {
t.Skip("This test is currently broken in gVisor")
}
container := dockerutil.MakeContainer(ctx, t)
defer container.CleanUp(ctx)
opts, err := dockerutil.GPURunOpts(dockerutil.SniffGPUOpts{
Capabilities: "NVIDIA_DRIVER_CAPABILITIES=video",
AllowIncompatibleIoctl: true, // TODO(gvisor.dev/issue/9452): Remove once supported in gVisor.
})
opts, err := dockerutil.GPURunOpts(dockerutil.SniffGPUOpts{Capabilities: "NVIDIA_DRIVER_CAPABILITIES=compute,video"})
if err != nil {
t.Fatalf("Failed to get GPU run options: %v", err)
}
Expand All @@ -50,26 +40,16 @@ func TestFffmpegEncodeGPU(t *testing.T) {
// TestFffmpegDecodeGPU runs ffmpeg in a GPU container using NVDEC.
func TestFffmpegDecodeGPU(t *testing.T) {
ctx := context.Background()
isGVisor, err := dockerutil.IsGVisorRuntime(ctx, t)
if err != nil {
t.Fatalf("Failed to determine if runtime is gVisor: %v", err)
}
if isGVisor {
t.Skip("This test is currently broken in gVisor")
}
container := dockerutil.MakeContainer(ctx, t)
defer container.CleanUp(ctx)
opts, err := dockerutil.GPURunOpts(dockerutil.SniffGPUOpts{
Capabilities: "NVIDIA_DRIVER_CAPABILITIES=video",
AllowIncompatibleIoctl: true, // TODO(gvisor.dev/issue/9452): Remove once supported in gVisor.
})
opts, err := dockerutil.GPURunOpts(dockerutil.SniffGPUOpts{Capabilities: "NVIDIA_DRIVER_CAPABILITIES=compute,video"})
if err != nil {
t.Fatalf("Failed to get GPU run options: %v", err)
}
opts.Image = "benchmarks/ffmpeg"
// h264_cuvid refers to NVDEC. See Section 4.2 in
// https://docs.nvidia.com/video-technologies/video-codec-sdk/pdf/Using_FFmpeg_with_NVIDIA_GPU_Hardware_Acceleration.pdf
cmd := strings.Split("ffmpeg -y -vsync 0 -c:v h264_cuvid -i video.mp4 output.yuv", " ")
cmd := []string{"bash", "-c", "ffmpeg -i video.mp4 -c:v h264_nvenc -preset fast output.mp4 && ffmpeg -y -vsync 0 -c:v h264_cuvid -i output.mp4 video.mp4"}
if output, err := container.Run(ctx, opts, cmd...); err != nil {
t.Errorf("failed to run container: %v; output:\n%s", err, output)
}
Expand Down

0 comments on commit 2404201

Please sign in to comment.