public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH qemu-server 1/2] tests: improve multiarch build support
@ 2026-02-03 14:16 Dominik Csapak
  2026-02-03 14:16 ` [PATCH qemu-server 2/2] tests: cfg2cmd: add some architecture tests Dominik Csapak
  2026-02-03 15:01 ` [PATCH qemu-server 1/2] tests: improve multiarch build support Thomas Lamprecht
  0 siblings, 2 replies; 5+ messages in thread
From: Dominik Csapak @ 2026-02-03 14:16 UTC (permalink / raw)
  To: pve-devel

The CPUConfig module sets the local 'host_arch' on loading, so instead
to try to mock all subs that access this variable, provide a setter only
intended for tests (and warn when using this).

Also, we have to override the 'get_host_arch' in the Helpers module too.

Without these changes, the config to command tests fail when building on
non-x86 hosts.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
not sure about the 'setter hack', which can be partially deleted when
we'll switch to using PVE::Tools::get_host_arch again, but we have to
keep the code changing the cpu_models_by_arch hash.

This patch requires these patches from fiona:
https://lore.proxmox.com/pve-devel/20260129131021.118199-1-f.ebner@proxmox.com/

 src/PVE/QemuServer/CPUConfig.pm      | 12 ++++++++++++
 src/test/run_config2command_tests.pl | 13 +++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm
index 32ec4954..686bbdc0 100644
--- a/src/PVE/QemuServer/CPUConfig.pm
+++ b/src/PVE/QemuServer/CPUConfig.pm
@@ -1230,6 +1230,18 @@ sub get_intel_tdx_object {
     return $tdx_object;
 }
 
+# CAUTION: for tests only, DO NOT USE outside of tests!
+# sets the package gloabl $host_arch value, and modifies the $cpu_models_by_arch
+# so that the 'host' model is available only in the newly set $arch
+sub set_host_arch($) {
+    my ($arch) = @_;
+    warn "CAUTION: use of 'set_host_arch' only intended in tests!\n";
+
+    delete $cpu_models_by_arch->{$host_arch}->{host};
+    $host_arch = $arch;
+    $cpu_models_by_arch->{$host_arch}->{host} = 'default';
+}
+
 __PACKAGE__->register();
 __PACKAGE__->init();
 
diff --git a/src/test/run_config2command_tests.pl b/src/test/run_config2command_tests.pl
index 4c872d1c..b8a2cf7e 100755
--- a/src/test/run_config2command_tests.pl
+++ b/src/test/run_config2command_tests.pl
@@ -235,6 +235,8 @@ sub parse_test($config_fn) {
         $testname = "'$testname' - $desc";
     }
     $current_test->{testname} = $testname;
+
+    PVE::QemuServer::CPUConfig::set_host_arch($current_test->{arch} // 'x86_64');
 }
 
 sub get_test_qemu_version {
@@ -264,6 +266,14 @@ $qemu_server_module->mock(
     },
 );
 
+my $qemu_server_helpers_module;
+$qemu_server_helpers_module = Test::MockModule->new('PVE::QemuServer::Helpers');
+$qemu_server_helpers_module->mock(
+    get_host_arch => sub() {
+        return $current_test->{host_arch} // 'x86_64';
+    },
+);
+
 my $storage_module = Test::MockModule->new("PVE::Storage");
 $storage_module->mock(
     activate_volumes => sub {
@@ -582,6 +592,9 @@ sub diff($a, $b) {
 $SIG{__WARN__} = sub {
     my $warning = shift;
     chomp $warning;
+    if ($warning =~ m/^CAUTION: use of 'set_host/) {
+        return;
+    }
     if (my $warn_expect = $current_test->{expect_warning}) {
         if ($warn_expect ne $warning) {
             fail($current_test->{testname});
-- 
2.47.3





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-02-03 15:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-03 14:16 [PATCH qemu-server 1/2] tests: improve multiarch build support Dominik Csapak
2026-02-03 14:16 ` [PATCH qemu-server 2/2] tests: cfg2cmd: add some architecture tests Dominik Csapak
2026-02-03 15:01 ` [PATCH qemu-server 1/2] tests: improve multiarch build support Thomas Lamprecht
2026-02-03 15:04   ` Dominik Csapak
2026-02-03 15:09     ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal