Module: tools Branch: master Commit: 423bbbb1797bed3ce92ae46e34422167422b17e8 URL: https://source.winehq.org/git/tools.git/?a=commit;h=423bbbb1797bed3ce92ae46e...
Author: Francois Gouget fgouget@codeweavers.com Date: Thu Feb 17 18:52:24 2022 +0100
testbot/LibvirtTool: Remove the Windows desktop wallpaper.
Removing the Windows desktop wallpaper when preparing a live snapshot greatly reduces the size of the screenshots. This requires rebooting Windows independently from SetWinLocale. Note that the old WaitForBoot() code expected TestAgentd to initially be unreachable which is no longer the case since it may now be called when the TestAgentd is already running (before the reboot). The new code expects start.count to be reset to 0 before a reboot instead.
Signed-off-by: Francois Gouget fgouget@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
testbot/bin/LibvirtTool.pl | 61 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 11 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index 62008b5..47839b6 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -279,18 +279,30 @@ sub GetPrivilegedTA($) return $TA->SetTime() ? $TA : $VM->GetAgent(1); }
-sub Halt() +sub RunAndWait($$) { + my ($TA, $Cmd) = @_; + Debug(Elapsed($Start), " Running: @$Cmd\n"); + my $Ret = $TA->RunAndWait($Cmd, 0, 30); + Debug(Elapsed($Start), " $Cmd->[0] returned $Ret\n") if ($Ret); + return $Ret; +} + +sub Halt($$) +{ + my ($TA, $Reboot) = @_; + my $Cmd = $VM->Type =~ /^win(?:32|64)$/ ? - ["shutdown.exe", "/s", "/d", "00:00", "/t", "0"] : - ["/sbin/shutdown", "--poweroff", "now"]; + ["shutdown.exe", ($Reboot ? "/r" : "/s"), "/d", "00:00", "/t", "0"] : + ["/sbin/shutdown", ($Reboot ? "--reboot" : "--poweroff"), "now"]; Debug(Elapsed($Start), " Running: @$Cmd\n"); - my $PTA = GetPrivilegedTA($VM->GetAgent()); + my $PTA = GetPrivilegedTA($TA); if (!$PTA->Run($Cmd, 0)) { Error "Could not run @$Cmd on $VMKey: ". $PTA->GetLastError() ."\n"; return 0; } + $TA->Disconnect(); return 1; }
@@ -319,7 +331,7 @@ sub ShutDownIfOffSnapshot()
Debug(Elapsed($Start), " Performing a clean shutdown of $VMKey/$CurrentSnapshot\n"); LogMsg "Performing a clean shutdown of $VMKey/$CurrentSnapshot\n"; - return 0 if (!Halt()); + return 0 if (!Halt($VM->GetAgent(), 0));
Debug(Elapsed($Start), " Waiting for the VM to shut down\n"); my $Deadline = time() + $WaitForShutdown; @@ -465,13 +477,18 @@ sub WaitForBoot($)
Debug(Elapsed($Start), " Waiting for the VM to boot\n"); LogMsg "Waiting for $VMKey to boot\n"; - my $MinTimeout = $TA->SetConnectTimeout(undef, undef, $WaitForBoot); - if (!$TA->GetVersion()) + + # Use small timeouts to avoid undue connection delays + my ($OneTimeout, $MinAttempts, $MinTimeout) = $TA->SetConnectTimeout(5, 1, 5); + my $Deadline = time() + $WaitForBoot; + while (time() <= $Deadline) { - my $ErrMessage = $TA->GetLastError(); - FatalError("Could not connect to the $VMKey TestAgent: $ErrMessage\n"); + my $Count = $TA->GetProperties("start.count"); + next if (!defined $Count); # Rebooting (TestAgentd is not running) + last if ($Count != 0); # start.count == 1 after the reboot + sleep(10); # Not rebooting yet } - $TA->SetConnectTimeout(undef, undef, $MinTimeout); + $TA->SetConnectTimeout($OneTimeout, $MinAttempts, $MinTimeout); }
sub WaitForSession($) @@ -581,6 +598,7 @@ sub CreateSnapshot($$$$) { my ($Domain, $TA, $Config, $Booting) = @_;
+ my $Reboot; if ($VM->Type =~ /^win(?:32|64)$/) { my $Version = $TA->GetVersion(); @@ -618,6 +636,18 @@ sub CreateSnapshot($$$$) # --set-time-only which means it cannot be upgraded since the restart RPC # is blacklisted. But that also means it's unlikely to need upgrading. # A side effect is that it will force TestAgentd.exe.old to stay around. + + # Remove the Windows desktop wallpaper so we get smaller screenshots. + # On Vista+ these require a logout+login to take effect. + if (RunAndWait($TA, ["reg.exe", "delete", "HKEY_CURRENT_USER\Control Panel\Desktop", "/v", "Wallpaper", "/f"])) + { + FatalError("Could not reset the $VMKey Windows desktop wallpaper\n"); + } + if (RunAndWait($TA, ["reg.exe", "add", "HKEY_CURRENT_USER\Control Panel\Colors", "/v", "Background", "/t", "REG_SZ", "/d", "140 20 20", "/f"])) + { + FatalError("Could not reset the $VMKey Windows desktop background color\n"); + } + $Reboot = 1; }
my @Locale; @@ -630,8 +660,9 @@ sub CreateSnapshot($$$$) if ($Config->{locale}) { push @Cmd, "--default", $Config->{locale}; - # SetWinLocale --default performs a reboot and WaitForBoot() + # SetWinLocale --default already performs a reboot and WaitForBoot() ResetBootCount($TA); + $Reboot = undef; $Booting = 1; } push @Cmd, "--utf8" if ($Config->{u8}); @@ -645,6 +676,14 @@ sub CreateSnapshot($$$$) } }
+ if ($Reboot) + { + # A reboot is still required for some changes to take effect + ResetBootCount($TA); + Halt($TA, "reboot"); + WaitForBoot($TA); + $Booting = 1; + } if ($Booting) { WaitForSession($TA);