Add a "GPU" passthrough functional test
@@ -4,6 +4,7 @@ import (
"encoding/xml"
"fmt"
"strings"
+ "time"
expect "github.com/google/goexpect"
. "github.com/onsi/ginkgo"
@@ -17,6 +18,7 @@ import (
"kubevirt.io/kubevirt/pkg/util"
"kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/api"
+ virtconfig "kubevirt.io/kubevirt/pkg/virt-config"
"kubevirt.io/kubevirt/tests"
"kubevirt.io/kubevirt/tests/console"
cd "kubevirt.io/kubevirt/tests/containerdisk"
@@ -138,5 +140,46 @@ var _ = Describe("[Serial]GPU", func() {
checkGPUDevice(randomVMI, "10de")
})
+
+ It("Should successfully passthrough an emulated PCI device", func() {
+ deviceName := "example.org/soundcard"
+ deviceIDs := "8086:2668"
+ kv := tests.GetCurrentKv(virtClient)
+
+ By("Adding the emulated sound card to the permitted host devices")
+ config := kv.Spec.Configuration
+ config.DeveloperConfiguration.FeatureGates = []string{virtconfig.GPUGate}
+ config.PermittedHostDevices = &v1.PermittedHostDevices{
+ PciHostDevices: []v1.PciHostDevice{
+ {
+ Selector: deviceIDs,
+ ResourceName: deviceName,
+ },
+ },
+ }
+ tests.UpdateKubeVirtConfigValueAndWait(config)
+
+ By("Creating a Fedora VMI with the sound card as a \"GPU\"")
+ randomVMI := tests.NewRandomFedoraVMIWitGuestAgent()
+ gpus := []v1.GPU{
+ v1.GPU{
+ Name: "sound",
+ DeviceName: deviceName,
+ },
+ }
+ randomVMI.Spec.Domain.Devices.GPUs = gpus
+ vmi, err := virtClient.VirtualMachineInstance(tests.NamespaceTestDefault).Create(randomVMI)
+ Expect(err).ToNot(HaveOccurred())
+ tests.WaitForSuccessfulVMIStart(vmi)
+ expecter, err := tests.LoggedInFedoraExpecter(vmi)
+ Expect(err).ToNot(HaveOccurred())
+
+ By("Making sure the sound card is present inside the VMI")
+ _, err = tests.ExpectBatchWithValidatedSend(expecter, []expect.Batcher{
+ &expect.BSnd{S: "grep -c " + strings.Replace(deviceIDs, ":", "", 1) + " /proc/bus/pci/devices\n"},
+ &expect.BExp{R: tests.RetValue("1")},
+ }, 15*time.Second)
+ Expect(err).ToNot(HaveOccurred(), "Device not found")
+ })
})
})
