From 86917c6c59bc0535d656a10680faa27e50d2b311 Mon Sep 17 00:00:00 2001 From: Mika Tammi Date: Wed, 1 Nov 2023 18:19:18 +0200 Subject: [PATCH] Verify passed PCI devices are visible inside VM Signed-off-by: Mika Tammi --- .../virtualization_keywords.resource | 54 +++++++++++++++++++ .../test-suites/bat-tests/netvm.robot | 9 ++++ 2 files changed, 63 insertions(+) create mode 100644 Robot-Framework/resources/virtualization_keywords.resource diff --git a/Robot-Framework/resources/virtualization_keywords.resource b/Robot-Framework/resources/virtualization_keywords.resource new file mode 100644 index 0000000..48dd109 --- /dev/null +++ b/Robot-Framework/resources/virtualization_keywords.resource @@ -0,0 +1,54 @@ +# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII) +# SPDX-License-Identifier: Apache-2.0 + +*** Settings *** +Library SSHLibrary +Resource ../config/variables.robot +Library BuiltIn +Library String + + +*** Keywords *** + +Verify microvm PCI device passthrough + [Documentation] Verify that proper PCI devices have been passed through to the VM + [Arguments] ${host_connection} ${vm_connection} ${vmname} + Switch Connection ${vm_connection} + @{pciids}= Get list of PCI IDs + Switch Connection ${host_connection} + @{pcipassthrus}= Get microvm PCI passthrough list vmname=${vmname} + FOR ${pcipass} IN @{pcipassthrus} + ${pciidpass}= Get PCI ID from PCI Address address=${pcipass} + Log Checking if PCI ID has been passed through to VM + Should Contain ${pciids} ${pciidpass} + END + +Get list of PCI IDs + [Documentation] Runs lspci and returns VENDORID:DEVICEID pairs + ... Pre-condition: requires active ssh connection to either + ... host or one of the VMs, and ability run + ... lspci in the target. + ${cmd}= Set Variable lspci -n | cut -d ' ' -f 3 + ${stdout} ${stderr} ${rc}= Execute Command ${cmd} return_stdout=True return_stderr=True return_rc=True + Should Be Equal As Integers ${rc} 0 + @{lines}= Split To Lines ${stdout} + [return] @{lines} + +Get microvm PCI passthrough list + [Documentation] Returns PCI Addresses, like 0001:01:00.0 + ... Pre-condition: requires active ssh connection to ghaf host + [Arguments] ${vmname} + ${cmd}= Format String cat /var/lib/microvms/{vmname}/booted/share/microvm/pci-devices vmname=${vmname} + ${stdout} ${stderr} ${rc}= Execute Command ${cmd} return_stdout=True return_stderr=True return_rc=True + Should Be Equal As Integers ${rc} 0 + @{lines}= Split To Lines ${stdout} + [return] @{lines} + +Get PCI ID from PCI Address + [Documentation] Gets VENDORID:DEVICEID pair from sysfs + [Arguments] ${address} + ${cmd}= Set Variable VENDOR=$(cut -c 3-7 /sys/bus/pci/devices/${address}/vendor) && DEVICE=$(cut -c 3-7 /sys/bus/pci/devices/${address}/device) && echo "$VENDOR:$DEVICE" + ${stdout} ${stderr} ${rc}= Execute Command ${cmd} return_stdout=True return_stderr=True return_rc=True + Should Be Equal As Integers ${rc} 0 + ${stripped}= Strip String ${stdout} + [return] ${stripped} diff --git a/Robot-Framework/test-suites/bat-tests/netvm.robot b/Robot-Framework/test-suites/bat-tests/netvm.robot index a0546ea..31ced6e 100644 --- a/Robot-Framework/test-suites/bat-tests/netvm.robot +++ b/Robot-Framework/test-suites/bat-tests/netvm.robot @@ -5,6 +5,7 @@ Documentation Testing Network VM Force Tags netvm Resource ../../resources/ssh_keywords.resource +Resource ../../resources/virtualization_keywords.resource Resource ../../config/variables.robot Suite Teardown Close All Connections @@ -75,6 +76,14 @@ Verify wpa_supplicant.service is running Switch Connection ${netvm} Verify service status service=wpa_supplicant.service +Verify NetVM PCI device passthrough + [Documentation] Verify that proper PCI devices have been passed through to the NetVM + [Tags] bat SP-T670 nuc orin-agx orin-nx + [Setup] Run Keywords + ... Connect to ghaf host AND Connect to netvm via tunnel + Verify microvm PCI device passthrough host_connection=${ghaf_host} vm_connection=${netvm} vmname=${NETVM_NAME} + [Teardown] Run Keywords Close All Connections + *** Keywords ***