Skip to content

Commit 7e0856e

Browse files
committed
windows_update_perf: support VBS
Create a test case about windows updatete performance, and complete the first scenario of vbs support. Signed-off-by: Xiaoling Gao <[email protected]>
1 parent 0a0f82e commit 7e0856e

File tree

2 files changed

+250
-0
lines changed

2 files changed

+250
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
- win_virtio_perf_test:
2+
only q35
3+
only ovmf
4+
only Win2022, Win2025
5+
type = win_virtio_perf_test
6+
login_timeout = 720
7+
start_vm = no
8+
auto_cpu_model = yes
9+
clone_master = yes
10+
master_images_clone = image1
11+
remove_image_image1 = yes
12+
# support nested virtualization
13+
HostCpuVendor.intel:
14+
cpu_model_flags += ',vmx=on'
15+
HostCpuVendor.amd:
16+
cpu_model_flags += ',svm=on'
17+
restore_ovmf_vars = yes
18+
check_secure_boot_enabled_cmd = 'powershell -command "Confirm-SecureBootUEFI"'
19+
dst_path = "C:\dgreadiness"
20+
dgreadiness_path_cmd = "cd ${dst_path}\dgreadiness"
21+
set_ps_policy_cmd = 'powershell -command "Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force"'
22+
vbs_enable_cmd = 'powershell -command ".\DG_Readiness_Tool_v3.6.ps1 -Enable"'
23+
vbs_disable_cmd = 'powershell -command ".\DG_Readiness_Tool_v3.6.ps1 -Disable"'
24+
vbs_ready_cmd = 'powershell -command ".\DG_Readiness_Tool_v3.6.ps1 -Ready"'
25+
vbs_enable_info = 'Enabling Hyper-V and IOMMU successful'
26+
vbs_disable_info = 'Disabling Hyper-V and IOMMU successful'
27+
vbs_ready_info = 'HVCI, Credential-Guard, and Config-CI are enabled and running'
28+
dg_command = 'powershell -command "Get-CimInstance -ClassName Win32_DeviceGuard'
29+
dg_command += ' -Namespace root/Microsoft/Windows/DeviceGuard"'
30+
# WSL2 commands
31+
wsl_enable_cmd = 'dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart'
32+
vm_platform_cmd = 'dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart'
33+
wsl_set_default_cmd = 'wsl --set-default-version 2'
34+
rhel_install_cmd = 'wsl --install -d RHEL'
35+
wsl_list_cmd = 'wsl --list --verbose'
36+
rhel_distro_name = 'RHEL'
37+
rhel_test_cmd = 'wsl -d RHEL -- uname -a'
38+
# iommu setting, currently qemu only compatible with intel model
39+
variants:
40+
- no_iommu:
41+
- iommu_enable:
42+
only HostCpuVendor.intel
43+
machine_type_extra_params = "kernel-irqchip=split"
44+
# iommu device
45+
intel_iommu = yes
46+
iommu_device_iotlb = on
47+
iommu_eim = off
48+
iommu_intremap = on
49+
iommu_aw_bits = 48
50+
# virtio device
51+
virtio_dev_iommu_platform = on
52+
virtio_dev_filter = '^(?:(?:virtio-)|(?:vhost-))(?!(?:user)|(?:iommu))'
53+
# ats=on parily used with device-iotlb=on
54+
virtio_dev_ats = on
55+
enable_guest_iommu = yes

qemu/tests/win_virtio_perf_test.py

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
from virttest import data_dir, env_process, error_context
2+
3+
4+
@error_context.context_aware
5+
def run(test, params, env):
6+
"""
7+
Please make sure the guest installed with signed driver
8+
Verify Secure MOR control feature using Device Guard tool in Windows guest:
9+
10+
1) Boot up a guest.
11+
2) Check if Secure Boot is enable.
12+
3) Download DG_Readiness_Tool and copy to guest.
13+
4) Enable Device Guard and check the output.
14+
5) Reboot guest.
15+
6) Check the result of Device Guard.
16+
7) Disable Device Guard and shutdown guest.
17+
18+
:param test: QEMU test object
19+
:param params: Dictionary with the test parameters
20+
:param env: Dictionary with test environment.
21+
"""
22+
23+
def set_powershell_execute_policy():
24+
"""
25+
Set PowerShell execution policy using the provided session.
26+
It is used when creating a new session.
27+
28+
:param cmd: The PowerShell command to set execution policy.
29+
"""
30+
error_context.context("Setting PowerShell execution policy.")
31+
status, output = session.cmd_status_output(executionPolicy_command)
32+
if status != 0:
33+
test.fail("Failed to set PowerShell execution policy: %s" % output)
34+
35+
def check_secure_boot_enabled():
36+
"""
37+
Checks if Secure Boot is enabled in the guest.
38+
"""
39+
error_context.context("Checking if Secure Boot is enabled in the guest")
40+
output = session.cmd_output(check_cmd)
41+
if "false" in output.lower():
42+
test.fail("Secure Boot is not enabled: %s" % output)
43+
44+
def copy_dg_readiness_tool():
45+
"""
46+
Copies the Device Guard Readiness tool from the host to the guest VM.
47+
"""
48+
dgreadiness_host_path = data_dir.get_deps_dir("dgreadiness")
49+
dst_path = params["dst_path"]
50+
test.log.info("Copy Device Guard tool to guest.")
51+
s, o = session.cmd_status_output("mkdir %s" % dst_path)
52+
if s and "already exists" not in o:
53+
test.error(
54+
"Could not create Device Guard directory in "
55+
"VM '%s', detail: '%s'" % (vm.name, o)
56+
)
57+
vm.copy_files_to(dgreadiness_host_path, dst_path)
58+
59+
def check_vbs_ready():
60+
"""
61+
Check the status of Virtualization-Based Security (VBS) using the provided
62+
session.
63+
64+
:return: True if VBS is enabled, False otherwise.
65+
"""
66+
status, output = session.cmd_status_output(ready_command)
67+
if status != 0:
68+
test.fail("Failed to check VBS status: %s" % output)
69+
if vbs_ready_info in output:
70+
test.log.info("VBS is already enabled, and guest boot up successfully")
71+
return True
72+
else:
73+
test.log.info(
74+
"VBS is not enabled or the expected info was not found in the output"
75+
)
76+
return False
77+
78+
def run_device_guard_tool(cmd, expect_info):
79+
"""
80+
Executes the Device Guard Readiness Tool command in the guest to enable
81+
or disable Virtualization-Based Security (VBS).
82+
83+
:param cmd: The command to enable or disable VBS.
84+
"""
85+
error_context.context("running device guard readiness tool with %s" % cmd)
86+
output = session.cmd_output(cmd, 360)
87+
if expect_info not in output:
88+
test.fail("Failed to enable VBS: %s" % output)
89+
90+
def install_wsl2_and_rhel():
91+
"""
92+
Install WSL2 and start RHEL distribution in Windows VM.
93+
This function is called after VBS verification (step 5).
94+
"""
95+
error_context.context("Installing WSL2 and RHEL distribution")
96+
97+
# Enable WSL feature
98+
test.log.info("Enabling WSL feature...")
99+
status, output = session.cmd_status_output(wsl_enable_cmd, timeout=300)
100+
if status != 0:
101+
test.fail("Failed to enable WSL feature: %s" % output)
102+
103+
# Enable Virtual Machine Platform
104+
test.log.info("Enabling Virtual Machine Platform...")
105+
status, output = session.cmd_status_output(vm_platform_cmd, timeout=300)
106+
if status != 0:
107+
test.fail("Failed to enable VM Platform: %s" % output)
108+
109+
# Reboot to apply WSL2 features
110+
test.log.info("Rebooting to apply WSL2 features...")
111+
vm.reboot(timeout=login_timeout)
112+
new_session = vm.wait_for_serial_login(timeout=login_timeout)
113+
set_powershell_execute_policy()
114+
new_session.cmd(dgreadiness_path_command)
115+
116+
# Set WSL2 as default
117+
test.log.info("Setting WSL2 as default version...")
118+
status, output = new_session.cmd_status_output(wsl_set_default_cmd, timeout=60)
119+
if status != 0:
120+
test.fail("Failed to set WSL2 default: %s" % output)
121+
122+
# Install RHEL distribution
123+
test.log.info("Installing RHEL distribution...")
124+
status, output = new_session.cmd_status_output(rhel_install_cmd, timeout=600)
125+
if status != 0:
126+
test.fail("Failed to install RHEL: %s" % output)
127+
128+
# Verify WSL2 and RHEL installation
129+
test.log.info("Verifying WSL2 and RHEL...")
130+
status, output = new_session.cmd_status_output(wsl_list_cmd, timeout=60)
131+
if status != 0:
132+
test.fail("Failed to list WSL distributions: %s" % output)
133+
if rhel_distro_name not in output:
134+
test.fail("RHEL distribution not found: %s" % output)
135+
136+
# Test RHEL functionality
137+
test.log.info("Testing RHEL in WSL2...")
138+
status, output = new_session.cmd_status_output(rhel_test_cmd, timeout=120)
139+
if status != 0:
140+
test.fail("RHEL test failed: %s" % output)
141+
test.log.info("WSL2 with RHEL installed and verified successfully")
142+
return new_session
143+
144+
login_timeout = int(params.get("login_timeout", 360))
145+
params["ovmf_vars_filename"] = "OVMF_VARS.secboot.fd"
146+
params["clone_master"] = "yes"
147+
params["master_images_clone"] = "image1"
148+
params["remove_image_image1"] = "yes"
149+
params["start_vm"] = "yes"
150+
env_process.preprocess_vm(test, params, env, params["main_vm"])
151+
vm = env.get_vm(params["main_vm"])
152+
session = vm.wait_for_serial_login(timeout=login_timeout)
153+
154+
check_cmd = params["check_secure_boot_enabled_cmd"]
155+
dgreadiness_path_command = params["dgreadiness_path_cmd"]
156+
executionPolicy_command = params["set_ps_policy_cmd"]
157+
enable_command = params["vbs_enable_cmd"]
158+
disable_command = params["vbs_disable_cmd"]
159+
ready_command = params["vbs_ready_cmd"]
160+
vbs_ready_info = params["vbs_ready_info"]
161+
vbs_enable_info = params["vbs_enable_info"]
162+
vbs_disable_info = params["vbs_disable_info"]
163+
wsl_enable_cmd = params["wsl_enable_cmd"]
164+
vm_platform_cmd = params["vm_platform_cmd"]
165+
wsl_set_default_cmd = params["wsl_set_default_cmd"]
166+
rhel_install_cmd = params["rhel_install_cmd"]
167+
wsl_list_cmd = params["wsl_list_cmd"]
168+
rhel_distro_name = params["rhel_distro_name"]
169+
rhel_test_cmd = params["rhel_test_cmd"]
170+
171+
try:
172+
check_secure_boot_enabled()
173+
copy_dg_readiness_tool()
174+
set_powershell_execute_policy()
175+
session.cmd(dgreadiness_path_command)
176+
if not check_vbs_ready():
177+
run_device_guard_tool(enable_command, vbs_enable_info)
178+
vm.reboot(timeout=login_timeout)
179+
session = vm.wait_for_serial_login(timeout=login_timeout)
180+
session.cmd(dgreadiness_path_command)
181+
set_powershell_execute_policy()
182+
if not check_vbs_ready():
183+
test.fail("VBS is not enabled after reboot.")
184+
185+
session = install_wsl2_and_rhel()
186+
run_device_guard_tool(disable_command, vbs_disable_info)
187+
except Exception as e:
188+
test.fail(f"Test failed: {e}")
189+
else:
190+
test.log.info("Test completed successfully.")
191+
finally:
192+
if vm.is_alive():
193+
vm.destroy()
194+
if session:
195+
session.close()

0 commit comments

Comments
 (0)