From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v5 1/4] ovmf: use helpers that can be mocked for tests
Date: Mon, 2 Mar 2026 15:46:35 +0100 [thread overview]
Message-ID: <20260302144642.3783463-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260302144642.3783463-1-d.csapak@proxmox.com>
This makes it easy for us to mock these in tests, so there is no need
for the files to actually exist during package build.
Makes the edk2-firmware build dependency unnecessary.
Co-developed-by: Fiona Ebner <f.ebner@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
the proper file_get_size code comes from fiona (Thanks!)
changes from v4:
* use new PVE::File helpers
src/PVE/QemuServer/OVMF.pm | 24 +++++++++++++-----------
src/test/run_config2command_tests.pl | 23 +++++++++++++++++++++++
2 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/src/PVE/QemuServer/OVMF.pm b/src/PVE/QemuServer/OVMF.pm
index 01b037ef..477a2023 100644
--- a/src/PVE/QemuServer/OVMF.pm
+++ b/src/PVE/QemuServer/OVMF.pm
@@ -5,6 +5,7 @@ use warnings;
use JSON qw(to_json);
+use PVE::File qw(file_exists file_get_size);
use PVE::GuestHelpers qw(safe_string_ne);
use PVE::RESTEnvironment qw(log_warn);
use PVE::Storage;
@@ -65,14 +66,14 @@ my sub get_ovmf_files($$$$) {
if ($cvm_type && $cvm_type eq 'snp') {
$type = "4m-snp";
my ($ovmf) = $types->{$type}->@*;
- die "EFI base image '$ovmf' not found\n" if !-f $ovmf;
+ die "EFI base image '$ovmf' not found\n" if !file_exists($ovmf);
return ($ovmf);
} elsif ($cvm_type && ($cvm_type eq 'std' || $cvm_type eq 'es')) {
$type = "4m-sev";
} elsif ($cvm_type && $cvm_type eq 'tdx') {
$type = "4m-tdx";
my ($ovmf) = $types->{$type}->@*;
- die "EFI base image '$ovmf' not found\n" if !-f $ovmf;
+ die "EFI base image '$ovmf' not found\n" if !file_exists($ovmf);
return ($ovmf);
} elsif (defined($efidisk->{efitype}) && $efidisk->{efitype} eq '4m') {
$type = $smm ? "4m" : "4m-no-smm";
@@ -83,8 +84,8 @@ my sub get_ovmf_files($$$$) {
}
my ($ovmf_code, $ovmf_vars) = $types->{$type}->@*;
- die "EFI base image '$ovmf_code' not found\n" if !-f $ovmf_code;
- die "EFI vars image '$ovmf_vars' not found\n" if !-f $ovmf_vars;
+ die "EFI base image '$ovmf_code' not found\n" if !file_exists($ovmf_code);
+ die "EFI vars image '$ovmf_vars' not found\n" if !file_exists($ovmf_vars);
return ($ovmf_code, $ovmf_vars);
}
@@ -103,6 +104,7 @@ my sub print_ovmf_drive_commandlines {
if $cvm_type && $cvm_type eq 'tdx';
my ($ovmf_code, $ovmf_vars) = get_ovmf_files($arch, $d, $q35, $cvm_type);
+ my $ovmf_vars_size = file_get_size($ovmf_vars);
my $var_drive_str = "if=pflash,unit=1,id=drive-efidisk0";
if ($d) {
@@ -121,15 +123,15 @@ my sub print_ovmf_drive_commandlines {
}
$var_drive_str .= ",format=$format,file=$path";
- $var_drive_str .= ",size=" . (-s $ovmf_vars)
+ $var_drive_str .= ",size=" . $ovmf_vars_size
if $format eq 'raw' && $version_guard->(4, 1, 2);
$var_drive_str .= ',readonly=on' if $readonly;
} else {
log_warn("no efidisk configured! Using temporary efivars disk.");
my $path = "/tmp/$vmid-ovmf.fd";
- PVE::Tools::file_copy($ovmf_vars, $path, -s $ovmf_vars);
+ PVE::Tools::file_copy($ovmf_vars, $path, $ovmf_vars_size);
$var_drive_str .= ",format=raw,file=$path";
- $var_drive_str .= ",size=" . (-s $ovmf_vars) if $version_guard->(4, 1, 2);
+ $var_drive_str .= ",size=" . $ovmf_vars_size if $version_guard->(4, 1, 2);
}
return ("if=pflash,unit=0,format=raw,readonly=on,file=$ovmf_code", $var_drive_str);
@@ -139,7 +141,7 @@ sub get_efivars_size {
my ($arch, $efidisk, $smm, $cvm_type) = @_;
my (undef, $ovmf_vars) = get_ovmf_files($arch, $efidisk, $smm, $cvm_type);
- return -s $ovmf_vars;
+ return file_get_size($ovmf_vars);
}
my sub is_ms_2023_cert_enrolled {
@@ -171,7 +173,7 @@ sub create_efidisk($$$$$$$$) {
my (undef, $ovmf_vars) = get_ovmf_files($arch, $efidisk, $smm, $cvm_type);
- my $vars_size_b = -s $ovmf_vars;
+ my $vars_size_b = file_get_size($ovmf_vars);
my $vars_size = PVE::Tools::convert_size($vars_size_b, 'b' => 'kb');
my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $vars_size);
PVE::Storage::activate_volumes($storecfg, [$volid]);
@@ -219,7 +221,7 @@ my sub generate_ovmf_blockdev {
} else {
log_warn("no efidisk configured! Using temporary efivars disk.");
my $path = "/tmp/$vmid-ovmf.fd";
- PVE::Tools::file_copy($ovmf_vars, $path, -s $ovmf_vars);
+ PVE::Tools::file_copy($ovmf_vars, $path, file_get_size($ovmf_vars));
$drive = { file => $path, interface => 'efidisk', index => 0 };
$format = 'raw';
}
@@ -231,7 +233,7 @@ my sub generate_ovmf_blockdev {
my $extra_blockdev_options = {};
$extra_blockdev_options->{'read-only'} = 1 if $readonly;
- $extra_blockdev_options->{size} = -s $ovmf_vars if $format eq 'raw';
+ $extra_blockdev_options->{size} = file_get_size($ovmf_vars) if $format eq 'raw';
my $throttle_group = PVE::QemuServer::Blockdev::generate_throttle_group($drive);
diff --git a/src/test/run_config2command_tests.pl b/src/test/run_config2command_tests.pl
index 4c872d1c..aca9765a 100755
--- a/src/test/run_config2command_tests.pl
+++ b/src/test/run_config2command_tests.pl
@@ -19,6 +19,7 @@ use PVE::QemuServer;
use PVE::QemuServer::Drive;
use PVE::QemuServer::Helpers;
use PVE::QemuServer::Monitor;
+use PVE::QemuServer::OVMF;
use PVE::QemuServer::QMPHelpers;
use PVE::QemuServer::CPUConfig;
use PVE::Storage;
@@ -264,6 +265,28 @@ $qemu_server_module->mock(
},
);
+my $qemu_server_ovmf_module = Test::MockModule->new("PVE::QemuServer::OVMF");
+$qemu_server_ovmf_module->mock(
+ file_exists => sub {
+ my ($path) = @_;
+ return 1;
+ },
+ file_get_size => sub {
+ my ($path) = @_;
+ if ($path =~ m/OVMF(32)?_(SEV_)?VARS_4M/) {
+ return 528 * 1024;
+ } elsif ($path =~ m/OVMF_VARS/) {
+ return 128 * 1024;
+ } elsif ($path =~ m/AAVMF_VARS/) {
+ return 64 * 1024 * 1024;
+ } elsif ($path =~ m/RISCV_VIRT_VARS/) {
+ return 32 * 1024 * 1024;
+ } else {
+ die "unknown ovmf vars image '$path' - implement me";
+ }
+ },
+);
+
my $storage_module = Test::MockModule->new("PVE::Storage");
$storage_module->mock(
activate_volumes => sub {
--
2.47.3
next prev parent reply other threads:[~2026-03-02 14:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 14:46 [PATCH common/qemu-server v5 0/5] improve multiarch build support Dominik Csapak
2026-03-02 14:46 ` [PATCH common v5 1/1] file: add exists and size helper Dominik Csapak
2026-03-03 21:23 ` applied: " Thomas Lamprecht
2026-03-02 14:46 ` Dominik Csapak [this message]
2026-03-02 14:46 ` [PATCH qemu-server v5 2/4] tests: improve multiarch build support by introducing local get_host_arch helper Dominik Csapak
2026-03-02 14:46 ` [PATCH qemu-server v5 3/4] tests: improve multiarch build support by allowing re-init of cpu models Dominik Csapak
2026-03-02 14:46 ` [PATCH qemu-server v5 4/4] tests: cfg2cmd: add some architecture tests 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=20260302144642.3783463-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.