From 5b47d132c228b998edd69ab11dfeecf225c77662 Mon Sep 17 00:00:00 2001 From: Anthony Cui Date: Wed, 31 Jul 2024 11:23:21 -0700 Subject: [PATCH] Add nvproxy test to ensure ABI and struct name maps cover the same ioctls. PiperOrigin-RevId: 658078138 --- pkg/sentry/devices/nvproxy/nvproxy_test.go | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/sentry/devices/nvproxy/nvproxy_test.go b/pkg/sentry/devices/nvproxy/nvproxy_test.go index 35373c152..0756fb9d3 100644 --- a/pkg/sentry/devices/nvproxy/nvproxy_test.go +++ b/pkg/sentry/devices/nvproxy/nvproxy_test.go @@ -37,3 +37,36 @@ func TestAllSupportedHashesPresent(t *testing.T) { } } } + +// TestABIStructNamesInSync tests that all the supported ioctls in an ABI version are also mapped +// by GetStructNames. +func TestABIStructNamesInSync(t *testing.T) { + Init() + for version, abiCons := range abis { + t.Run(version.String(), func(t *testing.T) { + abi := abiCons.cons() + structNames := abi.getStructNames() + + for ioctl := range abi.frontendIoctl { + if _, ok := structNames.frontendNames[ioctl]; !ok { + t.Errorf("Frontend ioctl %#x not found in struct names for version %v", ioctl, version.String()) + } + } + for ioctl := range abi.uvmIoctl { + if _, ok := structNames.uvmNames[ioctl]; !ok { + t.Errorf("UVM ioctl %#x not found in struct names for version %v", ioctl, version.String()) + } + } + for ioctl := range abi.controlCmd { + if _, ok := structNames.controlNames[ioctl]; !ok { + t.Errorf("Control command %#x not found in struct names for version %v", ioctl, version.String()) + } + } + for ioctl := range abi.allocationClass { + if _, ok := structNames.allocationNames[ioctl]; !ok { + t.Errorf("Alloc class %#x not found in struct names for version %v", ioctl, version.String()) + } + } + }) + } +}