From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 1/2] tests: improve multiarch build support
Date: Tue, 3 Feb 2026 15:16:30 +0100 [thread overview]
Message-ID: <20260203142209.3614946-1-d.csapak@proxmox.com> (raw)
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
next reply other threads:[~2026-02-03 14:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-03 14:16 Dominik Csapak [this message]
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
2026-02-04 10:09 ` superseded: " Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260203142209.3614946-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox