Skip to content

Commit ffb9dba

Browse files
committed
win_guest_debugging_tool: Optimize and simplify script
The test script for the Windows guest debugging tool was significantly refactored to improve its structure, eliminate redundancy, and increase maintainability. Key logical improvements include: - The complex three-class inheritance structure was consolidated into a single, self-contained WinDebugToolTest class, simplifying the overall architecture. - A centralized helper method, _run_script_and_get_paths, was created to handle all PowerShell script executions and output parsing. This removes significant code duplication that was present in each test variant. - Individual test methods were streamlined to focus purely on their specific validation logic, delegating common tasks like script execution and session management to helper functions. - VM session management was made more robust to ensure sessions are properly created, reused, and cleaned up. Signed-off-by: Dehan Meng <demeng@redhat.com>
1 parent f03b470 commit ffb9dba

File tree

2 files changed

+657
-903
lines changed

2 files changed

+657
-903
lines changed

qemu/tests/cfg/win_guest_debugging_tool.cfg

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
cdrom_virtio = isos/windows/virtio-win.iso
1414
cmd_findstr_in_file = type %s | findstr "%s"
1515
include_sensitive_data = False
16+
script_execution_timeout = 720
1617
target_files = "msinfo32.txt,system.evtx,security.evtx,application.evtx,drv_list.csv,virtio_disk.txt,WindowsUpdate.log,Services.csv,WindowsUptime.txt,RunningProcesses.csv,InstalledApplications.csv,InstalledKBs.csv,NetworkInterfaces.txt,IPConfiguration.txt,setupapi.dev.log,setupapi.setup.log,setupapi.offline.log,ErrorWindowsUpdate.log,OutputWindowsUpdate.log,LocaleMetaData"
1718
target_dump_files = "MEMORY.DMP,Minidump"
1819
script_name = "CollectSystemInfo.ps1"
1920
cmd_search_file_global = powershell.exe -Command "Get-PSDrive -PSProvider FileSystem | ForEach-Object { Get-ChildItem -Path $_.Root -Recurse -Filter '%s' -ErrorAction SilentlyContinue } | ForEach-Object { Join-Path -Path $_.Directory.FullName -ChildPath $_.Name }"
21+
Win2016:
22+
script_execution_timeout = 1200
23+
cmd_disable_ie_esc_admin = powershell.exe -Command "Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}' -Name 'IsInstalled' -Value 0"
24+
cmd_disable_ie_esc_user = powershell.exe -Command "Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}' -Name 'IsInstalled' -Value 0"
2025
variants:
2126
- check_script_execution:
2227
windegtool_check_type = script_execution
@@ -29,7 +34,7 @@
2934
- check_user_friendliness:
3035
windegtool_check_type = user_friendliness
3136
cmd_kill_powershell_process = taskkill /IM powershell.exe /F
32-
cmd_kill_powershell_process1 = powershell.exe -Command "Stop-Process -Name msinfo32 -Force"
37+
cmd_kill_powershell_process1 = powershell.exe -Command "Stop-Process -Name msinfo32 -Force -ErrorAction SilentlyContinue"
3338
invalid_params = "-invalidparam,IncludeSensitiveData,0000,hell,-H,-IncludeSensitiveData -h"
3439
expect_output_prompt = "Usage: .\CollectSystemInfo.ps1 [-IncludeSensitiveData] [-Help]"
3540
script_interrupt_signal_file = 'Collecting_Status.txt'
@@ -67,6 +72,7 @@
6772
setupapi_dev_file_path = "%s\setupapi.dev.log"
6873
target_driver = pvpanic
6974
cmd_query_oem_inf = powershell.exe -Command "pnputil.exe /enum-drivers | Select-String -Pattern '%s.inf' -Context 1,1 | ForEach-Object { if ($_ -match 'Published Name:\s+(oem\d+\.inf)') { $matches[1] } }"
75+
cmd_disable_device = powershell.exe -Command "$d=Get-PnpDevice -ErrorAction SilentlyContinue | Where-Object {$_.FriendlyName -like '*%s*' -or $_.InstanceId -like '*%s*'}; if ($d) { $d | Disable-PnpDevice -Confirm:$false -ErrorAction SilentlyContinue }"
7076
cmd_install_driver = pnputil.exe /add-driver %s /install
7177
cmd_uninstall_driver = pnputil.exe /delete-driver %s /uninstall /force
7278
cmd_scan_device = pnputil.exe /scan-devices
@@ -96,7 +102,7 @@
96102
standard_docs = "README.md", "LICENSE", "CollectSystemInfo.ps1"
97103
target_doc = "README.md"
98104
query_cmd_from_file = powershell.exe -Command "Get-Content %s | Select-String '```powershell' -Context 0,1"
99-
cmd_cp_file = powershell.exe -Command "cp %s %s"
105+
cmd_cp_file = powershell.exe -Command "cp %s %s -Force"
100106
- check_IO_limits:
101107
windegtool_check_type = IO_limits
102108
cmd_get_io_folder = powershell.exe -Command "Get-ChildItem -Path %s -Recurse -Filter '*IOLimits_C*' | Select-Object -ExpandProperty FullName"

0 commit comments

Comments
 (0)