all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v3 2/2] cpu config: Add tests for arch/reported-model misconfigurations
Date: Tue, 17 Feb 2026 15:06:52 +0100	[thread overview]
Message-ID: <20260217141036.338747-2-a.bied-charreton@proxmox.com> (raw)
In-Reply-To: <20260217141036.338747-1-a.bied-charreton@proxmox.com>

Test that validate_cpu_conf denies custom CPU models with
a 'reported-model' that does not exist on the specified (or
default) 'arch'.

Test that get_cpu_options denies configurations with custom
CPU model arch not matching the VM arch.

Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
Changes since v2:
* fix expected error message in custom-cpu-model-wrong-arch.conf,
  got out of sync with actual error message before submitting v2

 src/test/Makefile                             |  5 +-
 .../cfg2cmd/custom-cpu-model-wrong-arch.conf  |  9 +++
 src/test/run_config2command_tests.pl          |  4 ++
 src/test/run_cpu_config_tests.pl              | 57 +++++++++++++++++++
 4 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 src/test/cfg2cmd/custom-cpu-model-wrong-arch.conf
 create mode 100755 src/test/run_cpu_config_tests.pl

diff --git a/src/test/Makefile b/src/test/Makefile
index 2ef9073a..dcfab6d6 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -1,6 +1,6 @@
 all: test
 
-test: test_snapshot test_cfg_to_cmd test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config
+test: test_snapshot test_cfg_to_cmd test_pci_addr_conflicts test_pci_reservation test_qemu_img_convert test_migration test_restore_config test_parse_config test_cpu_config
 
 test_snapshot: run_snapshot_tests.pl
 	./run_snapshot_tests.pl
@@ -31,6 +31,9 @@ test_restore_config: run_qemu_restore_config_tests.pl
 test_parse_config: run_parse_config_tests.pl
 	./run_parse_config_tests.pl
 
+test_cpu_config: run_cpu_config_tests.pl
+	perl -I../ ./run_cpu_config_tests.pl
+
 .PHONY: clean
 clean:
 	rm -rf MigrationTest/run parse-config-output
diff --git a/src/test/cfg2cmd/custom-cpu-model-wrong-arch.conf b/src/test/cfg2cmd/custom-cpu-model-wrong-arch.conf
new file mode 100644
index 00000000..d1b9b08a
--- /dev/null
+++ b/src/test/cfg2cmd/custom-cpu-model-wrong-arch.conf
@@ -0,0 +1,9 @@
+# TEST: custom CPU model with wrong arch for VM is rejected
+# EXPECT_ERROR: custom CPU model has architecture 'aarch64', but VM has 'x86_64'
+cores: 2
+cpu: custom-aarch64cpu
+name: wrong-arch-cpu
+numa: 0
+ostype: l26
+smbios1: uuid=2ea3f676-dfa5-11e9-ae82-c721e12f3fcd
+sockets: 1
diff --git a/src/test/run_config2command_tests.pl b/src/test/run_config2command_tests.pl
index 4c872d1c..dec07bda 100755
--- a/src/test/run_config2command_tests.pl
+++ b/src/test/run_config2command_tests.pl
@@ -408,6 +408,10 @@ cpu-model: qemu64
 
 cpu-model: alldefault
 
+cpu-model: aarch64cpu
+    reported-model cortex-a76
+    arch aarch64
+
 EOF
         );
     },
diff --git a/src/test/run_cpu_config_tests.pl b/src/test/run_cpu_config_tests.pl
new file mode 100755
index 00000000..d3e587cc
--- /dev/null
+++ b/src/test/run_cpu_config_tests.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib qw(..);
+
+use Test::More;
+
+use PVE::JSONSchema;
+use PVE::QemuServer::CPUConfig;
+
+# Test that validate_cpu_conf rejects a custom CPU model whose reported-model
+# doesn't match the specified arch.
+
+my @tests = (
+    {
+        name => 'x86_64 reported-model with aarch64 arch is rejected',
+        input => 'custom-mycpu,reported-model=qemu64,arch=aarch64',
+        expected_error => qr/reported model 'qemu64' is not valid for architecture 'aarch64'/,
+    },
+    {
+        name => 'aarch64 reported-model with x86_64 arch is rejected',
+        input => 'custom-mycpu,reported-model=cortex-a76,arch=x86_64',
+        expected_error =>
+            qr/reported model 'cortex-a76' is not valid for architecture 'x86_64'/,
+    },
+    {
+        name => 'aarch64 reported-model with default (x86_64) arch is rejected',
+        input => 'custom-mycpu,reported-model=cortex-a76',
+        expected_error =>
+            qr/reported model 'cortex-a76' is not valid for architecture 'x86_64'/,
+    },
+    {
+        name => 'x86_64 reported-model with matching arch is accepted',
+        input => 'custom-mycpu,reported-model=qemu64,arch=x86_64',
+        expected_error => undef,
+    },
+    {
+        name => 'aarch64 reported-model with matching arch is accepted',
+        input => 'custom-mycpu,reported-model=cortex-a76,arch=aarch64',
+        expected_error => undef,
+    },
+);
+
+for my $test (@tests) {
+    eval { PVE::JSONSchema::parse_property_string('pve-cpu-conf', $test->{input}); };
+    my $err = $@;
+
+    if ($test->{expected_error}) {
+        like($err, $test->{expected_error}, $test->{name});
+    } else {
+        is($err, '', $test->{name});
+    }
+}
+
+done_testing();
-- 
2.47.3




      reply	other threads:[~2026-02-17 14:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-17 14:06 [PATCH qemu-server v3 1/2] cpu config: Add 'arch' property to cpu_fmt Arthur Bied-Charreton
2026-02-17 14:06 ` Arthur Bied-Charreton [this message]

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=20260217141036.338747-2-a.bied-charreton@proxmox.com \
    --to=a.bied-charreton@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal