kvm-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script
@ 2025-05-07 15:12 Alexandru Elisei
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params' Alexandru Elisei
                   ` (16 more replies)
  0 siblings, 17 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

v2 can be found here [1].

To goal is to allow the user to do:

$ ./configure --target=kvmtool
$ make clean && make
$ ./run_tests.sh

to run all the tests automatically with kvmtool.

Reasons to use kvmtool:

* kvmtool is smaller and a lot easier to hack than qemu, which means
developers may prefer it when adding or prototyping new features to KVM.
Being able to run all the tests reliably and automatically is very useful
in the development process.

* kvmtool is faster to run the tests (a couple of times faster on
my rockpro64), making for a quick turnaround. But do keep in mind that not
all tests work on kvmtool because of missing features compared to qemu.

* kvmtool does things differently than qemu: different memory layout,
different uart, PMU emulation is disabled by default, etc. This makes it a
good testing vehicule for kvm-unit-tests itself.

Changes in v3
-------------

Lots of changes following the excellent feedback I got. A bird's eye view:

* Split extra_params into qemu_params and test_args: qemu_params for qemu
arguments and test_args for the test's main() function.

Now that I'm putting the cover letter together I'm considering that maybe
having qemu_params, kvmtool_params and test_params (instead of test_args)
might be a better naming scheme.

* TARGET is now exported unconditionally. Unfortunately a side effect of
this is that checking out these series and running the tests will end up
with an error because the scripts now expect TARGET to be defined in
config.mak.

If it's unacceptable, I can drop this and handle everything in vmm.bash by
converting direct accesses to vmm_opts with functions defined in vmm.bash
(vmm_opts[$TARGET:parse_premature_failure] becomes
vmm_parse_premature_failure(), for example).

* Introduced scripts/vmm.bash to keep the vmm stuff contained. As a
consequence there's very little $TARGET stuff in scripts/runtime.bash (only
for premature_failure(), and no more 'case' statements anywhere) and
instead scripts/common.bash passes the correct arguments directly to
runtime.bash::run().

Unfortunately, because of all the changes, I decided not to keep some of
the Reviewed-by tags. That's not to say that the effort is not appreciated,
on the contrary, these changes are a direct result of the review; I dropped
the tags because I was worried they might not apply to the current content
of the patches.

If no major changes are needed following this round of review, for the next
iteration I'm planning to send the first two patches (extra_params renamed
to qemu_params and the new test_args) separately, to make sure it gets the
review it deserves from the rest of the architectures.

Still haven't managed to get EDK2 to work with kvmtool, so I've decided to
explicitely disabled UEFI tests in the last patch ("scripts: Enable
kvmtool") - this is new.

I would also like to point out that despite Drew's comment I kept the
'disabled_if' test definition because I think using 'targets', with the
default value of 'qemu', will probably lead to most, if not all, of the new
tests which will be added never being run or tested with kvmtool. More
details in patch #15 ("scripts: Add 'disabled_if' test definition parameter
for kvmtool to use").

[1] https://lore.kernel.org/kvm/20250120164316.31473-1-alexandru.elisei@arm.com/

Alexandru Elisei (16):
  scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params'
  scripts: Add 'test_args' test definition parameter
  configure: Export TARGET unconditionally
  run_tests.sh: Document --probe-maxsmp argument
  scripts: Document environment variables
  scripts: Refuse to run the tests if not configured for qemu
  scripts: Use an associative array for qemu argument names
  scripts: Add 'kvmtool_params' to test definition
  scripts: Add support for kvmtool
  scripts: Add default arguments for kvmtool
  scripts: Add KVMTOOL environment variable for kvmtool binary path
  scripts: Detect kvmtool failure in premature_failure()
  scripts: Do not probe for maximum number of VCPUs when using kvmtool
  scripts/mkstandalone: Export $TARGET
  scripts: Add 'disabled_if' test definition parameter for kvmtool to
    use
  scripts: Enable kvmtool

 README.md               |  18 ++++-
 arm/efi/run             |   8 ++
 arm/run                 | 161 +++++++++++++++++++++++--------------
 arm/unittests.cfg       | 125 ++++++++++++++++++++---------
 configure               |  37 ++++++---
 docs/unittests.txt      |  54 +++++++++++--
 powerpc/run             |   4 +-
 powerpc/unittests.cfg   |  21 ++---
 riscv/run               |   4 +-
 riscv/unittests.cfg     |   2 +-
 run_tests.sh            |  35 ++++++---
 s390x/run               |   2 +-
 s390x/unittests.cfg     |  53 +++++++------
 scripts/arch-run.bash   | 113 ++++++++++----------------
 scripts/common.bash     |  71 +++++++++++------
 scripts/mkstandalone.sh |   4 +
 scripts/runtime.bash    |  51 +++++-------
 scripts/vmm.bash        | 170 ++++++++++++++++++++++++++++++++++++++++
 x86/run                 |   4 +-
 x86/unittests.cfg       | 164 +++++++++++++++++++++-----------------
 20 files changed, 730 insertions(+), 371 deletions(-)
 create mode 100644 scripts/vmm.bash


base-commit: 08db0f5cfbca16b36f200b7bc54a78fa4941bcce
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params'
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 15:40   ` Andrew Jones
  2025-05-14  2:57   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 02/16] scripts: Add 'test_args' test definition parameter Alexandru Elisei
                   ` (15 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

The arm and arm64 architectures can also be run with kvmtool, and work is
under way to have it supported by the run_tests.sh test runner. Not
suprisingly, kvmtool's syntax for running a virtual machine is different to
qemu's.

Add a new unittest parameter, 'qemu_params', with the goal to add a similar
parameter for kvmtool, when that's supported.

'extra_params' has been kept in the scripts as an alias for 'qemu_params'
to preserve compatibility with custom test definition, but it is expected
that going forward new tests will use 'qemu_params'.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/unittests.cfg     |  76 +++++++++++------------
 docs/unittests.txt    |  15 +++--
 powerpc/unittests.cfg |  18 +++---
 riscv/unittests.cfg   |   2 +-
 s390x/unittests.cfg   |  50 +++++++--------
 scripts/common.bash   |   8 +--
 scripts/runtime.bash  |   6 +-
 x86/unittests.cfg     | 140 +++++++++++++++++++++---------------------
 8 files changed, 160 insertions(+), 155 deletions(-)

diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index fe1011454f88..6c6f76b2fb52 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -15,26 +15,26 @@
 [selftest-setup]
 file = selftest.flat
 smp = 2
-extra_params = -m 256 -append 'setup smp=2 mem=256'
+qemu_params = -m 256 -append 'setup smp=2 mem=256'
 groups = selftest
 
 # Test vector setup and exception handling (kernel mode).
 [selftest-vectors-kernel]
 file = selftest.flat
-extra_params = -append 'vectors-kernel'
+qemu_params = -append 'vectors-kernel'
 groups = selftest
 
 # Test vector setup and exception handling (user mode).
 [selftest-vectors-user]
 file = selftest.flat
-extra_params = -append 'vectors-user'
+qemu_params = -append 'vectors-user'
 groups = selftest
 
 # Test SMP support
 [selftest-smp]
 file = selftest.flat
 smp = $MAX_SMP
-extra_params = -append 'smp'
+qemu_params = -append 'smp'
 groups = selftest
 
 # Test PCI emulation
@@ -46,79 +46,79 @@ groups = pci
 [pmu-cycle-counter]
 file = pmu.flat
 groups = pmu
-extra_params = -append 'cycle-counter 0'
+qemu_params = -append 'cycle-counter 0'
 
 [pmu-event-introspection]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-event-introspection'
+qemu_params = -append 'pmu-event-introspection'
 
 [pmu-event-counter-config]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-event-counter-config'
+qemu_params = -append 'pmu-event-counter-config'
 
 [pmu-basic-event-count]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-basic-event-count'
+qemu_params = -append 'pmu-basic-event-count'
 
 [pmu-mem-access]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-mem-access'
+qemu_params = -append 'pmu-mem-access'
 
 [pmu-mem-access-reliability]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-mem-access-reliability'
+qemu_params = -append 'pmu-mem-access-reliability'
 
 [pmu-sw-incr]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-sw-incr'
+qemu_params = -append 'pmu-sw-incr'
 
 [pmu-chained-counters]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-chained-counters'
+qemu_params = -append 'pmu-chained-counters'
 
 [pmu-chained-sw-incr]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-chained-sw-incr'
+qemu_params = -append 'pmu-chained-sw-incr'
 
 [pmu-chain-promotion]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-chain-promotion'
+qemu_params = -append 'pmu-chain-promotion'
 
 [pmu-overflow-interrupt]
 file = pmu.flat
 groups = pmu
 arch = arm64
-extra_params = -append 'pmu-overflow-interrupt'
+qemu_params = -append 'pmu-overflow-interrupt'
 
 # Test PMU support (TCG) with -icount IPC=1
 #[pmu-tcg-icount-1]
 #file = pmu.flat
-#extra_params = -icount 0 -append 'cycle-counter 1'
+#qemu_params = -icount 0 -append 'cycle-counter 1'
 #groups = pmu
 #accel = tcg
 
 # Test PMU support (TCG) with -icount IPC=256
 #[pmu-tcg-icount-256]
 #file = pmu.flat
-#extra_params = -icount 8 -append 'cycle-counter 256'
+#qemu_params = -icount 8 -append 'cycle-counter 256'
 #groups = pmu
 #accel = tcg
 
@@ -126,77 +126,77 @@ extra_params = -append 'pmu-overflow-interrupt'
 [gicv2-ipi]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
-extra_params = -machine gic-version=2 -append 'ipi'
+qemu_params = -machine gic-version=2 -append 'ipi'
 groups = gic
 
 [gicv2-mmio]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
-extra_params = -machine gic-version=2 -append 'mmio'
+qemu_params = -machine gic-version=2 -append 'mmio'
 groups = gic
 
 [gicv2-mmio-up]
 file = gic.flat
 smp = 1
-extra_params = -machine gic-version=2 -append 'mmio'
+qemu_params = -machine gic-version=2 -append 'mmio'
 groups = gic
 
 [gicv2-mmio-3p]
 file = gic.flat
 smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
-extra_params = -machine gic-version=2 -append 'mmio'
+qemu_params = -machine gic-version=2 -append 'mmio'
 groups = gic
 
 [gicv3-ipi]
 file = gic.flat
 smp = $MAX_SMP
-extra_params = -machine gic-version=3 -append 'ipi'
+qemu_params = -machine gic-version=3 -append 'ipi'
 groups = gic
 
 [gicv2-active]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
-extra_params = -machine gic-version=2 -append 'active'
+qemu_params = -machine gic-version=2 -append 'active'
 groups = gic
 
 [gicv3-active]
 file = gic.flat
 smp = $MAX_SMP
-extra_params = -machine gic-version=3 -append 'active'
+qemu_params = -machine gic-version=3 -append 'active'
 groups = gic
 
 [its-introspection]
 file = gic.flat
 smp = $MAX_SMP
-extra_params = -machine gic-version=3 -append 'its-introspection'
+qemu_params = -machine gic-version=3 -append 'its-introspection'
 groups = its
 arch = arm64
 
 [its-trigger]
 file = gic.flat
 smp = $MAX_SMP
-extra_params = -machine gic-version=3 -append 'its-trigger'
+qemu_params = -machine gic-version=3 -append 'its-trigger'
 groups = its
 arch = arm64
 
 [its-migration]
 file = gic.flat
 smp = $MAX_SMP
-extra_params = -machine gic-version=3 -append 'its-migration'
+qemu_params = -machine gic-version=3 -append 'its-migration'
 groups = its migration
 arch = arm64
 
 [its-pending-migration]
 file = gic.flat
 smp = $MAX_SMP
-extra_params = -machine gic-version=3 -append 'its-pending-migration'
+qemu_params = -machine gic-version=3 -append 'its-pending-migration'
 groups = its migration
 arch = arm64
 
 [its-migrate-unmapped-collection]
 file = gic.flat
 smp = $MAX_SMP
-extra_params = -machine gic-version=3 -append 'its-migrate-unmapped-collection'
+qemu_params = -machine gic-version=3 -append 'its-migrate-unmapped-collection'
 groups = its migration
 arch = arm64
 
@@ -231,37 +231,37 @@ groups = cache
 [debug-bp]
 file = debug.flat
 arch = arm64
-extra_params = -append 'bp'
+qemu_params = -append 'bp'
 groups = debug
 
 [debug-bp-migration]
 file = debug.flat
 arch = arm64
-extra_params = -append 'bp-migration'
+qemu_params = -append 'bp-migration'
 groups = debug migration
 
 [debug-wp]
 file = debug.flat
 arch = arm64
-extra_params = -append 'wp'
+qemu_params = -append 'wp'
 groups = debug
 
 [debug-wp-migration]
 file = debug.flat
 arch = arm64
-extra_params = -append 'wp-migration'
+qemu_params = -append 'wp-migration'
 groups = debug migration
 
 [debug-sstep]
 file = debug.flat
 arch = arm64
-extra_params = -append 'ss'
+qemu_params = -append 'ss'
 groups = debug
 
 [debug-sstep-migration]
 file = debug.flat
 arch = arm64
-extra_params = -append 'ss-migration'
+qemu_params = -append 'ss-migration'
 groups = debug migration
 
 # FPU/SIMD test
@@ -276,17 +276,17 @@ arch = arm64
 [mte-sync]
 file = mte.flat
 groups = mte
-extra_params = -machine mte=on -append 'sync'
+qemu_params = -machine mte=on -append 'sync'
 arch = arm64
 
 [mte-async]
 file = mte.flat
 groups = mte
-extra_params = -machine mte=on -append 'async'
+qemu_params = -machine mte=on -append 'async'
 arch = arm64
 
 [mte-asymm]
 file = mte.flat
 groups = mte
-extra_params = -machine mte=on -append 'asymm'
+qemu_params = -machine mte=on -append 'asymm'
 arch = arm64
diff --git a/docs/unittests.txt b/docs/unittests.txt
index c4269f6230c8..3d19fd70953f 100644
--- a/docs/unittests.txt
+++ b/docs/unittests.txt
@@ -24,9 +24,9 @@ param = value format.
 
 Available parameters
 ====================
-Note! Some parameters like smp and extra_params modify how a test is run,
-while others like arch and accel restrict the configurations in which the
-test is run.
+Note! Some parameters like smp and qemu_params/extra_params modify how a
+test is run, while others like arch and accel restrict the configurations
+in which the test is run.
 
 file
 ----
@@ -56,13 +56,18 @@ smp = <number>
 Optional, the number of processors created in the machine to run the test.
 Defaults to 1. $MAX_SMP can be used to specify the maximum supported.
 
-extra_params
+qemu_params
 ------------
 These are extra parameters supplied to the QEMU process. -append '...' can
 be used to pass arguments into the test case argv. Multiple parameters can
 be added, for example:
 
-extra_params = -m 256 -append 'smp=2'
+qemu_params = -m 256 -append 'smp=2'
+
+extra_params
+------------
+Alias for 'qemu_params', supported for compatibility purposes. Use
+'qemu_params' for new tests.
 
 groups
 ------
diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg
index 149f963f3d53..5097911e4bf3 100644
--- a/powerpc/unittests.cfg
+++ b/powerpc/unittests.cfg
@@ -15,7 +15,7 @@
 [selftest-setup]
 file = selftest.elf
 smp = 2
-extra_params = -m 1g -append 'setup smp=2 mem=1024'
+qemu_params = -m 1g -append 'setup smp=2 mem=1024'
 groups = selftest
 
 [selftest-migration]
@@ -27,7 +27,7 @@ groups = selftest migration
 file = selftest-migration.elf
 machine = pseries
 groups = selftest migration
-extra_params = -append "skip"
+qemu_params = -append "skip"
 
 [migration-memory]
 file = memory-verify.elf
@@ -46,20 +46,20 @@ machine = pseries
 file = rtas.elf
 machine = pseries
 timeout = 5
-extra_params = -append "get-time-of-day date=$(date +%s)"
+qemu_params = -append "get-time-of-day date=$(date +%s)"
 groups = rtas
 
 [rtas-get-time-of-day-base]
 file = rtas.elf
 machine = pseries
 timeout = 5
-extra_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)"
+qemu_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)"
 groups = rtas
 
 [rtas-set-time-of-day]
 file = rtas.elf
 machine = pseries
-extra_params = -append "set-time-of-day"
+qemu_params = -append "set-time-of-day"
 timeout = 5
 groups = rtas
 
@@ -94,7 +94,7 @@ smp = 2
 [atomics-migration]
 file = atomics.elf
 machine = pseries
-extra_params = -append "migration -m"
+qemu_params = -append "migration -m"
 groups = migration
 
 [timebase]
@@ -103,14 +103,14 @@ file = timebase.elf
 [timebase-icount]
 file = timebase.elf
 accel = tcg
-extra_params = -icount shift=5
+qemu_params = -icount shift=5
 
 [h_cede_tm]
 file = tm.elf
 machine = pseries
 accel = kvm
 smp = 2,threads=2
-extra_params = -machine cap-htm=on -append "h_cede_tm"
+qemu_params = -machine cap-htm=on -append "h_cede_tm"
 groups = h_cede_tm
 
 [sprs]
@@ -119,7 +119,7 @@ file = sprs.elf
 [sprs-migration]
 file = sprs.elf
 machine = pseries
-extra_params = -append '-w'
+qemu_params = -append '-w'
 groups = migration
 
 [sieve]
diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg
index 2eb760eca24e..5b31047f75c7 100644
--- a/riscv/unittests.cfg
+++ b/riscv/unittests.cfg
@@ -10,7 +10,7 @@
 [selftest]
 file = selftest.flat
 smp = $MAX_SMP
-extra_params = -append 'foo bar baz'
+qemu_params = -append 'foo bar baz'
 groups = selftest
 
 # Set $FIRMWARE_OVERRIDE to /path/to/firmware to select the SBI implementation.
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index a9af6680f2a6..1e129fef3c38 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -10,7 +10,7 @@
 file = selftest.elf
 groups = selftest
 # please keep the kernel cmdline in sync with $(TEST_DIR)/selftest.parmfile
-extra_params = -append 'test 123'
+qemu_params = -append 'test 123'
 
 [selftest-migration]
 file = selftest-migration.elf
@@ -22,7 +22,7 @@ accel = kvm
 [selftest-migration-skip]
 file = selftest-migration.elf
 groups = selftest migration
-extra_params = -append "skip"
+qemu_params = -append "skip"
 
 # This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream
 [migration-memory]
@@ -47,7 +47,7 @@ file = sthyi.elf
 
 [skey]
 file = skey.elf
-extra_params = -device virtio-net-ccw
+qemu_params = -device virtio-net-ccw
 
 [diag10]
 file = diag10.elf
@@ -75,11 +75,11 @@ file = cpumodel.elf
 
 [diag288]
 file = diag288.elf
-extra_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi
+qemu_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi
 
 [stsi]
 file = stsi.elf
-extra_params=-name kvm-unit-test --uuid 0fb84a86-727c-11ea-bc55-0242ac130003 -smp 1,maxcpus=8
+qemu_params=-name kvm-unit-test --uuid 0fb84a86-727c-11ea-bc55-0242ac130003 -smp 1,maxcpus=8
 
 [smp]
 file = smp.elf
@@ -87,15 +87,15 @@ smp = 2
 
 [sclp-1g]
 file = sclp.elf
-extra_params = -m 1G
+qemu_params = -m 1G
 
 [sclp-3g]
 file = sclp.elf
-extra_params = -m 3G
+qemu_params = -m 3G
 
 [css]
 file = css.elf
-extra_params = -device virtio-net-ccw
+qemu_params = -device virtio-net-ccw
 
 [skrf]
 file = skrf.elf
@@ -126,25 +126,25 @@ file = spec_ex.elf
 [firq-linear-cpu-ids-kvm]
 file = firq.elf
 timeout = 20
-extra_params = -smp 1,maxcpus=3 -device host-s390x-cpu,core-id=1 -device host-s390x-cpu,core-id=2
+qemu_params = -smp 1,maxcpus=3 -device host-s390x-cpu,core-id=1 -device host-s390x-cpu,core-id=2
 accel = kvm
 
 [firq-nonlinear-cpu-ids-kvm]
 file = firq.elf
 timeout = 20
-extra_params = -smp 1,maxcpus=3 -device host-s390x-cpu,core-id=2 -device host-s390x-cpu,core-id=1
+qemu_params = -smp 1,maxcpus=3 -device host-s390x-cpu,core-id=2 -device host-s390x-cpu,core-id=1
 accel = kvm
 
 [firq-linear-cpu-ids-tcg]
 file = firq.elf
 timeout = 20
-extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=1 -device qemu-s390x-cpu,core-id=2
+qemu_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=1 -device qemu-s390x-cpu,core-id=2
 accel = tcg
 
 [firq-nonlinear-cpu-ids-tcg]
 file = firq.elf
 timeout = 20
-extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -device qemu-s390x-cpu,core-id=1
+qemu_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -device qemu-s390x-cpu,core-id=1
 accel = tcg
 
 [sck]
@@ -152,7 +152,7 @@ file = sck.elf
 
 [epsw]
 file = epsw.elf
-extra_params = -device virtio-net-ccw
+qemu_params = -device virtio-net-ccw
 
 [tprot]
 file = tprot.elf
@@ -161,26 +161,26 @@ file = tprot.elf
 file = adtl-status.elf
 smp = 2
 accel = kvm
-extra_params = -cpu host,gs=on,vx=on
+qemu_params = -cpu host,gs=on,vx=on
 
 [adtl-status-no-vec-no-gs-kvm]
 file = adtl-status.elf
 smp = 2
 accel = kvm
-extra_params = -cpu host,gs=off,vx=off
+qemu_params = -cpu host,gs=off,vx=off
 
 [adtl-status-tcg]
 file = adtl-status.elf
 smp = 2
 accel = tcg
 # no guarded-storage support in tcg
-extra_params = -cpu qemu,vx=on
+qemu_params = -cpu qemu,vx=on
 
 [adtl-status-no-vec-no-gs-tcg]
 file = adtl-status.elf
 smp = 2
 accel = tcg
-extra_params = -cpu qemu,gs=off,vx=off
+qemu_params = -cpu qemu,gs=off,vx=off
 
 [migration]
 file = migration.elf
@@ -214,13 +214,13 @@ smp = 2
 [migration-skey-sequential]
 file = migration-skey.elf
 groups = migration
-extra_params = -append '--sequential'
+qemu_params = -append '--sequential'
 
 [migration-skey-parallel]
 file = migration-skey.elf
 smp = 2
 groups = migration
-extra_params = -append '--parallel'
+qemu_params = -append '--parallel'
 
 [execute]
 file = ex.elf
@@ -229,34 +229,34 @@ file = ex.elf
 file = pv-icptcode.elf
 smp = 3
 groups = pv-host
-extra_params = -m 2200
+qemu_params = -m 2200
 
 [pv-ipl]
 file = pv-ipl.elf
 groups = pv-host
-extra_params = -m 2200
+qemu_params = -m 2200
 
 [pv-diags]
 file = pv-diags.elf
 groups = pv-host
-extra_params = -m 2200
+qemu_params = -m 2200
 
 [uv-host]
 file = uv-host.elf
 smp = 2
 groups = pv-host
-extra_params = -m 2200
+qemu_params = -m 2200
 
 [topology]
 file = topology.elf
 
 [topology-2]
 file = topology.elf
-extra_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248  -append '-sockets 31 -cores 8'
+qemu_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248  -append '-sockets 31 -cores 8'
 
 [topology-3]
 file = topology.elf
-extra_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores=16,maxcpus=128 \
+qemu_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores=16,maxcpus=128 \
 -append '-drawers 2 -books 2 -sockets 2 -cores 16' \
 -device max-s390x-cpu,core-id=31,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
 -device max-s390x-cpu,core-id=11,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
diff --git a/scripts/common.bash b/scripts/common.bash
index 3aa557c8c03d..bd7c82f1adda 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -38,8 +38,8 @@ function for_each_unittest()
 			kernel=$TEST_DIR/${BASH_REMATCH[1]}
 		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
 			smp=${BASH_REMATCH[1]}
-		elif [[ $line =~ ^extra_params\ *=\ *'"""'(.*)$ ]]; then
-			opts=${BASH_REMATCH[1]}$'\n'
+		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
+			opts=${BASH_REMATCH[2]}$'\n'
 			while read -r -u $fd; do
 				#escape backslash newline, but not double backslash
 				if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
@@ -54,8 +54,8 @@ function for_each_unittest()
 					opts+=$REPLY$'\n'
 				fi
 			done
-		elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
-			opts=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
+			opts=${BASH_REMATCH[2]}
 		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
 			groups=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index ee229631277d..400e8a082528 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -179,9 +179,9 @@ function run()
         echo $cmdline
     fi
 
-    # extra_params in the config file may contain backticks that need to be
-    # expanded, so use eval to start qemu.  Use "> >(foo)" instead of a pipe to
-    # preserve the exit status.
+    # qemu_params/extra_params in the config file may contain backticks that
+    # need to be expanded, so use eval to start qemu.  Use "> >(foo)" instead of
+    # a pipe to preserve the exit status.
     summary=$(eval "$cmdline" 2> >(RUNTIME_log_stderr $testname) \
                              > >(tee >(RUNTIME_log_stdout $testname $kernel) | extract_summary))
     ret=$?
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index 6e69c50b9b0d..a356f486eaec 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -10,20 +10,20 @@
 [apic-split]
 file = apic.flat
 smp = 2
-extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split
+qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split
 arch = x86_64
 groups = apic
 
 [ioapic-split]
 file = ioapic.flat
-extra_params = -cpu qemu64 -machine kernel_irqchip=split
+qemu_params = -cpu qemu64 -machine kernel_irqchip=split
 arch = x86_64
 groups = apic
 
 [x2apic]
 file = apic.flat
 smp = 2
-extra_params = -cpu qemu64,+x2apic,+tsc-deadline
+qemu_params = -cpu qemu64,+x2apic,+tsc-deadline
 arch = x86_64
 timeout = 30
 groups = apic
@@ -33,7 +33,7 @@ groups = apic
 [xapic]
 file = apic.flat
 smp = 2
-extra_params = -cpu qemu64,-x2apic,+tsc-deadline -machine pit=off
+qemu_params = -cpu qemu64,-x2apic,+tsc-deadline -machine pit=off
 arch = x86_64
 timeout = 60
 groups = apic
@@ -41,7 +41,7 @@ groups = apic
 [ioapic]
 file = ioapic.flat
 smp = 4
-extra_params = -cpu qemu64,+x2apic
+qemu_params = -cpu qemu64,+x2apic
 arch = x86_64
 
 [cmpxchg8b]
@@ -58,27 +58,27 @@ smp = 3
 
 [vmexit_cpuid]
 file = vmexit.flat
-extra_params = -append 'cpuid'
+qemu_params = -append 'cpuid'
 groups = vmexit
 
 [vmexit_vmcall]
 file = vmexit.flat
-extra_params = -append 'vmcall'
+qemu_params = -append 'vmcall'
 groups = vmexit
 
 [vmexit_mov_from_cr8]
 file = vmexit.flat
-extra_params = -append 'mov_from_cr8'
+qemu_params = -append 'mov_from_cr8'
 groups = vmexit
 
 [vmexit_mov_to_cr8]
 file = vmexit.flat
-extra_params = -append 'mov_to_cr8'
+qemu_params = -append 'mov_to_cr8'
 groups = vmexit
 
 [vmexit_inl_pmtimer]
 file = vmexit.flat
-extra_params = -append 'inl_from_pmtimer'
+qemu_params = -append 'inl_from_pmtimer'
 groups = vmexit
 
 # To allow IPIs to be accelerated by SVM AVIC when the feature is available and
@@ -87,77 +87,77 @@ groups = vmexit
 [vmexit_ipi]
 file = vmexit.flat
 smp = 2
-extra_params = -machine pit=off -append 'ipi'
+qemu_params = -machine pit=off -append 'ipi'
 groups = vmexit
 
 [vmexit_ipi_halt]
 file = vmexit.flat
 smp = 2
-extra_params = -append 'ipi_halt'
+qemu_params = -append 'ipi_halt'
 groups = vmexit
 
 [vmexit_ple_round_robin]
 file = vmexit.flat
-extra_params = -append 'ple_round_robin'
+qemu_params = -append 'ple_round_robin'
 groups = vmexit
 
 [vmexit_tscdeadline]
 file = vmexit.flat
 groups = vmexit
-extra_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline
+qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline
 
 [vmexit_tscdeadline_immed]
 file = vmexit.flat
 groups = vmexit
-extra_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline_immed
+qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline_immed
 
 [vmexit_cr0_wp]
 file = vmexit.flat
 smp = 2
-extra_params = -append 'toggle_cr0_wp'
+qemu_params = -append 'toggle_cr0_wp'
 groups = vmexit
 
 [vmexit_cr4_pge]
 file = vmexit.flat
 smp = 2
-extra_params = -append 'toggle_cr4_pge'
+qemu_params = -append 'toggle_cr4_pge'
 groups = vmexit
 
 [access]
 file = access_test.flat
 arch = x86_64
-extra_params = -cpu max,host-phys-bits
+qemu_params = -cpu max,host-phys-bits
 
 [access_fep]
 file = access_test.flat
 arch = x86_64
-extra_params = -cpu max,host-phys-bits -append force_emulation
+qemu_params = -cpu max,host-phys-bits -append force_emulation
 groups = nodefault
 timeout = 240
 
 [access-reduced-maxphyaddr]
 file = access_test.flat
 arch = x86_64
-extra_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off
+qemu_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off
 check = /sys/module/kvm_intel/parameters/allow_smaller_maxphyaddr=Y
 
 [smap]
 file = smap.flat
-extra_params = -cpu max
+qemu_params = -cpu max
 
 [pku]
 file = pku.flat
 arch = x86_64
-extra_params = -cpu max
+qemu_params = -cpu max
 
 [pks]
 file = pks.flat
 arch = x86_64
-extra_params = -cpu max
+qemu_params = -cpu max
 
 [asyncpf]
 file = asyncpf.flat
-extra_params = -cpu host -m 2048
+qemu_params = -cpu host -m 2048
 
 [emulator]
 file = emulator.flat
@@ -177,7 +177,7 @@ arch = x86_64
 
 [memory]
 file = memory.flat
-extra_params = -cpu max
+qemu_params = -cpu max
 arch = x86_64
 
 [msr]
@@ -186,11 +186,11 @@ arch = x86_64
 # support follows the host kernel.  Running a 32-bit guest on a 64-bit host
 # will fail due to shortcomings in KVM.
 file = msr.flat
-extra_params = -cpu max,vendor=GenuineIntel
+qemu_params = -cpu max,vendor=GenuineIntel
 
 [pmu]
 file = pmu.flat
-extra_params = -cpu max
+qemu_params = -cpu max
 check = /sys/module/kvm/parameters/enable_pmu=Y /proc/sys/kernel/nmi_watchdog=0
 accel = kvm
 groups = pmu
@@ -198,7 +198,7 @@ groups = pmu
 [pmu_lbr]
 arch = x86_64
 file = pmu_lbr.flat
-extra_params = -cpu host,migratable=no
+qemu_params = -cpu host,migratable=no
 check = /sys/module/kvm/parameters/enable_pmu=Y /proc/sys/kernel/nmi_watchdog=0 /sys/module/kvm/parameters/ignore_msrs=N
 accel = kvm
 groups = pmu
@@ -206,14 +206,14 @@ groups = pmu
 [pmu_pebs]
 arch = x86_64
 file = pmu_pebs.flat
-extra_params = -cpu host,migratable=no
+qemu_params = -cpu host,migratable=no
 check = /sys/module/kvm/parameters/enable_pmu=Y /proc/sys/kernel/nmi_watchdog=0
 accel = kvm
 groups = pmu
 
 [vmware_backdoors]
 file = vmware_backdoors.flat
-extra_params = -machine vmport=on -cpu max
+qemu_params = -machine vmport=on -cpu max
 check = /sys/module/kvm/parameters/enable_vmware_backdoor=Y
 arch = x86_64
 accel = kvm
@@ -234,20 +234,20 @@ timeout = 180
 [syscall]
 file = syscall.flat
 arch = x86_64
-extra_params = -cpu Opteron_G1,vendor=AuthenticAMD
+qemu_params = -cpu Opteron_G1,vendor=AuthenticAMD
 
 [tsc]
 file = tsc.flat
-extra_params = -cpu max
+qemu_params = -cpu max
 
 [tsc_adjust]
 file = tsc_adjust.flat
-extra_params = -cpu max
+qemu_params = -cpu max
 
 [xsave]
 file = xsave.flat
 arch = x86_64
-extra_params = -cpu max
+qemu_params = -cpu max
 
 [rmap_chain]
 file = rmap_chain.flat
@@ -256,20 +256,20 @@ arch = x86_64
 [svm]
 file = svm.flat
 smp = 2
-extra_params = -cpu max,+svm -m 4g -append "-pause_filter_test"
+qemu_params = -cpu max,+svm -m 4g -append "-pause_filter_test"
 arch = x86_64
 groups = svm
 
 [svm_pause_filter]
 file = svm.flat
-extra_params = -cpu max,+svm -overcommit cpu-pm=on -m 4g -append pause_filter_test
+qemu_params = -cpu max,+svm -overcommit cpu-pm=on -m 4g -append pause_filter_test
 arch = x86_64
 groups = svm
 
 [svm_npt]
 file = svm_npt.flat
 smp = 2
-extra_params = -cpu max,+svm -m 4g
+qemu_params = -cpu max,+svm -m 4g
 arch = x86_64
 
 [taskswitch]
@@ -285,68 +285,68 @@ groups = tasks
 [kvmclock_test]
 file = kvmclock_test.flat
 smp = 2
-extra_params = --append "10000000 `date +%s`"
+qemu_params = --append "10000000 `date +%s`"
 
 [pcid-enabled]
 file = pcid.flat
-extra_params = -cpu qemu64,+pcid,+invpcid
+qemu_params = -cpu qemu64,+pcid,+invpcid
 arch = x86_64
 groups = pcid
 
 [pcid-disabled]
 file = pcid.flat
-extra_params = -cpu qemu64,-pcid,-invpcid
+qemu_params = -cpu qemu64,-pcid,-invpcid
 arch = x86_64
 groups = pcid
 
 [pcid-asymmetric]
 file = pcid.flat
-extra_params = -cpu qemu64,-pcid,+invpcid
+qemu_params = -cpu qemu64,-pcid,+invpcid
 arch = x86_64
 groups = pcid
 
 [rdpru]
 file = rdpru.flat
-extra_params = -cpu max
+qemu_params = -cpu max
 arch = x86_64
 
 [umip]
 file = umip.flat
-extra_params = -cpu qemu64,+umip
+qemu_params = -cpu qemu64,+umip
 
 [la57]
 file = la57.flat
-extra_params = -cpu max,host-phys-bits
+qemu_params = -cpu max,host-phys-bits
 
 [vmx]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test -apic_reg_virt_test -virt_x2apic_mode_test -vmx_pf_exception_test -vmx_pf_exception_forced_emulation_test -vmx_pf_no_vpid_test -vmx_pf_invvpid_test -vmx_pf_vpid_test -vmx_basic_vid_test -vmx_eoi_virt_test -vmx_posted_interrupts_test"
+qemu_params = -cpu max,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test -apic_reg_virt_test -virt_x2apic_mode_test -vmx_pf_exception_test -vmx_pf_exception_forced_emulation_test -vmx_pf_no_vpid_test -vmx_pf_invvpid_test -vmx_pf_vpid_test -vmx_basic_vid_test -vmx_eoi_virt_test -vmx_posted_interrupts_test"
 arch = x86_64
 groups = vmx
 
 [ept]
 file = vmx.flat
-extra_params = -cpu max,host-phys-bits,+vmx -m 2560 -append "ept_access*"
+qemu_params = -cpu max,host-phys-bits,+vmx -m 2560 -append "ept_access*"
 arch = x86_64
 groups = vmx
 
 [vmx_eoi_bitmap_ioapic_scan]
 file = vmx.flat
 smp = 2
-extra_params = -cpu max,+vmx -m 2048 -append vmx_eoi_bitmap_ioapic_scan_test
+qemu_params = -cpu max,+vmx -m 2048 -append vmx_eoi_bitmap_ioapic_scan_test
 arch = x86_64
 groups = vmx
 
 [vmx_hlt_with_rvi_test]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append vmx_hlt_with_rvi_test
+qemu_params = -cpu max,+vmx -append vmx_hlt_with_rvi_test
 arch = x86_64
 groups = vmx
 timeout = 10
 
 [vmx_apicv_test]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append "apic_reg_virt_test virt_x2apic_mode_test vmx_basic_vid_test vmx_eoi_virt_test"
+qemu_params = -cpu max,+vmx -append "apic_reg_virt_test virt_x2apic_mode_test vmx_basic_vid_test vmx_eoi_virt_test"
 arch = x86_64
 groups = vmx
 timeout = 30
@@ -354,7 +354,7 @@ timeout = 30
 [vmx_posted_intr_test]
 file = vmx.flat
 smp = 2
-extra_params = -cpu max,+vmx -append "vmx_posted_interrupts_test"
+qemu_params = -cpu max,+vmx -append "vmx_posted_interrupts_test"
 arch = x86_64
 groups = vmx
 timeout = 10
@@ -362,14 +362,14 @@ timeout = 10
 [vmx_apic_passthrough_thread]
 file = vmx.flat
 smp = 2
-extra_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_thread_test
+qemu_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_thread_test
 arch = x86_64
 groups = vmx
 
 [vmx_init_signal_test]
 file = vmx.flat
 smp = 2
-extra_params = -cpu max,+vmx -m 2048 -append vmx_init_signal_test
+qemu_params = -cpu max,+vmx -m 2048 -append vmx_init_signal_test
 arch = x86_64
 groups = vmx
 timeout = 10
@@ -377,62 +377,62 @@ timeout = 10
 [vmx_sipi_signal_test]
 file = vmx.flat
 smp = 2
-extra_params = -cpu max,+vmx -m 2048 -append vmx_sipi_signal_test
+qemu_params = -cpu max,+vmx -m 2048 -append vmx_sipi_signal_test
 arch = x86_64
 groups = vmx
 timeout = 10
 
 [vmx_apic_passthrough_tpr_threshold_test]
 file = vmx.flat
-extra_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_tpr_threshold_test
+qemu_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_tpr_threshold_test
 arch = x86_64
 groups = vmx
 timeout = 10
 
 [vmx_vmcs_shadow_test]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append vmx_vmcs_shadow_test
+qemu_params = -cpu max,+vmx -append vmx_vmcs_shadow_test
 arch = x86_64
 groups = vmx
 timeout = 180
 
 [vmx_pf_exception_test]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append "vmx_pf_exception_test"
+qemu_params = -cpu max,+vmx -append "vmx_pf_exception_test"
 arch = x86_64
 groups = vmx nested_exception
 
 [vmx_pf_exception_test_fep]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append "vmx_pf_exception_forced_emulation_test"
+qemu_params = -cpu max,+vmx -append "vmx_pf_exception_forced_emulation_test"
 arch = x86_64
 groups = vmx nested_exception nodefault
 timeout = 240
 
 [vmx_pf_vpid_test]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append "vmx_pf_vpid_test"
+qemu_params = -cpu max,+vmx -append "vmx_pf_vpid_test"
 arch = x86_64
 groups = vmx nested_exception nodefault
 timeout = 240
 
 [vmx_pf_invvpid_test]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append "vmx_pf_invvpid_test"
+qemu_params = -cpu max,+vmx -append "vmx_pf_invvpid_test"
 arch = x86_64
 groups = vmx nested_exception nodefault
 timeout = 240
 
 [vmx_pf_no_vpid_test]
 file = vmx.flat
-extra_params = -cpu max,+vmx -append "vmx_pf_no_vpid_test"
+qemu_params = -cpu max,+vmx -append "vmx_pf_no_vpid_test"
 arch = x86_64
 groups = vmx nested_exception nodefault
 timeout = 240
 
 [vmx_pf_exception_test_reduced_maxphyaddr]
 file = vmx.flat
-extra_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off,+vmx -append "vmx_pf_exception_test"
+qemu_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off,+vmx -append "vmx_pf_exception_test"
 arch = x86_64
 groups = vmx nested_exception
 check = /sys/module/kvm_intel/parameters/allow_smaller_maxphyaddr=Y
@@ -444,31 +444,31 @@ arch = x86_64
 [hyperv_synic]
 file = hyperv_synic.flat
 smp = 2
-extra_params = -cpu host,hv_passthrough -device hyperv-testdev
+qemu_params = -cpu host,hv_passthrough -device hyperv-testdev
 groups = hyperv
 
 [hyperv_connections]
 file = hyperv_connections.flat
 smp = 2
-extra_params = -cpu host,hv_passthrough -device hyperv-testdev
+qemu_params = -cpu host,hv_passthrough -device hyperv-testdev
 groups = hyperv
 
 [hyperv_stimer]
 file = hyperv_stimer.flat
 smp = 2
-extra_params = -cpu host,hv_passthrough
+qemu_params = -cpu host,hv_passthrough
 groups = hyperv
 
 [hyperv_stimer_direct]
 file = hyperv_stimer.flat
 smp = 2
-extra_params = -cpu host,hv_passthrough -append direct
+qemu_params = -cpu host,hv_passthrough -append direct
 groups = hyperv
 
 [hyperv_clock]
 file = hyperv_clock.flat
 smp = 2
-extra_params = -cpu host,hv_passthrough
+qemu_params = -cpu host,hv_passthrough
 arch = x86_64
 groups = hyperv
 check = /sys/devices/system/clocksource/clocksource0/current_clocksource=tsc
@@ -478,20 +478,20 @@ file = intel-iommu.flat
 arch = x86_64
 timeout = 30
 smp = 4
-extra_params = -M q35,kernel-irqchip=split -device intel-iommu,intremap=on,eim=off -device edu
+qemu_params = -M q35,kernel-irqchip=split -device intel-iommu,intremap=on,eim=off -device edu
 
 [tsx-ctrl]
 file = tsx-ctrl.flat
-extra_params = -cpu max
+qemu_params = -cpu max
 groups = tsx-ctrl
 
 [intel_cet]
 file = cet.flat
 arch = x86_64
 smp = 2
-extra_params = -enable-kvm -m 2048 -cpu host
+qemu_params = -enable-kvm -m 2048 -cpu host
 
 [lam]
 file = lam.flat
 arch = x86_64
-extra_params = -enable-kvm -cpu max
+qemu_params = -enable-kvm -cpu max
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 02/16] scripts: Add 'test_args' test definition parameter
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params' Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 15:58   ` Andrew Jones
  2025-05-14  3:16   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally Alexandru Elisei
                   ` (14 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

kvm-unit-tests, on arm and arm64, is getting ready to support running all
the test automatically under kvmtool. kvmtool has a different syntax for
configuring and running a virtual machine, but what is common between
kvmtool and qemu, and any other virtual machine manager that kvm-unit-tests
might support in the future, is the test arguments that are passed to the
main() function.

So add a new test definition parameter, 'test_args', that contains only the
VMM-independent arguments that are passed to the main() function.

Suggested-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/unittests.cfg     | 94 ++++++++++++++++++++++++++-----------------
 docs/unittests.txt    | 17 ++++++--
 powerpc/unittests.cfg | 19 +++++----
 riscv/unittests.cfg   |  2 +-
 s390x/unittests.cfg   | 13 +++---
 scripts/common.bash   |  8 +++-
 scripts/runtime.bash  | 18 ++++++---
 x86/unittests.cfg     | 92 ++++++++++++++++++++++++++----------------
 8 files changed, 164 insertions(+), 99 deletions(-)

diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index 6c6f76b2fb52..a4192ed7e20b 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -15,26 +15,27 @@
 [selftest-setup]
 file = selftest.flat
 smp = 2
-qemu_params = -m 256 -append 'setup smp=2 mem=256'
+test_args = 'setup smp=2 mem=256'
+qemu_params = -m 256
 groups = selftest
 
 # Test vector setup and exception handling (kernel mode).
 [selftest-vectors-kernel]
 file = selftest.flat
-qemu_params = -append 'vectors-kernel'
+test_args = vectors-kernel
 groups = selftest
 
 # Test vector setup and exception handling (user mode).
 [selftest-vectors-user]
 file = selftest.flat
-qemu_params = -append 'vectors-user'
+test_args = vectors-user
 groups = selftest
 
 # Test SMP support
 [selftest-smp]
 file = selftest.flat
 smp = $MAX_SMP
-qemu_params = -append 'smp'
+test_args = smp
 groups = selftest
 
 # Test PCI emulation
@@ -46,79 +47,81 @@ groups = pci
 [pmu-cycle-counter]
 file = pmu.flat
 groups = pmu
-qemu_params = -append 'cycle-counter 0'
+test_args = "cycle-counter 0"
 
 [pmu-event-introspection]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-event-introspection'
+test_args = pmu-event-introspection
 
 [pmu-event-counter-config]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-event-counter-config'
+test_args = pmu-event-counter-config
 
 [pmu-basic-event-count]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-basic-event-count'
+test_args = pmu-basic-event-count
 
 [pmu-mem-access]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-mem-access'
+test_args = pmu-mem-access
 
 [pmu-mem-access-reliability]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-mem-access-reliability'
+test_args = pmu-mem-access-reliability
 
 [pmu-sw-incr]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-sw-incr'
+test_args = pmu-sw-incr
 
 [pmu-chained-counters]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-chained-counters'
+test_args = pmu-chained-counters
 
 [pmu-chained-sw-incr]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-chained-sw-incr'
+test_args = pmu-chained-sw-incr
 
 [pmu-chain-promotion]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-chain-promotion'
+test_args = pmu-chain-promotion
 
 [pmu-overflow-interrupt]
 file = pmu.flat
 groups = pmu
 arch = arm64
-qemu_params = -append 'pmu-overflow-interrupt'
+test_args = pmu-overflow-interrupt
 
 # Test PMU support (TCG) with -icount IPC=1
 #[pmu-tcg-icount-1]
 #file = pmu.flat
-#qemu_params = -icount 0 -append 'cycle-counter 1'
+#test_args = "cycle-counter 1"
+#qemu_params = -icount 0
 #groups = pmu
 #accel = tcg
 
 # Test PMU support (TCG) with -icount IPC=256
 #[pmu-tcg-icount-256]
 #file = pmu.flat
-#qemu_params = -icount 8 -append 'cycle-counter 256'
+#test_args = "cycle-counter 256"
+#qemu_params = -icount 8
 #groups = pmu
 #accel = tcg
 
@@ -126,77 +129,89 @@ qemu_params = -append 'pmu-overflow-interrupt'
 [gicv2-ipi]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
-qemu_params = -machine gic-version=2 -append 'ipi'
+test_args = ipi
+qemu_params = -machine gic-version=2
 groups = gic
 
 [gicv2-mmio]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
-qemu_params = -machine gic-version=2 -append 'mmio'
+test_args = mmio
+qemu_params = -machine gic-version=2
 groups = gic
 
 [gicv2-mmio-up]
 file = gic.flat
 smp = 1
-qemu_params = -machine gic-version=2 -append 'mmio'
+test_args = mmio
+qemu_params = -machine gic-version=2
 groups = gic
 
 [gicv2-mmio-3p]
 file = gic.flat
 smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
-qemu_params = -machine gic-version=2 -append 'mmio'
+test_args = mmio
+qemu_params = -machine gic-version=2
 groups = gic
 
 [gicv3-ipi]
 file = gic.flat
 smp = $MAX_SMP
-qemu_params = -machine gic-version=3 -append 'ipi'
+test_args = ipi
+qemu_params = -machine gic-version=3
 groups = gic
 
 [gicv2-active]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
-qemu_params = -machine gic-version=2 -append 'active'
+test_args = active
+qemu_params = -machine gic-version=2
 groups = gic
 
 [gicv3-active]
 file = gic.flat
 smp = $MAX_SMP
-qemu_params = -machine gic-version=3 -append 'active'
+test_args = active
+qemu_params = -machine gic-version=3
 groups = gic
 
 [its-introspection]
 file = gic.flat
 smp = $MAX_SMP
-qemu_params = -machine gic-version=3 -append 'its-introspection'
+test_args = its-introspection
+qemu_params = -machine gic-version=3
 groups = its
 arch = arm64
 
 [its-trigger]
 file = gic.flat
 smp = $MAX_SMP
-qemu_params = -machine gic-version=3 -append 'its-trigger'
+test_args = its-trigger
+qemu_params = -machine gic-version=3
 groups = its
 arch = arm64
 
 [its-migration]
 file = gic.flat
 smp = $MAX_SMP
-qemu_params = -machine gic-version=3 -append 'its-migration'
+test_args = its-migration
+qemu_params = -machine gic-version=3
 groups = its migration
 arch = arm64
 
 [its-pending-migration]
 file = gic.flat
 smp = $MAX_SMP
-qemu_params = -machine gic-version=3 -append 'its-pending-migration'
+test_args = its-pending-migration
+qemu_params = -machine gic-version=3
 groups = its migration
 arch = arm64
 
 [its-migrate-unmapped-collection]
 file = gic.flat
 smp = $MAX_SMP
-qemu_params = -machine gic-version=3 -append 'its-migrate-unmapped-collection'
+test_args = its-migrate-unmapped-collection
+qemu_params = -machine gic-version=3
 groups = its migration
 arch = arm64
 
@@ -231,37 +246,37 @@ groups = cache
 [debug-bp]
 file = debug.flat
 arch = arm64
-qemu_params = -append 'bp'
+test_args = bp
 groups = debug
 
 [debug-bp-migration]
 file = debug.flat
 arch = arm64
-qemu_params = -append 'bp-migration'
+test_args = bp-migration
 groups = debug migration
 
 [debug-wp]
 file = debug.flat
 arch = arm64
-qemu_params = -append 'wp'
+test_args = wp
 groups = debug
 
 [debug-wp-migration]
 file = debug.flat
 arch = arm64
-qemu_params = -append 'wp-migration'
+test_args = wp-migration
 groups = debug migration
 
 [debug-sstep]
 file = debug.flat
 arch = arm64
-qemu_params = -append 'ss'
+test_args = ss
 groups = debug
 
 [debug-sstep-migration]
 file = debug.flat
 arch = arm64
-qemu_params = -append 'ss-migration'
+test_args = ss-migration
 groups = debug migration
 
 # FPU/SIMD test
@@ -276,17 +291,20 @@ arch = arm64
 [mte-sync]
 file = mte.flat
 groups = mte
-qemu_params = -machine mte=on -append 'sync'
+test_args=sync
+qemu_params = -machine mte=on
 arch = arm64
 
 [mte-async]
 file = mte.flat
 groups = mte
-qemu_params = -machine mte=on -append 'async'
+test_args=async
+qemu_params = -machine mte=on
 arch = arm64
 
 [mte-asymm]
 file = mte.flat
 groups = mte
-qemu_params = -machine mte=on -append 'asymm'
+test_args=asymm
+qemu_params = -machine mte=on
 arch = arm64
diff --git a/docs/unittests.txt b/docs/unittests.txt
index 3d19fd70953f..6eb315618dbd 100644
--- a/docs/unittests.txt
+++ b/docs/unittests.txt
@@ -56,13 +56,22 @@ smp = <number>
 Optional, the number of processors created in the machine to run the test.
 Defaults to 1. $MAX_SMP can be used to specify the maximum supported.
 
+test_args
+---------
+test_args = "..."
+
+Optional, will be used to pass arguments into the test case argv. If multiple,
+space separated, arguments need to be passed to a test, wrap them in quotes.
+Backticks can be used to pass the result of shell commands, for example:
+
+test_args = "10000000 `date +%s`"
+
 qemu_params
 ------------
-These are extra parameters supplied to the QEMU process. -append '...' can
-be used to pass arguments into the test case argv. Multiple parameters can
-be added, for example:
+These are extra parameters supplied to the QEMU process. Multiple parameters
+can be added, for example:
 
-qemu_params = -m 256 -append 'smp=2'
+qemu_params = -m 256 -machine pit=off
 
 extra_params
 ------------
diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg
index 5097911e4bf3..2dd32edfa1ae 100644
--- a/powerpc/unittests.cfg
+++ b/powerpc/unittests.cfg
@@ -15,7 +15,8 @@
 [selftest-setup]
 file = selftest.elf
 smp = 2
-qemu_params = -m 1g -append 'setup smp=2 mem=1024'
+test_args = 'setup smp=2 mem=1024'
+qemu_params = -m 1g
 groups = selftest
 
 [selftest-migration]
@@ -27,7 +28,7 @@ groups = selftest migration
 file = selftest-migration.elf
 machine = pseries
 groups = selftest migration
-qemu_params = -append "skip"
+test_args = "skip"
 
 [migration-memory]
 file = memory-verify.elf
@@ -46,20 +47,21 @@ machine = pseries
 file = rtas.elf
 machine = pseries
 timeout = 5
-qemu_params = -append "get-time-of-day date=$(date +%s)"
+test_args = "get-time-of-day date=$(date +%s)"
 groups = rtas
 
 [rtas-get-time-of-day-base]
 file = rtas.elf
 machine = pseries
 timeout = 5
-qemu_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)"
+test_args = "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)"
+qemu_params = -rtc base="2006-06-17"
 groups = rtas
 
 [rtas-set-time-of-day]
 file = rtas.elf
 machine = pseries
-qemu_params = -append "set-time-of-day"
+test_args = "set-time-of-day"
 timeout = 5
 groups = rtas
 
@@ -94,7 +96,7 @@ smp = 2
 [atomics-migration]
 file = atomics.elf
 machine = pseries
-qemu_params = -append "migration -m"
+test_args = "migration -m"
 groups = migration
 
 [timebase]
@@ -110,7 +112,8 @@ file = tm.elf
 machine = pseries
 accel = kvm
 smp = 2,threads=2
-qemu_params = -machine cap-htm=on -append "h_cede_tm"
+test_args = "h_cede_tm"
+qemu_params = -machine cap-htm=on
 groups = h_cede_tm
 
 [sprs]
@@ -119,7 +122,7 @@ file = sprs.elf
 [sprs-migration]
 file = sprs.elf
 machine = pseries
-qemu_params = -append '-w'
+test_args = '-w'
 groups = migration
 
 [sieve]
diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg
index 5b31047f75c7..8a98ac723c2c 100644
--- a/riscv/unittests.cfg
+++ b/riscv/unittests.cfg
@@ -10,7 +10,7 @@
 [selftest]
 file = selftest.flat
 smp = $MAX_SMP
-qemu_params = -append 'foo bar baz'
+test_args = 'foo bar baz'
 groups = selftest
 
 # Set $FIRMWARE_OVERRIDE to /path/to/firmware to select the SBI implementation.
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index 1e129fef3c38..ed4d069ece38 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -10,7 +10,7 @@
 file = selftest.elf
 groups = selftest
 # please keep the kernel cmdline in sync with $(TEST_DIR)/selftest.parmfile
-qemu_params = -append 'test 123'
+test_args = 'test 123'
 
 [selftest-migration]
 file = selftest-migration.elf
@@ -22,7 +22,7 @@ accel = kvm
 [selftest-migration-skip]
 file = selftest-migration.elf
 groups = selftest migration
-qemu_params = -append "skip"
+test_args = "skip"
 
 # This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream
 [migration-memory]
@@ -214,13 +214,13 @@ smp = 2
 [migration-skey-sequential]
 file = migration-skey.elf
 groups = migration
-qemu_params = -append '--sequential'
+test_args = '--sequential'
 
 [migration-skey-parallel]
 file = migration-skey.elf
 smp = 2
 groups = migration
-qemu_params = -append '--parallel'
+test_args = '--parallel'
 
 [execute]
 file = ex.elf
@@ -252,12 +252,13 @@ file = topology.elf
 
 [topology-2]
 file = topology.elf
-qemu_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248  -append '-sockets 31 -cores 8'
+test_args = '-sockets 31 -cores 8'
+qemu_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248
 
 [topology-3]
 file = topology.elf
+test_args = '-drawers 2 -books 2 -sockets 2 -cores 16'
 qemu_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores=16,maxcpus=128 \
--append '-drawers 2 -books 2 -sockets 2 -cores 16' \
 -device max-s390x-cpu,core-id=31,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
 -device max-s390x-cpu,core-id=11,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
 -device max-s390x-cpu,core-id=95,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
diff --git a/scripts/common.bash b/scripts/common.bash
index bd7c82f1adda..9deb87d4050d 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -7,6 +7,7 @@ function for_each_unittest()
 	local testname
 	local smp
 	local kernel
+	local test_args
 	local opts
 	local groups
 	local arch
@@ -22,11 +23,12 @@ function for_each_unittest()
 		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
 			rematch=${BASH_REMATCH[1]}
 			if [ -n "${testname}" ]; then
-				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
+				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
 			fi
 			testname=$rematch
 			smp=1
 			kernel=""
+			test_args=""
 			opts=""
 			groups=""
 			arch=""
@@ -38,6 +40,8 @@ function for_each_unittest()
 			kernel=$TEST_DIR/${BASH_REMATCH[1]}
 		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
 			smp=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
+			test_args=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
 			opts=${BASH_REMATCH[2]}$'\n'
 			while read -r -u $fd; do
@@ -71,7 +75,7 @@ function for_each_unittest()
 		fi
 	done
 	if [ -n "${testname}" ]; then
-		$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
+		$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
 	fi
 	exec {fd}<&-
 }
diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index 400e8a082528..06cc58e79b69 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -80,12 +80,18 @@ function run()
     local groups="$2"
     local smp="$3"
     local kernel="$4"
-    local opts="$5"
-    local arch="$6"
-    local machine="$7"
-    local check="${CHECK:-$8}"
-    local accel="$9"
-    local timeout="${10:-$TIMEOUT}" # unittests.cfg overrides the default
+    local test_args="$5"
+    local opts="$6"
+    local arch="$7"
+    local machine="$8"
+    local check="${CHECK:-$9}"
+    local accel="${10}"
+    local timeout="${11:-$TIMEOUT}" # unittests.cfg overrides the default
+
+    # If $test_args is empty, qemu will interpret the first option after -append
+    # as a kernel parameter instead of a qemu option, so make sure the -append
+    # option is used only if $test_args is not empy.
+    [ -n "$test_args" ] && opts="-append $test_args $opts"
 
     if [ "${CONFIG_EFI}" == "y" ]; then
         kernel=${kernel/%.flat/.efi}
diff --git a/x86/unittests.cfg b/x86/unittests.cfg
index a356f486eaec..3effddfe4207 100644
--- a/x86/unittests.cfg
+++ b/x86/unittests.cfg
@@ -58,27 +58,27 @@ smp = 3
 
 [vmexit_cpuid]
 file = vmexit.flat
-qemu_params = -append 'cpuid'
+test_args = 'cpuid'
 groups = vmexit
 
 [vmexit_vmcall]
 file = vmexit.flat
-qemu_params = -append 'vmcall'
+test_args = 'vmcall'
 groups = vmexit
 
 [vmexit_mov_from_cr8]
 file = vmexit.flat
-qemu_params = -append 'mov_from_cr8'
+test_args = 'mov_from_cr8'
 groups = vmexit
 
 [vmexit_mov_to_cr8]
 file = vmexit.flat
-qemu_params = -append 'mov_to_cr8'
+test_args = 'mov_to_cr8'
 groups = vmexit
 
 [vmexit_inl_pmtimer]
 file = vmexit.flat
-qemu_params = -append 'inl_from_pmtimer'
+test_args = 'inl_from_pmtimer'
 groups = vmexit
 
 # To allow IPIs to be accelerated by SVM AVIC when the feature is available and
@@ -87,40 +87,43 @@ groups = vmexit
 [vmexit_ipi]
 file = vmexit.flat
 smp = 2
-qemu_params = -machine pit=off -append 'ipi'
+test_args = 'ipi'
+qemu_params = -machine pit=off
 groups = vmexit
 
 [vmexit_ipi_halt]
 file = vmexit.flat
 smp = 2
-qemu_params = -append 'ipi_halt'
+test_args = 'ipi_halt'
 groups = vmexit
 
 [vmexit_ple_round_robin]
 file = vmexit.flat
-qemu_params = -append 'ple_round_robin'
+test_args = 'ple_round_robin'
 groups = vmexit
 
 [vmexit_tscdeadline]
 file = vmexit.flat
 groups = vmexit
-qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline
+test_args = tscdeadline
+qemu_params = -cpu qemu64,+x2apic,+tsc-deadline
 
 [vmexit_tscdeadline_immed]
 file = vmexit.flat
 groups = vmexit
-qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline_immed
+test_args = tscdeadline_immed
+qemu_params = -cpu qemu64,+x2apic,+tsc-deadline
 
 [vmexit_cr0_wp]
 file = vmexit.flat
 smp = 2
-qemu_params = -append 'toggle_cr0_wp'
+test_args = 'toggle_cr0_wp'
 groups = vmexit
 
 [vmexit_cr4_pge]
 file = vmexit.flat
 smp = 2
-qemu_params = -append 'toggle_cr4_pge'
+test_args = 'toggle_cr4_pge'
 groups = vmexit
 
 [access]
@@ -131,7 +134,8 @@ qemu_params = -cpu max,host-phys-bits
 [access_fep]
 file = access_test.flat
 arch = x86_64
-qemu_params = -cpu max,host-phys-bits -append force_emulation
+test_args = force_emulation
+qemu_params = -cpu max,host-phys-bits
 groups = nodefault
 timeout = 240
 
@@ -256,13 +260,15 @@ arch = x86_64
 [svm]
 file = svm.flat
 smp = 2
-qemu_params = -cpu max,+svm -m 4g -append "-pause_filter_test"
+test_args = "-pause_filter_test"
+qemu_params = -cpu max,+svm -m 4g
 arch = x86_64
 groups = svm
 
 [svm_pause_filter]
 file = svm.flat
-qemu_params = -cpu max,+svm -overcommit cpu-pm=on -m 4g -append pause_filter_test
+test_args = pause_filter_test
+qemu_params = -cpu max,+svm -overcommit cpu-pm=on -m 4g
 arch = x86_64
 groups = svm
 
@@ -285,7 +291,7 @@ groups = tasks
 [kvmclock_test]
 file = kvmclock_test.flat
 smp = 2
-qemu_params = --append "10000000 `date +%s`"
+test_args = "10000000 `date +%s`"
 
 [pcid-enabled]
 file = pcid.flat
@@ -320,33 +326,38 @@ qemu_params = -cpu max,host-phys-bits
 
 [vmx]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test -apic_reg_virt_test -virt_x2apic_mode_test -vmx_pf_exception_test -vmx_pf_exception_forced_emulation_test -vmx_pf_no_vpid_test -vmx_pf_invvpid_test -vmx_pf_vpid_test -vmx_basic_vid_test -vmx_eoi_virt_test -vmx_posted_interrupts_test"
+test_args = "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test -apic_reg_virt_test -virt_x2apic_mode_test -vmx_pf_exception_test -vmx_pf_exception_forced_emulation_test -vmx_pf_no_vpid_test -vmx_pf_invvpid_test -vmx_pf_vpid_test -vmx_basic_vid_test -vmx_eoi_virt_test -vmx_posted_interrupts_test"
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx
 
 [ept]
 file = vmx.flat
-qemu_params = -cpu max,host-phys-bits,+vmx -m 2560 -append "ept_access*"
+test_args = "ept_access*"
+qemu_params = -cpu max,host-phys-bits,+vmx -m 2560
 arch = x86_64
 groups = vmx
 
 [vmx_eoi_bitmap_ioapic_scan]
 file = vmx.flat
 smp = 2
-qemu_params = -cpu max,+vmx -m 2048 -append vmx_eoi_bitmap_ioapic_scan_test
+test_args = vmx_eoi_bitmap_ioapic_scan_test
+qemu_params = -cpu max,+vmx -m 2048
 arch = x86_64
 groups = vmx
 
 [vmx_hlt_with_rvi_test]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append vmx_hlt_with_rvi_test
+test_args = vmx_hlt_with_rvi_test
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx
 timeout = 10
 
 [vmx_apicv_test]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append "apic_reg_virt_test virt_x2apic_mode_test vmx_basic_vid_test vmx_eoi_virt_test"
+test_args = "apic_reg_virt_test virt_x2apic_mode_test vmx_basic_vid_test vmx_eoi_virt_test"
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx
 timeout = 30
@@ -354,7 +365,8 @@ timeout = 30
 [vmx_posted_intr_test]
 file = vmx.flat
 smp = 2
-qemu_params = -cpu max,+vmx -append "vmx_posted_interrupts_test"
+test_args = "vmx_posted_interrupts_test"
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx
 timeout = 10
@@ -362,14 +374,16 @@ timeout = 10
 [vmx_apic_passthrough_thread]
 file = vmx.flat
 smp = 2
-qemu_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_thread_test
+test_args = vmx_apic_passthrough_thread_test
+qemu_params = -cpu max,+vmx -m 2048
 arch = x86_64
 groups = vmx
 
 [vmx_init_signal_test]
 file = vmx.flat
 smp = 2
-qemu_params = -cpu max,+vmx -m 2048 -append vmx_init_signal_test
+test_args = vmx_init_signal_test
+qemu_params = -cpu max,+vmx -m 2048
 arch = x86_64
 groups = vmx
 timeout = 10
@@ -377,62 +391,71 @@ timeout = 10
 [vmx_sipi_signal_test]
 file = vmx.flat
 smp = 2
-qemu_params = -cpu max,+vmx -m 2048 -append vmx_sipi_signal_test
+test_args = vmx_sipi_signal_test
+qemu_params = -cpu max,+vmx -m 2048
 arch = x86_64
 groups = vmx
 timeout = 10
 
 [vmx_apic_passthrough_tpr_threshold_test]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_tpr_threshold_test
+test_args = vmx_apic_passthrough_tpr_threshold_test
+qemu_params = -cpu max,+vmx -m 2048
 arch = x86_64
 groups = vmx
 timeout = 10
 
 [vmx_vmcs_shadow_test]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append vmx_vmcs_shadow_test
+test_args = vmx_vmcs_shadow_test
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx
 timeout = 180
 
 [vmx_pf_exception_test]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append "vmx_pf_exception_test"
+test_args = "vmx_pf_exception_test"
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx nested_exception
 
 [vmx_pf_exception_test_fep]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append "vmx_pf_exception_forced_emulation_test"
+test_args = "vmx_pf_exception_forced_emulation_test"
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx nested_exception nodefault
 timeout = 240
 
 [vmx_pf_vpid_test]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append "vmx_pf_vpid_test"
+test_args = "vmx_pf_vpid_test"
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx nested_exception nodefault
 timeout = 240
 
 [vmx_pf_invvpid_test]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append "vmx_pf_invvpid_test"
+test_args = "vmx_pf_invvpid_test"
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx nested_exception nodefault
 timeout = 240
 
 [vmx_pf_no_vpid_test]
 file = vmx.flat
-qemu_params = -cpu max,+vmx -append "vmx_pf_no_vpid_test"
+test_args = "vmx_pf_no_vpid_test"
+qemu_params = -cpu max,+vmx
 arch = x86_64
 groups = vmx nested_exception nodefault
 timeout = 240
 
 [vmx_pf_exception_test_reduced_maxphyaddr]
 file = vmx.flat
-qemu_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off,+vmx -append "vmx_pf_exception_test"
+test_args = "vmx_pf_exception_test"
+qemu_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off,+vmx
 arch = x86_64
 groups = vmx nested_exception
 check = /sys/module/kvm_intel/parameters/allow_smaller_maxphyaddr=Y
@@ -462,7 +485,8 @@ groups = hyperv
 [hyperv_stimer_direct]
 file = hyperv_stimer.flat
 smp = 2
-qemu_params = -cpu host,hv_passthrough -append direct
+test_args = direct
+qemu_params = -cpu host,hv_passthrough
 groups = hyperv
 
 [hyperv_clock]
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params' Alexandru Elisei
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 02/16] scripts: Add 'test_args' test definition parameter Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:02   ` Andrew Jones
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 04/16] run_tests.sh: Document --probe-maxsmp argument Alexandru Elisei
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Only arm and arm64 are allowed to set --target to kvmtool; the rest of the
architectures can only set --target to 'qemu', which is also the default.

Needed to make the changes necessary to add support for kvmtool to the test
runner.

kvmtool also supports running the riscv tests, so it's not outside of the
realm of the possibily for the riscv tests to get support for kvmtool.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 configure | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/configure b/configure
index 20bf5042cb9e..8c4400db42bc 100755
--- a/configure
+++ b/configure
@@ -38,6 +38,21 @@ function get_default_qemu_cpu()
     esac
 }
 
+# Return the targets that the architecture supports
+function get_supported_targets()
+{
+    local arch=$1
+
+    case "$arch" in
+    "arm" | "arm64" | "aarch64")
+        echo "qemu kvmtool"
+	;;
+    *)
+        echo "qemu"
+	;;
+    esac
+}
+
 srcdir=$(cd "$(dirname "$0")"; pwd)
 prefix=/usr/local
 cc=gcc
@@ -79,6 +94,7 @@ fi
 usage() {
     [ "$arch" = "aarch64" ] && arch="arm64"
     [ -z "$processor" ] && processor=$(get_default_processor $arch)
+    [ -z $target ] && target=qemu
     cat <<-EOF
 	Usage: $0 [options]
 
@@ -89,8 +105,8 @@ usage() {
 	    --target-cpu=CPU       the CPU model to run on. If left unset, the run script
 	                           selects the best value based on the host system and the
 	                           test configuration.
-	    --target=TARGET        target platform that the tests will be running on (qemu or
-	                           kvmtool, default is qemu) (arm/arm64 only)
+	    --target=TARGET        target platform that the tests will be running on ($target).
+	                           Supported targets: $(get_supported_targets $arch)
 	    --cross-prefix=PREFIX  cross compiler prefix
 	    --cc=CC                c compiler to use ($cc)
 	    --cflags=FLAGS         extra options to be passed to the c compiler
@@ -281,13 +297,11 @@ if [ "$arch" = "riscv" ]; then
     exit 1
 fi
 
-if [ -z "$target" ]; then
-    target="qemu"
-else
-    if [ "$arch" != "arm64" ] && [ "$arch" != "arm" ]; then
-        echo "--target is not supported for $arch"
-        usage
-    fi
+if [ -z $target ]; then
+    target=qemu
+elif ! grep -Fq " $target " <<< " $(get_supported_targets $arch) "; then
+    echo "Target $target is not supported for $arch"
+    usage
 fi
 
 if [ "$efi" ] && [ "$arch" != "x86_64" ] &&
@@ -519,10 +533,8 @@ CONFIG_EFI=$efi
 EFI_DIRECT=$efi_direct
 CONFIG_WERROR=$werror
 GEN_SE_HEADER=$gen_se_header
+TARGET=$target
 EOF
-if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
-    echo "TARGET=$target" >> config.mak
-fi
 
 cat <<EOF > lib/config.h
 #ifndef _CONFIG_H_
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 04/16] run_tests.sh: Document --probe-maxsmp argument
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (2 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-14  3:29   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 05/16] scripts: Document environment variables Alexandru Elisei
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Commit 5dd20ec76ea63 ("runtime: Update MAX_SMP probe") added the
--probe-maxmp argument, but the help message for run_tests.sh wasn't
updated. Document --probe-maxsmp.

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 run_tests.sh | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/run_tests.sh b/run_tests.sh
index 152323ffc8a2..f30b6dbd131c 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -17,14 +17,15 @@ cat <<EOF
 
 Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t] [-l]
 
-    -h, --help      Output this help text
-    -v, --verbose   Enables verbose mode
-    -a, --all       Run all tests, including those flagged as 'nodefault'
-                    and those guarded by errata.
-    -g, --group     Only execute tests in the given group
-    -j, --parallel  Execute tests in parallel
-    -t, --tap13     Output test results in TAP format
-    -l, --list      Only output all tests list
+    -h, --help          Output this help text
+    -v, --verbose       Enables verbose mode
+    -a, --all           Run all tests, including those flagged as 'nodefault'
+                        and those guarded by errata.
+    -g, --group         Only execute tests in the given group
+    -j, --parallel      Execute tests in parallel
+    -t, --tap13         Output test results in TAP format
+    -l, --list          Only output all tests list
+        --probe-maxsmp  Update the maximum number of VCPUs supported by host
 
 Set the environment variable QEMU=/path/to/qemu-system-ARCH to
 specify the appropriate qemu binary for ARCH-run.
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 05/16] scripts: Document environment variables
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (3 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 04/16] run_tests.sh: Document --probe-maxsmp argument Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-14  3:36   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu Alexandru Elisei
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara, Andrew Jones

Document the environment variables that influence how a test is executed
by the run_tests.sh test runner.

Suggested-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 docs/unittests.txt |  5 ++++-
 run_tests.sh       | 12 +++++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/docs/unittests.txt b/docs/unittests.txt
index 6eb315618dbd..ea0da959f008 100644
--- a/docs/unittests.txt
+++ b/docs/unittests.txt
@@ -102,7 +102,8 @@ timeout
 -------
 timeout = <duration>
 
-Optional timeout in seconds, after which the test will be killed and fail.
+Optional timeout in seconds, after which the test will be killed and fail. Can
+be overwritten with the TIMEOUT=<duration> environment variable.
 
 check
 -----
@@ -113,3 +114,5 @@ can contain multiple files to check separated by a space, but each check
 parameter needs to be of the form <path>=<value>
 
 The path and value cannot contain space, =, or shell wildcard characters.
+
+Can be overwritten with the CHECK environment variable with the same syntax.
diff --git a/run_tests.sh b/run_tests.sh
index f30b6dbd131c..dd9d27377905 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -27,9 +27,15 @@ Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t] [-l]
     -l, --list          Only output all tests list
         --probe-maxsmp  Update the maximum number of VCPUs supported by host
 
-Set the environment variable QEMU=/path/to/qemu-system-ARCH to
-specify the appropriate qemu binary for ARCH-run.
-
+The following environment variables are used:
+
+    QEMU            Path to QEMU binary for ARCH-run
+    ACCEL           QEMU accelerator to use, e.g. 'kvm', 'hvf' or 'tcg'
+    ACCEL_PROPS     Extra argument(s) to ACCEL
+    MACHINE         QEMU machine type
+    TIMEOUT         Timeout duration for the timeout(1) command
+    CHECK           Overwrites the 'check' unit test parameter (see
+                    docs/unittests.txt)
 EOF
 }
 
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (4 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 05/16] scripts: Document environment variables Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:10   ` Andrew Jones
  2025-05-14  7:49   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 07/16] scripts: Use an associative array for qemu argument names Alexandru Elisei
                   ` (10 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Arm and arm64 support running the tests under kvmtool. kvmtool has a
different command line syntax for configuring and running a virtual
machine, and the automated scripts know only how to use qemu.

One issue with that is even though the tests have been configured for
kvmtool (with ./configure --target=kvmtool), the scripts will use qemu to
run the tests, and without looking at the logs there is no indication that
the tests haven't been run with kvmtool, as configured.

Another issue is that kvmtool uses a different address for the UART and
when running the tests with qemu via the scripts, this warning is
displayed:

WARNING: early print support may not work. Found uart at 0x9000000, but early base is 0x1000000.

which might trip up an unsuspected user.

There are four different ways to run a test using the test infrastructure:
with run_tests.sh, by invoking arm/run or arm/efi/run with the correct
parameters (only the arm directory is mentioned here because the tests can
be configured for kvmtool only on arm and arm64), and by creating
standalone tests.

run_tests.sh ends up execuing either arm/run or arm/efi/run, so add a check
to these two scripts for the test target, and refuse to run the test if
kvm-unit-tests has been configured for kvmtool.

mkstandalone.sh also executes arm/run or arm/efi run, but the usual use
case for standalone tests is to compile them on one machine, and then to
run them on a different machine. This two step process can be time
consuming, so save the user time (and frustration!) and add a check
directly to mkstandalone.sh.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/efi/run             |  3 +++
 arm/run                 |  4 ++++
 scripts/mkstandalone.sh |  3 +++
 scripts/vmm.bash        | 14 ++++++++++++++
 4 files changed, 24 insertions(+)
 create mode 100644 scripts/vmm.bash

diff --git a/arm/efi/run b/arm/efi/run
index 8f41fc02df31..53d71297cc52 100755
--- a/arm/efi/run
+++ b/arm/efi/run
@@ -11,6 +11,9 @@ if [ ! -f config.mak ]; then
 fi
 source config.mak
 source scripts/arch-run.bash
+source scripts/vmm.bash
+
+check_vmm_supported
 
 if [ -f /usr/share/qemu-efi-aarch64/QEMU_EFI.fd ]; then
 	DEFAULT_UEFI=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
diff --git a/arm/run b/arm/run
index ef58558231b7..56562ed1628f 100755
--- a/arm/run
+++ b/arm/run
@@ -7,7 +7,11 @@ if [ -z "$KUT_STANDALONE" ]; then
 	fi
 	source config.mak
 	source scripts/arch-run.bash
+	source scripts/vmm.bash
 fi
+
+check_vmm_supported
+
 qemu_cpu="$TARGET_CPU"
 
 if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
index c4ba81f18935..4f666cefe076 100755
--- a/scripts/mkstandalone.sh
+++ b/scripts/mkstandalone.sh
@@ -6,6 +6,9 @@ if [ ! -f config.mak ]; then
 fi
 source config.mak
 source scripts/common.bash
+source scripts/vmm.bash
+
+check_vmm_supported
 
 temp_file ()
 {
diff --git a/scripts/vmm.bash b/scripts/vmm.bash
new file mode 100644
index 000000000000..39325858c6b3
--- /dev/null
+++ b/scripts/vmm.bash
@@ -0,0 +1,14 @@
+source config.mak
+
+function check_vmm_supported()
+{
+	case "$TARGET" in
+	qemu)
+		return 0
+		;;
+	*)
+		echo "$0 does not support target '$TARGET'"
+		exit 2
+		;;
+	esac
+}
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 07/16] scripts: Use an associative array for qemu argument names
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (5 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:17   ` Andrew Jones
  2025-05-14  8:02   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 08/16] scripts: Add 'kvmtool_params' to test definition Alexandru Elisei
                   ` (9 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Move away from hardcoded qemu arguments and use instead an associative
array to get the needed arguments. This paves the way for adding kvmtool
support to the scripts, which has a different syntax for the same VM
configuration parameters.

Suggested-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 scripts/common.bash  | 10 +++++++---
 scripts/runtime.bash |  7 +------
 scripts/vmm.bash     |  7 +++++++
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/scripts/common.bash b/scripts/common.bash
index 9deb87d4050d..649f1c737617 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -1,4 +1,5 @@
 source config.mak
+source scripts/vmm.bash
 
 function for_each_unittest()
 {
@@ -26,8 +27,11 @@ function for_each_unittest()
 				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
 			fi
 			testname=$rematch
-			smp=1
+			smp="${vmm_opts[$TARGET:nr_cpus]} 1"
 			kernel=""
+			# Intentionally don't use -append if test_args is empty
+			# because qemu interprets the first argument after
+			# -append as a kernel parameter.
 			test_args=""
 			opts=""
 			groups=""
@@ -39,9 +43,9 @@ function for_each_unittest()
 		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
 			kernel=$TEST_DIR/${BASH_REMATCH[1]}
 		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
-			smp=${BASH_REMATCH[1]}
+			smp="${vmm_opts[$TARGET:nr_cpus]} ${BASH_REMATCH[1]}"
 		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
-			test_args=${BASH_REMATCH[1]}
+			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
 		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
 			opts=${BASH_REMATCH[2]}$'\n'
 			while read -r -u $fd; do
diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index 06cc58e79b69..86d8a2cd8528 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -34,7 +34,7 @@ premature_failure()
 get_cmdline()
 {
     local kernel=$1
-    echo "TESTNAME=$testname TIMEOUT=$timeout MACHINE=$machine ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
+    echo "TESTNAME=$testname TIMEOUT=$timeout MACHINE=$machine ACCEL=$accel $RUNTIME_arch_run $kernel $smp $test_args $opts"
 }
 
 skip_nodefault()
@@ -88,11 +88,6 @@ function run()
     local accel="${10}"
     local timeout="${11:-$TIMEOUT}" # unittests.cfg overrides the default
 
-    # If $test_args is empty, qemu will interpret the first option after -append
-    # as a kernel parameter instead of a qemu option, so make sure the -append
-    # option is used only if $test_args is not empy.
-    [ -n "$test_args" ] && opts="-append $test_args $opts"
-
     if [ "${CONFIG_EFI}" == "y" ]; then
         kernel=${kernel/%.flat/.efi}
     fi
diff --git a/scripts/vmm.bash b/scripts/vmm.bash
index 39325858c6b3..b02055a5c0b6 100644
--- a/scripts/vmm.bash
+++ b/scripts/vmm.bash
@@ -1,5 +1,12 @@
 source config.mak
 
+declare -A vmm_opts=(
+	[qemu:nr_cpus]='-smp'
+	[qemu:kernel]='-kernel'
+	[qemu:args]='-append'
+	[qemu:initrd]='-initrd'
+)
+
 function check_vmm_supported()
 {
 	case "$TARGET" in
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 08/16] scripts: Add 'kvmtool_params' to test definition
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (6 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 07/16] scripts: Use an associative array for qemu argument names Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:28   ` Andrew Jones
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 09/16] scripts: Add support for kvmtool Alexandru Elisei
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

arm/arm64 supports running tests under kvmtool, but kvmtool's syntax for
running and configuring a virtual machine is different to qemu. To run
tests using the automated test infrastructure, add a new test parameter,
'kvmtool_params'. The parameter serves the exact purpose as 'qemu_params',
but using kvmtool's syntax.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/unittests.cfg   | 24 +++++++++++++++++++++++
 docs/unittests.txt  |  8 ++++++++
 scripts/common.bash | 47 +++++++++++++++++++++++++++++----------------
 3 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index a4192ed7e20b..f3c773e56933 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -17,6 +17,7 @@ file = selftest.flat
 smp = 2
 test_args = 'setup smp=2 mem=256'
 qemu_params = -m 256
+kvmtool_params = --mem 256
 groups = selftest
 
 # Test vector setup and exception handling (kernel mode).
@@ -48,66 +49,77 @@ groups = pci
 file = pmu.flat
 groups = pmu
 test_args = "cycle-counter 0"
+kvmtool_params = --pmu
 
 [pmu-event-introspection]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-event-introspection
+kvmtool_params = --pmu
 
 [pmu-event-counter-config]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-event-counter-config
+kvmtool_params = --pmu
 
 [pmu-basic-event-count]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-basic-event-count
+kvmtool_params = --pmu
 
 [pmu-mem-access]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-mem-access
+kvmtool_params = --pmu
 
 [pmu-mem-access-reliability]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-mem-access-reliability
+kvmtool_params = --pmu
 
 [pmu-sw-incr]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-sw-incr
+kvmtool_params = --pmu
 
 [pmu-chained-counters]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-chained-counters
+kvmtool_params = --pmu
 
 [pmu-chained-sw-incr]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-chained-sw-incr
+kvmtool_params = --pmu
 
 [pmu-chain-promotion]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-chain-promotion
+kvmtool_params = --pmu
 
 [pmu-overflow-interrupt]
 file = pmu.flat
 groups = pmu
 arch = arm64
 test_args = pmu-overflow-interrupt
+kvmtool_params = --pmu
 
 # Test PMU support (TCG) with -icount IPC=1
 #[pmu-tcg-icount-1]
@@ -131,6 +143,7 @@ file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 test_args = ipi
 qemu_params = -machine gic-version=2
+kvmtool_params = --irqchip=gicv2
 groups = gic
 
 [gicv2-mmio]
@@ -138,6 +151,7 @@ file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 test_args = mmio
 qemu_params = -machine gic-version=2
+kvmtool_params = --irqchip=gicv2
 groups = gic
 
 [gicv2-mmio-up]
@@ -145,6 +159,7 @@ file = gic.flat
 smp = 1
 test_args = mmio
 qemu_params = -machine gic-version=2
+kvmtool_params = --irqchip=gicv2
 groups = gic
 
 [gicv2-mmio-3p]
@@ -152,6 +167,7 @@ file = gic.flat
 smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
 test_args = mmio
 qemu_params = -machine gic-version=2
+kvmtool_params = --irqchip=gicv2
 groups = gic
 
 [gicv3-ipi]
@@ -159,6 +175,7 @@ file = gic.flat
 smp = $MAX_SMP
 test_args = ipi
 qemu_params = -machine gic-version=3
+kvmtool_params = --irqchip=gicv3
 groups = gic
 
 [gicv2-active]
@@ -166,6 +183,7 @@ file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 test_args = active
 qemu_params = -machine gic-version=2
+kvmtool_params = --irqchip=gicv2
 groups = gic
 
 [gicv3-active]
@@ -173,6 +191,7 @@ file = gic.flat
 smp = $MAX_SMP
 test_args = active
 qemu_params = -machine gic-version=3
+kvmtool_params = --irqchip=gicv3
 groups = gic
 
 [its-introspection]
@@ -180,6 +199,7 @@ file = gic.flat
 smp = $MAX_SMP
 test_args = its-introspection
 qemu_params = -machine gic-version=3
+kvmtool_params = --irqchip=gicv3-its
 groups = its
 arch = arm64
 
@@ -188,6 +208,7 @@ file = gic.flat
 smp = $MAX_SMP
 test_args = its-trigger
 qemu_params = -machine gic-version=3
+kvmtool_params = --irqchip=gicv3-its
 groups = its
 arch = arm64
 
@@ -196,6 +217,7 @@ file = gic.flat
 smp = $MAX_SMP
 test_args = its-migration
 qemu_params = -machine gic-version=3
+kvmtool_params = --irqchip=gicv3
 groups = its migration
 arch = arm64
 
@@ -204,6 +226,7 @@ file = gic.flat
 smp = $MAX_SMP
 test_args = its-pending-migration
 qemu_params = -machine gic-version=3
+kvmtool_params = --irqchip=gicv3
 groups = its migration
 arch = arm64
 
@@ -212,6 +235,7 @@ file = gic.flat
 smp = $MAX_SMP
 test_args = its-migrate-unmapped-collection
 qemu_params = -machine gic-version=3
+kvmtool_params = --irqchip=gicv3
 groups = its migration
 arch = arm64
 
diff --git a/docs/unittests.txt b/docs/unittests.txt
index ea0da959f008..a9164bccc24c 100644
--- a/docs/unittests.txt
+++ b/docs/unittests.txt
@@ -78,6 +78,14 @@ extra_params
 Alias for 'qemu_params', supported for compatibility purposes. Use
 'qemu_params' for new tests.
 
+kvmtool_params
+--------------
+Extra parameters supplied to the kvmtool process. Works similarly to
+'qemu_params', but uses kvmtool's syntax for command line arguments. The
+example for 'qemu_params', applied to kvmtool, would be:
+
+kvmtool_params = --mem 256
+
 groups
 ------
 groups = <group_name1> <group_name2> ...
diff --git a/scripts/common.bash b/scripts/common.bash
index 649f1c737617..0645235d8baa 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -1,6 +1,29 @@
 source config.mak
 source scripts/vmm.bash
 
+function parse_opts()
+{
+	local opts="$1"
+	local fd="$2"
+
+	while read -r -u $fd; do
+		#escape backslash newline, but not double backslash
+		if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
+			if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
+				opts=${opts%\\$'\n'}
+			fi
+		fi
+		if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
+			opts+=${BASH_REMATCH[1]}
+			break
+		else
+			opts+=$REPLY$'\n'
+		fi
+	done
+
+	echo "$opts"
+}
+
 function for_each_unittest()
 {
 	local unittests="$1"
@@ -46,24 +69,14 @@ function for_each_unittest()
 			smp="${vmm_opts[$TARGET:nr_cpus]} ${BASH_REMATCH[1]}"
 		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
 			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
-		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
-			opts=${BASH_REMATCH[2]}$'\n'
-			while read -r -u $fd; do
-				#escape backslash newline, but not double backslash
-				if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
-					if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
-						opts=${opts%\\$'\n'}
-					fi
-				fi
-				if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
-					opts+=${BASH_REMATCH[1]}
-					break
-				else
-					opts+=$REPLY$'\n'
-				fi
-			done
-		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
+		elif [[ $TARGET = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
+			opts=$(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)
+		elif [[ $TARGET  = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
 			opts=${BASH_REMATCH[2]}
+		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *'"""'(.*)$ ]]; then
+			opts=$(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)
+		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *(.*)$ ]]; then
+			opts=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
 			groups=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 09/16] scripts: Add support for kvmtool
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (7 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 08/16] scripts: Add 'kvmtool_params' to test definition Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:38   ` Andrew Jones
  2025-05-19  8:55   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 10/16] scripts: Add default arguments " Alexandru Elisei
                   ` (7 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Teach the arm runner to use kvmtool when kvm-unit-tests has been configured
appropriately.

The test is ran using run_test_status(), and a 0 return code (which means
success) is converted to 1, because kvmtool does not have a testdev device
to return the test exit code, so kvm-unit-tests must always parse the
"EXIT: STATUS" line for the exit code.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/run               | 161 ++++++++++++++++++++++++++----------------
 powerpc/run           |   4 +-
 riscv/run             |   4 +-
 s390x/run             |   2 +-
 scripts/arch-run.bash | 112 +++++++++++------------------
 scripts/vmm.bash      |  89 +++++++++++++++++++++++
 x86/run               |   4 +-
 7 files changed, 236 insertions(+), 140 deletions(-)

diff --git a/arm/run b/arm/run
index 56562ed1628f..e3c4ffc49136 100755
--- a/arm/run
+++ b/arm/run
@@ -12,80 +12,117 @@ fi
 
 check_vmm_supported
 
-qemu_cpu="$TARGET_CPU"
-
-if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
-   [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ] &&
-   [ "$(basename $QEMU)" = "qemu-system-arm" ]; then
-	ACCEL="tcg"
-fi
+function arch_run_qemu()
+{
+	qemu_cpu="$TARGET_CPU"
+
+	if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
+	   [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ] &&
+	   [ "$(basename $QEMU)" = "qemu-system-arm" ]; then
+		ACCEL="tcg"
+	fi
 
-set_qemu_accelerator || exit $?
-if [ "$ACCEL" = "kvm" ]; then
-	QEMU_ARCH=$HOST
-fi
+	set_qemu_accelerator || exit $?
+	if [ "$ACCEL" = "kvm" ]; then
+		QEMU_ARCH=$HOST
+	fi
 
-qemu=$(search_qemu_binary) ||
-	exit $?
+	qemu=$(search_qemu_binary) ||
+		exit $?
 
-if ! $qemu -machine '?' | grep -q 'ARM Virtual Machine'; then
-	echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting."
-	exit 2
-fi
+	if ! $qemu -machine '?' | grep -q 'ARM Virtual Machine'; then
+		echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting."
+		exit 2
+	fi
 
-M='-machine virt'
+	M='-machine virt'
 
-if [ "$ACCEL" = "kvm" ]; then
-	if $qemu $M,\? | grep -q gic-version; then
-		M+=',gic-version=host'
+	if [ "$ACCEL" = "kvm" ]; then
+		if $qemu $M,\? | grep -q gic-version; then
+			M+=',gic-version=host'
+		fi
 	fi
-fi
 
-if [ -z "$qemu_cpu" ]; then
-	if ( [ "$ACCEL" = "kvm" ] || [ "$ACCEL" = "hvf" ] ) &&
-	   ( [ "$HOST" = "aarch64" ] || [ "$HOST" = "arm" ] ); then
-		qemu_cpu="host"
-		if [ "$ARCH" = "arm" ] && [ "$HOST" = "aarch64" ]; then
-			qemu_cpu+=",aarch64=off"
+	if [ -z "$qemu_cpu" ]; then
+		if ( [ "$ACCEL" = "kvm" ] || [ "$ACCEL" = "hvf" ] ) &&
+		   ( [ "$HOST" = "aarch64" ] || [ "$HOST" = "arm" ] ); then
+			qemu_cpu="host"
+			if [ "$ARCH" = "arm" ] && [ "$HOST" = "aarch64" ]; then
+				qemu_cpu+=",aarch64=off"
+			fi
+		else
+			qemu_cpu="$DEFAULT_QEMU_CPU"
 		fi
-	else
-		qemu_cpu="$DEFAULT_QEMU_CPU"
 	fi
-fi
 
-if [ "$ARCH" = "arm" ]; then
-	M+=",highmem=off"
-fi
+	if [ "$ARCH" = "arm" ]; then
+		M+=",highmem=off"
+	fi
 
-if ! $qemu $M -device '?' | grep -q virtconsole; then
-	echo "$qemu doesn't support virtio-console for chr-testdev. Exiting."
-	exit 2
-fi
+	if ! $qemu $M -device '?' | grep -q virtconsole; then
+		echo "$qemu doesn't support virtio-console for chr-testdev. Exiting."
+		exit 2
+	fi
 
-if ! $qemu $M -chardev '?' | grep -q testdev; then
-	echo "$qemu doesn't support chr-testdev. Exiting."
-	exit 2
-fi
+	if ! $qemu $M -chardev '?' | grep -q testdev; then
+		echo "$qemu doesn't support chr-testdev. Exiting."
+		exit 2
+	fi
 
-if [ "$UEFI_SHELL_RUN" != "y" ] && [ "$EFI_USE_ACPI" != "y" ]; then
-	chr_testdev='-device virtio-serial-device'
-	chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
-fi
+	if [ "$UEFI_SHELL_RUN" != "y" ] && [ "$EFI_USE_ACPI" != "y" ]; then
+		chr_testdev='-device virtio-serial-device'
+		chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
+	fi
 
-pci_testdev=
-if $qemu $M -device '?' | grep -q pci-testdev; then
-	pci_testdev="-device pci-testdev"
-fi
+	pci_testdev=
+	if $qemu $M -device '?' | grep -q pci-testdev; then
+		pci_testdev="-device pci-testdev"
+	fi
 
-A="-accel $ACCEL$ACCEL_PROPS"
-command="$qemu -nodefaults $M $A -cpu $qemu_cpu $chr_testdev $pci_testdev"
-command+=" -display none -serial stdio"
-command="$(migration_cmd) $(timeout_cmd) $command"
-
-if [ "$UEFI_SHELL_RUN" = "y" ]; then
-	ENVIRON_DEFAULT=n run_qemu_status $command "$@"
-elif [ "$EFI_USE_ACPI" = "y" ]; then
-	run_qemu_status $command -kernel "$@"
-else
-	run_qemu $command -kernel "$@"
-fi
+	A="-accel $ACCEL$ACCEL_PROPS"
+	command="$qemu -nodefaults $M $A -cpu $qemu_cpu $chr_testdev $pci_testdev"
+	command+=" -display none -serial stdio"
+	command="$(migration_cmd) $(timeout_cmd) $command"
+
+	if [ "$UEFI_SHELL_RUN" = "y" ]; then
+		ENVIRON_DEFAULT=n run_test_status $command "$@"
+	elif [ "$EFI_USE_ACPI" = "y" ]; then
+		run_test_status $command -kernel "$@"
+	else
+		run_test $command -kernel "$@"
+	fi
+}
+
+function arch_run_kvmtool()
+{
+	local command
+
+	kvmtool=$(search_kvmtool_binary) ||
+		exit $?
+
+	if [ "$ACCEL" ] && [ "$ACCEL" != "kvm" ]; then
+		echo "kvmtool does not support $ACCEL" >&2
+		exit 2
+	fi
+
+	if ! kvm_available; then
+		echo "kvmtool requires KVM but not available on the host" >&2
+		exit 2
+	fi
+
+	command="$(timeout_cmd) $kvmtool run"
+	if [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ]; then
+		run_test_status $command --kernel "$@" --aarch32
+	else
+		run_test_status $command --kernel "$@"
+	fi
+}
+
+case $TARGET in
+qemu)
+	arch_run_qemu "$@"
+	;;
+kvmtool)
+	arch_run_kvmtool "$@"
+	;;
+esac
diff --git a/powerpc/run b/powerpc/run
index 27abf1ef6a4d..0b25a227429a 100755
--- a/powerpc/run
+++ b/powerpc/run
@@ -59,8 +59,8 @@ command+=" -display none -serial stdio -kernel"
 command="$(migration_cmd) $(timeout_cmd) $command"
 
 # powerpc tests currently exit with rtas-poweroff, which exits with 0.
-# run_qemu treats that as a failure exit and returns 1, so we need
+# run_test treats that as a failure exit and returns 1, so we need
 # to fixup the fixup below by parsing the true exit code from the output.
 # The second fixup is also a FIXME, because once we add chr-testdev
 # support for powerpc, we won't need the second fixup.
-run_qemu_status $command "$@"
+run_test_status $command "$@"
diff --git a/riscv/run b/riscv/run
index 3b2fc36f2afb..562347e8bea2 100755
--- a/riscv/run
+++ b/riscv/run
@@ -36,8 +36,8 @@ command+=" $mach $acc $firmware -cpu $qemu_cpu "
 command="$(migration_cmd) $(timeout_cmd) $command"
 
 if [ "$UEFI_SHELL_RUN" = "y" ]; then
-	ENVIRON_DEFAULT=n run_qemu_status $command "$@"
+	ENVIRON_DEFAULT=n run_test_status $command "$@"
 else
 	# We return the exit code via stdout, not via the QEMU return code
-	run_qemu_status $command -kernel "$@"
+	run_test_status $command -kernel "$@"
 fi
diff --git a/s390x/run b/s390x/run
index 34552c2747d4..9ecfaf983a3d 100755
--- a/s390x/run
+++ b/s390x/run
@@ -47,4 +47,4 @@ command+=" -kernel"
 command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command"
 
 # We return the exit code via stdout, not via the QEMU return code
-run_qemu_status $command "$@"
+run_test_status $command "$@"
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 8643bab3b252..8cf67e4f3b51 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -1,30 +1,7 @@
-##############################################################################
-# run_qemu translates the ambiguous exit status in Table1 to that in Table2.
-# Table3 simply documents the complete status table.
-#
-# Table1: Before fixup
-# --------------------
-# 0      - Unexpected exit from QEMU (possible signal), or the unittest did
-#          not use debug-exit
-# 1      - most likely unittest succeeded, or QEMU failed
-#
-# Table2: After fixup
-# -------------------
-# 0      - Everything succeeded
-# 1      - most likely QEMU failed
-#
-# Table3: Complete table
-# ----------------------
-# 0      - SUCCESS
-# 1      - most likely QEMU failed
-# 2      - most likely a run script failed
-# 3      - most likely the unittest failed
-# 124    - most likely the unittest timed out
-# 127    - most likely the unittest called abort()
-# 1..127 - FAILURE (could be QEMU, a run script, or the unittest)
-# >= 128 - Signal (signum = status - 128)
-##############################################################################
-run_qemu ()
+source config.mak
+source scripts/vmm.bash
+
+run_test ()
 {
 	local stdout errors ret sig
 
@@ -39,48 +16,17 @@ run_qemu ()
 	ret=$?
 	exec {stdout}>&-
 
-	[ $ret -eq 134 ] && echo "QEMU Aborted" >&2
-
-	if [ "$errors" ]; then
-		sig=$(grep 'terminating on signal' <<<"$errors")
-		if [ "$sig" ]; then
-			# This is too complex for ${var/search/replace}
-			# shellcheck disable=SC2001
-			sig=$(sed 's/.*terminating on signal \([0-9][0-9]*\).*/\1/' <<<"$sig")
-		fi
-	fi
-
-	if [ $ret -eq 0 ]; then
-		# Some signals result in a zero return status, but the
-		# error log tells the truth.
-		if [ "$sig" ]; then
-			((ret=sig+128))
-		else
-			# Exiting with zero (non-debugexit) is an error
-			ret=1
-		fi
-	elif [ $ret -eq 1 ]; then
-		# Even when ret==1 (unittest success) if we also got stderr
-		# logs, then we assume a QEMU failure. Otherwise we translate
-		# status of 1 to 0 (SUCCESS)
-	        if [ "$errors" ]; then
-			if ! grep -qvi warning <<<"$errors" ; then
-				ret=0
-			fi
-		else
-			ret=0
-		fi
-	fi
+	ret=$(${vmm_opts[$TARGET:fixup_return_code]} $ret $errors)
 
 	return $ret
 }
 
-run_qemu_status ()
+run_test_status ()
 {
 	local stdout ret
 
 	exec {stdout}>&1
-	lines=$(run_qemu "$@" > >(tee /dev/fd/$stdout))
+	lines=$(run_test "$@" > >(tee /dev/fd/$stdout))
 	ret=$?
 	exec {stdout}>&-
 
@@ -422,6 +368,25 @@ search_qemu_binary ()
 	export PATH=$save_path
 }
 
+search_kvmtool_binary ()
+{
+	local kvmtoolcmd kvmtool
+
+	for kvmtoolcmd in lkvm vm lkvm-static; do
+		if "$kvmtoolcmd" --help 2>/dev/null| grep -q 'The most commonly used'; then
+			kvmtool="$kvmtoolcmd"
+			break
+		fi
+	done
+
+	if [ -z "$kvmtool" ]; then
+		echo "A kvmtool binary was not found." >&2
+		return 2
+	fi
+
+	command -v $kvmtool
+}
+
 initrd_cleanup ()
 {
 	rm -f $KVM_UNIT_TESTS_ENV
@@ -447,7 +412,7 @@ initrd_create ()
 	fi
 
 	unset INITRD
-	[ -f "$KVM_UNIT_TESTS_ENV" ] && INITRD="-initrd $KVM_UNIT_TESTS_ENV"
+	[ -f "$KVM_UNIT_TESTS_ENV" ] && INITRD="${vmm_opts[$TARGET:initrd]} $KVM_UNIT_TESTS_ENV"
 
 	return 0
 }
@@ -471,18 +436,23 @@ env_params ()
 	local qemu have_qemu
 	local _ rest
 
-	qemu=$(search_qemu_binary) && have_qemu=1
+	env_add_params TARGET
 
-	if [ "$have_qemu" ]; then
-		if [ -n "$ACCEL" ] || [ -n "$QEMU_ACCEL" ]; then
-			[ -n "$ACCEL" ] && QEMU_ACCEL=$ACCEL
+	# kvmtool's versioning has been broken since it was split from the
+	# kernel source.
+	if [ $TARGET = "qemu" ]; then
+		qemu=$(search_qemu_binary) && have_qemu=1
+		if [ "$have_qemu" ]; then
+			if [ -n "$ACCEL" ] || [ -n "$QEMU_ACCEL" ]; then
+				[ -n "$ACCEL" ] && QEMU_ACCEL=$ACCEL
+			fi
+			QEMU_VERSION_STRING="$($qemu -h | head -1)"
+			# Shellcheck does not see QEMU_MAJOR|MINOR|MICRO are used
+			# shellcheck disable=SC2034
+			IFS='[ .]' read -r _ _ _ QEMU_MAJOR QEMU_MINOR QEMU_MICRO rest <<<"$QEMU_VERSION_STRING"
 		fi
-		QEMU_VERSION_STRING="$($qemu -h | head -1)"
-		# Shellcheck does not see QEMU_MAJOR|MINOR|MICRO are used
-		# shellcheck disable=SC2034
-		IFS='[ .]' read -r _ _ _ QEMU_MAJOR QEMU_MINOR QEMU_MICRO rest <<<"$QEMU_VERSION_STRING"
+		env_add_params QEMU_ACCEL QEMU_VERSION_STRING QEMU_MAJOR QEMU_MINOR QEMU_MICRO
 	fi
-	env_add_params QEMU_ACCEL QEMU_VERSION_STRING QEMU_MAJOR QEMU_MINOR QEMU_MICRO
 
 	KERNEL_VERSION_STRING=$(uname -r)
 	IFS=. read -r KERNEL_VERSION KERNEL_PATCHLEVEL rest <<<"$KERNEL_VERSION_STRING"
diff --git a/scripts/vmm.bash b/scripts/vmm.bash
index b02055a5c0b6..20968f2e6b10 100644
--- a/scripts/vmm.bash
+++ b/scripts/vmm.bash
@@ -1,10 +1,99 @@
 source config.mak
 
+##############################################################################
+# qemu_fixup_return_code translates the ambiguous exit status in Table1 to that
+# in Table2.  Table3 simply documents the complete status table.
+#
+# Table1: Before fixup
+# --------------------
+# 0      - Unexpected exit from QEMU (possible signal), or the unittest did
+#          not use debug-exit
+# 1      - most likely unittest succeeded, or QEMU failed
+#
+# Table2: After fixup
+# -------------------
+# 0      - Everything succeeded
+# 1      - most likely QEMU failed
+#
+# Table3: Complete table
+# ----------------------
+# 0      - SUCCESS
+# 1      - most likely QEMU failed
+# 2      - most likely a run script failed
+# 3      - most likely the unittest failed
+# 124    - most likely the unittest timed out
+# 127    - most likely the unittest called abort()
+# 1..127 - FAILURE (could be QEMU, a run script, or the unittest)
+# >= 128 - Signal (signum = status - 128)
+##############################################################################
+qemu_fixup_return_code()
+{
+	local ret=$1
+	# Remove $ret from the list of arguments
+	shift 1
+	local errors="$@"
+	local sig
+
+	[ $ret -eq 134 ] && echo "QEMU Aborted" >&2
+
+	if [ "$errors" ]; then
+		sig=$(grep 'terminating on signal' <<<"$errors")
+		if [ "$sig" ]; then
+			# This is too complex for ${var/search/replace}
+			# shellcheck disable=SC2001
+			sig=$(sed 's/.*terminating on signal \([0-9][0-9]*\).*/\1/' <<<"$sig")
+		fi
+	fi
+
+	if [ $ret -eq 0 ]; then
+		# Some signals result in a zero return status, but the
+		# error log tells the truth.
+		if [ "$sig" ]; then
+			((ret=sig+128))
+		else
+			# Exiting with zero (non-debugexit) is an error
+			ret=1
+		fi
+	elif [ $ret -eq 1 ]; then
+		# Even when ret==1 (unittest success) if we also got stderr
+		# logs, then we assume a QEMU failure. Otherwise we translate
+		# status of 1 to 0 (SUCCESS)
+	        if [ "$errors" ]; then
+			if ! grep -qvi warning <<<"$errors" ; then
+				ret=0
+			fi
+		else
+			ret=0
+		fi
+	fi
+
+	echo $ret
+}
+
+kvmtool_fixup_return_code()
+{
+	local ret=$1
+
+	# Force run_test_status() to interpret the STATUS line.
+	if [ $ret -eq 0 ]; then
+		ret=1
+	fi
+
+	echo $ret
+}
+
 declare -A vmm_opts=(
 	[qemu:nr_cpus]='-smp'
 	[qemu:kernel]='-kernel'
 	[qemu:args]='-append'
 	[qemu:initrd]='-initrd'
+	[qemu:fixup_return_code]=qemu_fixup_return_code
+
+	[kvmtool:nr_cpus]='--cpus'
+	[kvmtool:kernel]='--kernel'
+	[kvmtool:args]='--params'
+	[kvmtool:initrd]='--initrd'
+	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
 )
 
 function check_vmm_supported()
diff --git a/x86/run b/x86/run
index a3d3e7db8891..91bcd0b9ae41 100755
--- a/x86/run
+++ b/x86/run
@@ -49,7 +49,7 @@ if [ "${CONFIG_EFI}" = y ]; then
 	# UEFI, the test case binaries are passed to QEMU through the disk
 	# image, not through the '-kernel' flag. And QEMU reports an error if it
 	# gets '-initrd' without a '-kernel'
-	ENVIRON_DEFAULT=n run_qemu ${command} "$@"
+	ENVIRON_DEFAULT=n run_test ${command} "$@"
 else
-	run_qemu ${command} "$@"
+	run_test ${command} "$@"
 fi
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 10/16] scripts: Add default arguments for kvmtool
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (8 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 09/16] scripts: Add support for kvmtool Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:43   ` Andrew Jones
  2025-05-21  3:21   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 11/16] scripts: Add KVMTOOL environment variable for kvmtool binary path Alexandru Elisei
                   ` (6 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

kvmtool, unless told otherwise, will do its best to make sure that a kernel
successfully boots in a virtual machine. It does things like automatically
creating a rootfs and adding extra parameters to the kernel command line.
This is actively harmful to kvm-unit-tests, because some tests parse the
kernel command line and they will fail if they encounter the options added
by kvmtool.

Fortunately for us, kvmtool commit 5613ae26b998 ("Add --nodefaults command
line argument") addded the --nodefaults kvmtool parameter which disables
all the implicit virtual machine configuration that cannot be disabled by
using other parameters, like modifying the kernel command line. So always
use --nodefaults to allow a test to run.

kvmtool can also be too verbose when running a virtual machine, and this is
controlled by several parameters. Add those to the default kvmtool command
line to reduce this verbosity to a minimum.

Before:

$ vm run arm/selftest.flat --cpus 2 --mem 256 --params "setup smp=2 mem=256"
Info: # lkvm run -k arm/selftest.flat -m 256 -c 2 --name guest-5035
Unknown subtest

EXIT: STATUS=127
Warning: KVM compatibility warning.
    virtio-9p device was not detected.
    While you have requested a virtio-9p device, the guest kernel did not initialize it.
    Please make sure that the guest kernel was compiled with CONFIG_NET_9P_VIRTIO=y enabled in .config.
Warning: KVM compatibility warning.
    virtio-net device was not detected.
    While you have requested a virtio-net device, the guest kernel did not initialize it.
    Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_NET=y enabled in .config.
Info: KVM session ended normally.

After:

$ vm run arm/selftest.flat --nodefaults --network mode=none --loglevel=warning --cpus 2 --mem 256 --params "setup smp=2 mem=256"
PASS: selftest: setup: smp: number of CPUs matches expectation
INFO: selftest: setup: smp: found 2 CPUs
PASS: selftest: setup: mem: memory size matches expectation
INFO: selftest: setup: mem: found 256 MB
SUMMARY: 2 tests

EXIT: STATUS=1

Note that KVMTOOL_DEFAULT_OPTS can be overwritten by an environment
variable with the same name, but it's not documented in the help string for
run_tests.sh. This has been done on purpose, since overwritting
KVMTOOL_DEFAULT_OPTS should only be necessary for debugging or development
purposes.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 scripts/common.bash | 10 +++++-----
 scripts/vmm.bash    | 13 +++++++++++++
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/scripts/common.bash b/scripts/common.bash
index 0645235d8baa..ee0ae71948c2 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -56,7 +56,7 @@ function for_each_unittest()
 			# because qemu interprets the first argument after
 			# -append as a kernel parameter.
 			test_args=""
-			opts=""
+			opts="${vmm_opts[$TARGET:default_opts]}"
 			groups=""
 			arch=""
 			machine=""
@@ -70,13 +70,13 @@ function for_each_unittest()
 		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
 			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
 		elif [[ $TARGET = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
-			opts=$(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)
+			opts="${vmm_opts[$TARGET:default_opts]} $(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)"
 		elif [[ $TARGET  = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
-			opts=${BASH_REMATCH[2]}
+			opts="${vmm_opts[$TARGET:default_opts]} ${BASH_REMATCH[2]}"
 		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *'"""'(.*)$ ]]; then
-			opts=$(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)
+			opts="${vmm_opts[$TARGET:default_opts]} $(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)"
 		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *(.*)$ ]]; then
-			opts=${BASH_REMATCH[1]}
+			opts="${vmm_opts[$TARGET:default_opts]} ${BASH_REMATCH[1]}"
 		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
 			groups=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
diff --git a/scripts/vmm.bash b/scripts/vmm.bash
index 20968f2e6b10..d24a4c4b8713 100644
--- a/scripts/vmm.bash
+++ b/scripts/vmm.bash
@@ -1,5 +1,16 @@
 source config.mak
 
+# The following parameters are enabled by default when running a test with
+# kvmtool:
+# --nodefaults: suppress VM configuration that cannot be disabled otherwise
+#               (like modifying the supplied kernel command line). Tests that
+#               use the command line will fail without this parameter.
+# --network mode=none: do not create a network device. kvmtool tries to help the
+#               user by automatically create one, and then prints a warning
+#               when the VM terminates if the device hasn't been initialized.
+# --loglevel=warning: reduce verbosity
+: "${KVMTOOL_DEFAULT_OPTS:="--nodefaults --network mode=none --loglevel=warning"}"
+
 ##############################################################################
 # qemu_fixup_return_code translates the ambiguous exit status in Table1 to that
 # in Table2.  Table3 simply documents the complete status table.
@@ -87,12 +98,14 @@ declare -A vmm_opts=(
 	[qemu:kernel]='-kernel'
 	[qemu:args]='-append'
 	[qemu:initrd]='-initrd'
+	[qemu:default_opts]=''
 	[qemu:fixup_return_code]=qemu_fixup_return_code
 
 	[kvmtool:nr_cpus]='--cpus'
 	[kvmtool:kernel]='--kernel'
 	[kvmtool:args]='--params'
 	[kvmtool:initrd]='--initrd'
+	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
 	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
 )
 
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 11/16] scripts: Add KVMTOOL environment variable for kvmtool binary path
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (9 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 10/16] scripts: Add default arguments " Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:45   ` Andrew Jones
  2025-05-19  8:13   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 12/16] scripts: Detect kvmtool failure in premature_failure() Alexandru Elisei
                   ` (5 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

kvmtool is often used for prototyping new features, and a developer might
not want to install it system-wide. Add a KVMTOOL environment variable to
make it easier for tests to use a binary not in $PATH.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 run_tests.sh          | 1 +
 scripts/arch-run.bash | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/run_tests.sh b/run_tests.sh
index dd9d27377905..150a06a91064 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -36,6 +36,7 @@ The following environment variables are used:
     TIMEOUT         Timeout duration for the timeout(1) command
     CHECK           Overwrites the 'check' unit test parameter (see
                     docs/unittests.txt)
+    KVMTOOL         Path to kvmtool binary for ARCH-run
 EOF
 }
 
diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
index 8cf67e4f3b51..d4fc7116abbe 100644
--- a/scripts/arch-run.bash
+++ b/scripts/arch-run.bash
@@ -372,7 +372,7 @@ search_kvmtool_binary ()
 {
 	local kvmtoolcmd kvmtool
 
-	for kvmtoolcmd in lkvm vm lkvm-static; do
+	for kvmtoolcmd in ${KVMTOOL:-lkvm vm lkvm-static}; do
 		if "$kvmtoolcmd" --help 2>/dev/null| grep -q 'The most commonly used'; then
 			kvmtool="$kvmtoolcmd"
 			break
@@ -381,6 +381,7 @@ search_kvmtool_binary ()
 
 	if [ -z "$kvmtool" ]; then
 		echo "A kvmtool binary was not found." >&2
+		echo "You can set a custom location by using the KVMTOOL=<path> environment variable." >&2
 		return 2
 	fi
 
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 12/16] scripts: Detect kvmtool failure in premature_failure()
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (10 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 11/16] scripts: Add KVMTOOL environment variable for kvmtool binary path Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:47   ` Andrew Jones
  2025-05-21  5:58   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 13/16] scripts: Do not probe for maximum number of VCPUs when using kvmtool Alexandru Elisei
                   ` (4 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

kvm-unit-tests assumes that if the VMM is able to get to where it tries to
load the kernel, then the VMM and the configuration parameters will also
work for running the test. All of this is done in premature_failure().

Teach premature_failure() about the kvmtool's error message when it fails
to load the dummy kernel.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 scripts/runtime.bash |  8 +++-----
 scripts/vmm.bash     | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index 86d8a2cd8528..01ec8eae2bba 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -1,3 +1,5 @@
+source scripts/vmm.bash
+
 : "${RUNTIME_arch_run?}"
 : "${MAX_SMP:=$(getconf _NPROCESSORS_ONLN)}"
 : "${TIMEOUT:=90s}"
@@ -19,11 +21,7 @@ premature_failure()
 
     log="$(eval "$(get_cmdline _NO_FILE_4Uhere_)" 2>&1)"
 
-    echo "$log" | grep "_NO_FILE_4Uhere_" |
-        grep -q -e "[Cc]ould not \(load\|open\) kernel" \
-                -e "error loading" \
-                -e "failed to load" &&
-        return 1
+    ${vmm_opts[$TARGET:parse_premature_failure]} "$log" || return 1
 
     RUNTIME_log_stderr <<< "$log"
 
diff --git a/scripts/vmm.bash b/scripts/vmm.bash
index d24a4c4b8713..a1d50ed51981 100644
--- a/scripts/vmm.bash
+++ b/scripts/vmm.bash
@@ -93,6 +93,27 @@ kvmtool_fixup_return_code()
 	echo $ret
 }
 
+function qemu_parse_premature_failure()
+{
+	local log="$@"
+
+	echo "$log" | grep "_NO_FILE_4Uhere_" |
+		grep -q -e "[Cc]ould not \(load\|open\) kernel" \
+			-e "error loading" \
+			-e "failed to load" &&
+		return 1
+	return 0
+}
+
+function kvmtool_parse_premature_failure()
+{
+	local log="$@"
+
+	echo "$log" | grep "Fatal: Unable to open kernel _NO_FILE_4Uhere_" &&
+		return 1
+	return 0
+}
+
 declare -A vmm_opts=(
 	[qemu:nr_cpus]='-smp'
 	[qemu:kernel]='-kernel'
@@ -100,6 +121,7 @@ declare -A vmm_opts=(
 	[qemu:initrd]='-initrd'
 	[qemu:default_opts]=''
 	[qemu:fixup_return_code]=qemu_fixup_return_code
+	[qemu:parse_premature_failure]=qemu_parse_premature_failure
 
 	[kvmtool:nr_cpus]='--cpus'
 	[kvmtool:kernel]='--kernel'
@@ -107,6 +129,7 @@ declare -A vmm_opts=(
 	[kvmtool:initrd]='--initrd'
 	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
 	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
+	[kvmtool:parse_premature_failure]=kvmtool_parse_premature_failure
 )
 
 function check_vmm_supported()
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 13/16] scripts: Do not probe for maximum number of VCPUs when using kvmtool
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (11 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 12/16] scripts: Detect kvmtool failure in premature_failure() Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:48   ` Andrew Jones
  2025-05-21  6:02   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 14/16] scripts/mkstandalone: Export $TARGET Alexandru Elisei
                   ` (3 subsequent siblings)
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

The --probe-maxsmp parameter updates MAX_SMP with the maximum number of
VCPUs that the host supports. Qemu will exit with an error when creating a
virtual machine if the number of VCPUs is exceeded.

kvmtool behaves differently: it will automatically limit the number of
VCPUs to the what KVM supports, which is exactly what --probe-maxsmp wants
to achieve. When doing --probe-maxsmp with kvmtool, print a message
explaining why it's redundant and don't do anything else.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 run_tests.sh         |  3 ++-
 scripts/runtime.bash | 16 ----------------
 scripts/vmm.bash     | 24 ++++++++++++++++++++++++
 3 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/run_tests.sh b/run_tests.sh
index 150a06a91064..a69c3665b7a4 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -10,6 +10,7 @@ if [ ! -f config.mak ]; then
 fi
 source config.mak
 source scripts/common.bash
+source scripts/vmm.bash
 
 function usage()
 {
@@ -90,7 +91,7 @@ while [ $# -gt 0 ]; do
             list_tests="yes"
             ;;
         --probe-maxsmp)
-            probe_maxsmp
+            ${vmm_opts[$TARGET:probe_maxsmp]}
             ;;
         --)
             ;;
diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index 01ec8eae2bba..a802686c511d 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -209,19 +209,3 @@ function run()
 
     return $ret
 }
-
-#
-# Probe for MAX_SMP, in case it's less than the number of host cpus.
-#
-function probe_maxsmp()
-{
-	local smp
-
-	if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'SMP CPUs'); then
-		smp=${smp##* }
-		smp=${smp/\(}
-		smp=${smp/\)}
-		echo "Restricting MAX_SMP from ($MAX_SMP) to the max supported ($smp)" >&2
-		MAX_SMP=$smp
-	fi
-}
diff --git a/scripts/vmm.bash b/scripts/vmm.bash
index a1d50ed51981..ef9819f4132c 100644
--- a/scripts/vmm.bash
+++ b/scripts/vmm.bash
@@ -105,6 +105,22 @@ function qemu_parse_premature_failure()
 	return 0
 }
 
+#
+# Probe for MAX_SMP, in case it's less than the number of host cpus.
+#
+function qemu_probe_maxsmp()
+{
+	local smp
+
+	if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'SMP CPUs'); then
+		smp=${smp##* }
+		smp=${smp/\(}
+		smp=${smp/\)}
+		echo "Restricting MAX_SMP from ($MAX_SMP) to the max supported ($smp)" >&2
+		MAX_SMP=$smp
+	fi
+}
+
 function kvmtool_parse_premature_failure()
 {
 	local log="$@"
@@ -114,6 +130,12 @@ function kvmtool_parse_premature_failure()
 	return 0
 }
 
+function kvmtool_probe_maxsmp()
+{
+	echo "kvmtool automatically limits the number of VCPUs to maximum supported"
+	echo "The 'smp' test parameter won't be modified"
+}
+
 declare -A vmm_opts=(
 	[qemu:nr_cpus]='-smp'
 	[qemu:kernel]='-kernel'
@@ -122,6 +144,7 @@ declare -A vmm_opts=(
 	[qemu:default_opts]=''
 	[qemu:fixup_return_code]=qemu_fixup_return_code
 	[qemu:parse_premature_failure]=qemu_parse_premature_failure
+	[qemu:probe_maxsmp]=qemu_probe_maxsmp
 
 	[kvmtool:nr_cpus]='--cpus'
 	[kvmtool:kernel]='--kernel'
@@ -130,6 +153,7 @@ declare -A vmm_opts=(
 	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
 	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
 	[kvmtool:parse_premature_failure]=kvmtool_parse_premature_failure
+	[kvmtool:probe_maxsmp]=kvmtool_probe_maxsmp
 )
 
 function check_vmm_supported()
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 14/16] scripts/mkstandalone: Export $TARGET
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (12 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 13/16] scripts: Do not probe for maximum number of VCPUs when using kvmtool Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-21  6:16   ` Shaoqin Huang
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 15/16] scripts: Add 'disabled_if' test definition parameter for kvmtool to use Alexandru Elisei
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

$TARGET is needed for the test runner to decide if it should use qemu or
kvmtool, so export it.

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 scripts/mkstandalone.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
index 4f666cefe076..3b2caf198b00 100755
--- a/scripts/mkstandalone.sh
+++ b/scripts/mkstandalone.sh
@@ -47,6 +47,7 @@ generate_test ()
 	config_export ARCH_NAME
 	config_export TARGET_CPU
 	config_export DEFAULT_QEMU_CPU
+	config_export TARGET
 
 	echo "echo BUILD_HEAD=$(cat build-head)"
 
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 15/16] scripts: Add 'disabled_if' test definition parameter for kvmtool to use
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (13 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 14/16] scripts/mkstandalone: Export $TARGET Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:56   ` Andrew Jones
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 16/16] scripts: Enable kvmtool Alexandru Elisei
  2025-05-19  8:56 ` [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Shaoqin Huang
  16 siblings, 1 reply; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

The pci-test is qemu specific. Other tests perform migration, which
isn't supported by kvmtool. In general, kvmtool is not as feature-rich
as qemu, so add a new unittest parameter, 'disabled_if', that causes a
test to be skipped if the condition evaluates to true.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---

This is what Drew said about the patch in the previous iteration [1]:

'I like disabled_if because I like the lambda-like thing it's doing, but I
wonder if it wouldn't be better to make TARGET a first class citizen by
adding a 'targets' unittest parameter which allows listing all targets the
test can run on [..]

If targets isn't present then the default is only qemu.'

Like I've said on the cover letter, I think making qemu the default (if
'targets' isn't specified in the test definition) will mean that new tests
will not run with kvmtool. I was thinking something along the lines
'excluded_targets', with the default (when left unspecified) being that the
tests run with all the vmms that the architecture support (or, to put it
another way, no vmms are excluded).

Or we could go with 'targets' and say that when left empty it means 'all
the vmms that the architecture supports' - though in my opinion this
semantic is somewhat better conveyed with the name 'excluded_targets'.

[1] https://lore.kernel.org/all/20250123-3eda2c10fdce584bdfb14971@orel/

 arm/unittests.cfg    |  7 +++++++
 docs/unittests.txt   | 13 +++++++++++++
 scripts/common.bash  |  6 +++++-
 scripts/runtime.bash |  6 ++++++
 4 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index f3c773e56933..8f9434aad865 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -43,6 +43,7 @@ groups = selftest
 [pci-test]
 file = pci-test.flat
 groups = pci
+disabled_if = [[ "$TARGET" != qemu ]]
 
 # Test PMU support
 [pmu-cycle-counter]
@@ -219,6 +220,7 @@ test_args = its-migration
 qemu_params = -machine gic-version=3
 kvmtool_params = --irqchip=gicv3
 groups = its migration
+disabled_if = [[ "$TARGET" != qemu ]]
 arch = arm64
 
 [its-pending-migration]
@@ -228,6 +230,7 @@ test_args = its-pending-migration
 qemu_params = -machine gic-version=3
 kvmtool_params = --irqchip=gicv3
 groups = its migration
+disabled_if = [[ "$TARGET" != qemu ]]
 arch = arm64
 
 [its-migrate-unmapped-collection]
@@ -237,6 +240,7 @@ test_args = its-migrate-unmapped-collection
 qemu_params = -machine gic-version=3
 kvmtool_params = --irqchip=gicv3
 groups = its migration
+disabled_if = [[ "$TARGET" != qemu ]]
 arch = arm64
 
 # Test PSCI emulation
@@ -278,6 +282,7 @@ file = debug.flat
 arch = arm64
 test_args = bp-migration
 groups = debug migration
+disabled_if = [[ "$TARGET" != qemu ]]
 
 [debug-wp]
 file = debug.flat
@@ -290,6 +295,7 @@ file = debug.flat
 arch = arm64
 test_args = wp-migration
 groups = debug migration
+disabled_if = [[ "$TARGET" != qemu ]]
 
 [debug-sstep]
 file = debug.flat
@@ -302,6 +308,7 @@ file = debug.flat
 arch = arm64
 test_args = ss-migration
 groups = debug migration
+disabled_if = [[ "$TARGET" != qemu ]]
 
 # FPU/SIMD test
 [fpu-context]
diff --git a/docs/unittests.txt b/docs/unittests.txt
index a9164bccc24c..921318a6d85a 100644
--- a/docs/unittests.txt
+++ b/docs/unittests.txt
@@ -124,3 +124,16 @@ parameter needs to be of the form <path>=<value>
 The path and value cannot contain space, =, or shell wildcard characters.
 
 Can be overwritten with the CHECK environment variable with the same syntax.
+
+disabled_if
+-----------
+disabled_if = <condition>
+
+Do not run the test if <condition> is met. <condition> will be fed unmodified
+to a bash 'if' statement and follows the same syntax.
+
+This can be used to prevent running a test when kvm-unit-tests is configured a
+certain way. For example, it can be used to skip a qemu specific test when
+using another VMM and using UEFI:
+
+disabled_if = [[ "$TARGET" != qemu ]] && [[ "$CONFIG_EFI" = y ]]
diff --git a/scripts/common.bash b/scripts/common.bash
index ee0ae71948c2..8557d60461ba 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -39,6 +39,7 @@ function for_each_unittest()
 	local check
 	local accel
 	local timeout
+	local disabled_cond
 	local rematch
 
 	exec {fd}<"$unittests"
@@ -47,7 +48,7 @@ function for_each_unittest()
 		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
 			rematch=${BASH_REMATCH[1]}
 			if [ -n "${testname}" ]; then
-				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
+				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout" "$disabled_cond"
 			fi
 			testname=$rematch
 			smp="${vmm_opts[$TARGET:nr_cpus]} 1"
@@ -63,6 +64,7 @@ function for_each_unittest()
 			check=""
 			accel=""
 			timeout=""
+			disabled_cond=""
 		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
 			kernel=$TEST_DIR/${BASH_REMATCH[1]}
 		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
@@ -85,6 +87,8 @@ function for_each_unittest()
 			machine=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
 			check=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^disabled_if\ *=\ *(.*)$ ]]; then
+			disabled_cond=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then
 			accel=${BASH_REMATCH[1]}
 		elif [[ $line =~ ^timeout\ *=\ *(.*)$ ]]; then
diff --git a/scripts/runtime.bash b/scripts/runtime.bash
index a802686c511d..8755927dbc49 100644
--- a/scripts/runtime.bash
+++ b/scripts/runtime.bash
@@ -85,6 +85,7 @@ function run()
     local check="${CHECK:-$9}"
     local accel="${10}"
     local timeout="${11:-$TIMEOUT}" # unittests.cfg overrides the default
+    local disabled_cond="${12}"
 
     if [ "${CONFIG_EFI}" == "y" ]; then
         kernel=${kernel/%.flat/.efi}
@@ -132,6 +133,11 @@ function run()
         accel="$ACCEL"
     fi
 
+    if [[ "$disabled_cond" ]] && (eval $disabled_cond); then
+        print_result "SKIP" $testname "" "disabled because: $disabled_cond"
+	return 2
+    fi
+
     # check a file for a particular value before running a test
     # the check line can contain multiple files to check separated by a space
     # but each check parameter needs to be of the form <path>=<value>
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* [kvm-unit-tests PATCH v3 16/16] scripts: Enable kvmtool
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (14 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 15/16] scripts: Add 'disabled_if' test definition parameter for kvmtool to use Alexandru Elisei
@ 2025-05-07 15:12 ` Alexandru Elisei
  2025-05-07 16:59   ` Andrew Jones
  2025-05-21  6:20   ` Shaoqin Huang
  2025-05-19  8:56 ` [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Shaoqin Huang
  16 siblings, 2 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 15:12 UTC (permalink / raw)
  To: andrew.jones, eric.auger, lvivier, thuth, frankja, imbrenda, nrb,
	david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Everything is in place to run the tests using kvmtool:

$ ./configure --target=kvmtool
$ make clean && make
$ KVMTOOL=<path/to/kvmtool> ./run_tests.sh

so enable it, and remove ERRATA_FORCE=y when configuring for kvmtool,
because the runner will generate and pass the correct environment to
kvmtool.

Missing is support for EFI tests. That's because distros don't ship a
EDK2 binary compiled for kvmtool, and on top of that kvm-unit-tests as
an EFI app hasn't been tested to work with kvmtool.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 README.md        | 18 +++++++++++++++++-
 arm/efi/run      |  5 +++++
 configure        |  1 -
 scripts/vmm.bash |  2 +-
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index be07dc28a094..723ce04cd978 100644
--- a/README.md
+++ b/README.md
@@ -65,6 +65,9 @@ or:
 
 to run them all.
 
+All tests can be run using QEMU. On arm and arm64, tests can also be run using
+kvmtool.
+
 By default the runner script searches for a suitable QEMU binary in the system.
 To select a specific QEMU binary though, specify the QEMU=path/to/binary
 environment variable:
@@ -78,12 +81,25 @@ ACCEL=name environment variable:
 
 For running tests that involve migration from one QEMU instance to another
 you also need to have the "ncat" binary (from the nmap.org project) installed,
-otherwise the related tests will be skipped.
+otherwise the related tests will be skipped. kvmtool does not support migration.
+
+As for running a test with kvmtool, please configure kvm-unit-tests accordingly
+first:
+
+   ./configure --arch=arm64 --target=kvmtool
+
+then run the test(s) like with QEMU above.
+
+To select a kvmtool binary, specify the KVMTOOL=path/to/binary environment
+variable. kvmtool supports only kvm as the accelerator.
 
 ## Running the tests with UEFI
 
 Check [x86/efi/README.md](./x86/efi/README.md).
 
+On arm and arm64, this is only supported with QEMU; kvmtool cannot run the
+tests under UEFI.
+
 # Tests configuration file
 
 The test case may need specific runtime configurations, for
diff --git a/arm/efi/run b/arm/efi/run
index 53d71297cc52..0843725ec360 100755
--- a/arm/efi/run
+++ b/arm/efi/run
@@ -15,6 +15,11 @@ source scripts/vmm.bash
 
 check_vmm_supported
 
+if [[ $TARGET = "kvmtool" ]]; then
+	echo "kvmtool does not support EFI tests."
+	exit 2
+fi
+
 if [ -f /usr/share/qemu-efi-aarch64/QEMU_EFI.fd ]; then
 	DEFAULT_UEFI=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
 elif [ -f /usr/share/edk2/aarch64/QEMU_EFI.silent.fd ]; then
diff --git a/configure b/configure
index 8c4400db42bc..d5f9995172f8 100755
--- a/configure
+++ b/configure
@@ -392,7 +392,6 @@ elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
         : "${uart_early_addr:=0x9000000}"
     elif [ "$target" = "kvmtool" ]; then
         : "${uart_early_addr:=0x1000000}"
-        errata_force=1
     else
         echo "--target must be one of 'qemu' or 'kvmtool'!"
         usage
diff --git a/scripts/vmm.bash b/scripts/vmm.bash
index ef9819f4132c..4ae60c37a6e8 100644
--- a/scripts/vmm.bash
+++ b/scripts/vmm.bash
@@ -159,7 +159,7 @@ declare -A vmm_opts=(
 function check_vmm_supported()
 {
 	case "$TARGET" in
-	qemu)
+	qemu | kvmtool)
 		return 0
 		;;
 	*)
-- 
2.49.0


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params'
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params' Alexandru Elisei
@ 2025-05-07 15:40   ` Andrew Jones
  2025-05-14  2:57   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 15:40 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:41PM +0100, Alexandru Elisei wrote:
> The arm and arm64 architectures can also be run with kvmtool, and work is
> under way to have it supported by the run_tests.sh test runner. Not
> suprisingly, kvmtool's syntax for running a virtual machine is different to
> qemu's.
> 
> Add a new unittest parameter, 'qemu_params', with the goal to add a similar
> parameter for kvmtool, when that's supported.
> 
> 'extra_params' has been kept in the scripts as an alias for 'qemu_params'
> to preserve compatibility with custom test definition, but it is expected
> that going forward new tests will use 'qemu_params'.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  arm/unittests.cfg     |  76 +++++++++++------------
>  docs/unittests.txt    |  15 +++--
>  powerpc/unittests.cfg |  18 +++---
>  riscv/unittests.cfg   |   2 +-
>  s390x/unittests.cfg   |  50 +++++++--------
>  scripts/common.bash   |   8 +--
>  scripts/runtime.bash  |   6 +-
>  x86/unittests.cfg     | 140 +++++++++++++++++++++---------------------
>  8 files changed, 160 insertions(+), 155 deletions(-)
>

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 02/16] scripts: Add 'test_args' test definition parameter
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 02/16] scripts: Add 'test_args' test definition parameter Alexandru Elisei
@ 2025-05-07 15:58   ` Andrew Jones
  2025-05-14  3:16   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 15:58 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:42PM +0100, Alexandru Elisei wrote:
...
>  # FPU/SIMD test
> @@ -276,17 +291,20 @@ arch = arm64
>  [mte-sync]
>  file = mte.flat
>  groups = mte
> -qemu_params = -machine mte=on -append 'sync'
> +test_args=sync

add spaces around =

> +qemu_params = -machine mte=on
>  arch = arm64
>  
>  [mte-async]
>  file = mte.flat
>  groups = mte
> -qemu_params = -machine mte=on -append 'async'
> +test_args=async

spaces

> +qemu_params = -machine mte=on
>  arch = arm64
>  
>  [mte-asymm]
>  file = mte.flat
>  groups = mte
> -qemu_params = -machine mte=on -append 'asymm'
> +test_args=asymm

spaces

...
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 400e8a082528..06cc58e79b69 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -80,12 +80,18 @@ function run()
>      local groups="$2"
>      local smp="$3"
>      local kernel="$4"
> -    local opts="$5"
> -    local arch="$6"
> -    local machine="$7"
> -    local check="${CHECK:-$8}"
> -    local accel="$9"
> -    local timeout="${10:-$TIMEOUT}" # unittests.cfg overrides the default
> +    local test_args="$5"
> +    local opts="$6"
> +    local arch="$7"
> +    local machine="$8"
> +    local check="${CHECK:-$9}"
> +    local accel="${10}"
> +    local timeout="${11:-$TIMEOUT}" # unittests.cfg overrides the default
> +
> +    # If $test_args is empty, qemu will interpret the first option after -append
> +    # as a kernel parameter instead of a qemu option, so make sure the -append
> +    # option is used only if $test_args is not empy.

                                                  ^ empty

Otherwise,

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally Alexandru Elisei
@ 2025-05-07 16:02   ` Andrew Jones
  2025-05-08  8:52     ` Alexandru Elisei
  0 siblings, 1 reply; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:02 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:43PM +0100, Alexandru Elisei wrote:
> Only arm and arm64 are allowed to set --target to kvmtool; the rest of the
> architectures can only set --target to 'qemu', which is also the default.
> 
> Needed to make the changes necessary to add support for kvmtool to the test
> runner.
> 
> kvmtool also supports running the riscv tests, so it's not outside of the
> realm of the possibily for the riscv tests to get support for kvmtool.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  configure | 36 ++++++++++++++++++++++++------------
>  1 file changed, 24 insertions(+), 12 deletions(-)
>

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu Alexandru Elisei
@ 2025-05-07 16:10   ` Andrew Jones
  2025-05-07 16:14     ` Alexandru Elisei
  2025-05-14  7:49   ` Shaoqin Huang
  1 sibling, 1 reply; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:10 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:46PM +0100, Alexandru Elisei wrote:
> Arm and arm64 support running the tests under kvmtool. kvmtool has a
> different command line syntax for configuring and running a virtual
> machine, and the automated scripts know only how to use qemu.
> 
> One issue with that is even though the tests have been configured for
> kvmtool (with ./configure --target=kvmtool), the scripts will use qemu to
> run the tests, and without looking at the logs there is no indication that
> the tests haven't been run with kvmtool, as configured.
> 
> Another issue is that kvmtool uses a different address for the UART and
> when running the tests with qemu via the scripts, this warning is
> displayed:
> 
> WARNING: early print support may not work. Found uart at 0x9000000, but early base is 0x1000000.
> 
> which might trip up an unsuspected user.
> 
> There are four different ways to run a test using the test infrastructure:
> with run_tests.sh, by invoking arm/run or arm/efi/run with the correct
> parameters (only the arm directory is mentioned here because the tests can
> be configured for kvmtool only on arm and arm64), and by creating
> standalone tests.
> 
> run_tests.sh ends up execuing either arm/run or arm/efi/run, so add a check

executing

> to these two scripts for the test target, and refuse to run the test if
> kvm-unit-tests has been configured for kvmtool.
> 
> mkstandalone.sh also executes arm/run or arm/efi run, but the usual use
> case for standalone tests is to compile them on one machine, and then to
> run them on a different machine. This two step process can be time
> consuming, so save the user time (and frustration!) and add a check
> directly to mkstandalone.sh.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  arm/efi/run             |  3 +++
>  arm/run                 |  4 ++++
>  scripts/mkstandalone.sh |  3 +++
>  scripts/vmm.bash        | 14 ++++++++++++++
>  4 files changed, 24 insertions(+)
>  create mode 100644 scripts/vmm.bash
> 
> diff --git a/arm/efi/run b/arm/efi/run
> index 8f41fc02df31..53d71297cc52 100755
> --- a/arm/efi/run
> +++ b/arm/efi/run
> @@ -11,6 +11,9 @@ if [ ! -f config.mak ]; then
>  fi
>  source config.mak
>  source scripts/arch-run.bash
> +source scripts/vmm.bash
> +
> +check_vmm_supported
>  
>  if [ -f /usr/share/qemu-efi-aarch64/QEMU_EFI.fd ]; then
>  	DEFAULT_UEFI=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
> diff --git a/arm/run b/arm/run
> index ef58558231b7..56562ed1628f 100755
> --- a/arm/run
> +++ b/arm/run
> @@ -7,7 +7,11 @@ if [ -z "$KUT_STANDALONE" ]; then
>  	fi
>  	source config.mak
>  	source scripts/arch-run.bash
> +	source scripts/vmm.bash
>  fi
> +
> +check_vmm_supported
> +
>  qemu_cpu="$TARGET_CPU"
>  
>  if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
> diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
> index c4ba81f18935..4f666cefe076 100755
> --- a/scripts/mkstandalone.sh
> +++ b/scripts/mkstandalone.sh
> @@ -6,6 +6,9 @@ if [ ! -f config.mak ]; then
>  fi
>  source config.mak
>  source scripts/common.bash
> +source scripts/vmm.bash
> +
> +check_vmm_supported
>  
>  temp_file ()
>  {
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> new file mode 100644
> index 000000000000..39325858c6b3
> --- /dev/null
> +++ b/scripts/vmm.bash
> @@ -0,0 +1,14 @@
> +source config.mak
> +
> +function check_vmm_supported()
> +{
> +	case "$TARGET" in
> +	qemu)
> +		return 0
> +		;;
> +	*)
> +		echo "$0 does not support target '$TARGET'"
> +		exit 2
> +		;;
> +	esac
> +}

Hmm. We now have configure saying one thing for arm/arm64 and this
function saying another. Assuming this is just temporary and will
be resolved in the next patches, then that's probably OK, though.

Thanks,
drew

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu
  2025-05-07 16:10   ` Andrew Jones
@ 2025-05-07 16:14     ` Alexandru Elisei
  0 siblings, 0 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-07 16:14 UTC (permalink / raw)
  To: Andrew Jones
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Hi Drew,

On Wed, May 07, 2025 at 06:10:08PM +0200, Andrew Jones wrote:
> On Wed, May 07, 2025 at 04:12:46PM +0100, Alexandru Elisei wrote:
> > Arm and arm64 support running the tests under kvmtool. kvmtool has a
> > different command line syntax for configuring and running a virtual
> > machine, and the automated scripts know only how to use qemu.
> > 
> > One issue with that is even though the tests have been configured for
> > kvmtool (with ./configure --target=kvmtool), the scripts will use qemu to
> > run the tests, and without looking at the logs there is no indication that
> > the tests haven't been run with kvmtool, as configured.
> > 
> > Another issue is that kvmtool uses a different address for the UART and
> > when running the tests with qemu via the scripts, this warning is
> > displayed:
> > 
> > WARNING: early print support may not work. Found uart at 0x9000000, but early base is 0x1000000.
> > 
> > which might trip up an unsuspected user.
> > 
> > There are four different ways to run a test using the test infrastructure:
> > with run_tests.sh, by invoking arm/run or arm/efi/run with the correct
> > parameters (only the arm directory is mentioned here because the tests can
> > be configured for kvmtool only on arm and arm64), and by creating
> > standalone tests.
> > 
> > run_tests.sh ends up execuing either arm/run or arm/efi/run, so add a check
> 
> executing

Ack.

> 
> > to these two scripts for the test target, and refuse to run the test if
> > kvm-unit-tests has been configured for kvmtool.
> > 
> > mkstandalone.sh also executes arm/run or arm/efi run, but the usual use
> > case for standalone tests is to compile them on one machine, and then to
> > run them on a different machine. This two step process can be time
> > consuming, so save the user time (and frustration!) and add a check
> > directly to mkstandalone.sh.
> > 
> > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> > ---
> >  arm/efi/run             |  3 +++
> >  arm/run                 |  4 ++++
> >  scripts/mkstandalone.sh |  3 +++
> >  scripts/vmm.bash        | 14 ++++++++++++++
> >  4 files changed, 24 insertions(+)
> >  create mode 100644 scripts/vmm.bash
> > 
> > diff --git a/arm/efi/run b/arm/efi/run
> > index 8f41fc02df31..53d71297cc52 100755
> > --- a/arm/efi/run
> > +++ b/arm/efi/run
> > @@ -11,6 +11,9 @@ if [ ! -f config.mak ]; then
> >  fi
> >  source config.mak
> >  source scripts/arch-run.bash
> > +source scripts/vmm.bash
> > +
> > +check_vmm_supported
> >  
> >  if [ -f /usr/share/qemu-efi-aarch64/QEMU_EFI.fd ]; then
> >  	DEFAULT_UEFI=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
> > diff --git a/arm/run b/arm/run
> > index ef58558231b7..56562ed1628f 100755
> > --- a/arm/run
> > +++ b/arm/run
> > @@ -7,7 +7,11 @@ if [ -z "$KUT_STANDALONE" ]; then
> >  	fi
> >  	source config.mak
> >  	source scripts/arch-run.bash
> > +	source scripts/vmm.bash
> >  fi
> > +
> > +check_vmm_supported
> > +
> >  qemu_cpu="$TARGET_CPU"
> >  
> >  if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
> > diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
> > index c4ba81f18935..4f666cefe076 100755
> > --- a/scripts/mkstandalone.sh
> > +++ b/scripts/mkstandalone.sh
> > @@ -6,6 +6,9 @@ if [ ! -f config.mak ]; then
> >  fi
> >  source config.mak
> >  source scripts/common.bash
> > +source scripts/vmm.bash
> > +
> > +check_vmm_supported
> >  
> >  temp_file ()
> >  {
> > diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> > new file mode 100644
> > index 000000000000..39325858c6b3
> > --- /dev/null
> > +++ b/scripts/vmm.bash
> > @@ -0,0 +1,14 @@
> > +source config.mak
> > +
> > +function check_vmm_supported()
> > +{
> > +	case "$TARGET" in
> > +	qemu)
> > +		return 0
> > +		;;
> > +	*)
> > +		echo "$0 does not support target '$TARGET'"
> > +		exit 2
> > +		;;
> > +	esac
> > +}
> 
> Hmm. We now have configure saying one thing for arm/arm64 and this
> function saying another. Assuming this is just temporary and will
> be resolved in the next patches, then that's probably OK, though.

This is resolved in the last patch. Wanted to add this in case someone doesn't
apply the entire series and they end up with partial kvmtool support.

And thanks for having a look so fast!

Alex

> 
> Thanks,
> drew

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 07/16] scripts: Use an associative array for qemu argument names
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 07/16] scripts: Use an associative array for qemu argument names Alexandru Elisei
@ 2025-05-07 16:17   ` Andrew Jones
  2025-05-14  8:02   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:17 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:47PM +0100, Alexandru Elisei wrote:
> Move away from hardcoded qemu arguments and use instead an associative
> array to get the needed arguments. This paves the way for adding kvmtool
> support to the scripts, which has a different syntax for the same VM
> configuration parameters.
> 
> Suggested-by: Andrew Jones <andrew.jones@linux.dev>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  scripts/common.bash  | 10 +++++++---
>  scripts/runtime.bash |  7 +------
>  scripts/vmm.bash     |  7 +++++++
>  3 files changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/scripts/common.bash b/scripts/common.bash
> index 9deb87d4050d..649f1c737617 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -1,4 +1,5 @@
>  source config.mak
> +source scripts/vmm.bash
>  
>  function for_each_unittest()
>  {
> @@ -26,8 +27,11 @@ function for_each_unittest()
>  				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
>  			fi
>  			testname=$rematch
> -			smp=1
> +			smp="${vmm_opts[$TARGET:nr_cpus]} 1"

I think the wrapper functions you suggested in the cover letter might be
nice just to keep Bash from hurting people's brains too much. At least to
me,

  smp="$(vmm_optname_nr_cpus) 1"

would read better. Also note the use of 'optname' in the name to try and
help self-document that this array is holding option names, not option
values.

>  			kernel=""
> +			# Intentionally don't use -append if test_args is empty
> +			# because qemu interprets the first argument after
> +			# -append as a kernel parameter.
>  			test_args=""
>  			opts=""
>  			groups=""
> @@ -39,9 +43,9 @@ function for_each_unittest()
>  		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
>  			kernel=$TEST_DIR/${BASH_REMATCH[1]}
>  		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
> -			smp=${BASH_REMATCH[1]}
> +			smp="${vmm_opts[$TARGET:nr_cpus]} ${BASH_REMATCH[1]}"
>  		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
> -			test_args=${BASH_REMATCH[1]}
> +			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
>  		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
>  			opts=${BASH_REMATCH[2]}$'\n'
>  			while read -r -u $fd; do
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 06cc58e79b69..86d8a2cd8528 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -34,7 +34,7 @@ premature_failure()
>  get_cmdline()
>  {
>      local kernel=$1
> -    echo "TESTNAME=$testname TIMEOUT=$timeout MACHINE=$machine ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
> +    echo "TESTNAME=$testname TIMEOUT=$timeout MACHINE=$machine ACCEL=$accel $RUNTIME_arch_run $kernel $smp $test_args $opts"
>  }
>  
>  skip_nodefault()
> @@ -88,11 +88,6 @@ function run()
>      local accel="${10}"
>      local timeout="${11:-$TIMEOUT}" # unittests.cfg overrides the default
>  
> -    # If $test_args is empty, qemu will interpret the first option after -append
> -    # as a kernel parameter instead of a qemu option, so make sure the -append
> -    # option is used only if $test_args is not empy.
> -    [ -n "$test_args" ] && opts="-append $test_args $opts"
> -
>      if [ "${CONFIG_EFI}" == "y" ]; then
>          kernel=${kernel/%.flat/.efi}
>      fi
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index 39325858c6b3..b02055a5c0b6 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -1,5 +1,12 @@
>  source config.mak
>  
> +declare -A vmm_opts=(
> +	[qemu:nr_cpus]='-smp'
> +	[qemu:kernel]='-kernel'
> +	[qemu:args]='-append'
> +	[qemu:initrd]='-initrd'
> +)
> +
>  function check_vmm_supported()
>  {
>  	case "$TARGET" in
> -- 
> 2.49.0

Otherwise,

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

Thanks,
drew

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 08/16] scripts: Add 'kvmtool_params' to test definition
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 08/16] scripts: Add 'kvmtool_params' to test definition Alexandru Elisei
@ 2025-05-07 16:28   ` Andrew Jones
  2025-05-08 15:54     ` Alexandru Elisei
  0 siblings, 1 reply; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:28 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:48PM +0100, Alexandru Elisei wrote:
> arm/arm64 supports running tests under kvmtool, but kvmtool's syntax for
> running and configuring a virtual machine is different to qemu. To run
> tests using the automated test infrastructure, add a new test parameter,
> 'kvmtool_params'. The parameter serves the exact purpose as 'qemu_params',
> but using kvmtool's syntax.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  arm/unittests.cfg   | 24 +++++++++++++++++++++++
>  docs/unittests.txt  |  8 ++++++++
>  scripts/common.bash | 47 +++++++++++++++++++++++++++++----------------
>  3 files changed, 62 insertions(+), 17 deletions(-)
> 
> diff --git a/arm/unittests.cfg b/arm/unittests.cfg
> index a4192ed7e20b..f3c773e56933 100644
> --- a/arm/unittests.cfg
> +++ b/arm/unittests.cfg
> @@ -17,6 +17,7 @@ file = selftest.flat
>  smp = 2
>  test_args = 'setup smp=2 mem=256'
>  qemu_params = -m 256
> +kvmtool_params = --mem 256
>  groups = selftest
>  
>  # Test vector setup and exception handling (kernel mode).
> @@ -48,66 +49,77 @@ groups = pci
>  file = pmu.flat
>  groups = pmu
>  test_args = "cycle-counter 0"
> +kvmtool_params = --pmu
>  
>  [pmu-event-introspection]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-event-introspection
> +kvmtool_params = --pmu
>  
>  [pmu-event-counter-config]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-event-counter-config
> +kvmtool_params = --pmu
>  
>  [pmu-basic-event-count]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-basic-event-count
> +kvmtool_params = --pmu
>  
>  [pmu-mem-access]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-mem-access
> +kvmtool_params = --pmu
>  
>  [pmu-mem-access-reliability]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-mem-access-reliability
> +kvmtool_params = --pmu
>  
>  [pmu-sw-incr]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-sw-incr
> +kvmtool_params = --pmu
>  
>  [pmu-chained-counters]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-chained-counters
> +kvmtool_params = --pmu
>  
>  [pmu-chained-sw-incr]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-chained-sw-incr
> +kvmtool_params = --pmu
>  
>  [pmu-chain-promotion]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-chain-promotion
> +kvmtool_params = --pmu
>  
>  [pmu-overflow-interrupt]
>  file = pmu.flat
>  groups = pmu
>  arch = arm64
>  test_args = pmu-overflow-interrupt
> +kvmtool_params = --pmu
>  
>  # Test PMU support (TCG) with -icount IPC=1
>  #[pmu-tcg-icount-1]
> @@ -131,6 +143,7 @@ file = gic.flat
>  smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
>  test_args = ipi
>  qemu_params = -machine gic-version=2
> +kvmtool_params = --irqchip=gicv2
>  groups = gic
>  
>  [gicv2-mmio]
> @@ -138,6 +151,7 @@ file = gic.flat
>  smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
>  test_args = mmio
>  qemu_params = -machine gic-version=2
> +kvmtool_params = --irqchip=gicv2
>  groups = gic
>  
>  [gicv2-mmio-up]
> @@ -145,6 +159,7 @@ file = gic.flat
>  smp = 1
>  test_args = mmio
>  qemu_params = -machine gic-version=2
> +kvmtool_params = --irqchip=gicv2
>  groups = gic
>  
>  [gicv2-mmio-3p]
> @@ -152,6 +167,7 @@ file = gic.flat
>  smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
>  test_args = mmio
>  qemu_params = -machine gic-version=2
> +kvmtool_params = --irqchip=gicv2
>  groups = gic
>  
>  [gicv3-ipi]
> @@ -159,6 +175,7 @@ file = gic.flat
>  smp = $MAX_SMP
>  test_args = ipi
>  qemu_params = -machine gic-version=3
> +kvmtool_params = --irqchip=gicv3
>  groups = gic
>  
>  [gicv2-active]
> @@ -166,6 +183,7 @@ file = gic.flat
>  smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
>  test_args = active
>  qemu_params = -machine gic-version=2
> +kvmtool_params = --irqchip=gicv2
>  groups = gic
>  
>  [gicv3-active]
> @@ -173,6 +191,7 @@ file = gic.flat
>  smp = $MAX_SMP
>  test_args = active
>  qemu_params = -machine gic-version=3
> +kvmtool_params = --irqchip=gicv3
>  groups = gic
>  
>  [its-introspection]
> @@ -180,6 +199,7 @@ file = gic.flat
>  smp = $MAX_SMP
>  test_args = its-introspection
>  qemu_params = -machine gic-version=3
> +kvmtool_params = --irqchip=gicv3-its
>  groups = its
>  arch = arm64
>  
> @@ -188,6 +208,7 @@ file = gic.flat
>  smp = $MAX_SMP
>  test_args = its-trigger
>  qemu_params = -machine gic-version=3
> +kvmtool_params = --irqchip=gicv3-its
>  groups = its
>  arch = arm64
>  
> @@ -196,6 +217,7 @@ file = gic.flat
>  smp = $MAX_SMP
>  test_args = its-migration
>  qemu_params = -machine gic-version=3
> +kvmtool_params = --irqchip=gicv3
>  groups = its migration
>  arch = arm64
>  
> @@ -204,6 +226,7 @@ file = gic.flat
>  smp = $MAX_SMP
>  test_args = its-pending-migration
>  qemu_params = -machine gic-version=3
> +kvmtool_params = --irqchip=gicv3
>  groups = its migration
>  arch = arm64
>  
> @@ -212,6 +235,7 @@ file = gic.flat
>  smp = $MAX_SMP
>  test_args = its-migrate-unmapped-collection
>  qemu_params = -machine gic-version=3
> +kvmtool_params = --irqchip=gicv3
>  groups = its migration
>  arch = arm64
>  
> diff --git a/docs/unittests.txt b/docs/unittests.txt
> index ea0da959f008..a9164bccc24c 100644
> --- a/docs/unittests.txt
> +++ b/docs/unittests.txt
> @@ -78,6 +78,14 @@ extra_params
>  Alias for 'qemu_params', supported for compatibility purposes. Use
>  'qemu_params' for new tests.
>  
> +kvmtool_params
> +--------------
> +Extra parameters supplied to the kvmtool process. Works similarly to
> +'qemu_params', but uses kvmtool's syntax for command line arguments. The
> +example for 'qemu_params', applied to kvmtool, would be:
> +
> +kvmtool_params = --mem 256
> +
>  groups
>  ------
>  groups = <group_name1> <group_name2> ...
> diff --git a/scripts/common.bash b/scripts/common.bash
> index 649f1c737617..0645235d8baa 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -1,6 +1,29 @@
>  source config.mak
>  source scripts/vmm.bash
>  
> +function parse_opts()
> +{
> +	local opts="$1"
> +	local fd="$2"
> +
> +	while read -r -u $fd; do
> +		#escape backslash newline, but not double backslash
> +		if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
> +			if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
> +				opts=${opts%\\$'\n'}
> +			fi
> +		fi
> +		if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
> +			opts+=${BASH_REMATCH[1]}
> +			break
> +		else
> +			opts+=$REPLY$'\n'
> +		fi
> +	done
> +
> +	echo "$opts"
> +}
> +
>  function for_each_unittest()
>  {
>  	local unittests="$1"
> @@ -46,24 +69,14 @@ function for_each_unittest()
>  			smp="${vmm_opts[$TARGET:nr_cpus]} ${BASH_REMATCH[1]}"
>  		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
>  			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
> -		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
> -			opts=${BASH_REMATCH[2]}$'\n'
> -			while read -r -u $fd; do
> -				#escape backslash newline, but not double backslash
> -				if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
> -					if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
> -						opts=${opts%\\$'\n'}
> -					fi
> -				fi
> -				if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
> -					opts+=${BASH_REMATCH[1]}
> -					break
> -				else
> -					opts+=$REPLY$'\n'
> -				fi
> -			done
> -		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
> +		elif [[ $TARGET = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then

Should use == with [[ ]]

> +			opts=$(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)
> +		elif [[ $TARGET  = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
                               ^ extra space

>  			opts=${BASH_REMATCH[2]}
> +		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *'"""'(.*)$ ]]; then
> +			opts=$(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)
> +		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *(.*)$ ]]; then
> +			opts=${BASH_REMATCH[1]}

I think we can do something like

if [[ $TARGET == "qemu" ]]; then
   params='(extra_params|qemu_params)'
elif [[ $TARGET == "kvmtool" ]]; then
   params='(kvmtool_params)'
else
   ...fail...
fi

And then use $params in the regular expressions and always use
BASH_REMATCH[2]. That would allow us to avoid duplicating the if
statements and then we wouldn't need to factor out parse_opts either.

Thanks,
drew

>  		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
>  			groups=${BASH_REMATCH[1]}
>  		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
> -- 
> 2.49.0
> 
> 
> -- 
> kvm-riscv mailing list
> kvm-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kvm-riscv

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 09/16] scripts: Add support for kvmtool
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 09/16] scripts: Add support for kvmtool Alexandru Elisei
@ 2025-05-07 16:38   ` Andrew Jones
  2025-05-19  8:55   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:38 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:49PM +0100, Alexandru Elisei wrote:
> Teach the arm runner to use kvmtool when kvm-unit-tests has been configured
> appropriately.
> 
> The test is ran using run_test_status(), and a 0 return code (which means
> success) is converted to 1, because kvmtool does not have a testdev device
> to return the test exit code, so kvm-unit-tests must always parse the
> "EXIT: STATUS" line for the exit code.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  arm/run               | 161 ++++++++++++++++++++++++++----------------
>  powerpc/run           |   4 +-
>  riscv/run             |   4 +-
>  s390x/run             |   2 +-
>  scripts/arch-run.bash | 112 +++++++++++------------------
>  scripts/vmm.bash      |  89 +++++++++++++++++++++++
>  x86/run               |   4 +-
>  7 files changed, 236 insertions(+), 140 deletions(-)
>

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 10/16] scripts: Add default arguments for kvmtool
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 10/16] scripts: Add default arguments " Alexandru Elisei
@ 2025-05-07 16:43   ` Andrew Jones
  2025-05-21  3:21   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:43 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:50PM +0100, Alexandru Elisei wrote:
> kvmtool, unless told otherwise, will do its best to make sure that a kernel
> successfully boots in a virtual machine. It does things like automatically
> creating a rootfs and adding extra parameters to the kernel command line.
> This is actively harmful to kvm-unit-tests, because some tests parse the
> kernel command line and they will fail if they encounter the options added
> by kvmtool.
> 
> Fortunately for us, kvmtool commit 5613ae26b998 ("Add --nodefaults command
> line argument") addded the --nodefaults kvmtool parameter which disables
> all the implicit virtual machine configuration that cannot be disabled by
> using other parameters, like modifying the kernel command line. So always
> use --nodefaults to allow a test to run.
> 
> kvmtool can also be too verbose when running a virtual machine, and this is
> controlled by several parameters. Add those to the default kvmtool command
> line to reduce this verbosity to a minimum.
> 
> Before:
> 
> $ vm run arm/selftest.flat --cpus 2 --mem 256 --params "setup smp=2 mem=256"
> Info: # lkvm run -k arm/selftest.flat -m 256 -c 2 --name guest-5035
> Unknown subtest
> 
> EXIT: STATUS=127
> Warning: KVM compatibility warning.
>     virtio-9p device was not detected.
>     While you have requested a virtio-9p device, the guest kernel did not initialize it.
>     Please make sure that the guest kernel was compiled with CONFIG_NET_9P_VIRTIO=y enabled in .config.
> Warning: KVM compatibility warning.
>     virtio-net device was not detected.
>     While you have requested a virtio-net device, the guest kernel did not initialize it.
>     Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_NET=y enabled in .config.
> Info: KVM session ended normally.
> 
> After:
> 
> $ vm run arm/selftest.flat --nodefaults --network mode=none --loglevel=warning --cpus 2 --mem 256 --params "setup smp=2 mem=256"
> PASS: selftest: setup: smp: number of CPUs matches expectation
> INFO: selftest: setup: smp: found 2 CPUs
> PASS: selftest: setup: mem: memory size matches expectation
> INFO: selftest: setup: mem: found 256 MB
> SUMMARY: 2 tests
> 
> EXIT: STATUS=1
> 
> Note that KVMTOOL_DEFAULT_OPTS can be overwritten by an environment
> variable with the same name, but it's not documented in the help string for
> run_tests.sh. This has been done on purpose, since overwritting
> KVMTOOL_DEFAULT_OPTS should only be necessary for debugging or development
> purposes.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  scripts/common.bash | 10 +++++-----
>  scripts/vmm.bash    | 13 +++++++++++++
>  2 files changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/common.bash b/scripts/common.bash
> index 0645235d8baa..ee0ae71948c2 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -56,7 +56,7 @@ function for_each_unittest()
>  			# because qemu interprets the first argument after
>  			# -append as a kernel parameter.
>  			test_args=""
> -			opts=""
> +			opts="${vmm_opts[$TARGET:default_opts]}"
>  			groups=""
>  			arch=""
>  			machine=""
> @@ -70,13 +70,13 @@ function for_each_unittest()
>  		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
>  			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
>  		elif [[ $TARGET = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
> -			opts=$(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)
> +			opts="${vmm_opts[$TARGET:default_opts]} $(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)"
>  		elif [[ $TARGET  = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
> -			opts=${BASH_REMATCH[2]}
> +			opts="${vmm_opts[$TARGET:default_opts]} ${BASH_REMATCH[2]}"
>  		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *'"""'(.*)$ ]]; then
> -			opts=$(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)
> +			opts="${vmm_opts[$TARGET:default_opts]} $(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)"
>  		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *(.*)$ ]]; then
> -			opts=${BASH_REMATCH[1]}
> +			opts="${vmm_opts[$TARGET:default_opts]} ${BASH_REMATCH[1]}"
>  		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
>  			groups=${BASH_REMATCH[1]}
>  		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index 20968f2e6b10..d24a4c4b8713 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -1,5 +1,16 @@
>  source config.mak
>  
> +# The following parameters are enabled by default when running a test with
> +# kvmtool:
> +# --nodefaults: suppress VM configuration that cannot be disabled otherwise
> +#               (like modifying the supplied kernel command line). Tests that
> +#               use the command line will fail without this parameter.
> +# --network mode=none: do not create a network device. kvmtool tries to help the
> +#               user by automatically create one, and then prints a warning
> +#               when the VM terminates if the device hasn't been initialized.
> +# --loglevel=warning: reduce verbosity
> +: "${KVMTOOL_DEFAULT_OPTS:="--nodefaults --network mode=none --loglevel=warning"}"
> +
>  ##############################################################################
>  # qemu_fixup_return_code translates the ambiguous exit status in Table1 to that
>  # in Table2.  Table3 simply documents the complete status table.
> @@ -87,12 +98,14 @@ declare -A vmm_opts=(
>  	[qemu:kernel]='-kernel'
>  	[qemu:args]='-append'
>  	[qemu:initrd]='-initrd'
> +	[qemu:default_opts]=''
>  	[qemu:fixup_return_code]=qemu_fixup_return_code
>  
>  	[kvmtool:nr_cpus]='--cpus'
>  	[kvmtool:kernel]='--kernel'
>  	[kvmtool:args]='--params'
>  	[kvmtool:initrd]='--initrd'
> +	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
>  	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
>  )
>  
> -- 
> 2.49.0

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 11/16] scripts: Add KVMTOOL environment variable for kvmtool binary path
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 11/16] scripts: Add KVMTOOL environment variable for kvmtool binary path Alexandru Elisei
@ 2025-05-07 16:45   ` Andrew Jones
  2025-05-19  8:13   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:45 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:51PM +0100, Alexandru Elisei wrote:
> kvmtool is often used for prototyping new features, and a developer might
> not want to install it system-wide. Add a KVMTOOL environment variable to
> make it easier for tests to use a binary not in $PATH.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  run_tests.sh          | 1 +
>  scripts/arch-run.bash | 3 ++-
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/run_tests.sh b/run_tests.sh
> index dd9d27377905..150a06a91064 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -36,6 +36,7 @@ The following environment variables are used:
>      TIMEOUT         Timeout duration for the timeout(1) command
>      CHECK           Overwrites the 'check' unit test parameter (see
>                      docs/unittests.txt)
> +    KVMTOOL         Path to kvmtool binary for ARCH-run
>  EOF
>  }
>  
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index 8cf67e4f3b51..d4fc7116abbe 100644
> --- a/scripts/arch-run.bash
> +++ b/scripts/arch-run.bash
> @@ -372,7 +372,7 @@ search_kvmtool_binary ()
>  {
>  	local kvmtoolcmd kvmtool
>  
> -	for kvmtoolcmd in lkvm vm lkvm-static; do
> +	for kvmtoolcmd in ${KVMTOOL:-lkvm vm lkvm-static}; do
>  		if "$kvmtoolcmd" --help 2>/dev/null| grep -q 'The most commonly used'; then
>  			kvmtool="$kvmtoolcmd"
>  			break
> @@ -381,6 +381,7 @@ search_kvmtool_binary ()
>  
>  	if [ -z "$kvmtool" ]; then
>  		echo "A kvmtool binary was not found." >&2
> +		echo "You can set a custom location by using the KVMTOOL=<path> environment variable." >&2
>  		return 2
>  	fi
>  
> -- 
> 2.49.0
>

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 12/16] scripts: Detect kvmtool failure in premature_failure()
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 12/16] scripts: Detect kvmtool failure in premature_failure() Alexandru Elisei
@ 2025-05-07 16:47   ` Andrew Jones
  2025-05-21  5:58   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:47 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:52PM +0100, Alexandru Elisei wrote:
> kvm-unit-tests assumes that if the VMM is able to get to where it tries to
> load the kernel, then the VMM and the configuration parameters will also
> work for running the test. All of this is done in premature_failure().
> 
> Teach premature_failure() about the kvmtool's error message when it fails
> to load the dummy kernel.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  scripts/runtime.bash |  8 +++-----
>  scripts/vmm.bash     | 23 +++++++++++++++++++++++
>  2 files changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 86d8a2cd8528..01ec8eae2bba 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -1,3 +1,5 @@
> +source scripts/vmm.bash
> +
>  : "${RUNTIME_arch_run?}"
>  : "${MAX_SMP:=$(getconf _NPROCESSORS_ONLN)}"
>  : "${TIMEOUT:=90s}"
> @@ -19,11 +21,7 @@ premature_failure()
>  
>      log="$(eval "$(get_cmdline _NO_FILE_4Uhere_)" 2>&1)"
>  
> -    echo "$log" | grep "_NO_FILE_4Uhere_" |
> -        grep -q -e "[Cc]ould not \(load\|open\) kernel" \
> -                -e "error loading" \
> -                -e "failed to load" &&
> -        return 1
> +    ${vmm_opts[$TARGET:parse_premature_failure]} "$log" || return 1
>  
>      RUNTIME_log_stderr <<< "$log"
>  
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index d24a4c4b8713..a1d50ed51981 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -93,6 +93,27 @@ kvmtool_fixup_return_code()
>  	echo $ret
>  }
>  
> +function qemu_parse_premature_failure()
> +{
> +	local log="$@"
> +
> +	echo "$log" | grep "_NO_FILE_4Uhere_" |
> +		grep -q -e "[Cc]ould not \(load\|open\) kernel" \
> +			-e "error loading" \
> +			-e "failed to load" &&
> +		return 1
> +	return 0
> +}
> +
> +function kvmtool_parse_premature_failure()
> +{
> +	local log="$@"
> +
> +	echo "$log" | grep "Fatal: Unable to open kernel _NO_FILE_4Uhere_" &&
> +		return 1
> +	return 0
> +}
> +
>  declare -A vmm_opts=(
>  	[qemu:nr_cpus]='-smp'
>  	[qemu:kernel]='-kernel'
> @@ -100,6 +121,7 @@ declare -A vmm_opts=(
>  	[qemu:initrd]='-initrd'
>  	[qemu:default_opts]=''
>  	[qemu:fixup_return_code]=qemu_fixup_return_code
> +	[qemu:parse_premature_failure]=qemu_parse_premature_failure
>  
>  	[kvmtool:nr_cpus]='--cpus'
>  	[kvmtool:kernel]='--kernel'
> @@ -107,6 +129,7 @@ declare -A vmm_opts=(
>  	[kvmtool:initrd]='--initrd'
>  	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
>  	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
> +	[kvmtool:parse_premature_failure]=kvmtool_parse_premature_failure
>  )
>  
>  function check_vmm_supported()
> -- 
> 2.49.0
>

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 13/16] scripts: Do not probe for maximum number of VCPUs when using kvmtool
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 13/16] scripts: Do not probe for maximum number of VCPUs when using kvmtool Alexandru Elisei
@ 2025-05-07 16:48   ` Andrew Jones
  2025-05-21  6:02   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:48 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:53PM +0100, Alexandru Elisei wrote:
> The --probe-maxsmp parameter updates MAX_SMP with the maximum number of
> VCPUs that the host supports. Qemu will exit with an error when creating a
> virtual machine if the number of VCPUs is exceeded.
> 
> kvmtool behaves differently: it will automatically limit the number of
> VCPUs to the what KVM supports, which is exactly what --probe-maxsmp wants
> to achieve. When doing --probe-maxsmp with kvmtool, print a message
> explaining why it's redundant and don't do anything else.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  run_tests.sh         |  3 ++-
>  scripts/runtime.bash | 16 ----------------
>  scripts/vmm.bash     | 24 ++++++++++++++++++++++++
>  3 files changed, 26 insertions(+), 17 deletions(-)
> 
> diff --git a/run_tests.sh b/run_tests.sh
> index 150a06a91064..a69c3665b7a4 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -10,6 +10,7 @@ if [ ! -f config.mak ]; then
>  fi
>  source config.mak
>  source scripts/common.bash
> +source scripts/vmm.bash
>  
>  function usage()
>  {
> @@ -90,7 +91,7 @@ while [ $# -gt 0 ]; do
>              list_tests="yes"
>              ;;
>          --probe-maxsmp)
> -            probe_maxsmp
> +            ${vmm_opts[$TARGET:probe_maxsmp]}
>              ;;
>          --)
>              ;;
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 01ec8eae2bba..a802686c511d 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -209,19 +209,3 @@ function run()
>  
>      return $ret
>  }
> -
> -#
> -# Probe for MAX_SMP, in case it's less than the number of host cpus.
> -#
> -function probe_maxsmp()
> -{
> -	local smp
> -
> -	if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'SMP CPUs'); then
> -		smp=${smp##* }
> -		smp=${smp/\(}
> -		smp=${smp/\)}
> -		echo "Restricting MAX_SMP from ($MAX_SMP) to the max supported ($smp)" >&2
> -		MAX_SMP=$smp
> -	fi
> -}
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index a1d50ed51981..ef9819f4132c 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -105,6 +105,22 @@ function qemu_parse_premature_failure()
>  	return 0
>  }
>  
> +#
> +# Probe for MAX_SMP, in case it's less than the number of host cpus.
> +#
> +function qemu_probe_maxsmp()
> +{
> +	local smp
> +
> +	if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'SMP CPUs'); then
> +		smp=${smp##* }
> +		smp=${smp/\(}
> +		smp=${smp/\)}
> +		echo "Restricting MAX_SMP from ($MAX_SMP) to the max supported ($smp)" >&2
> +		MAX_SMP=$smp
> +	fi
> +}
> +
>  function kvmtool_parse_premature_failure()
>  {
>  	local log="$@"
> @@ -114,6 +130,12 @@ function kvmtool_parse_premature_failure()
>  	return 0
>  }
>  
> +function kvmtool_probe_maxsmp()
> +{
> +	echo "kvmtool automatically limits the number of VCPUs to maximum supported"
> +	echo "The 'smp' test parameter won't be modified"
> +}
> +
>  declare -A vmm_opts=(
>  	[qemu:nr_cpus]='-smp'
>  	[qemu:kernel]='-kernel'
> @@ -122,6 +144,7 @@ declare -A vmm_opts=(
>  	[qemu:default_opts]=''
>  	[qemu:fixup_return_code]=qemu_fixup_return_code
>  	[qemu:parse_premature_failure]=qemu_parse_premature_failure
> +	[qemu:probe_maxsmp]=qemu_probe_maxsmp
>  
>  	[kvmtool:nr_cpus]='--cpus'
>  	[kvmtool:kernel]='--kernel'
> @@ -130,6 +153,7 @@ declare -A vmm_opts=(
>  	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
>  	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
>  	[kvmtool:parse_premature_failure]=kvmtool_parse_premature_failure
> +	[kvmtool:probe_maxsmp]=kvmtool_probe_maxsmp
>  )
>  
>  function check_vmm_supported()
> -- 
> 2.49.0
>

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 15/16] scripts: Add 'disabled_if' test definition parameter for kvmtool to use
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 15/16] scripts: Add 'disabled_if' test definition parameter for kvmtool to use Alexandru Elisei
@ 2025-05-07 16:56   ` Andrew Jones
  0 siblings, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:56 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:55PM +0100, Alexandru Elisei wrote:
> The pci-test is qemu specific. Other tests perform migration, which
> isn't supported by kvmtool. In general, kvmtool is not as feature-rich
> as qemu, so add a new unittest parameter, 'disabled_if', that causes a
> test to be skipped if the condition evaluates to true.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
> 
> This is what Drew said about the patch in the previous iteration [1]:
> 
> 'I like disabled_if because I like the lambda-like thing it's doing, but I
> wonder if it wouldn't be better to make TARGET a first class citizen by
> adding a 'targets' unittest parameter which allows listing all targets the
> test can run on [..]
> 
> If targets isn't present then the default is only qemu.'
> 
> Like I've said on the cover letter, I think making qemu the default (if
> 'targets' isn't specified in the test definition) will mean that new tests
> will not run with kvmtool. I was thinking something along the lines
> 'excluded_targets', with the default (when left unspecified) being that the
> tests run with all the vmms that the architecture support (or, to put it
> another way, no vmms are excluded).
> 
> Or we could go with 'targets' and say that when left empty it means 'all
> the vmms that the architecture supports' - though in my opinion this
> semantic is somewhat better conveyed with the name 'excluded_targets'.

excluded_targets sounds good, but disabled_if is growing on me. So, unless
you or others also prefer excluded_targets, then

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

Thanks,
drew

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 16/16] scripts: Enable kvmtool
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 16/16] scripts: Enable kvmtool Alexandru Elisei
@ 2025-05-07 16:59   ` Andrew Jones
  2025-05-21  6:20   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-07 16:59 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Wed, May 07, 2025 at 04:12:56PM +0100, Alexandru Elisei wrote:
> Everything is in place to run the tests using kvmtool:
> 
> $ ./configure --target=kvmtool
> $ make clean && make
> $ KVMTOOL=<path/to/kvmtool> ./run_tests.sh
> 
> so enable it, and remove ERRATA_FORCE=y when configuring for kvmtool,
> because the runner will generate and pass the correct environment to
> kvmtool.
> 
> Missing is support for EFI tests. That's because distros don't ship a
> EDK2 binary compiled for kvmtool, and on top of that kvm-unit-tests as
> an EFI app hasn't been tested to work with kvmtool.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  README.md        | 18 +++++++++++++++++-
>  arm/efi/run      |  5 +++++
>  configure        |  1 -
>  scripts/vmm.bash |  2 +-
>  4 files changed, 23 insertions(+), 3 deletions(-)
>

Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally
  2025-05-07 16:02   ` Andrew Jones
@ 2025-05-08  8:52     ` Alexandru Elisei
  2025-05-08  9:39       ` Andrew Jones
  0 siblings, 1 reply; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-08  8:52 UTC (permalink / raw)
  To: Andrew Jones
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Hi Drew,

On Wed, May 07, 2025 at 06:02:31PM +0200, Andrew Jones wrote:
> On Wed, May 07, 2025 at 04:12:43PM +0100, Alexandru Elisei wrote:
> > Only arm and arm64 are allowed to set --target to kvmtool; the rest of the
> > architectures can only set --target to 'qemu', which is also the default.
> > 
> > Needed to make the changes necessary to add support for kvmtool to the test
> > runner.
> > 
> > kvmtool also supports running the riscv tests, so it's not outside of the
> > realm of the possibily for the riscv tests to get support for kvmtool.
> > 
> > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> > ---
> >  configure | 36 ++++++++++++++++++++++++------------
> >  1 file changed, 24 insertions(+), 12 deletions(-)
> >
> 
> Reviewed-by: Andrew Jones <andrew.jones@linux.dev>

Thank you for the review!

Just to be clear, you are ok with this happening because of the patch:

$ git pull
$ make clean && make
$ ./run_tests.sh
scripts/runtime.bash: line 24: scripts/arch-run.bash: line 444: [: =: unary operator expected
timeout -k 1s --foreground 90s /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel _NO_FILE_4Uhere_ 2 #  /tmp/tmp.bME9I2BZRG
qemu-system-x86_64: 2: Could not open '2': No such file or directory
scripts/arch-run.bash: line 19: 1: command not found: No such file or directory
FAIL apic-split
scripts/runtime.bash: line 24: scripts/arch-run.bash: line 444: [: =: unary operator expected
timeout -k 1s --foreground 90s /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel _NO_FILE_4Uhere_ 1 #  /tmp/tmp.11und6qZbL
qemu-system-x86_64: 1: Could not open '1': No such file or directory
scripts/arch-run.bash: line 19: 1: command not found: No such file or directory
FAIL ioapic-split
[..]

That's because TARGET is missing from config.mak. If you're ok with the
error, I'll make it clear in the commit message why this is happening.

Thanks,
Alex

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally
  2025-05-08  8:52     ` Alexandru Elisei
@ 2025-05-08  9:39       ` Andrew Jones
  2025-05-08 10:05         ` Alexandru Elisei
  0 siblings, 1 reply; 50+ messages in thread
From: Andrew Jones @ 2025-05-08  9:39 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Thu, May 08, 2025 at 09:52:38AM +0100, Alexandru Elisei wrote:
> Hi Drew,
> 
> On Wed, May 07, 2025 at 06:02:31PM +0200, Andrew Jones wrote:
> > On Wed, May 07, 2025 at 04:12:43PM +0100, Alexandru Elisei wrote:
> > > Only arm and arm64 are allowed to set --target to kvmtool; the rest of the
> > > architectures can only set --target to 'qemu', which is also the default.
> > > 
> > > Needed to make the changes necessary to add support for kvmtool to the test
> > > runner.
> > > 
> > > kvmtool also supports running the riscv tests, so it's not outside of the
> > > realm of the possibily for the riscv tests to get support for kvmtool.
> > > 
> > > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> > > ---
> > >  configure | 36 ++++++++++++++++++++++++------------
> > >  1 file changed, 24 insertions(+), 12 deletions(-)
> > >
> > 
> > Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> 
> Thank you for the review!
> 
> Just to be clear, you are ok with this happening because of the patch:
> 
> $ git pull
> $ make clean && make
> $ ./run_tests.sh
> scripts/runtime.bash: line 24: scripts/arch-run.bash: line 444: [: =: unary operator expected
> timeout -k 1s --foreground 90s /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel _NO_FILE_4Uhere_ 2 #  /tmp/tmp.bME9I2BZRG
> qemu-system-x86_64: 2: Could not open '2': No such file or directory
> scripts/arch-run.bash: line 19: 1: command not found: No such file or directory
> FAIL apic-split
> scripts/runtime.bash: line 24: scripts/arch-run.bash: line 444: [: =: unary operator expected
> timeout -k 1s --foreground 90s /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel _NO_FILE_4Uhere_ 1 #  /tmp/tmp.11und6qZbL
> qemu-system-x86_64: 1: Could not open '1': No such file or directory
> scripts/arch-run.bash: line 19: 1: command not found: No such file or directory
> FAIL ioapic-split
> [..]
> 
> That's because TARGET is missing from config.mak. If you're ok with the
> error, I'll make it clear in the commit message why this is happening.
>

It's not ideal, but I think it's pretty common to run configure before
make after an update to the git repo, so it's not horrible. However,
as you pointed out in your cover letter, this can be mitigated if we
use function wrappers for the associative array accesses, allowing
$TARGET to be checked before it's used. I'd prefer the function wrappers
anyway for readability reasons, so let's do that.

Thanks,
drew

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally
  2025-05-08  9:39       ` Andrew Jones
@ 2025-05-08 10:05         ` Alexandru Elisei
  2025-05-08 10:17           ` Andrew Jones
  0 siblings, 1 reply; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-08 10:05 UTC (permalink / raw)
  To: Andrew Jones
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Hi Drew,

On Thu, May 08, 2025 at 11:39:54AM +0200, Andrew Jones wrote:
> On Thu, May 08, 2025 at 09:52:38AM +0100, Alexandru Elisei wrote:
> > Hi Drew,
> > 
> > On Wed, May 07, 2025 at 06:02:31PM +0200, Andrew Jones wrote:
> > > On Wed, May 07, 2025 at 04:12:43PM +0100, Alexandru Elisei wrote:
> > > > Only arm and arm64 are allowed to set --target to kvmtool; the rest of the
> > > > architectures can only set --target to 'qemu', which is also the default.
> > > > 
> > > > Needed to make the changes necessary to add support for kvmtool to the test
> > > > runner.
> > > > 
> > > > kvmtool also supports running the riscv tests, so it's not outside of the
> > > > realm of the possibily for the riscv tests to get support for kvmtool.
> > > > 
> > > > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> > > > ---
> > > >  configure | 36 ++++++++++++++++++++++++------------
> > > >  1 file changed, 24 insertions(+), 12 deletions(-)
> > > >
> > > 
> > > Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> > 
> > Thank you for the review!
> > 
> > Just to be clear, you are ok with this happening because of the patch:
> > 
> > $ git pull
> > $ make clean && make
> > $ ./run_tests.sh
> > scripts/runtime.bash: line 24: scripts/arch-run.bash: line 444: [: =: unary operator expected
> > timeout -k 1s --foreground 90s /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel _NO_FILE_4Uhere_ 2 #  /tmp/tmp.bME9I2BZRG
> > qemu-system-x86_64: 2: Could not open '2': No such file or directory
> > scripts/arch-run.bash: line 19: 1: command not found: No such file or directory
> > FAIL apic-split
> > scripts/runtime.bash: line 24: scripts/arch-run.bash: line 444: [: =: unary operator expected
> > timeout -k 1s --foreground 90s /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel _NO_FILE_4Uhere_ 1 #  /tmp/tmp.11und6qZbL
> > qemu-system-x86_64: 1: Could not open '1': No such file or directory
> > scripts/arch-run.bash: line 19: 1: command not found: No such file or directory
> > FAIL ioapic-split
> > [..]
> > 
> > That's because TARGET is missing from config.mak. If you're ok with the
> > error, I'll make it clear in the commit message why this is happening.
> >
> 
> It's not ideal, but I think it's pretty common to run configure before
> make after an update to the git repo, so it's not horrible. However,
> as you pointed out in your cover letter, this can be mitigated if we
> use function wrappers for the associative array accesses, allowing
> $TARGET to be checked before it's used. I'd prefer the function wrappers
> anyway for readability reasons, so let's do that.

I'm all for the function wrappers, I was planning to reply to that comment
later.

As to this patch, is this what you're thinking:

function vmm_optname_nr_cpus()
{
	if [ -z $TARGET ]; then
		echo vmm_opts[qemu:nr_cpus]
	else
		echo vmm_opts[$TARGET:nr_cpus]
	fi
}

But checking if $TARGET is defined makes this patch useless, and I would
rather drop it if that's the case.

Thanks,
Alex

> 
> Thanks,
> drew
> 

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally
  2025-05-08 10:05         ` Alexandru Elisei
@ 2025-05-08 10:17           ` Andrew Jones
  0 siblings, 0 replies; 50+ messages in thread
From: Andrew Jones @ 2025-05-08 10:17 UTC (permalink / raw)
  To: Alexandru Elisei
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

On Thu, May 08, 2025 at 11:05:32AM +0100, Alexandru Elisei wrote:
> Hi Drew,
> 
> On Thu, May 08, 2025 at 11:39:54AM +0200, Andrew Jones wrote:
> > On Thu, May 08, 2025 at 09:52:38AM +0100, Alexandru Elisei wrote:
> > > Hi Drew,
> > > 
> > > On Wed, May 07, 2025 at 06:02:31PM +0200, Andrew Jones wrote:
> > > > On Wed, May 07, 2025 at 04:12:43PM +0100, Alexandru Elisei wrote:
> > > > > Only arm and arm64 are allowed to set --target to kvmtool; the rest of the
> > > > > architectures can only set --target to 'qemu', which is also the default.
> > > > > 
> > > > > Needed to make the changes necessary to add support for kvmtool to the test
> > > > > runner.
> > > > > 
> > > > > kvmtool also supports running the riscv tests, so it's not outside of the
> > > > > realm of the possibily for the riscv tests to get support for kvmtool.
> > > > > 
> > > > > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> > > > > ---
> > > > >  configure | 36 ++++++++++++++++++++++++------------
> > > > >  1 file changed, 24 insertions(+), 12 deletions(-)
> > > > >
> > > > 
> > > > Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> > > 
> > > Thank you for the review!
> > > 
> > > Just to be clear, you are ok with this happening because of the patch:
> > > 
> > > $ git pull
> > > $ make clean && make
> > > $ ./run_tests.sh
> > > scripts/runtime.bash: line 24: scripts/arch-run.bash: line 444: [: =: unary operator expected
> > > timeout -k 1s --foreground 90s /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel _NO_FILE_4Uhere_ 2 #  /tmp/tmp.bME9I2BZRG
> > > qemu-system-x86_64: 2: Could not open '2': No such file or directory
> > > scripts/arch-run.bash: line 19: 1: command not found: No such file or directory
> > > FAIL apic-split
> > > scripts/runtime.bash: line 24: scripts/arch-run.bash: line 444: [: =: unary operator expected
> > > timeout -k 1s --foreground 90s /usr/bin/qemu-system-x86_64 --no-reboot -nodefaults -device pc-testdev -device isa-debug-exit,iobase=0xf4,iosize=0x4 -vnc none -serial stdio -device pci-testdev -machine accel=kvm -kernel _NO_FILE_4Uhere_ 1 #  /tmp/tmp.11und6qZbL
> > > qemu-system-x86_64: 1: Could not open '1': No such file or directory
> > > scripts/arch-run.bash: line 19: 1: command not found: No such file or directory
> > > FAIL ioapic-split
> > > [..]
> > > 
> > > That's because TARGET is missing from config.mak. If you're ok with the
> > > error, I'll make it clear in the commit message why this is happening.
> > >
> > 
> > It's not ideal, but I think it's pretty common to run configure before
> > make after an update to the git repo, so it's not horrible. However,
> > as you pointed out in your cover letter, this can be mitigated if we
> > use function wrappers for the associative array accesses, allowing
> > $TARGET to be checked before it's used. I'd prefer the function wrappers
> > anyway for readability reasons, so let's do that.
> 
> I'm all for the function wrappers, I was planning to reply to that comment
> later.
> 
> As to this patch, is this what you're thinking:
> 
> function vmm_optname_nr_cpus()
> {
> 	if [ -z $TARGET ]; then
> 		echo vmm_opts[qemu:nr_cpus]
> 	else
> 		echo vmm_opts[$TARGET:nr_cpus]
> 	fi
> }

Yup

> 
> But checking if $TARGET is defined makes this patch useless, and I would
> rather drop it if that's the case.

Sounds good.

Thanks,
drew

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 08/16] scripts: Add 'kvmtool_params' to test definition
  2025-05-07 16:28   ` Andrew Jones
@ 2025-05-08 15:54     ` Alexandru Elisei
  0 siblings, 0 replies; 50+ messages in thread
From: Alexandru Elisei @ 2025-05-08 15:54 UTC (permalink / raw)
  To: Andrew Jones
  Cc: eric.auger, lvivier, thuth, frankja, imbrenda, nrb, david,
	pbonzini, kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Hi Drew,

On Wed, May 07, 2025 at 06:28:04PM +0200, Andrew Jones wrote:
> On Wed, May 07, 2025 at 04:12:48PM +0100, Alexandru Elisei wrote:
> > arm/arm64 supports running tests under kvmtool, but kvmtool's syntax for
> > running and configuring a virtual machine is different to qemu. To run
> > tests using the automated test infrastructure, add a new test parameter,
> > 'kvmtool_params'. The parameter serves the exact purpose as 'qemu_params',
> > but using kvmtool's syntax.
> > 
> > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> > ---
> >  arm/unittests.cfg   | 24 +++++++++++++++++++++++
> >  docs/unittests.txt  |  8 ++++++++
> >  scripts/common.bash | 47 +++++++++++++++++++++++++++++----------------
> >  3 files changed, 62 insertions(+), 17 deletions(-)
> > 
> > diff --git a/arm/unittests.cfg b/arm/unittests.cfg
> > index a4192ed7e20b..f3c773e56933 100644
> > --- a/arm/unittests.cfg
> > +++ b/arm/unittests.cfg
> > @@ -17,6 +17,7 @@ file = selftest.flat
> >  smp = 2
> >  test_args = 'setup smp=2 mem=256'
> >  qemu_params = -m 256
> > +kvmtool_params = --mem 256
> >  groups = selftest
> >  
> >  # Test vector setup and exception handling (kernel mode).
> > @@ -48,66 +49,77 @@ groups = pci
> >  file = pmu.flat
> >  groups = pmu
> >  test_args = "cycle-counter 0"
> > +kvmtool_params = --pmu
> >  
> >  [pmu-event-introspection]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-event-introspection
> > +kvmtool_params = --pmu
> >  
> >  [pmu-event-counter-config]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-event-counter-config
> > +kvmtool_params = --pmu
> >  
> >  [pmu-basic-event-count]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-basic-event-count
> > +kvmtool_params = --pmu
> >  
> >  [pmu-mem-access]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-mem-access
> > +kvmtool_params = --pmu
> >  
> >  [pmu-mem-access-reliability]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-mem-access-reliability
> > +kvmtool_params = --pmu
> >  
> >  [pmu-sw-incr]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-sw-incr
> > +kvmtool_params = --pmu
> >  
> >  [pmu-chained-counters]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-chained-counters
> > +kvmtool_params = --pmu
> >  
> >  [pmu-chained-sw-incr]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-chained-sw-incr
> > +kvmtool_params = --pmu
> >  
> >  [pmu-chain-promotion]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-chain-promotion
> > +kvmtool_params = --pmu
> >  
> >  [pmu-overflow-interrupt]
> >  file = pmu.flat
> >  groups = pmu
> >  arch = arm64
> >  test_args = pmu-overflow-interrupt
> > +kvmtool_params = --pmu
> >  
> >  # Test PMU support (TCG) with -icount IPC=1
> >  #[pmu-tcg-icount-1]
> > @@ -131,6 +143,7 @@ file = gic.flat
> >  smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> >  test_args = ipi
> >  qemu_params = -machine gic-version=2
> > +kvmtool_params = --irqchip=gicv2
> >  groups = gic
> >  
> >  [gicv2-mmio]
> > @@ -138,6 +151,7 @@ file = gic.flat
> >  smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> >  test_args = mmio
> >  qemu_params = -machine gic-version=2
> > +kvmtool_params = --irqchip=gicv2
> >  groups = gic
> >  
> >  [gicv2-mmio-up]
> > @@ -145,6 +159,7 @@ file = gic.flat
> >  smp = 1
> >  test_args = mmio
> >  qemu_params = -machine gic-version=2
> > +kvmtool_params = --irqchip=gicv2
> >  groups = gic
> >  
> >  [gicv2-mmio-3p]
> > @@ -152,6 +167,7 @@ file = gic.flat
> >  smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
> >  test_args = mmio
> >  qemu_params = -machine gic-version=2
> > +kvmtool_params = --irqchip=gicv2
> >  groups = gic
> >  
> >  [gicv3-ipi]
> > @@ -159,6 +175,7 @@ file = gic.flat
> >  smp = $MAX_SMP
> >  test_args = ipi
> >  qemu_params = -machine gic-version=3
> > +kvmtool_params = --irqchip=gicv3
> >  groups = gic
> >  
> >  [gicv2-active]
> > @@ -166,6 +183,7 @@ file = gic.flat
> >  smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> >  test_args = active
> >  qemu_params = -machine gic-version=2
> > +kvmtool_params = --irqchip=gicv2
> >  groups = gic
> >  
> >  [gicv3-active]
> > @@ -173,6 +191,7 @@ file = gic.flat
> >  smp = $MAX_SMP
> >  test_args = active
> >  qemu_params = -machine gic-version=3
> > +kvmtool_params = --irqchip=gicv3
> >  groups = gic
> >  
> >  [its-introspection]
> > @@ -180,6 +199,7 @@ file = gic.flat
> >  smp = $MAX_SMP
> >  test_args = its-introspection
> >  qemu_params = -machine gic-version=3
> > +kvmtool_params = --irqchip=gicv3-its
> >  groups = its
> >  arch = arm64
> >  
> > @@ -188,6 +208,7 @@ file = gic.flat
> >  smp = $MAX_SMP
> >  test_args = its-trigger
> >  qemu_params = -machine gic-version=3
> > +kvmtool_params = --irqchip=gicv3-its
> >  groups = its
> >  arch = arm64
> >  
> > @@ -196,6 +217,7 @@ file = gic.flat
> >  smp = $MAX_SMP
> >  test_args = its-migration
> >  qemu_params = -machine gic-version=3
> > +kvmtool_params = --irqchip=gicv3
> >  groups = its migration
> >  arch = arm64
> >  
> > @@ -204,6 +226,7 @@ file = gic.flat
> >  smp = $MAX_SMP
> >  test_args = its-pending-migration
> >  qemu_params = -machine gic-version=3
> > +kvmtool_params = --irqchip=gicv3
> >  groups = its migration
> >  arch = arm64
> >  
> > @@ -212,6 +235,7 @@ file = gic.flat
> >  smp = $MAX_SMP
> >  test_args = its-migrate-unmapped-collection
> >  qemu_params = -machine gic-version=3
> > +kvmtool_params = --irqchip=gicv3
> >  groups = its migration
> >  arch = arm64
> >  
> > diff --git a/docs/unittests.txt b/docs/unittests.txt
> > index ea0da959f008..a9164bccc24c 100644
> > --- a/docs/unittests.txt
> > +++ b/docs/unittests.txt
> > @@ -78,6 +78,14 @@ extra_params
> >  Alias for 'qemu_params', supported for compatibility purposes. Use
> >  'qemu_params' for new tests.
> >  
> > +kvmtool_params
> > +--------------
> > +Extra parameters supplied to the kvmtool process. Works similarly to
> > +'qemu_params', but uses kvmtool's syntax for command line arguments. The
> > +example for 'qemu_params', applied to kvmtool, would be:
> > +
> > +kvmtool_params = --mem 256
> > +
> >  groups
> >  ------
> >  groups = <group_name1> <group_name2> ...
> > diff --git a/scripts/common.bash b/scripts/common.bash
> > index 649f1c737617..0645235d8baa 100644
> > --- a/scripts/common.bash
> > +++ b/scripts/common.bash
> > @@ -1,6 +1,29 @@
> >  source config.mak
> >  source scripts/vmm.bash
> >  
> > +function parse_opts()
> > +{
> > +	local opts="$1"
> > +	local fd="$2"
> > +
> > +	while read -r -u $fd; do
> > +		#escape backslash newline, but not double backslash
> > +		if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
> > +			if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
> > +				opts=${opts%\\$'\n'}
> > +			fi
> > +		fi
> > +		if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
> > +			opts+=${BASH_REMATCH[1]}
> > +			break
> > +		else
> > +			opts+=$REPLY$'\n'
> > +		fi
> > +	done
> > +
> > +	echo "$opts"
> > +}
> > +
> >  function for_each_unittest()
> >  {
> >  	local unittests="$1"
> > @@ -46,24 +69,14 @@ function for_each_unittest()
> >  			smp="${vmm_opts[$TARGET:nr_cpus]} ${BASH_REMATCH[1]}"
> >  		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
> >  			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
> > -		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
> > -			opts=${BASH_REMATCH[2]}$'\n'
> > -			while read -r -u $fd; do
> > -				#escape backslash newline, but not double backslash
> > -				if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
> > -					if (( ${#BASH_REMATCH[1]} % 2 == 1 )); then
> > -						opts=${opts%\\$'\n'}
> > -					fi
> > -				fi
> > -				if [[ "$REPLY" =~ ^(.*)'"""'[:blank:]*$ ]]; then
> > -					opts+=${BASH_REMATCH[1]}
> > -					break
> > -				else
> > -					opts+=$REPLY$'\n'
> > -				fi
> > -			done
> > -		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
> > +		elif [[ $TARGET = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
> 
> Should use == with [[ ]]

Ack.

> 
> > +			opts=$(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)
> > +		elif [[ $TARGET  = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
>                                ^ extra space
> 
> >  			opts=${BASH_REMATCH[2]}
> > +		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *'"""'(.*)$ ]]; then
> > +			opts=$(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)
> > +		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *(.*)$ ]]; then
> > +			opts=${BASH_REMATCH[1]}
> 
> I think we can do something like
> 
> if [[ $TARGET == "qemu" ]]; then
>    params='(extra_params|qemu_params)'
> elif [[ $TARGET == "kvmtool" ]]; then
>    params='(kvmtool_params)'
> else
>    ...fail...
> fi
> 
> And then use $params in the regular expressions and always use
> BASH_REMATCH[2]. That would allow us to avoid duplicating the if
> statements and then we wouldn't need to factor out parse_opts either.

Sounds good. I can even wrap it with with a vmm function, something like
vmm_get_params_name().

Thanks,
Alex

> 
> Thanks,
> drew
> 
> >  		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
> >  			groups=${BASH_REMATCH[1]}
> >  		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
> > -- 
> > 2.49.0
> > 
> > 
> > -- 
> > kvm-riscv mailing list
> > kvm-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/kvm-riscv

-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params'
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params' Alexandru Elisei
  2025-05-07 15:40   ` Andrew Jones
@ 2025-05-14  2:57   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-14  2:57 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> The arm and arm64 architectures can also be run with kvmtool, and work is
> under way to have it supported by the run_tests.sh test runner. Not
> suprisingly, kvmtool's syntax for running a virtual machine is different to
> qemu's.
> 
> Add a new unittest parameter, 'qemu_params', with the goal to add a similar
> parameter for kvmtool, when that's supported.
> 
> 'extra_params' has been kept in the scripts as an alias for 'qemu_params'
> to preserve compatibility with custom test definition, but it is expected
> that going forward new tests will use 'qemu_params'.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   arm/unittests.cfg     |  76 +++++++++++------------
>   docs/unittests.txt    |  15 +++--
>   powerpc/unittests.cfg |  18 +++---
>   riscv/unittests.cfg   |   2 +-
>   s390x/unittests.cfg   |  50 +++++++--------
>   scripts/common.bash   |   8 +--
>   scripts/runtime.bash  |   6 +-
>   x86/unittests.cfg     | 140 +++++++++++++++++++++---------------------
>   8 files changed, 160 insertions(+), 155 deletions(-)
> 
> diff --git a/arm/unittests.cfg b/arm/unittests.cfg
> index fe1011454f88..6c6f76b2fb52 100644
> --- a/arm/unittests.cfg
> +++ b/arm/unittests.cfg
> @@ -15,26 +15,26 @@
>   [selftest-setup]
>   file = selftest.flat
>   smp = 2
> -extra_params = -m 256 -append 'setup smp=2 mem=256'
> +qemu_params = -m 256 -append 'setup smp=2 mem=256'
>   groups = selftest
>   
>   # Test vector setup and exception handling (kernel mode).
>   [selftest-vectors-kernel]
>   file = selftest.flat
> -extra_params = -append 'vectors-kernel'
> +qemu_params = -append 'vectors-kernel'
>   groups = selftest
>   
>   # Test vector setup and exception handling (user mode).
>   [selftest-vectors-user]
>   file = selftest.flat
> -extra_params = -append 'vectors-user'
> +qemu_params = -append 'vectors-user'
>   groups = selftest
>   
>   # Test SMP support
>   [selftest-smp]
>   file = selftest.flat
>   smp = $MAX_SMP
> -extra_params = -append 'smp'
> +qemu_params = -append 'smp'
>   groups = selftest
>   
>   # Test PCI emulation
> @@ -46,79 +46,79 @@ groups = pci
>   [pmu-cycle-counter]
>   file = pmu.flat
>   groups = pmu
> -extra_params = -append 'cycle-counter 0'
> +qemu_params = -append 'cycle-counter 0'
>   
>   [pmu-event-introspection]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-event-introspection'
> +qemu_params = -append 'pmu-event-introspection'
>   
>   [pmu-event-counter-config]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-event-counter-config'
> +qemu_params = -append 'pmu-event-counter-config'
>   
>   [pmu-basic-event-count]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-basic-event-count'
> +qemu_params = -append 'pmu-basic-event-count'
>   
>   [pmu-mem-access]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-mem-access'
> +qemu_params = -append 'pmu-mem-access'
>   
>   [pmu-mem-access-reliability]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-mem-access-reliability'
> +qemu_params = -append 'pmu-mem-access-reliability'
>   
>   [pmu-sw-incr]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-sw-incr'
> +qemu_params = -append 'pmu-sw-incr'
>   
>   [pmu-chained-counters]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-chained-counters'
> +qemu_params = -append 'pmu-chained-counters'
>   
>   [pmu-chained-sw-incr]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-chained-sw-incr'
> +qemu_params = -append 'pmu-chained-sw-incr'
>   
>   [pmu-chain-promotion]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-chain-promotion'
> +qemu_params = -append 'pmu-chain-promotion'
>   
>   [pmu-overflow-interrupt]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -extra_params = -append 'pmu-overflow-interrupt'
> +qemu_params = -append 'pmu-overflow-interrupt'
>   
>   # Test PMU support (TCG) with -icount IPC=1
>   #[pmu-tcg-icount-1]
>   #file = pmu.flat
> -#extra_params = -icount 0 -append 'cycle-counter 1'
> +#qemu_params = -icount 0 -append 'cycle-counter 1'
>   #groups = pmu
>   #accel = tcg
>   
>   # Test PMU support (TCG) with -icount IPC=256
>   #[pmu-tcg-icount-256]
>   #file = pmu.flat
> -#extra_params = -icount 8 -append 'cycle-counter 256'
> +#qemu_params = -icount 8 -append 'cycle-counter 256'
>   #groups = pmu
>   #accel = tcg
>   
> @@ -126,77 +126,77 @@ extra_params = -append 'pmu-overflow-interrupt'
>   [gicv2-ipi]
>   file = gic.flat
>   smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> -extra_params = -machine gic-version=2 -append 'ipi'
> +qemu_params = -machine gic-version=2 -append 'ipi'
>   groups = gic
>   
>   [gicv2-mmio]
>   file = gic.flat
>   smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> -extra_params = -machine gic-version=2 -append 'mmio'
> +qemu_params = -machine gic-version=2 -append 'mmio'
>   groups = gic
>   
>   [gicv2-mmio-up]
>   file = gic.flat
>   smp = 1
> -extra_params = -machine gic-version=2 -append 'mmio'
> +qemu_params = -machine gic-version=2 -append 'mmio'
>   groups = gic
>   
>   [gicv2-mmio-3p]
>   file = gic.flat
>   smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
> -extra_params = -machine gic-version=2 -append 'mmio'
> +qemu_params = -machine gic-version=2 -append 'mmio'
>   groups = gic
>   
>   [gicv3-ipi]
>   file = gic.flat
>   smp = $MAX_SMP
> -extra_params = -machine gic-version=3 -append 'ipi'
> +qemu_params = -machine gic-version=3 -append 'ipi'
>   groups = gic
>   
>   [gicv2-active]
>   file = gic.flat
>   smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> -extra_params = -machine gic-version=2 -append 'active'
> +qemu_params = -machine gic-version=2 -append 'active'
>   groups = gic
>   
>   [gicv3-active]
>   file = gic.flat
>   smp = $MAX_SMP
> -extra_params = -machine gic-version=3 -append 'active'
> +qemu_params = -machine gic-version=3 -append 'active'
>   groups = gic
>   
>   [its-introspection]
>   file = gic.flat
>   smp = $MAX_SMP
> -extra_params = -machine gic-version=3 -append 'its-introspection'
> +qemu_params = -machine gic-version=3 -append 'its-introspection'
>   groups = its
>   arch = arm64
>   
>   [its-trigger]
>   file = gic.flat
>   smp = $MAX_SMP
> -extra_params = -machine gic-version=3 -append 'its-trigger'
> +qemu_params = -machine gic-version=3 -append 'its-trigger'
>   groups = its
>   arch = arm64
>   
>   [its-migration]
>   file = gic.flat
>   smp = $MAX_SMP
> -extra_params = -machine gic-version=3 -append 'its-migration'
> +qemu_params = -machine gic-version=3 -append 'its-migration'
>   groups = its migration
>   arch = arm64
>   
>   [its-pending-migration]
>   file = gic.flat
>   smp = $MAX_SMP
> -extra_params = -machine gic-version=3 -append 'its-pending-migration'
> +qemu_params = -machine gic-version=3 -append 'its-pending-migration'
>   groups = its migration
>   arch = arm64
>   
>   [its-migrate-unmapped-collection]
>   file = gic.flat
>   smp = $MAX_SMP
> -extra_params = -machine gic-version=3 -append 'its-migrate-unmapped-collection'
> +qemu_params = -machine gic-version=3 -append 'its-migrate-unmapped-collection'
>   groups = its migration
>   arch = arm64
>   
> @@ -231,37 +231,37 @@ groups = cache
>   [debug-bp]
>   file = debug.flat
>   arch = arm64
> -extra_params = -append 'bp'
> +qemu_params = -append 'bp'
>   groups = debug
>   
>   [debug-bp-migration]
>   file = debug.flat
>   arch = arm64
> -extra_params = -append 'bp-migration'
> +qemu_params = -append 'bp-migration'
>   groups = debug migration
>   
>   [debug-wp]
>   file = debug.flat
>   arch = arm64
> -extra_params = -append 'wp'
> +qemu_params = -append 'wp'
>   groups = debug
>   
>   [debug-wp-migration]
>   file = debug.flat
>   arch = arm64
> -extra_params = -append 'wp-migration'
> +qemu_params = -append 'wp-migration'
>   groups = debug migration
>   
>   [debug-sstep]
>   file = debug.flat
>   arch = arm64
> -extra_params = -append 'ss'
> +qemu_params = -append 'ss'
>   groups = debug
>   
>   [debug-sstep-migration]
>   file = debug.flat
>   arch = arm64
> -extra_params = -append 'ss-migration'
> +qemu_params = -append 'ss-migration'
>   groups = debug migration
>   
>   # FPU/SIMD test
> @@ -276,17 +276,17 @@ arch = arm64
>   [mte-sync]
>   file = mte.flat
>   groups = mte
> -extra_params = -machine mte=on -append 'sync'
> +qemu_params = -machine mte=on -append 'sync'
>   arch = arm64
>   
>   [mte-async]
>   file = mte.flat
>   groups = mte
> -extra_params = -machine mte=on -append 'async'
> +qemu_params = -machine mte=on -append 'async'
>   arch = arm64
>   
>   [mte-asymm]
>   file = mte.flat
>   groups = mte
> -extra_params = -machine mte=on -append 'asymm'
> +qemu_params = -machine mte=on -append 'asymm'
>   arch = arm64
> diff --git a/docs/unittests.txt b/docs/unittests.txt
> index c4269f6230c8..3d19fd70953f 100644
> --- a/docs/unittests.txt
> +++ b/docs/unittests.txt
> @@ -24,9 +24,9 @@ param = value format.
>   
>   Available parameters
>   ====================
> -Note! Some parameters like smp and extra_params modify how a test is run,
> -while others like arch and accel restrict the configurations in which the
> -test is run.
> +Note! Some parameters like smp and qemu_params/extra_params modify how a
> +test is run, while others like arch and accel restrict the configurations
> +in which the test is run.
>   
>   file
>   ----
> @@ -56,13 +56,18 @@ smp = <number>
>   Optional, the number of processors created in the machine to run the test.
>   Defaults to 1. $MAX_SMP can be used to specify the maximum supported.
>   
> -extra_params
> +qemu_params
>   ------------
>   These are extra parameters supplied to the QEMU process. -append '...' can
>   be used to pass arguments into the test case argv. Multiple parameters can
>   be added, for example:
>   
> -extra_params = -m 256 -append 'smp=2'
> +qemu_params = -m 256 -append 'smp=2'
> +
> +extra_params
> +------------
> +Alias for 'qemu_params', supported for compatibility purposes. Use
> +'qemu_params' for new tests.
>   
>   groups
>   ------
> diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg
> index 149f963f3d53..5097911e4bf3 100644
> --- a/powerpc/unittests.cfg
> +++ b/powerpc/unittests.cfg
> @@ -15,7 +15,7 @@
>   [selftest-setup]
>   file = selftest.elf
>   smp = 2
> -extra_params = -m 1g -append 'setup smp=2 mem=1024'
> +qemu_params = -m 1g -append 'setup smp=2 mem=1024'
>   groups = selftest
>   
>   [selftest-migration]
> @@ -27,7 +27,7 @@ groups = selftest migration
>   file = selftest-migration.elf
>   machine = pseries
>   groups = selftest migration
> -extra_params = -append "skip"
> +qemu_params = -append "skip"
>   
>   [migration-memory]
>   file = memory-verify.elf
> @@ -46,20 +46,20 @@ machine = pseries
>   file = rtas.elf
>   machine = pseries
>   timeout = 5
> -extra_params = -append "get-time-of-day date=$(date +%s)"
> +qemu_params = -append "get-time-of-day date=$(date +%s)"
>   groups = rtas
>   
>   [rtas-get-time-of-day-base]
>   file = rtas.elf
>   machine = pseries
>   timeout = 5
> -extra_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)"
> +qemu_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)"
>   groups = rtas
>   
>   [rtas-set-time-of-day]
>   file = rtas.elf
>   machine = pseries
> -extra_params = -append "set-time-of-day"
> +qemu_params = -append "set-time-of-day"
>   timeout = 5
>   groups = rtas
>   
> @@ -94,7 +94,7 @@ smp = 2
>   [atomics-migration]
>   file = atomics.elf
>   machine = pseries
> -extra_params = -append "migration -m"
> +qemu_params = -append "migration -m"
>   groups = migration
>   
>   [timebase]
> @@ -103,14 +103,14 @@ file = timebase.elf
>   [timebase-icount]
>   file = timebase.elf
>   accel = tcg
> -extra_params = -icount shift=5
> +qemu_params = -icount shift=5
>   
>   [h_cede_tm]
>   file = tm.elf
>   machine = pseries
>   accel = kvm
>   smp = 2,threads=2
> -extra_params = -machine cap-htm=on -append "h_cede_tm"
> +qemu_params = -machine cap-htm=on -append "h_cede_tm"
>   groups = h_cede_tm
>   
>   [sprs]
> @@ -119,7 +119,7 @@ file = sprs.elf
>   [sprs-migration]
>   file = sprs.elf
>   machine = pseries
> -extra_params = -append '-w'
> +qemu_params = -append '-w'
>   groups = migration
>   
>   [sieve]
> diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg
> index 2eb760eca24e..5b31047f75c7 100644
> --- a/riscv/unittests.cfg
> +++ b/riscv/unittests.cfg
> @@ -10,7 +10,7 @@
>   [selftest]
>   file = selftest.flat
>   smp = $MAX_SMP
> -extra_params = -append 'foo bar baz'
> +qemu_params = -append 'foo bar baz'
>   groups = selftest
>   
>   # Set $FIRMWARE_OVERRIDE to /path/to/firmware to select the SBI implementation.
> diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
> index a9af6680f2a6..1e129fef3c38 100644
> --- a/s390x/unittests.cfg
> +++ b/s390x/unittests.cfg
> @@ -10,7 +10,7 @@
>   file = selftest.elf
>   groups = selftest
>   # please keep the kernel cmdline in sync with $(TEST_DIR)/selftest.parmfile
> -extra_params = -append 'test 123'
> +qemu_params = -append 'test 123'
>   
>   [selftest-migration]
>   file = selftest-migration.elf
> @@ -22,7 +22,7 @@ accel = kvm
>   [selftest-migration-skip]
>   file = selftest-migration.elf
>   groups = selftest migration
> -extra_params = -append "skip"
> +qemu_params = -append "skip"
>   
>   # This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream
>   [migration-memory]
> @@ -47,7 +47,7 @@ file = sthyi.elf
>   
>   [skey]
>   file = skey.elf
> -extra_params = -device virtio-net-ccw
> +qemu_params = -device virtio-net-ccw
>   
>   [diag10]
>   file = diag10.elf
> @@ -75,11 +75,11 @@ file = cpumodel.elf
>   
>   [diag288]
>   file = diag288.elf
> -extra_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi
> +qemu_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi
>   
>   [stsi]
>   file = stsi.elf
> -extra_params=-name kvm-unit-test --uuid 0fb84a86-727c-11ea-bc55-0242ac130003 -smp 1,maxcpus=8
> +qemu_params=-name kvm-unit-test --uuid 0fb84a86-727c-11ea-bc55-0242ac130003 -smp 1,maxcpus=8
>   
>   [smp]
>   file = smp.elf
> @@ -87,15 +87,15 @@ smp = 2
>   
>   [sclp-1g]
>   file = sclp.elf
> -extra_params = -m 1G
> +qemu_params = -m 1G
>   
>   [sclp-3g]
>   file = sclp.elf
> -extra_params = -m 3G
> +qemu_params = -m 3G
>   
>   [css]
>   file = css.elf
> -extra_params = -device virtio-net-ccw
> +qemu_params = -device virtio-net-ccw
>   
>   [skrf]
>   file = skrf.elf
> @@ -126,25 +126,25 @@ file = spec_ex.elf
>   [firq-linear-cpu-ids-kvm]
>   file = firq.elf
>   timeout = 20
> -extra_params = -smp 1,maxcpus=3 -device host-s390x-cpu,core-id=1 -device host-s390x-cpu,core-id=2
> +qemu_params = -smp 1,maxcpus=3 -device host-s390x-cpu,core-id=1 -device host-s390x-cpu,core-id=2
>   accel = kvm
>   
>   [firq-nonlinear-cpu-ids-kvm]
>   file = firq.elf
>   timeout = 20
> -extra_params = -smp 1,maxcpus=3 -device host-s390x-cpu,core-id=2 -device host-s390x-cpu,core-id=1
> +qemu_params = -smp 1,maxcpus=3 -device host-s390x-cpu,core-id=2 -device host-s390x-cpu,core-id=1
>   accel = kvm
>   
>   [firq-linear-cpu-ids-tcg]
>   file = firq.elf
>   timeout = 20
> -extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=1 -device qemu-s390x-cpu,core-id=2
> +qemu_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=1 -device qemu-s390x-cpu,core-id=2
>   accel = tcg
>   
>   [firq-nonlinear-cpu-ids-tcg]
>   file = firq.elf
>   timeout = 20
> -extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -device qemu-s390x-cpu,core-id=1
> +qemu_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -device qemu-s390x-cpu,core-id=1
>   accel = tcg
>   
>   [sck]
> @@ -152,7 +152,7 @@ file = sck.elf
>   
>   [epsw]
>   file = epsw.elf
> -extra_params = -device virtio-net-ccw
> +qemu_params = -device virtio-net-ccw
>   
>   [tprot]
>   file = tprot.elf
> @@ -161,26 +161,26 @@ file = tprot.elf
>   file = adtl-status.elf
>   smp = 2
>   accel = kvm
> -extra_params = -cpu host,gs=on,vx=on
> +qemu_params = -cpu host,gs=on,vx=on
>   
>   [adtl-status-no-vec-no-gs-kvm]
>   file = adtl-status.elf
>   smp = 2
>   accel = kvm
> -extra_params = -cpu host,gs=off,vx=off
> +qemu_params = -cpu host,gs=off,vx=off
>   
>   [adtl-status-tcg]
>   file = adtl-status.elf
>   smp = 2
>   accel = tcg
>   # no guarded-storage support in tcg
> -extra_params = -cpu qemu,vx=on
> +qemu_params = -cpu qemu,vx=on
>   
>   [adtl-status-no-vec-no-gs-tcg]
>   file = adtl-status.elf
>   smp = 2
>   accel = tcg
> -extra_params = -cpu qemu,gs=off,vx=off
> +qemu_params = -cpu qemu,gs=off,vx=off
>   
>   [migration]
>   file = migration.elf
> @@ -214,13 +214,13 @@ smp = 2
>   [migration-skey-sequential]
>   file = migration-skey.elf
>   groups = migration
> -extra_params = -append '--sequential'
> +qemu_params = -append '--sequential'
>   
>   [migration-skey-parallel]
>   file = migration-skey.elf
>   smp = 2
>   groups = migration
> -extra_params = -append '--parallel'
> +qemu_params = -append '--parallel'
>   
>   [execute]
>   file = ex.elf
> @@ -229,34 +229,34 @@ file = ex.elf
>   file = pv-icptcode.elf
>   smp = 3
>   groups = pv-host
> -extra_params = -m 2200
> +qemu_params = -m 2200
>   
>   [pv-ipl]
>   file = pv-ipl.elf
>   groups = pv-host
> -extra_params = -m 2200
> +qemu_params = -m 2200
>   
>   [pv-diags]
>   file = pv-diags.elf
>   groups = pv-host
> -extra_params = -m 2200
> +qemu_params = -m 2200
>   
>   [uv-host]
>   file = uv-host.elf
>   smp = 2
>   groups = pv-host
> -extra_params = -m 2200
> +qemu_params = -m 2200
>   
>   [topology]
>   file = topology.elf
>   
>   [topology-2]
>   file = topology.elf
> -extra_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248  -append '-sockets 31 -cores 8'
> +qemu_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248  -append '-sockets 31 -cores 8'
>   
>   [topology-3]
>   file = topology.elf
> -extra_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores=16,maxcpus=128 \
> +qemu_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores=16,maxcpus=128 \
>   -append '-drawers 2 -books 2 -sockets 2 -cores 16' \
>   -device max-s390x-cpu,core-id=31,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
>   -device max-s390x-cpu,core-id=11,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
> diff --git a/scripts/common.bash b/scripts/common.bash
> index 3aa557c8c03d..bd7c82f1adda 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -38,8 +38,8 @@ function for_each_unittest()
>   			kernel=$TEST_DIR/${BASH_REMATCH[1]}
>   		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
>   			smp=${BASH_REMATCH[1]}
> -		elif [[ $line =~ ^extra_params\ *=\ *'"""'(.*)$ ]]; then
> -			opts=${BASH_REMATCH[1]}$'\n'
> +		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
> +			opts=${BASH_REMATCH[2]}$'\n'
>   			while read -r -u $fd; do
>   				#escape backslash newline, but not double backslash
>   				if [[ $opts =~ [^\\]*(\\*)$'\n'$ ]]; then
> @@ -54,8 +54,8 @@ function for_each_unittest()
>   					opts+=$REPLY$'\n'
>   				fi
>   			done
> -		elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
> -			opts=${BASH_REMATCH[1]}
> +		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
> +			opts=${BASH_REMATCH[2]}
>   		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
>   			groups=${BASH_REMATCH[1]}
>   		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index ee229631277d..400e8a082528 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -179,9 +179,9 @@ function run()
>           echo $cmdline
>       fi
>   
> -    # extra_params in the config file may contain backticks that need to be
> -    # expanded, so use eval to start qemu.  Use "> >(foo)" instead of a pipe to
> -    # preserve the exit status.
> +    # qemu_params/extra_params in the config file may contain backticks that
> +    # need to be expanded, so use eval to start qemu.  Use "> >(foo)" instead of
> +    # a pipe to preserve the exit status.
>       summary=$(eval "$cmdline" 2> >(RUNTIME_log_stderr $testname) \
>                                > >(tee >(RUNTIME_log_stdout $testname $kernel) | extract_summary))
>       ret=$?
> diff --git a/x86/unittests.cfg b/x86/unittests.cfg
> index 6e69c50b9b0d..a356f486eaec 100644
> --- a/x86/unittests.cfg
> +++ b/x86/unittests.cfg
> @@ -10,20 +10,20 @@
>   [apic-split]
>   file = apic.flat
>   smp = 2
> -extra_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split
> +qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -machine kernel_irqchip=split
>   arch = x86_64
>   groups = apic
>   
>   [ioapic-split]
>   file = ioapic.flat
> -extra_params = -cpu qemu64 -machine kernel_irqchip=split
> +qemu_params = -cpu qemu64 -machine kernel_irqchip=split
>   arch = x86_64
>   groups = apic
>   
>   [x2apic]
>   file = apic.flat
>   smp = 2
> -extra_params = -cpu qemu64,+x2apic,+tsc-deadline
> +qemu_params = -cpu qemu64,+x2apic,+tsc-deadline
>   arch = x86_64
>   timeout = 30
>   groups = apic
> @@ -33,7 +33,7 @@ groups = apic
>   [xapic]
>   file = apic.flat
>   smp = 2
> -extra_params = -cpu qemu64,-x2apic,+tsc-deadline -machine pit=off
> +qemu_params = -cpu qemu64,-x2apic,+tsc-deadline -machine pit=off
>   arch = x86_64
>   timeout = 60
>   groups = apic
> @@ -41,7 +41,7 @@ groups = apic
>   [ioapic]
>   file = ioapic.flat
>   smp = 4
> -extra_params = -cpu qemu64,+x2apic
> +qemu_params = -cpu qemu64,+x2apic
>   arch = x86_64
>   
>   [cmpxchg8b]
> @@ -58,27 +58,27 @@ smp = 3
>   
>   [vmexit_cpuid]
>   file = vmexit.flat
> -extra_params = -append 'cpuid'
> +qemu_params = -append 'cpuid'
>   groups = vmexit
>   
>   [vmexit_vmcall]
>   file = vmexit.flat
> -extra_params = -append 'vmcall'
> +qemu_params = -append 'vmcall'
>   groups = vmexit
>   
>   [vmexit_mov_from_cr8]
>   file = vmexit.flat
> -extra_params = -append 'mov_from_cr8'
> +qemu_params = -append 'mov_from_cr8'
>   groups = vmexit
>   
>   [vmexit_mov_to_cr8]
>   file = vmexit.flat
> -extra_params = -append 'mov_to_cr8'
> +qemu_params = -append 'mov_to_cr8'
>   groups = vmexit
>   
>   [vmexit_inl_pmtimer]
>   file = vmexit.flat
> -extra_params = -append 'inl_from_pmtimer'
> +qemu_params = -append 'inl_from_pmtimer'
>   groups = vmexit
>   
>   # To allow IPIs to be accelerated by SVM AVIC when the feature is available and
> @@ -87,77 +87,77 @@ groups = vmexit
>   [vmexit_ipi]
>   file = vmexit.flat
>   smp = 2
> -extra_params = -machine pit=off -append 'ipi'
> +qemu_params = -machine pit=off -append 'ipi'
>   groups = vmexit
>   
>   [vmexit_ipi_halt]
>   file = vmexit.flat
>   smp = 2
> -extra_params = -append 'ipi_halt'
> +qemu_params = -append 'ipi_halt'
>   groups = vmexit
>   
>   [vmexit_ple_round_robin]
>   file = vmexit.flat
> -extra_params = -append 'ple_round_robin'
> +qemu_params = -append 'ple_round_robin'
>   groups = vmexit
>   
>   [vmexit_tscdeadline]
>   file = vmexit.flat
>   groups = vmexit
> -extra_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline
> +qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline
>   
>   [vmexit_tscdeadline_immed]
>   file = vmexit.flat
>   groups = vmexit
> -extra_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline_immed
> +qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline_immed
>   
>   [vmexit_cr0_wp]
>   file = vmexit.flat
>   smp = 2
> -extra_params = -append 'toggle_cr0_wp'
> +qemu_params = -append 'toggle_cr0_wp'
>   groups = vmexit
>   
>   [vmexit_cr4_pge]
>   file = vmexit.flat
>   smp = 2
> -extra_params = -append 'toggle_cr4_pge'
> +qemu_params = -append 'toggle_cr4_pge'
>   groups = vmexit
>   
>   [access]
>   file = access_test.flat
>   arch = x86_64
> -extra_params = -cpu max,host-phys-bits
> +qemu_params = -cpu max,host-phys-bits
>   
>   [access_fep]
>   file = access_test.flat
>   arch = x86_64
> -extra_params = -cpu max,host-phys-bits -append force_emulation
> +qemu_params = -cpu max,host-phys-bits -append force_emulation
>   groups = nodefault
>   timeout = 240
>   
>   [access-reduced-maxphyaddr]
>   file = access_test.flat
>   arch = x86_64
> -extra_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off
> +qemu_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off
>   check = /sys/module/kvm_intel/parameters/allow_smaller_maxphyaddr=Y
>   
>   [smap]
>   file = smap.flat
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   
>   [pku]
>   file = pku.flat
>   arch = x86_64
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   
>   [pks]
>   file = pks.flat
>   arch = x86_64
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   
>   [asyncpf]
>   file = asyncpf.flat
> -extra_params = -cpu host -m 2048
> +qemu_params = -cpu host -m 2048
>   
>   [emulator]
>   file = emulator.flat
> @@ -177,7 +177,7 @@ arch = x86_64
>   
>   [memory]
>   file = memory.flat
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   arch = x86_64
>   
>   [msr]
> @@ -186,11 +186,11 @@ arch = x86_64
>   # support follows the host kernel.  Running a 32-bit guest on a 64-bit host
>   # will fail due to shortcomings in KVM.
>   file = msr.flat
> -extra_params = -cpu max,vendor=GenuineIntel
> +qemu_params = -cpu max,vendor=GenuineIntel
>   
>   [pmu]
>   file = pmu.flat
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   check = /sys/module/kvm/parameters/enable_pmu=Y /proc/sys/kernel/nmi_watchdog=0
>   accel = kvm
>   groups = pmu
> @@ -198,7 +198,7 @@ groups = pmu
>   [pmu_lbr]
>   arch = x86_64
>   file = pmu_lbr.flat
> -extra_params = -cpu host,migratable=no
> +qemu_params = -cpu host,migratable=no
>   check = /sys/module/kvm/parameters/enable_pmu=Y /proc/sys/kernel/nmi_watchdog=0 /sys/module/kvm/parameters/ignore_msrs=N
>   accel = kvm
>   groups = pmu
> @@ -206,14 +206,14 @@ groups = pmu
>   [pmu_pebs]
>   arch = x86_64
>   file = pmu_pebs.flat
> -extra_params = -cpu host,migratable=no
> +qemu_params = -cpu host,migratable=no
>   check = /sys/module/kvm/parameters/enable_pmu=Y /proc/sys/kernel/nmi_watchdog=0
>   accel = kvm
>   groups = pmu
>   
>   [vmware_backdoors]
>   file = vmware_backdoors.flat
> -extra_params = -machine vmport=on -cpu max
> +qemu_params = -machine vmport=on -cpu max
>   check = /sys/module/kvm/parameters/enable_vmware_backdoor=Y
>   arch = x86_64
>   accel = kvm
> @@ -234,20 +234,20 @@ timeout = 180
>   [syscall]
>   file = syscall.flat
>   arch = x86_64
> -extra_params = -cpu Opteron_G1,vendor=AuthenticAMD
> +qemu_params = -cpu Opteron_G1,vendor=AuthenticAMD
>   
>   [tsc]
>   file = tsc.flat
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   
>   [tsc_adjust]
>   file = tsc_adjust.flat
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   
>   [xsave]
>   file = xsave.flat
>   arch = x86_64
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   
>   [rmap_chain]
>   file = rmap_chain.flat
> @@ -256,20 +256,20 @@ arch = x86_64
>   [svm]
>   file = svm.flat
>   smp = 2
> -extra_params = -cpu max,+svm -m 4g -append "-pause_filter_test"
> +qemu_params = -cpu max,+svm -m 4g -append "-pause_filter_test"
>   arch = x86_64
>   groups = svm
>   
>   [svm_pause_filter]
>   file = svm.flat
> -extra_params = -cpu max,+svm -overcommit cpu-pm=on -m 4g -append pause_filter_test
> +qemu_params = -cpu max,+svm -overcommit cpu-pm=on -m 4g -append pause_filter_test
>   arch = x86_64
>   groups = svm
>   
>   [svm_npt]
>   file = svm_npt.flat
>   smp = 2
> -extra_params = -cpu max,+svm -m 4g
> +qemu_params = -cpu max,+svm -m 4g
>   arch = x86_64
>   
>   [taskswitch]
> @@ -285,68 +285,68 @@ groups = tasks
>   [kvmclock_test]
>   file = kvmclock_test.flat
>   smp = 2
> -extra_params = --append "10000000 `date +%s`"
> +qemu_params = --append "10000000 `date +%s`"
>   
>   [pcid-enabled]
>   file = pcid.flat
> -extra_params = -cpu qemu64,+pcid,+invpcid
> +qemu_params = -cpu qemu64,+pcid,+invpcid
>   arch = x86_64
>   groups = pcid
>   
>   [pcid-disabled]
>   file = pcid.flat
> -extra_params = -cpu qemu64,-pcid,-invpcid
> +qemu_params = -cpu qemu64,-pcid,-invpcid
>   arch = x86_64
>   groups = pcid
>   
>   [pcid-asymmetric]
>   file = pcid.flat
> -extra_params = -cpu qemu64,-pcid,+invpcid
> +qemu_params = -cpu qemu64,-pcid,+invpcid
>   arch = x86_64
>   groups = pcid
>   
>   [rdpru]
>   file = rdpru.flat
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   arch = x86_64
>   
>   [umip]
>   file = umip.flat
> -extra_params = -cpu qemu64,+umip
> +qemu_params = -cpu qemu64,+umip
>   
>   [la57]
>   file = la57.flat
> -extra_params = -cpu max,host-phys-bits
> +qemu_params = -cpu max,host-phys-bits
>   
>   [vmx]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test -apic_reg_virt_test -virt_x2apic_mode_test -vmx_pf_exception_test -vmx_pf_exception_forced_emulation_test -vmx_pf_no_vpid_test -vmx_pf_invvpid_test -vmx_pf_vpid_test -vmx_basic_vid_test -vmx_eoi_virt_test -vmx_posted_interrupts_test"
> +qemu_params = -cpu max,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test -apic_reg_virt_test -virt_x2apic_mode_test -vmx_pf_exception_test -vmx_pf_exception_forced_emulation_test -vmx_pf_no_vpid_test -vmx_pf_invvpid_test -vmx_pf_vpid_test -vmx_basic_vid_test -vmx_eoi_virt_test -vmx_posted_interrupts_test"
>   arch = x86_64
>   groups = vmx
>   
>   [ept]
>   file = vmx.flat
> -extra_params = -cpu max,host-phys-bits,+vmx -m 2560 -append "ept_access*"
> +qemu_params = -cpu max,host-phys-bits,+vmx -m 2560 -append "ept_access*"
>   arch = x86_64
>   groups = vmx
>   
>   [vmx_eoi_bitmap_ioapic_scan]
>   file = vmx.flat
>   smp = 2
> -extra_params = -cpu max,+vmx -m 2048 -append vmx_eoi_bitmap_ioapic_scan_test
> +qemu_params = -cpu max,+vmx -m 2048 -append vmx_eoi_bitmap_ioapic_scan_test
>   arch = x86_64
>   groups = vmx
>   
>   [vmx_hlt_with_rvi_test]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append vmx_hlt_with_rvi_test
> +qemu_params = -cpu max,+vmx -append vmx_hlt_with_rvi_test
>   arch = x86_64
>   groups = vmx
>   timeout = 10
>   
>   [vmx_apicv_test]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append "apic_reg_virt_test virt_x2apic_mode_test vmx_basic_vid_test vmx_eoi_virt_test"
> +qemu_params = -cpu max,+vmx -append "apic_reg_virt_test virt_x2apic_mode_test vmx_basic_vid_test vmx_eoi_virt_test"
>   arch = x86_64
>   groups = vmx
>   timeout = 30
> @@ -354,7 +354,7 @@ timeout = 30
>   [vmx_posted_intr_test]
>   file = vmx.flat
>   smp = 2
> -extra_params = -cpu max,+vmx -append "vmx_posted_interrupts_test"
> +qemu_params = -cpu max,+vmx -append "vmx_posted_interrupts_test"
>   arch = x86_64
>   groups = vmx
>   timeout = 10
> @@ -362,14 +362,14 @@ timeout = 10
>   [vmx_apic_passthrough_thread]
>   file = vmx.flat
>   smp = 2
> -extra_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_thread_test
> +qemu_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_thread_test
>   arch = x86_64
>   groups = vmx
>   
>   [vmx_init_signal_test]
>   file = vmx.flat
>   smp = 2
> -extra_params = -cpu max,+vmx -m 2048 -append vmx_init_signal_test
> +qemu_params = -cpu max,+vmx -m 2048 -append vmx_init_signal_test
>   arch = x86_64
>   groups = vmx
>   timeout = 10
> @@ -377,62 +377,62 @@ timeout = 10
>   [vmx_sipi_signal_test]
>   file = vmx.flat
>   smp = 2
> -extra_params = -cpu max,+vmx -m 2048 -append vmx_sipi_signal_test
> +qemu_params = -cpu max,+vmx -m 2048 -append vmx_sipi_signal_test
>   arch = x86_64
>   groups = vmx
>   timeout = 10
>   
>   [vmx_apic_passthrough_tpr_threshold_test]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_tpr_threshold_test
> +qemu_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_tpr_threshold_test
>   arch = x86_64
>   groups = vmx
>   timeout = 10
>   
>   [vmx_vmcs_shadow_test]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append vmx_vmcs_shadow_test
> +qemu_params = -cpu max,+vmx -append vmx_vmcs_shadow_test
>   arch = x86_64
>   groups = vmx
>   timeout = 180
>   
>   [vmx_pf_exception_test]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append "vmx_pf_exception_test"
> +qemu_params = -cpu max,+vmx -append "vmx_pf_exception_test"
>   arch = x86_64
>   groups = vmx nested_exception
>   
>   [vmx_pf_exception_test_fep]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append "vmx_pf_exception_forced_emulation_test"
> +qemu_params = -cpu max,+vmx -append "vmx_pf_exception_forced_emulation_test"
>   arch = x86_64
>   groups = vmx nested_exception nodefault
>   timeout = 240
>   
>   [vmx_pf_vpid_test]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append "vmx_pf_vpid_test"
> +qemu_params = -cpu max,+vmx -append "vmx_pf_vpid_test"
>   arch = x86_64
>   groups = vmx nested_exception nodefault
>   timeout = 240
>   
>   [vmx_pf_invvpid_test]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append "vmx_pf_invvpid_test"
> +qemu_params = -cpu max,+vmx -append "vmx_pf_invvpid_test"
>   arch = x86_64
>   groups = vmx nested_exception nodefault
>   timeout = 240
>   
>   [vmx_pf_no_vpid_test]
>   file = vmx.flat
> -extra_params = -cpu max,+vmx -append "vmx_pf_no_vpid_test"
> +qemu_params = -cpu max,+vmx -append "vmx_pf_no_vpid_test"
>   arch = x86_64
>   groups = vmx nested_exception nodefault
>   timeout = 240
>   
>   [vmx_pf_exception_test_reduced_maxphyaddr]
>   file = vmx.flat
> -extra_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off,+vmx -append "vmx_pf_exception_test"
> +qemu_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off,+vmx -append "vmx_pf_exception_test"
>   arch = x86_64
>   groups = vmx nested_exception
>   check = /sys/module/kvm_intel/parameters/allow_smaller_maxphyaddr=Y
> @@ -444,31 +444,31 @@ arch = x86_64
>   [hyperv_synic]
>   file = hyperv_synic.flat
>   smp = 2
> -extra_params = -cpu host,hv_passthrough -device hyperv-testdev
> +qemu_params = -cpu host,hv_passthrough -device hyperv-testdev
>   groups = hyperv
>   
>   [hyperv_connections]
>   file = hyperv_connections.flat
>   smp = 2
> -extra_params = -cpu host,hv_passthrough -device hyperv-testdev
> +qemu_params = -cpu host,hv_passthrough -device hyperv-testdev
>   groups = hyperv
>   
>   [hyperv_stimer]
>   file = hyperv_stimer.flat
>   smp = 2
> -extra_params = -cpu host,hv_passthrough
> +qemu_params = -cpu host,hv_passthrough
>   groups = hyperv
>   
>   [hyperv_stimer_direct]
>   file = hyperv_stimer.flat
>   smp = 2
> -extra_params = -cpu host,hv_passthrough -append direct
> +qemu_params = -cpu host,hv_passthrough -append direct
>   groups = hyperv
>   
>   [hyperv_clock]
>   file = hyperv_clock.flat
>   smp = 2
> -extra_params = -cpu host,hv_passthrough
> +qemu_params = -cpu host,hv_passthrough
>   arch = x86_64
>   groups = hyperv
>   check = /sys/devices/system/clocksource/clocksource0/current_clocksource=tsc
> @@ -478,20 +478,20 @@ file = intel-iommu.flat
>   arch = x86_64
>   timeout = 30
>   smp = 4
> -extra_params = -M q35,kernel-irqchip=split -device intel-iommu,intremap=on,eim=off -device edu
> +qemu_params = -M q35,kernel-irqchip=split -device intel-iommu,intremap=on,eim=off -device edu
>   
>   [tsx-ctrl]
>   file = tsx-ctrl.flat
> -extra_params = -cpu max
> +qemu_params = -cpu max
>   groups = tsx-ctrl
>   
>   [intel_cet]
>   file = cet.flat
>   arch = x86_64
>   smp = 2
> -extra_params = -enable-kvm -m 2048 -cpu host
> +qemu_params = -enable-kvm -m 2048 -cpu host
>   
>   [lam]
>   file = lam.flat
>   arch = x86_64
> -extra_params = -enable-kvm -cpu max
> +qemu_params = -enable-kvm -cpu max

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 02/16] scripts: Add 'test_args' test definition parameter
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 02/16] scripts: Add 'test_args' test definition parameter Alexandru Elisei
  2025-05-07 15:58   ` Andrew Jones
@ 2025-05-14  3:16   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-14  3:16 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> kvm-unit-tests, on arm and arm64, is getting ready to support running all
> the test automatically under kvmtool. kvmtool has a different syntax for
> configuring and running a virtual machine, but what is common between
> kvmtool and qemu, and any other virtual machine manager that kvm-unit-tests
> might support in the future, is the test arguments that are passed to the
> main() function.
> 
> So add a new test definition parameter, 'test_args', that contains only the
> VMM-independent arguments that are passed to the main() function.
> 
> Suggested-by: Andrew Jones <andrew.jones@linux.dev>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   arm/unittests.cfg     | 94 ++++++++++++++++++++++++++-----------------
>   docs/unittests.txt    | 17 ++++++--
>   powerpc/unittests.cfg | 19 +++++----
>   riscv/unittests.cfg   |  2 +-
>   s390x/unittests.cfg   | 13 +++---
>   scripts/common.bash   |  8 +++-
>   scripts/runtime.bash  | 18 ++++++---
>   x86/unittests.cfg     | 92 ++++++++++++++++++++++++++----------------
>   8 files changed, 164 insertions(+), 99 deletions(-)
> 
> diff --git a/arm/unittests.cfg b/arm/unittests.cfg
> index 6c6f76b2fb52..a4192ed7e20b 100644
> --- a/arm/unittests.cfg
> +++ b/arm/unittests.cfg
> @@ -15,26 +15,27 @@
>   [selftest-setup]
>   file = selftest.flat
>   smp = 2
> -qemu_params = -m 256 -append 'setup smp=2 mem=256'
> +test_args = 'setup smp=2 mem=256'
> +qemu_params = -m 256
>   groups = selftest
>   
>   # Test vector setup and exception handling (kernel mode).
>   [selftest-vectors-kernel]
>   file = selftest.flat
> -qemu_params = -append 'vectors-kernel'
> +test_args = vectors-kernel
>   groups = selftest
>   
>   # Test vector setup and exception handling (user mode).
>   [selftest-vectors-user]
>   file = selftest.flat
> -qemu_params = -append 'vectors-user'
> +test_args = vectors-user
>   groups = selftest
>   
>   # Test SMP support
>   [selftest-smp]
>   file = selftest.flat
>   smp = $MAX_SMP
> -qemu_params = -append 'smp'
> +test_args = smp
>   groups = selftest
>   
>   # Test PCI emulation
> @@ -46,79 +47,81 @@ groups = pci
>   [pmu-cycle-counter]
>   file = pmu.flat
>   groups = pmu
> -qemu_params = -append 'cycle-counter 0'
> +test_args = "cycle-counter 0"
>   
>   [pmu-event-introspection]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-event-introspection'
> +test_args = pmu-event-introspection
>   
>   [pmu-event-counter-config]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-event-counter-config'
> +test_args = pmu-event-counter-config
>   
>   [pmu-basic-event-count]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-basic-event-count'
> +test_args = pmu-basic-event-count
>   
>   [pmu-mem-access]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-mem-access'
> +test_args = pmu-mem-access
>   
>   [pmu-mem-access-reliability]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-mem-access-reliability'
> +test_args = pmu-mem-access-reliability
>   
>   [pmu-sw-incr]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-sw-incr'
> +test_args = pmu-sw-incr
>   
>   [pmu-chained-counters]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-chained-counters'
> +test_args = pmu-chained-counters
>   
>   [pmu-chained-sw-incr]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-chained-sw-incr'
> +test_args = pmu-chained-sw-incr
>   
>   [pmu-chain-promotion]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-chain-promotion'
> +test_args = pmu-chain-promotion
>   
>   [pmu-overflow-interrupt]
>   file = pmu.flat
>   groups = pmu
>   arch = arm64
> -qemu_params = -append 'pmu-overflow-interrupt'
> +test_args = pmu-overflow-interrupt
>   
>   # Test PMU support (TCG) with -icount IPC=1
>   #[pmu-tcg-icount-1]
>   #file = pmu.flat
> -#qemu_params = -icount 0 -append 'cycle-counter 1'
> +#test_args = "cycle-counter 1"
> +#qemu_params = -icount 0
>   #groups = pmu
>   #accel = tcg
>   
>   # Test PMU support (TCG) with -icount IPC=256
>   #[pmu-tcg-icount-256]
>   #file = pmu.flat
> -#qemu_params = -icount 8 -append 'cycle-counter 256'
> +#test_args = "cycle-counter 256"
> +#qemu_params = -icount 8
>   #groups = pmu
>   #accel = tcg
>   
> @@ -126,77 +129,89 @@ qemu_params = -append 'pmu-overflow-interrupt'
>   [gicv2-ipi]
>   file = gic.flat
>   smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> -qemu_params = -machine gic-version=2 -append 'ipi'
> +test_args = ipi
> +qemu_params = -machine gic-version=2
>   groups = gic
>   
>   [gicv2-mmio]
>   file = gic.flat
>   smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> -qemu_params = -machine gic-version=2 -append 'mmio'
> +test_args = mmio
> +qemu_params = -machine gic-version=2
>   groups = gic
>   
>   [gicv2-mmio-up]
>   file = gic.flat
>   smp = 1
> -qemu_params = -machine gic-version=2 -append 'mmio'
> +test_args = mmio
> +qemu_params = -machine gic-version=2
>   groups = gic
>   
>   [gicv2-mmio-3p]
>   file = gic.flat
>   smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
> -qemu_params = -machine gic-version=2 -append 'mmio'
> +test_args = mmio
> +qemu_params = -machine gic-version=2
>   groups = gic
>   
>   [gicv3-ipi]
>   file = gic.flat
>   smp = $MAX_SMP
> -qemu_params = -machine gic-version=3 -append 'ipi'
> +test_args = ipi
> +qemu_params = -machine gic-version=3
>   groups = gic
>   
>   [gicv2-active]
>   file = gic.flat
>   smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
> -qemu_params = -machine gic-version=2 -append 'active'
> +test_args = active
> +qemu_params = -machine gic-version=2
>   groups = gic
>   
>   [gicv3-active]
>   file = gic.flat
>   smp = $MAX_SMP
> -qemu_params = -machine gic-version=3 -append 'active'
> +test_args = active
> +qemu_params = -machine gic-version=3
>   groups = gic
>   
>   [its-introspection]
>   file = gic.flat
>   smp = $MAX_SMP
> -qemu_params = -machine gic-version=3 -append 'its-introspection'
> +test_args = its-introspection
> +qemu_params = -machine gic-version=3
>   groups = its
>   arch = arm64
>   
>   [its-trigger]
>   file = gic.flat
>   smp = $MAX_SMP
> -qemu_params = -machine gic-version=3 -append 'its-trigger'
> +test_args = its-trigger
> +qemu_params = -machine gic-version=3
>   groups = its
>   arch = arm64
>   
>   [its-migration]
>   file = gic.flat
>   smp = $MAX_SMP
> -qemu_params = -machine gic-version=3 -append 'its-migration'
> +test_args = its-migration
> +qemu_params = -machine gic-version=3
>   groups = its migration
>   arch = arm64
>   
>   [its-pending-migration]
>   file = gic.flat
>   smp = $MAX_SMP
> -qemu_params = -machine gic-version=3 -append 'its-pending-migration'
> +test_args = its-pending-migration
> +qemu_params = -machine gic-version=3
>   groups = its migration
>   arch = arm64
>   
>   [its-migrate-unmapped-collection]
>   file = gic.flat
>   smp = $MAX_SMP
> -qemu_params = -machine gic-version=3 -append 'its-migrate-unmapped-collection'
> +test_args = its-migrate-unmapped-collection
> +qemu_params = -machine gic-version=3
>   groups = its migration
>   arch = arm64
>   
> @@ -231,37 +246,37 @@ groups = cache
>   [debug-bp]
>   file = debug.flat
>   arch = arm64
> -qemu_params = -append 'bp'
> +test_args = bp
>   groups = debug
>   
>   [debug-bp-migration]
>   file = debug.flat
>   arch = arm64
> -qemu_params = -append 'bp-migration'
> +test_args = bp-migration
>   groups = debug migration
>   
>   [debug-wp]
>   file = debug.flat
>   arch = arm64
> -qemu_params = -append 'wp'
> +test_args = wp
>   groups = debug
>   
>   [debug-wp-migration]
>   file = debug.flat
>   arch = arm64
> -qemu_params = -append 'wp-migration'
> +test_args = wp-migration
>   groups = debug migration
>   
>   [debug-sstep]
>   file = debug.flat
>   arch = arm64
> -qemu_params = -append 'ss'
> +test_args = ss
>   groups = debug
>   
>   [debug-sstep-migration]
>   file = debug.flat
>   arch = arm64
> -qemu_params = -append 'ss-migration'
> +test_args = ss-migration
>   groups = debug migration
>   
>   # FPU/SIMD test
> @@ -276,17 +291,20 @@ arch = arm64
>   [mte-sync]
>   file = mte.flat
>   groups = mte
> -qemu_params = -machine mte=on -append 'sync'
> +test_args=sync
> +qemu_params = -machine mte=on
>   arch = arm64
>   
>   [mte-async]
>   file = mte.flat
>   groups = mte
> -qemu_params = -machine mte=on -append 'async'
> +test_args=async
> +qemu_params = -machine mte=on
>   arch = arm64
>   
>   [mte-asymm]
>   file = mte.flat
>   groups = mte
> -qemu_params = -machine mte=on -append 'asymm'
> +test_args=asymm
> +qemu_params = -machine mte=on
>   arch = arm64
> diff --git a/docs/unittests.txt b/docs/unittests.txt
> index 3d19fd70953f..6eb315618dbd 100644
> --- a/docs/unittests.txt
> +++ b/docs/unittests.txt
> @@ -56,13 +56,22 @@ smp = <number>
>   Optional, the number of processors created in the machine to run the test.
>   Defaults to 1. $MAX_SMP can be used to specify the maximum supported.
>   
> +test_args
> +---------
> +test_args = "..."
> +
> +Optional, will be used to pass arguments into the test case argv. If multiple,
> +space separated, arguments need to be passed to a test, wrap them in quotes.
> +Backticks can be used to pass the result of shell commands, for example:
> +
> +test_args = "10000000 `date +%s`"
> +
>   qemu_params
>   ------------
> -These are extra parameters supplied to the QEMU process. -append '...' can
> -be used to pass arguments into the test case argv. Multiple parameters can
> -be added, for example:
> +These are extra parameters supplied to the QEMU process. Multiple parameters
> +can be added, for example:
>   
> -qemu_params = -m 256 -append 'smp=2'
> +qemu_params = -m 256 -machine pit=off
>   
>   extra_params
>   ------------
> diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg
> index 5097911e4bf3..2dd32edfa1ae 100644
> --- a/powerpc/unittests.cfg
> +++ b/powerpc/unittests.cfg
> @@ -15,7 +15,8 @@
>   [selftest-setup]
>   file = selftest.elf
>   smp = 2
> -qemu_params = -m 1g -append 'setup smp=2 mem=1024'
> +test_args = 'setup smp=2 mem=1024'
> +qemu_params = -m 1g
>   groups = selftest
>   
>   [selftest-migration]
> @@ -27,7 +28,7 @@ groups = selftest migration
>   file = selftest-migration.elf
>   machine = pseries
>   groups = selftest migration
> -qemu_params = -append "skip"
> +test_args = "skip"
>   
>   [migration-memory]
>   file = memory-verify.elf
> @@ -46,20 +47,21 @@ machine = pseries
>   file = rtas.elf
>   machine = pseries
>   timeout = 5
> -qemu_params = -append "get-time-of-day date=$(date +%s)"
> +test_args = "get-time-of-day date=$(date +%s)"
>   groups = rtas
>   
>   [rtas-get-time-of-day-base]
>   file = rtas.elf
>   machine = pseries
>   timeout = 5
> -qemu_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)"
> +test_args = "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)"
> +qemu_params = -rtc base="2006-06-17"
>   groups = rtas
>   
>   [rtas-set-time-of-day]
>   file = rtas.elf
>   machine = pseries
> -qemu_params = -append "set-time-of-day"
> +test_args = "set-time-of-day"
>   timeout = 5
>   groups = rtas
>   
> @@ -94,7 +96,7 @@ smp = 2
>   [atomics-migration]
>   file = atomics.elf
>   machine = pseries
> -qemu_params = -append "migration -m"
> +test_args = "migration -m"
>   groups = migration
>   
>   [timebase]
> @@ -110,7 +112,8 @@ file = tm.elf
>   machine = pseries
>   accel = kvm
>   smp = 2,threads=2
> -qemu_params = -machine cap-htm=on -append "h_cede_tm"
> +test_args = "h_cede_tm"
> +qemu_params = -machine cap-htm=on
>   groups = h_cede_tm
>   
>   [sprs]
> @@ -119,7 +122,7 @@ file = sprs.elf
>   [sprs-migration]
>   file = sprs.elf
>   machine = pseries
> -qemu_params = -append '-w'
> +test_args = '-w'
>   groups = migration
>   
>   [sieve]
> diff --git a/riscv/unittests.cfg b/riscv/unittests.cfg
> index 5b31047f75c7..8a98ac723c2c 100644
> --- a/riscv/unittests.cfg
> +++ b/riscv/unittests.cfg
> @@ -10,7 +10,7 @@
>   [selftest]
>   file = selftest.flat
>   smp = $MAX_SMP
> -qemu_params = -append 'foo bar baz'
> +test_args = 'foo bar baz'
>   groups = selftest
>   
>   # Set $FIRMWARE_OVERRIDE to /path/to/firmware to select the SBI implementation.
> diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
> index 1e129fef3c38..ed4d069ece38 100644
> --- a/s390x/unittests.cfg
> +++ b/s390x/unittests.cfg
> @@ -10,7 +10,7 @@
>   file = selftest.elf
>   groups = selftest
>   # please keep the kernel cmdline in sync with $(TEST_DIR)/selftest.parmfile
> -qemu_params = -append 'test 123'
> +test_args = 'test 123'
>   
>   [selftest-migration]
>   file = selftest-migration.elf
> @@ -22,7 +22,7 @@ accel = kvm
>   [selftest-migration-skip]
>   file = selftest-migration.elf
>   groups = selftest migration
> -qemu_params = -append "skip"
> +test_args = "skip"
>   
>   # This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream
>   [migration-memory]
> @@ -214,13 +214,13 @@ smp = 2
>   [migration-skey-sequential]
>   file = migration-skey.elf
>   groups = migration
> -qemu_params = -append '--sequential'
> +test_args = '--sequential'
>   
>   [migration-skey-parallel]
>   file = migration-skey.elf
>   smp = 2
>   groups = migration
> -qemu_params = -append '--parallel'
> +test_args = '--parallel'
>   
>   [execute]
>   file = ex.elf
> @@ -252,12 +252,13 @@ file = topology.elf
>   
>   [topology-2]
>   file = topology.elf
> -qemu_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248  -append '-sockets 31 -cores 8'
> +test_args = '-sockets 31 -cores 8'
> +qemu_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248
>   
>   [topology-3]
>   file = topology.elf
> +test_args = '-drawers 2 -books 2 -sockets 2 -cores 16'
>   qemu_params = """-cpu max,ctop=on -smp cpus=1,drawers=2,books=2,sockets=2,cores=16,maxcpus=128 \
> --append '-drawers 2 -books 2 -sockets 2 -cores 16' \
>   -device max-s390x-cpu,core-id=31,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
>   -device max-s390x-cpu,core-id=11,drawer-id=0,book-id=0,socket-id=0,entitlement=high,dedicated=true \
>   -device max-s390x-cpu,core-id=95,drawer-id=0,book-id=0,socket-id=0,entitlement=medium,dedicated=false \
> diff --git a/scripts/common.bash b/scripts/common.bash
> index bd7c82f1adda..9deb87d4050d 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -7,6 +7,7 @@ function for_each_unittest()
>   	local testname
>   	local smp
>   	local kernel
> +	local test_args
>   	local opts
>   	local groups
>   	local arch
> @@ -22,11 +23,12 @@ function for_each_unittest()
>   		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
>   			rematch=${BASH_REMATCH[1]}
>   			if [ -n "${testname}" ]; then
> -				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
> +				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
>   			fi
>   			testname=$rematch
>   			smp=1
>   			kernel=""
> +			test_args=""
>   			opts=""
>   			groups=""
>   			arch=""
> @@ -38,6 +40,8 @@ function for_each_unittest()
>   			kernel=$TEST_DIR/${BASH_REMATCH[1]}
>   		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
>   			smp=${BASH_REMATCH[1]}
> +		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
> +			test_args=${BASH_REMATCH[1]}
>   		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
>   			opts=${BASH_REMATCH[2]}$'\n'
>   			while read -r -u $fd; do
> @@ -71,7 +75,7 @@ function for_each_unittest()
>   		fi
>   	done
>   	if [ -n "${testname}" ]; then
> -		$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
> +		$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
>   	fi
>   	exec {fd}<&-
>   }
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 400e8a082528..06cc58e79b69 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -80,12 +80,18 @@ function run()
>       local groups="$2"
>       local smp="$3"
>       local kernel="$4"
> -    local opts="$5"
> -    local arch="$6"
> -    local machine="$7"
> -    local check="${CHECK:-$8}"
> -    local accel="$9"
> -    local timeout="${10:-$TIMEOUT}" # unittests.cfg overrides the default
> +    local test_args="$5"
> +    local opts="$6"
> +    local arch="$7"
> +    local machine="$8"
> +    local check="${CHECK:-$9}"
> +    local accel="${10}"
> +    local timeout="${11:-$TIMEOUT}" # unittests.cfg overrides the default
> +
> +    # If $test_args is empty, qemu will interpret the first option after -append
> +    # as a kernel parameter instead of a qemu option, so make sure the -append
> +    # option is used only if $test_args is not empy.
> +    [ -n "$test_args" ] && opts="-append $test_args $opts"
>   
>       if [ "${CONFIG_EFI}" == "y" ]; then
>           kernel=${kernel/%.flat/.efi}
> diff --git a/x86/unittests.cfg b/x86/unittests.cfg
> index a356f486eaec..3effddfe4207 100644
> --- a/x86/unittests.cfg
> +++ b/x86/unittests.cfg
> @@ -58,27 +58,27 @@ smp = 3
>   
>   [vmexit_cpuid]
>   file = vmexit.flat
> -qemu_params = -append 'cpuid'
> +test_args = 'cpuid'
>   groups = vmexit
>   
>   [vmexit_vmcall]
>   file = vmexit.flat
> -qemu_params = -append 'vmcall'
> +test_args = 'vmcall'
>   groups = vmexit
>   
>   [vmexit_mov_from_cr8]
>   file = vmexit.flat
> -qemu_params = -append 'mov_from_cr8'
> +test_args = 'mov_from_cr8'
>   groups = vmexit
>   
>   [vmexit_mov_to_cr8]
>   file = vmexit.flat
> -qemu_params = -append 'mov_to_cr8'
> +test_args = 'mov_to_cr8'
>   groups = vmexit
>   
>   [vmexit_inl_pmtimer]
>   file = vmexit.flat
> -qemu_params = -append 'inl_from_pmtimer'
> +test_args = 'inl_from_pmtimer'
>   groups = vmexit
>   
>   # To allow IPIs to be accelerated by SVM AVIC when the feature is available and
> @@ -87,40 +87,43 @@ groups = vmexit
>   [vmexit_ipi]
>   file = vmexit.flat
>   smp = 2
> -qemu_params = -machine pit=off -append 'ipi'
> +test_args = 'ipi'
> +qemu_params = -machine pit=off
>   groups = vmexit
>   
>   [vmexit_ipi_halt]
>   file = vmexit.flat
>   smp = 2
> -qemu_params = -append 'ipi_halt'
> +test_args = 'ipi_halt'
>   groups = vmexit
>   
>   [vmexit_ple_round_robin]
>   file = vmexit.flat
> -qemu_params = -append 'ple_round_robin'
> +test_args = 'ple_round_robin'
>   groups = vmexit
>   
>   [vmexit_tscdeadline]
>   file = vmexit.flat
>   groups = vmexit
> -qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline
> +test_args = tscdeadline
> +qemu_params = -cpu qemu64,+x2apic,+tsc-deadline
>   
>   [vmexit_tscdeadline_immed]
>   file = vmexit.flat
>   groups = vmexit
> -qemu_params = -cpu qemu64,+x2apic,+tsc-deadline -append tscdeadline_immed
> +test_args = tscdeadline_immed
> +qemu_params = -cpu qemu64,+x2apic,+tsc-deadline
>   
>   [vmexit_cr0_wp]
>   file = vmexit.flat
>   smp = 2
> -qemu_params = -append 'toggle_cr0_wp'
> +test_args = 'toggle_cr0_wp'
>   groups = vmexit
>   
>   [vmexit_cr4_pge]
>   file = vmexit.flat
>   smp = 2
> -qemu_params = -append 'toggle_cr4_pge'
> +test_args = 'toggle_cr4_pge'
>   groups = vmexit
>   
>   [access]
> @@ -131,7 +134,8 @@ qemu_params = -cpu max,host-phys-bits
>   [access_fep]
>   file = access_test.flat
>   arch = x86_64
> -qemu_params = -cpu max,host-phys-bits -append force_emulation
> +test_args = force_emulation
> +qemu_params = -cpu max,host-phys-bits
>   groups = nodefault
>   timeout = 240
>   
> @@ -256,13 +260,15 @@ arch = x86_64
>   [svm]
>   file = svm.flat
>   smp = 2
> -qemu_params = -cpu max,+svm -m 4g -append "-pause_filter_test"
> +test_args = "-pause_filter_test"
> +qemu_params = -cpu max,+svm -m 4g
>   arch = x86_64
>   groups = svm
>   
>   [svm_pause_filter]
>   file = svm.flat
> -qemu_params = -cpu max,+svm -overcommit cpu-pm=on -m 4g -append pause_filter_test
> +test_args = pause_filter_test
> +qemu_params = -cpu max,+svm -overcommit cpu-pm=on -m 4g
>   arch = x86_64
>   groups = svm
>   
> @@ -285,7 +291,7 @@ groups = tasks
>   [kvmclock_test]
>   file = kvmclock_test.flat
>   smp = 2
> -qemu_params = --append "10000000 `date +%s`"
> +test_args = "10000000 `date +%s`"
>   
>   [pcid-enabled]
>   file = pcid.flat
> @@ -320,33 +326,38 @@ qemu_params = -cpu max,host-phys-bits
>   
>   [vmx]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test -apic_reg_virt_test -virt_x2apic_mode_test -vmx_pf_exception_test -vmx_pf_exception_forced_emulation_test -vmx_pf_no_vpid_test -vmx_pf_invvpid_test -vmx_pf_vpid_test -vmx_basic_vid_test -vmx_eoi_virt_test -vmx_posted_interrupts_test"
> +test_args = "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test -vmx_init_signal_test -vmx_apic_passthrough_tpr_threshold_test -apic_reg_virt_test -virt_x2apic_mode_test -vmx_pf_exception_test -vmx_pf_exception_forced_emulation_test -vmx_pf_no_vpid_test -vmx_pf_invvpid_test -vmx_pf_vpid_test -vmx_basic_vid_test -vmx_eoi_virt_test -vmx_posted_interrupts_test"
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx
>   
>   [ept]
>   file = vmx.flat
> -qemu_params = -cpu max,host-phys-bits,+vmx -m 2560 -append "ept_access*"
> +test_args = "ept_access*"
> +qemu_params = -cpu max,host-phys-bits,+vmx -m 2560
>   arch = x86_64
>   groups = vmx
>   
>   [vmx_eoi_bitmap_ioapic_scan]
>   file = vmx.flat
>   smp = 2
> -qemu_params = -cpu max,+vmx -m 2048 -append vmx_eoi_bitmap_ioapic_scan_test
> +test_args = vmx_eoi_bitmap_ioapic_scan_test
> +qemu_params = -cpu max,+vmx -m 2048
>   arch = x86_64
>   groups = vmx
>   
>   [vmx_hlt_with_rvi_test]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append vmx_hlt_with_rvi_test
> +test_args = vmx_hlt_with_rvi_test
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx
>   timeout = 10
>   
>   [vmx_apicv_test]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append "apic_reg_virt_test virt_x2apic_mode_test vmx_basic_vid_test vmx_eoi_virt_test"
> +test_args = "apic_reg_virt_test virt_x2apic_mode_test vmx_basic_vid_test vmx_eoi_virt_test"
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx
>   timeout = 30
> @@ -354,7 +365,8 @@ timeout = 30
>   [vmx_posted_intr_test]
>   file = vmx.flat
>   smp = 2
> -qemu_params = -cpu max,+vmx -append "vmx_posted_interrupts_test"
> +test_args = "vmx_posted_interrupts_test"
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx
>   timeout = 10
> @@ -362,14 +374,16 @@ timeout = 10
>   [vmx_apic_passthrough_thread]
>   file = vmx.flat
>   smp = 2
> -qemu_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_thread_test
> +test_args = vmx_apic_passthrough_thread_test
> +qemu_params = -cpu max,+vmx -m 2048
>   arch = x86_64
>   groups = vmx
>   
>   [vmx_init_signal_test]
>   file = vmx.flat
>   smp = 2
> -qemu_params = -cpu max,+vmx -m 2048 -append vmx_init_signal_test
> +test_args = vmx_init_signal_test
> +qemu_params = -cpu max,+vmx -m 2048
>   arch = x86_64
>   groups = vmx
>   timeout = 10
> @@ -377,62 +391,71 @@ timeout = 10
>   [vmx_sipi_signal_test]
>   file = vmx.flat
>   smp = 2
> -qemu_params = -cpu max,+vmx -m 2048 -append vmx_sipi_signal_test
> +test_args = vmx_sipi_signal_test
> +qemu_params = -cpu max,+vmx -m 2048
>   arch = x86_64
>   groups = vmx
>   timeout = 10
>   
>   [vmx_apic_passthrough_tpr_threshold_test]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -m 2048 -append vmx_apic_passthrough_tpr_threshold_test
> +test_args = vmx_apic_passthrough_tpr_threshold_test
> +qemu_params = -cpu max,+vmx -m 2048
>   arch = x86_64
>   groups = vmx
>   timeout = 10
>   
>   [vmx_vmcs_shadow_test]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append vmx_vmcs_shadow_test
> +test_args = vmx_vmcs_shadow_test
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx
>   timeout = 180
>   
>   [vmx_pf_exception_test]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append "vmx_pf_exception_test"
> +test_args = "vmx_pf_exception_test"
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx nested_exception
>   
>   [vmx_pf_exception_test_fep]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append "vmx_pf_exception_forced_emulation_test"
> +test_args = "vmx_pf_exception_forced_emulation_test"
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx nested_exception nodefault
>   timeout = 240
>   
>   [vmx_pf_vpid_test]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append "vmx_pf_vpid_test"
> +test_args = "vmx_pf_vpid_test"
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx nested_exception nodefault
>   timeout = 240
>   
>   [vmx_pf_invvpid_test]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append "vmx_pf_invvpid_test"
> +test_args = "vmx_pf_invvpid_test"
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx nested_exception nodefault
>   timeout = 240
>   
>   [vmx_pf_no_vpid_test]
>   file = vmx.flat
> -qemu_params = -cpu max,+vmx -append "vmx_pf_no_vpid_test"
> +test_args = "vmx_pf_no_vpid_test"
> +qemu_params = -cpu max,+vmx
>   arch = x86_64
>   groups = vmx nested_exception nodefault
>   timeout = 240
>   
>   [vmx_pf_exception_test_reduced_maxphyaddr]
>   file = vmx.flat
> -qemu_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off,+vmx -append "vmx_pf_exception_test"
> +test_args = "vmx_pf_exception_test"
> +qemu_params = -cpu IvyBridge,phys-bits=36,host-phys-bits=off,+vmx
>   arch = x86_64
>   groups = vmx nested_exception
>   check = /sys/module/kvm_intel/parameters/allow_smaller_maxphyaddr=Y
> @@ -462,7 +485,8 @@ groups = hyperv
>   [hyperv_stimer_direct]
>   file = hyperv_stimer.flat
>   smp = 2
> -qemu_params = -cpu host,hv_passthrough -append direct
> +test_args = direct
> +qemu_params = -cpu host,hv_passthrough
>   groups = hyperv
>   
>   [hyperv_clock]

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 04/16] run_tests.sh: Document --probe-maxsmp argument
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 04/16] run_tests.sh: Document --probe-maxsmp argument Alexandru Elisei
@ 2025-05-14  3:29   ` Shaoqin Huang
  0 siblings, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-14  3:29 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> Commit 5dd20ec76ea63 ("runtime: Update MAX_SMP probe") added the
> --probe-maxmp argument, but the help message for run_tests.sh wasn't
> updated. Document --probe-maxsmp.
> 
> Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   run_tests.sh | 17 +++++++++--------
>   1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/run_tests.sh b/run_tests.sh
> index 152323ffc8a2..f30b6dbd131c 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -17,14 +17,15 @@ cat <<EOF
>   
>   Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t] [-l]
>   
> -    -h, --help      Output this help text
> -    -v, --verbose   Enables verbose mode
> -    -a, --all       Run all tests, including those flagged as 'nodefault'
> -                    and those guarded by errata.
> -    -g, --group     Only execute tests in the given group
> -    -j, --parallel  Execute tests in parallel
> -    -t, --tap13     Output test results in TAP format
> -    -l, --list      Only output all tests list
> +    -h, --help          Output this help text
> +    -v, --verbose       Enables verbose mode
> +    -a, --all           Run all tests, including those flagged as 'nodefault'
> +                        and those guarded by errata.
> +    -g, --group         Only execute tests in the given group
> +    -j, --parallel      Execute tests in parallel
> +    -t, --tap13         Output test results in TAP format
> +    -l, --list          Only output all tests list
> +        --probe-maxsmp  Update the maximum number of VCPUs supported by host
>   
>   Set the environment variable QEMU=/path/to/qemu-system-ARCH to
>   specify the appropriate qemu binary for ARCH-run.

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 05/16] scripts: Document environment variables
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 05/16] scripts: Document environment variables Alexandru Elisei
@ 2025-05-14  3:36   ` Shaoqin Huang
  0 siblings, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-14  3:36 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara, Andrew Jones



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> Document the environment variables that influence how a test is executed
> by the run_tests.sh test runner.
> 
> Suggested-by: Andrew Jones <drjones@redhat.com>
> Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   docs/unittests.txt |  5 ++++-
>   run_tests.sh       | 12 +++++++++---
>   2 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/docs/unittests.txt b/docs/unittests.txt
> index 6eb315618dbd..ea0da959f008 100644
> --- a/docs/unittests.txt
> +++ b/docs/unittests.txt
> @@ -102,7 +102,8 @@ timeout
>   -------
>   timeout = <duration>
>   
> -Optional timeout in seconds, after which the test will be killed and fail.
> +Optional timeout in seconds, after which the test will be killed and fail. Can
> +be overwritten with the TIMEOUT=<duration> environment variable.
>   
>   check
>   -----
> @@ -113,3 +114,5 @@ can contain multiple files to check separated by a space, but each check
>   parameter needs to be of the form <path>=<value>
>   
>   The path and value cannot contain space, =, or shell wildcard characters.
> +
> +Can be overwritten with the CHECK environment variable with the same syntax.
> diff --git a/run_tests.sh b/run_tests.sh
> index f30b6dbd131c..dd9d27377905 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -27,9 +27,15 @@ Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS] [-t] [-l]
>       -l, --list          Only output all tests list
>           --probe-maxsmp  Update the maximum number of VCPUs supported by host
>   
> -Set the environment variable QEMU=/path/to/qemu-system-ARCH to
> -specify the appropriate qemu binary for ARCH-run.
> -
> +The following environment variables are used:
> +
> +    QEMU            Path to QEMU binary for ARCH-run
> +    ACCEL           QEMU accelerator to use, e.g. 'kvm', 'hvf' or 'tcg'
> +    ACCEL_PROPS     Extra argument(s) to ACCEL
> +    MACHINE         QEMU machine type
> +    TIMEOUT         Timeout duration for the timeout(1) command
> +    CHECK           Overwrites the 'check' unit test parameter (see
> +                    docs/unittests.txt)
>   EOF
>   }
>   

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu Alexandru Elisei
  2025-05-07 16:10   ` Andrew Jones
@ 2025-05-14  7:49   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-14  7:49 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> Arm and arm64 support running the tests under kvmtool. kvmtool has a
> different command line syntax for configuring and running a virtual
> machine, and the automated scripts know only how to use qemu.
> 
> One issue with that is even though the tests have been configured for
> kvmtool (with ./configure --target=kvmtool), the scripts will use qemu to
> run the tests, and without looking at the logs there is no indication that
> the tests haven't been run with kvmtool, as configured.
> 
> Another issue is that kvmtool uses a different address for the UART and
> when running the tests with qemu via the scripts, this warning is
> displayed:
> 
> WARNING: early print support may not work. Found uart at 0x9000000, but early base is 0x1000000.
> 
> which might trip up an unsuspected user.
> 
> There are four different ways to run a test using the test infrastructure:
> with run_tests.sh, by invoking arm/run or arm/efi/run with the correct
> parameters (only the arm directory is mentioned here because the tests can
> be configured for kvmtool only on arm and arm64), and by creating
> standalone tests.
> 
> run_tests.sh ends up execuing either arm/run or arm/efi/run, so add a check
> to these two scripts for the test target, and refuse to run the test if
> kvm-unit-tests has been configured for kvmtool.
> 
> mkstandalone.sh also executes arm/run or arm/efi run, but the usual use
> case for standalone tests is to compile them on one machine, and then to
> run them on a different machine. This two step process can be time
> consuming, so save the user time (and frustration!) and add a check
> directly to mkstandalone.sh.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   arm/efi/run             |  3 +++
>   arm/run                 |  4 ++++
>   scripts/mkstandalone.sh |  3 +++
>   scripts/vmm.bash        | 14 ++++++++++++++
>   4 files changed, 24 insertions(+)
>   create mode 100644 scripts/vmm.bash
> 
> diff --git a/arm/efi/run b/arm/efi/run
> index 8f41fc02df31..53d71297cc52 100755
> --- a/arm/efi/run
> +++ b/arm/efi/run
> @@ -11,6 +11,9 @@ if [ ! -f config.mak ]; then
>   fi
>   source config.mak
>   source scripts/arch-run.bash
> +source scripts/vmm.bash
> +
> +check_vmm_supported
>   
>   if [ -f /usr/share/qemu-efi-aarch64/QEMU_EFI.fd ]; then
>   	DEFAULT_UEFI=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
> diff --git a/arm/run b/arm/run
> index ef58558231b7..56562ed1628f 100755
> --- a/arm/run
> +++ b/arm/run
> @@ -7,7 +7,11 @@ if [ -z "$KUT_STANDALONE" ]; then
>   	fi
>   	source config.mak
>   	source scripts/arch-run.bash
> +	source scripts/vmm.bash
>   fi
> +
> +check_vmm_supported
> +
>   qemu_cpu="$TARGET_CPU"
>   
>   if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
> diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
> index c4ba81f18935..4f666cefe076 100755
> --- a/scripts/mkstandalone.sh
> +++ b/scripts/mkstandalone.sh
> @@ -6,6 +6,9 @@ if [ ! -f config.mak ]; then
>   fi
>   source config.mak
>   source scripts/common.bash
> +source scripts/vmm.bash
> +
> +check_vmm_supported
>   
>   temp_file ()
>   {
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> new file mode 100644
> index 000000000000..39325858c6b3
> --- /dev/null
> +++ b/scripts/vmm.bash
> @@ -0,0 +1,14 @@
> +source config.mak
> +
> +function check_vmm_supported()
> +{
> +	case "$TARGET" in
> +	qemu)
> +		return 0
> +		;;
> +	*)
> +		echo "$0 does not support target '$TARGET'"
> +		exit 2
> +		;;
> +	esac
> +}

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 07/16] scripts: Use an associative array for qemu argument names
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 07/16] scripts: Use an associative array for qemu argument names Alexandru Elisei
  2025-05-07 16:17   ` Andrew Jones
@ 2025-05-14  8:02   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-14  8:02 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> Move away from hardcoded qemu arguments and use instead an associative
> array to get the needed arguments. This paves the way for adding kvmtool
> support to the scripts, which has a different syntax for the same VM
> configuration parameters.
> 
> Suggested-by: Andrew Jones <andrew.jones@linux.dev>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   scripts/common.bash  | 10 +++++++---
>   scripts/runtime.bash |  7 +------
>   scripts/vmm.bash     |  7 +++++++
>   3 files changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/scripts/common.bash b/scripts/common.bash
> index 9deb87d4050d..649f1c737617 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -1,4 +1,5 @@
>   source config.mak
> +source scripts/vmm.bash
>   
>   function for_each_unittest()
>   {
> @@ -26,8 +27,11 @@ function for_each_unittest()
>   				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$test_args" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
>   			fi
>   			testname=$rematch
> -			smp=1
> +			smp="${vmm_opts[$TARGET:nr_cpus]} 1"
>   			kernel=""
> +			# Intentionally don't use -append if test_args is empty
> +			# because qemu interprets the first argument after
> +			# -append as a kernel parameter.
>   			test_args=""
>   			opts=""
>   			groups=""
> @@ -39,9 +43,9 @@ function for_each_unittest()
>   		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
>   			kernel=$TEST_DIR/${BASH_REMATCH[1]}
>   		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
> -			smp=${BASH_REMATCH[1]}
> +			smp="${vmm_opts[$TARGET:nr_cpus]} ${BASH_REMATCH[1]}"
>   		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
> -			test_args=${BASH_REMATCH[1]}
> +			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
>   		elif [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
>   			opts=${BASH_REMATCH[2]}$'\n'
>   			while read -r -u $fd; do
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 06cc58e79b69..86d8a2cd8528 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -34,7 +34,7 @@ premature_failure()
>   get_cmdline()
>   {
>       local kernel=$1
> -    echo "TESTNAME=$testname TIMEOUT=$timeout MACHINE=$machine ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
> +    echo "TESTNAME=$testname TIMEOUT=$timeout MACHINE=$machine ACCEL=$accel $RUNTIME_arch_run $kernel $smp $test_args $opts"
>   }
>   
>   skip_nodefault()
> @@ -88,11 +88,6 @@ function run()
>       local accel="${10}"
>       local timeout="${11:-$TIMEOUT}" # unittests.cfg overrides the default
>   
> -    # If $test_args is empty, qemu will interpret the first option after -append
> -    # as a kernel parameter instead of a qemu option, so make sure the -append
> -    # option is used only if $test_args is not empy.
> -    [ -n "$test_args" ] && opts="-append $test_args $opts"
> -
>       if [ "${CONFIG_EFI}" == "y" ]; then
>           kernel=${kernel/%.flat/.efi}
>       fi
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index 39325858c6b3..b02055a5c0b6 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -1,5 +1,12 @@
>   source config.mak
>   
> +declare -A vmm_opts=(
> +	[qemu:nr_cpus]='-smp'
> +	[qemu:kernel]='-kernel'
> +	[qemu:args]='-append'
> +	[qemu:initrd]='-initrd'
> +)
> +
>   function check_vmm_supported()
>   {
>   	case "$TARGET" in

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 11/16] scripts: Add KVMTOOL environment variable for kvmtool binary path
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 11/16] scripts: Add KVMTOOL environment variable for kvmtool binary path Alexandru Elisei
  2025-05-07 16:45   ` Andrew Jones
@ 2025-05-19  8:13   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-19  8:13 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> kvmtool is often used for prototyping new features, and a developer might
> not want to install it system-wide. Add a KVMTOOL environment variable to
> make it easier for tests to use a binary not in $PATH.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   run_tests.sh          | 1 +
>   scripts/arch-run.bash | 3 ++-
>   2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/run_tests.sh b/run_tests.sh
> index dd9d27377905..150a06a91064 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -36,6 +36,7 @@ The following environment variables are used:
>       TIMEOUT         Timeout duration for the timeout(1) command
>       CHECK           Overwrites the 'check' unit test parameter (see
>                       docs/unittests.txt)
> +    KVMTOOL         Path to kvmtool binary for ARCH-run
>   EOF
>   }
>   
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index 8cf67e4f3b51..d4fc7116abbe 100644
> --- a/scripts/arch-run.bash
> +++ b/scripts/arch-run.bash
> @@ -372,7 +372,7 @@ search_kvmtool_binary ()
>   {
>   	local kvmtoolcmd kvmtool
>   
> -	for kvmtoolcmd in lkvm vm lkvm-static; do
> +	for kvmtoolcmd in ${KVMTOOL:-lkvm vm lkvm-static}; do
>   		if "$kvmtoolcmd" --help 2>/dev/null| grep -q 'The most commonly used'; then
>   			kvmtool="$kvmtoolcmd"
>   			break
> @@ -381,6 +381,7 @@ search_kvmtool_binary ()
>   
>   	if [ -z "$kvmtool" ]; then
>   		echo "A kvmtool binary was not found." >&2
> +		echo "You can set a custom location by using the KVMTOOL=<path> environment variable." >&2
>   		return 2
>   	fi
>   

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 09/16] scripts: Add support for kvmtool
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 09/16] scripts: Add support for kvmtool Alexandru Elisei
  2025-05-07 16:38   ` Andrew Jones
@ 2025-05-19  8:55   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-19  8:55 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> Teach the arm runner to use kvmtool when kvm-unit-tests has been configured
> appropriately.
> 
> The test is ran using run_test_status(), and a 0 return code (which means
> success) is converted to 1, because kvmtool does not have a testdev device
> to return the test exit code, so kvm-unit-tests must always parse the
> "EXIT: STATUS" line for the exit code.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   arm/run               | 161 ++++++++++++++++++++++++++----------------
>   powerpc/run           |   4 +-
>   riscv/run             |   4 +-
>   s390x/run             |   2 +-
>   scripts/arch-run.bash | 112 +++++++++++------------------
>   scripts/vmm.bash      |  89 +++++++++++++++++++++++
>   x86/run               |   4 +-
>   7 files changed, 236 insertions(+), 140 deletions(-)
> 
> diff --git a/arm/run b/arm/run
> index 56562ed1628f..e3c4ffc49136 100755
> --- a/arm/run
> +++ b/arm/run
> @@ -12,80 +12,117 @@ fi
>   
>   check_vmm_supported
>   
> -qemu_cpu="$TARGET_CPU"
> -
> -if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
> -   [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ] &&
> -   [ "$(basename $QEMU)" = "qemu-system-arm" ]; then
> -	ACCEL="tcg"
> -fi
> +function arch_run_qemu()
> +{
> +	qemu_cpu="$TARGET_CPU"
> +
> +	if [ "$QEMU" ] && [ -z "$ACCEL" ] &&
> +	   [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ] &&
> +	   [ "$(basename $QEMU)" = "qemu-system-arm" ]; then
> +		ACCEL="tcg"
> +	fi
>   
> -set_qemu_accelerator || exit $?
> -if [ "$ACCEL" = "kvm" ]; then
> -	QEMU_ARCH=$HOST
> -fi
> +	set_qemu_accelerator || exit $?
> +	if [ "$ACCEL" = "kvm" ]; then
> +		QEMU_ARCH=$HOST
> +	fi
>   
> -qemu=$(search_qemu_binary) ||
> -	exit $?
> +	qemu=$(search_qemu_binary) ||
> +		exit $?
>   
> -if ! $qemu -machine '?' | grep -q 'ARM Virtual Machine'; then
> -	echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting."
> -	exit 2
> -fi
> +	if ! $qemu -machine '?' | grep -q 'ARM Virtual Machine'; then
> +		echo "$qemu doesn't support mach-virt ('-machine virt'). Exiting."
> +		exit 2
> +	fi
>   
> -M='-machine virt'
> +	M='-machine virt'
>   
> -if [ "$ACCEL" = "kvm" ]; then
> -	if $qemu $M,\? | grep -q gic-version; then
> -		M+=',gic-version=host'
> +	if [ "$ACCEL" = "kvm" ]; then
> +		if $qemu $M,\? | grep -q gic-version; then
> +			M+=',gic-version=host'
> +		fi
>   	fi
> -fi
>   
> -if [ -z "$qemu_cpu" ]; then
> -	if ( [ "$ACCEL" = "kvm" ] || [ "$ACCEL" = "hvf" ] ) &&
> -	   ( [ "$HOST" = "aarch64" ] || [ "$HOST" = "arm" ] ); then
> -		qemu_cpu="host"
> -		if [ "$ARCH" = "arm" ] && [ "$HOST" = "aarch64" ]; then
> -			qemu_cpu+=",aarch64=off"
> +	if [ -z "$qemu_cpu" ]; then
> +		if ( [ "$ACCEL" = "kvm" ] || [ "$ACCEL" = "hvf" ] ) &&
> +		   ( [ "$HOST" = "aarch64" ] || [ "$HOST" = "arm" ] ); then
> +			qemu_cpu="host"
> +			if [ "$ARCH" = "arm" ] && [ "$HOST" = "aarch64" ]; then
> +				qemu_cpu+=",aarch64=off"
> +			fi
> +		else
> +			qemu_cpu="$DEFAULT_QEMU_CPU"
>   		fi
> -	else
> -		qemu_cpu="$DEFAULT_QEMU_CPU"
>   	fi
> -fi
>   
> -if [ "$ARCH" = "arm" ]; then
> -	M+=",highmem=off"
> -fi
> +	if [ "$ARCH" = "arm" ]; then
> +		M+=",highmem=off"
> +	fi
>   
> -if ! $qemu $M -device '?' | grep -q virtconsole; then
> -	echo "$qemu doesn't support virtio-console for chr-testdev. Exiting."
> -	exit 2
> -fi
> +	if ! $qemu $M -device '?' | grep -q virtconsole; then
> +		echo "$qemu doesn't support virtio-console for chr-testdev. Exiting."
> +		exit 2
> +	fi
>   
> -if ! $qemu $M -chardev '?' | grep -q testdev; then
> -	echo "$qemu doesn't support chr-testdev. Exiting."
> -	exit 2
> -fi
> +	if ! $qemu $M -chardev '?' | grep -q testdev; then
> +		echo "$qemu doesn't support chr-testdev. Exiting."
> +		exit 2
> +	fi
>   
> -if [ "$UEFI_SHELL_RUN" != "y" ] && [ "$EFI_USE_ACPI" != "y" ]; then
> -	chr_testdev='-device virtio-serial-device'
> -	chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
> -fi
> +	if [ "$UEFI_SHELL_RUN" != "y" ] && [ "$EFI_USE_ACPI" != "y" ]; then
> +		chr_testdev='-device virtio-serial-device'
> +		chr_testdev+=' -device virtconsole,chardev=ctd -chardev testdev,id=ctd'
> +	fi
>   
> -pci_testdev=
> -if $qemu $M -device '?' | grep -q pci-testdev; then
> -	pci_testdev="-device pci-testdev"
> -fi
> +	pci_testdev=
> +	if $qemu $M -device '?' | grep -q pci-testdev; then
> +		pci_testdev="-device pci-testdev"
> +	fi
>   
> -A="-accel $ACCEL$ACCEL_PROPS"
> -command="$qemu -nodefaults $M $A -cpu $qemu_cpu $chr_testdev $pci_testdev"
> -command+=" -display none -serial stdio"
> -command="$(migration_cmd) $(timeout_cmd) $command"
> -
> -if [ "$UEFI_SHELL_RUN" = "y" ]; then
> -	ENVIRON_DEFAULT=n run_qemu_status $command "$@"
> -elif [ "$EFI_USE_ACPI" = "y" ]; then
> -	run_qemu_status $command -kernel "$@"
> -else
> -	run_qemu $command -kernel "$@"
> -fi
> +	A="-accel $ACCEL$ACCEL_PROPS"
> +	command="$qemu -nodefaults $M $A -cpu $qemu_cpu $chr_testdev $pci_testdev"
> +	command+=" -display none -serial stdio"
> +	command="$(migration_cmd) $(timeout_cmd) $command"
> +
> +	if [ "$UEFI_SHELL_RUN" = "y" ]; then
> +		ENVIRON_DEFAULT=n run_test_status $command "$@"
> +	elif [ "$EFI_USE_ACPI" = "y" ]; then
> +		run_test_status $command -kernel "$@"
> +	else
> +		run_test $command -kernel "$@"
> +	fi
> +}
> +
> +function arch_run_kvmtool()
> +{
> +	local command
> +
> +	kvmtool=$(search_kvmtool_binary) ||
> +		exit $?
> +
> +	if [ "$ACCEL" ] && [ "$ACCEL" != "kvm" ]; then
> +		echo "kvmtool does not support $ACCEL" >&2
> +		exit 2
> +	fi
> +
> +	if ! kvm_available; then
> +		echo "kvmtool requires KVM but not available on the host" >&2
> +		exit 2
> +	fi
> +
> +	command="$(timeout_cmd) $kvmtool run"
> +	if [ "$HOST" = "aarch64" ] && [ "$ARCH" = "arm" ]; then
> +		run_test_status $command --kernel "$@" --aarch32
> +	else
> +		run_test_status $command --kernel "$@"
> +	fi
> +}
> +
> +case $TARGET in
> +qemu)
> +	arch_run_qemu "$@"
> +	;;
> +kvmtool)
> +	arch_run_kvmtool "$@"
> +	;;
> +esac
> diff --git a/powerpc/run b/powerpc/run
> index 27abf1ef6a4d..0b25a227429a 100755
> --- a/powerpc/run
> +++ b/powerpc/run
> @@ -59,8 +59,8 @@ command+=" -display none -serial stdio -kernel"
>   command="$(migration_cmd) $(timeout_cmd) $command"
>   
>   # powerpc tests currently exit with rtas-poweroff, which exits with 0.
> -# run_qemu treats that as a failure exit and returns 1, so we need
> +# run_test treats that as a failure exit and returns 1, so we need
>   # to fixup the fixup below by parsing the true exit code from the output.
>   # The second fixup is also a FIXME, because once we add chr-testdev
>   # support for powerpc, we won't need the second fixup.
> -run_qemu_status $command "$@"
> +run_test_status $command "$@"
> diff --git a/riscv/run b/riscv/run
> index 3b2fc36f2afb..562347e8bea2 100755
> --- a/riscv/run
> +++ b/riscv/run
> @@ -36,8 +36,8 @@ command+=" $mach $acc $firmware -cpu $qemu_cpu "
>   command="$(migration_cmd) $(timeout_cmd) $command"
>   
>   if [ "$UEFI_SHELL_RUN" = "y" ]; then
> -	ENVIRON_DEFAULT=n run_qemu_status $command "$@"
> +	ENVIRON_DEFAULT=n run_test_status $command "$@"
>   else
>   	# We return the exit code via stdout, not via the QEMU return code
> -	run_qemu_status $command -kernel "$@"
> +	run_test_status $command -kernel "$@"
>   fi
> diff --git a/s390x/run b/s390x/run
> index 34552c2747d4..9ecfaf983a3d 100755
> --- a/s390x/run
> +++ b/s390x/run
> @@ -47,4 +47,4 @@ command+=" -kernel"
>   command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command"
>   
>   # We return the exit code via stdout, not via the QEMU return code
> -run_qemu_status $command "$@"
> +run_test_status $command "$@"
> diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash
> index 8643bab3b252..8cf67e4f3b51 100644
> --- a/scripts/arch-run.bash
> +++ b/scripts/arch-run.bash
> @@ -1,30 +1,7 @@
> -##############################################################################
> -# run_qemu translates the ambiguous exit status in Table1 to that in Table2.
> -# Table3 simply documents the complete status table.
> -#
> -# Table1: Before fixup
> -# --------------------
> -# 0      - Unexpected exit from QEMU (possible signal), or the unittest did
> -#          not use debug-exit
> -# 1      - most likely unittest succeeded, or QEMU failed
> -#
> -# Table2: After fixup
> -# -------------------
> -# 0      - Everything succeeded
> -# 1      - most likely QEMU failed
> -#
> -# Table3: Complete table
> -# ----------------------
> -# 0      - SUCCESS
> -# 1      - most likely QEMU failed
> -# 2      - most likely a run script failed
> -# 3      - most likely the unittest failed
> -# 124    - most likely the unittest timed out
> -# 127    - most likely the unittest called abort()
> -# 1..127 - FAILURE (could be QEMU, a run script, or the unittest)
> -# >= 128 - Signal (signum = status - 128)
> -##############################################################################
> -run_qemu ()
> +source config.mak
> +source scripts/vmm.bash
> +
> +run_test ()
>   {
>   	local stdout errors ret sig
>   
> @@ -39,48 +16,17 @@ run_qemu ()
>   	ret=$?
>   	exec {stdout}>&-
>   
> -	[ $ret -eq 134 ] && echo "QEMU Aborted" >&2
> -
> -	if [ "$errors" ]; then
> -		sig=$(grep 'terminating on signal' <<<"$errors")
> -		if [ "$sig" ]; then
> -			# This is too complex for ${var/search/replace}
> -			# shellcheck disable=SC2001
> -			sig=$(sed 's/.*terminating on signal \([0-9][0-9]*\).*/\1/' <<<"$sig")
> -		fi
> -	fi
> -
> -	if [ $ret -eq 0 ]; then
> -		# Some signals result in a zero return status, but the
> -		# error log tells the truth.
> -		if [ "$sig" ]; then
> -			((ret=sig+128))
> -		else
> -			# Exiting with zero (non-debugexit) is an error
> -			ret=1
> -		fi
> -	elif [ $ret -eq 1 ]; then
> -		# Even when ret==1 (unittest success) if we also got stderr
> -		# logs, then we assume a QEMU failure. Otherwise we translate
> -		# status of 1 to 0 (SUCCESS)
> -	        if [ "$errors" ]; then
> -			if ! grep -qvi warning <<<"$errors" ; then
> -				ret=0
> -			fi
> -		else
> -			ret=0
> -		fi
> -	fi
> +	ret=$(${vmm_opts[$TARGET:fixup_return_code]} $ret $errors)
>   
>   	return $ret
>   }
>   
> -run_qemu_status ()
> +run_test_status ()
>   {
>   	local stdout ret
>   
>   	exec {stdout}>&1
> -	lines=$(run_qemu "$@" > >(tee /dev/fd/$stdout))
> +	lines=$(run_test "$@" > >(tee /dev/fd/$stdout))
>   	ret=$?
>   	exec {stdout}>&-
>   
> @@ -422,6 +368,25 @@ search_qemu_binary ()
>   	export PATH=$save_path
>   }
>   
> +search_kvmtool_binary ()
> +{
> +	local kvmtoolcmd kvmtool
> +
> +	for kvmtoolcmd in lkvm vm lkvm-static; do
> +		if "$kvmtoolcmd" --help 2>/dev/null| grep -q 'The most commonly used'; then
> +			kvmtool="$kvmtoolcmd"
> +			break
> +		fi
> +	done
> +
> +	if [ -z "$kvmtool" ]; then
> +		echo "A kvmtool binary was not found." >&2
> +		return 2
> +	fi
> +
> +	command -v $kvmtool
> +}
> +
>   initrd_cleanup ()
>   {
>   	rm -f $KVM_UNIT_TESTS_ENV
> @@ -447,7 +412,7 @@ initrd_create ()
>   	fi
>   
>   	unset INITRD
> -	[ -f "$KVM_UNIT_TESTS_ENV" ] && INITRD="-initrd $KVM_UNIT_TESTS_ENV"
> +	[ -f "$KVM_UNIT_TESTS_ENV" ] && INITRD="${vmm_opts[$TARGET:initrd]} $KVM_UNIT_TESTS_ENV"
>   
>   	return 0
>   }
> @@ -471,18 +436,23 @@ env_params ()
>   	local qemu have_qemu
>   	local _ rest
>   
> -	qemu=$(search_qemu_binary) && have_qemu=1
> +	env_add_params TARGET
>   
> -	if [ "$have_qemu" ]; then
> -		if [ -n "$ACCEL" ] || [ -n "$QEMU_ACCEL" ]; then
> -			[ -n "$ACCEL" ] && QEMU_ACCEL=$ACCEL
> +	# kvmtool's versioning has been broken since it was split from the
> +	# kernel source.
> +	if [ $TARGET = "qemu" ]; then
> +		qemu=$(search_qemu_binary) && have_qemu=1
> +		if [ "$have_qemu" ]; then
> +			if [ -n "$ACCEL" ] || [ -n "$QEMU_ACCEL" ]; then
> +				[ -n "$ACCEL" ] && QEMU_ACCEL=$ACCEL
> +			fi
> +			QEMU_VERSION_STRING="$($qemu -h | head -1)"
> +			# Shellcheck does not see QEMU_MAJOR|MINOR|MICRO are used
> +			# shellcheck disable=SC2034
> +			IFS='[ .]' read -r _ _ _ QEMU_MAJOR QEMU_MINOR QEMU_MICRO rest <<<"$QEMU_VERSION_STRING"
>   		fi
> -		QEMU_VERSION_STRING="$($qemu -h | head -1)"
> -		# Shellcheck does not see QEMU_MAJOR|MINOR|MICRO are used
> -		# shellcheck disable=SC2034
> -		IFS='[ .]' read -r _ _ _ QEMU_MAJOR QEMU_MINOR QEMU_MICRO rest <<<"$QEMU_VERSION_STRING"
> +		env_add_params QEMU_ACCEL QEMU_VERSION_STRING QEMU_MAJOR QEMU_MINOR QEMU_MICRO
>   	fi
> -	env_add_params QEMU_ACCEL QEMU_VERSION_STRING QEMU_MAJOR QEMU_MINOR QEMU_MICRO
>   
>   	KERNEL_VERSION_STRING=$(uname -r)
>   	IFS=. read -r KERNEL_VERSION KERNEL_PATCHLEVEL rest <<<"$KERNEL_VERSION_STRING"
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index b02055a5c0b6..20968f2e6b10 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -1,10 +1,99 @@
>   source config.mak
>   
> +##############################################################################
> +# qemu_fixup_return_code translates the ambiguous exit status in Table1 to that
> +# in Table2.  Table3 simply documents the complete status table.
> +#
> +# Table1: Before fixup
> +# --------------------
> +# 0      - Unexpected exit from QEMU (possible signal), or the unittest did
> +#          not use debug-exit
> +# 1      - most likely unittest succeeded, or QEMU failed
> +#
> +# Table2: After fixup
> +# -------------------
> +# 0      - Everything succeeded
> +# 1      - most likely QEMU failed
> +#
> +# Table3: Complete table
> +# ----------------------
> +# 0      - SUCCESS
> +# 1      - most likely QEMU failed
> +# 2      - most likely a run script failed
> +# 3      - most likely the unittest failed
> +# 124    - most likely the unittest timed out
> +# 127    - most likely the unittest called abort()
> +# 1..127 - FAILURE (could be QEMU, a run script, or the unittest)
> +# >= 128 - Signal (signum = status - 128)
> +##############################################################################
> +qemu_fixup_return_code()
> +{
> +	local ret=$1
> +	# Remove $ret from the list of arguments
> +	shift 1
> +	local errors="$@"
> +	local sig
> +
> +	[ $ret -eq 134 ] && echo "QEMU Aborted" >&2
> +
> +	if [ "$errors" ]; then
> +		sig=$(grep 'terminating on signal' <<<"$errors")
> +		if [ "$sig" ]; then
> +			# This is too complex for ${var/search/replace}
> +			# shellcheck disable=SC2001
> +			sig=$(sed 's/.*terminating on signal \([0-9][0-9]*\).*/\1/' <<<"$sig")
> +		fi
> +	fi
> +
> +	if [ $ret -eq 0 ]; then
> +		# Some signals result in a zero return status, but the
> +		# error log tells the truth.
> +		if [ "$sig" ]; then
> +			((ret=sig+128))
> +		else
> +			# Exiting with zero (non-debugexit) is an error
> +			ret=1
> +		fi
> +	elif [ $ret -eq 1 ]; then
> +		# Even when ret==1 (unittest success) if we also got stderr
> +		# logs, then we assume a QEMU failure. Otherwise we translate
> +		# status of 1 to 0 (SUCCESS)
> +	        if [ "$errors" ]; then
> +			if ! grep -qvi warning <<<"$errors" ; then
> +				ret=0
> +			fi
> +		else
> +			ret=0
> +		fi
> +	fi
> +
> +	echo $ret
> +}
> +
> +kvmtool_fixup_return_code()
> +{
> +	local ret=$1
> +
> +	# Force run_test_status() to interpret the STATUS line.
> +	if [ $ret -eq 0 ]; then
> +		ret=1
> +	fi
> +
> +	echo $ret
> +}
> +
>   declare -A vmm_opts=(
>   	[qemu:nr_cpus]='-smp'
>   	[qemu:kernel]='-kernel'
>   	[qemu:args]='-append'
>   	[qemu:initrd]='-initrd'
> +	[qemu:fixup_return_code]=qemu_fixup_return_code
> +
> +	[kvmtool:nr_cpus]='--cpus'
> +	[kvmtool:kernel]='--kernel'
> +	[kvmtool:args]='--params'
> +	[kvmtool:initrd]='--initrd'
> +	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
>   )
>   
>   function check_vmm_supported()
> diff --git a/x86/run b/x86/run
> index a3d3e7db8891..91bcd0b9ae41 100755
> --- a/x86/run
> +++ b/x86/run
> @@ -49,7 +49,7 @@ if [ "${CONFIG_EFI}" = y ]; then
>   	# UEFI, the test case binaries are passed to QEMU through the disk
>   	# image, not through the '-kernel' flag. And QEMU reports an error if it
>   	# gets '-initrd' without a '-kernel'
> -	ENVIRON_DEFAULT=n run_qemu ${command} "$@"
> +	ENVIRON_DEFAULT=n run_test ${command} "$@"
>   else
> -	run_qemu ${command} "$@"
> +	run_test ${command} "$@"
>   fi

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script
  2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
                   ` (15 preceding siblings ...)
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 16/16] scripts: Enable kvmtool Alexandru Elisei
@ 2025-05-19  8:56 ` Shaoqin Huang
  16 siblings, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-19  8:56 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara

Hi Alexandru,

For this series, I've tested it, everything works good.

On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> v2 can be found here [1].
> 
> To goal is to allow the user to do:
> 
> $ ./configure --target=kvmtool
> $ make clean && make
> $ ./run_tests.sh
> 
> to run all the tests automatically with kvmtool.
> 
> Reasons to use kvmtool:
> 
> * kvmtool is smaller and a lot easier to hack than qemu, which means
> developers may prefer it when adding or prototyping new features to KVM.
> Being able to run all the tests reliably and automatically is very useful
> in the development process.
> 
> * kvmtool is faster to run the tests (a couple of times faster on
> my rockpro64), making for a quick turnaround. But do keep in mind that not
> all tests work on kvmtool because of missing features compared to qemu.
> 
> * kvmtool does things differently than qemu: different memory layout,
> different uart, PMU emulation is disabled by default, etc. This makes it a
> good testing vehicule for kvm-unit-tests itself.
> 
> Changes in v3
> -------------
> 
> Lots of changes following the excellent feedback I got. A bird's eye view:
> 
> * Split extra_params into qemu_params and test_args: qemu_params for qemu
> arguments and test_args for the test's main() function.
> 
> Now that I'm putting the cover letter together I'm considering that maybe
> having qemu_params, kvmtool_params and test_params (instead of test_args)
> might be a better naming scheme.
> 
> * TARGET is now exported unconditionally. Unfortunately a side effect of
> this is that checking out these series and running the tests will end up
> with an error because the scripts now expect TARGET to be defined in
> config.mak.
> 
> If it's unacceptable, I can drop this and handle everything in vmm.bash by
> converting direct accesses to vmm_opts with functions defined in vmm.bash
> (vmm_opts[$TARGET:parse_premature_failure] becomes
> vmm_parse_premature_failure(), for example).
> 
> * Introduced scripts/vmm.bash to keep the vmm stuff contained. As a
> consequence there's very little $TARGET stuff in scripts/runtime.bash (only
> for premature_failure(), and no more 'case' statements anywhere) and
> instead scripts/common.bash passes the correct arguments directly to
> runtime.bash::run().
> 
> Unfortunately, because of all the changes, I decided not to keep some of
> the Reviewed-by tags. That's not to say that the effort is not appreciated,
> on the contrary, these changes are a direct result of the review; I dropped
> the tags because I was worried they might not apply to the current content
> of the patches.
> 
> If no major changes are needed following this round of review, for the next
> iteration I'm planning to send the first two patches (extra_params renamed
> to qemu_params and the new test_args) separately, to make sure it gets the
> review it deserves from the rest of the architectures.
> 
> Still haven't managed to get EDK2 to work with kvmtool, so I've decided to
> explicitely disabled UEFI tests in the last patch ("scripts: Enable
> kvmtool") - this is new.
> 
> I would also like to point out that despite Drew's comment I kept the
> 'disabled_if' test definition because I think using 'targets', with the
> default value of 'qemu', will probably lead to most, if not all, of the new
> tests which will be added never being run or tested with kvmtool. More
> details in patch #15 ("scripts: Add 'disabled_if' test definition parameter
> for kvmtool to use").
> 
> [1] https://lore.kernel.org/kvm/20250120164316.31473-1-alexandru.elisei@arm.com/
> 
> Alexandru Elisei (16):
>    scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params'
>    scripts: Add 'test_args' test definition parameter
>    configure: Export TARGET unconditionally
>    run_tests.sh: Document --probe-maxsmp argument
>    scripts: Document environment variables
>    scripts: Refuse to run the tests if not configured for qemu
>    scripts: Use an associative array for qemu argument names
>    scripts: Add 'kvmtool_params' to test definition
>    scripts: Add support for kvmtool
>    scripts: Add default arguments for kvmtool
>    scripts: Add KVMTOOL environment variable for kvmtool binary path
>    scripts: Detect kvmtool failure in premature_failure()
>    scripts: Do not probe for maximum number of VCPUs when using kvmtool
>    scripts/mkstandalone: Export $TARGET
>    scripts: Add 'disabled_if' test definition parameter for kvmtool to
>      use
>    scripts: Enable kvmtool
> 
>   README.md               |  18 ++++-
>   arm/efi/run             |   8 ++
>   arm/run                 | 161 +++++++++++++++++++++++--------------
>   arm/unittests.cfg       | 125 ++++++++++++++++++++---------
>   configure               |  37 ++++++---
>   docs/unittests.txt      |  54 +++++++++++--
>   powerpc/run             |   4 +-
>   powerpc/unittests.cfg   |  21 ++---
>   riscv/run               |   4 +-
>   riscv/unittests.cfg     |   2 +-
>   run_tests.sh            |  35 ++++++---
>   s390x/run               |   2 +-
>   s390x/unittests.cfg     |  53 +++++++------
>   scripts/arch-run.bash   | 113 ++++++++++----------------
>   scripts/common.bash     |  71 +++++++++++------
>   scripts/mkstandalone.sh |   4 +
>   scripts/runtime.bash    |  51 +++++-------
>   scripts/vmm.bash        | 170 ++++++++++++++++++++++++++++++++++++++++
>   x86/run                 |   4 +-
>   x86/unittests.cfg       | 164 +++++++++++++++++++++-----------------
>   20 files changed, 730 insertions(+), 371 deletions(-)
>   create mode 100644 scripts/vmm.bash
> 
> 
> base-commit: 08db0f5cfbca16b36f200b7bc54a78fa4941bcce

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 10/16] scripts: Add default arguments for kvmtool
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 10/16] scripts: Add default arguments " Alexandru Elisei
  2025-05-07 16:43   ` Andrew Jones
@ 2025-05-21  3:21   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-21  3:21 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> kvmtool, unless told otherwise, will do its best to make sure that a kernel
> successfully boots in a virtual machine. It does things like automatically
> creating a rootfs and adding extra parameters to the kernel command line.
> This is actively harmful to kvm-unit-tests, because some tests parse the
> kernel command line and they will fail if they encounter the options added
> by kvmtool.
> 
> Fortunately for us, kvmtool commit 5613ae26b998 ("Add --nodefaults command
> line argument") addded the --nodefaults kvmtool parameter which disables
> all the implicit virtual machine configuration that cannot be disabled by
> using other parameters, like modifying the kernel command line. So always
> use --nodefaults to allow a test to run.
> 
> kvmtool can also be too verbose when running a virtual machine, and this is
> controlled by several parameters. Add those to the default kvmtool command
> line to reduce this verbosity to a minimum.
> 
> Before:
> 
> $ vm run arm/selftest.flat --cpus 2 --mem 256 --params "setup smp=2 mem=256"
> Info: # lkvm run -k arm/selftest.flat -m 256 -c 2 --name guest-5035
> Unknown subtest
> 
> EXIT: STATUS=127
> Warning: KVM compatibility warning.
>      virtio-9p device was not detected.
>      While you have requested a virtio-9p device, the guest kernel did not initialize it.
>      Please make sure that the guest kernel was compiled with CONFIG_NET_9P_VIRTIO=y enabled in .config.
> Warning: KVM compatibility warning.
>      virtio-net device was not detected.
>      While you have requested a virtio-net device, the guest kernel did not initialize it.
>      Please make sure that the guest kernel was compiled with CONFIG_VIRTIO_NET=y enabled in .config.
> Info: KVM session ended normally.
> 
> After:
> 
> $ vm run arm/selftest.flat --nodefaults --network mode=none --loglevel=warning --cpus 2 --mem 256 --params "setup smp=2 mem=256"
> PASS: selftest: setup: smp: number of CPUs matches expectation
> INFO: selftest: setup: smp: found 2 CPUs
> PASS: selftest: setup: mem: memory size matches expectation
> INFO: selftest: setup: mem: found 256 MB
> SUMMARY: 2 tests
> 
> EXIT: STATUS=1
> 
> Note that KVMTOOL_DEFAULT_OPTS can be overwritten by an environment
> variable with the same name, but it's not documented in the help string for
> run_tests.sh. This has been done on purpose, since overwritting
> KVMTOOL_DEFAULT_OPTS should only be necessary for debugging or development
> purposes.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>   scripts/common.bash | 10 +++++-----
>   scripts/vmm.bash    | 13 +++++++++++++
>   2 files changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/common.bash b/scripts/common.bash
> index 0645235d8baa..ee0ae71948c2 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -56,7 +56,7 @@ function for_each_unittest()
>   			# because qemu interprets the first argument after
>   			# -append as a kernel parameter.
>   			test_args=""
> -			opts=""
> +			opts="${vmm_opts[$TARGET:default_opts]}"
>   			groups=""
>   			arch=""
>   			machine=""
> @@ -70,13 +70,13 @@ function for_each_unittest()
>   		elif [[ $line =~ ^test_args\ *=\ *(.*)$ ]]; then
>   			test_args="${vmm_opts[$TARGET:args]} ${BASH_REMATCH[1]}"
>   		elif [[ $TARGET = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *'"""'(.*)$ ]]; then
> -			opts=$(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)
> +			opts="${vmm_opts[$TARGET:default_opts]} $(parse_opts ${BASH_REMATCH[2]}$'\n' $fd)"
>   		elif [[ $TARGET  = "qemu" ]] && [[ $line =~ ^(extra_params|qemu_params)\ *=\ *(.*)$ ]]; then
> -			opts=${BASH_REMATCH[2]}
> +			opts="${vmm_opts[$TARGET:default_opts]} ${BASH_REMATCH[2]}"
>   		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *'"""'(.*)$ ]]; then
> -			opts=$(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)
> +			opts="${vmm_opts[$TARGET:default_opts]} $(parse_opts ${BASH_REMATCH[1]}$'\n' $fd)"
>   		elif [[ $TARGET = "kvmtool" ]] && [[ $line =~ ^kvmtool_params\ *=\ *(.*)$ ]]; then
> -			opts=${BASH_REMATCH[1]}
> +			opts="${vmm_opts[$TARGET:default_opts]} ${BASH_REMATCH[1]}"
>   		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
>   			groups=${BASH_REMATCH[1]}
>   		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index 20968f2e6b10..d24a4c4b8713 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -1,5 +1,16 @@
>   source config.mak
>   
> +# The following parameters are enabled by default when running a test with
> +# kvmtool:
> +# --nodefaults: suppress VM configuration that cannot be disabled otherwise
> +#               (like modifying the supplied kernel command line). Tests that
> +#               use the command line will fail without this parameter.

Maybe change it to below is better? (Put the 'Otherwise' to the next 
paragraph)

# --nodefaults: suppress VM configuration that cannot be disabled
#               (like modifying the supplied kernel command line). 	# 
            Otherwise tests that use the command line will fail
#               without this parameter.

Others looks good to me.

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> +# --network mode=none: do not create a network device. kvmtool tries to help the
> +#               user by automatically create one, and then prints a warning
> +#               when the VM terminates if the device hasn't been initialized.
> +# --loglevel=warning: reduce verbosity
> +: "${KVMTOOL_DEFAULT_OPTS:="--nodefaults --network mode=none --loglevel=warning"}"
> +
>   ##############################################################################
>   # qemu_fixup_return_code translates the ambiguous exit status in Table1 to that
>   # in Table2.  Table3 simply documents the complete status table.
> @@ -87,12 +98,14 @@ declare -A vmm_opts=(
>   	[qemu:kernel]='-kernel'
>   	[qemu:args]='-append'
>   	[qemu:initrd]='-initrd'
> +	[qemu:default_opts]=''
>   	[qemu:fixup_return_code]=qemu_fixup_return_code
>   
>   	[kvmtool:nr_cpus]='--cpus'
>   	[kvmtool:kernel]='--kernel'
>   	[kvmtool:args]='--params'
>   	[kvmtool:initrd]='--initrd'
> +	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
>   	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
>   )
>   

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 12/16] scripts: Detect kvmtool failure in premature_failure()
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 12/16] scripts: Detect kvmtool failure in premature_failure() Alexandru Elisei
  2025-05-07 16:47   ` Andrew Jones
@ 2025-05-21  5:58   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-21  5:58 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> kvm-unit-tests assumes that if the VMM is able to get to where it tries to
> load the kernel, then the VMM and the configuration parameters will also
> work for running the test. All of this is done in premature_failure().
> 
> Teach premature_failure() about the kvmtool's error message when it fails
> to load the dummy kernel.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   scripts/runtime.bash |  8 +++-----
>   scripts/vmm.bash     | 23 +++++++++++++++++++++++
>   2 files changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 86d8a2cd8528..01ec8eae2bba 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -1,3 +1,5 @@
> +source scripts/vmm.bash
> +
>   : "${RUNTIME_arch_run?}"
>   : "${MAX_SMP:=$(getconf _NPROCESSORS_ONLN)}"
>   : "${TIMEOUT:=90s}"
> @@ -19,11 +21,7 @@ premature_failure()
>   
>       log="$(eval "$(get_cmdline _NO_FILE_4Uhere_)" 2>&1)"
>   
> -    echo "$log" | grep "_NO_FILE_4Uhere_" |
> -        grep -q -e "[Cc]ould not \(load\|open\) kernel" \
> -                -e "error loading" \
> -                -e "failed to load" &&
> -        return 1
> +    ${vmm_opts[$TARGET:parse_premature_failure]} "$log" || return 1
>   
>       RUNTIME_log_stderr <<< "$log"
>   
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index d24a4c4b8713..a1d50ed51981 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -93,6 +93,27 @@ kvmtool_fixup_return_code()
>   	echo $ret
>   }
>   
> +function qemu_parse_premature_failure()
> +{
> +	local log="$@"
> +
> +	echo "$log" | grep "_NO_FILE_4Uhere_" |
> +		grep -q -e "[Cc]ould not \(load\|open\) kernel" \
> +			-e "error loading" \
> +			-e "failed to load" &&
> +		return 1
> +	return 0
> +}
> +
> +function kvmtool_parse_premature_failure()
> +{
> +	local log="$@"
> +
> +	echo "$log" | grep "Fatal: Unable to open kernel _NO_FILE_4Uhere_" &&
> +		return 1
> +	return 0
> +}
> +
>   declare -A vmm_opts=(
>   	[qemu:nr_cpus]='-smp'
>   	[qemu:kernel]='-kernel'
> @@ -100,6 +121,7 @@ declare -A vmm_opts=(
>   	[qemu:initrd]='-initrd'
>   	[qemu:default_opts]=''
>   	[qemu:fixup_return_code]=qemu_fixup_return_code
> +	[qemu:parse_premature_failure]=qemu_parse_premature_failure
>   
>   	[kvmtool:nr_cpus]='--cpus'
>   	[kvmtool:kernel]='--kernel'
> @@ -107,6 +129,7 @@ declare -A vmm_opts=(
>   	[kvmtool:initrd]='--initrd'
>   	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
>   	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
> +	[kvmtool:parse_premature_failure]=kvmtool_parse_premature_failure
>   )
>   
>   function check_vmm_supported()

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 13/16] scripts: Do not probe for maximum number of VCPUs when using kvmtool
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 13/16] scripts: Do not probe for maximum number of VCPUs when using kvmtool Alexandru Elisei
  2025-05-07 16:48   ` Andrew Jones
@ 2025-05-21  6:02   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-21  6:02 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> The --probe-maxsmp parameter updates MAX_SMP with the maximum number of
> VCPUs that the host supports. Qemu will exit with an error when creating a
> virtual machine if the number of VCPUs is exceeded.
> 
> kvmtool behaves differently: it will automatically limit the number of
> VCPUs to the what KVM supports, which is exactly what --probe-maxsmp wants
> to achieve. When doing --probe-maxsmp with kvmtool, print a message
> explaining why it's redundant and don't do anything else.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   run_tests.sh         |  3 ++-
>   scripts/runtime.bash | 16 ----------------
>   scripts/vmm.bash     | 24 ++++++++++++++++++++++++
>   3 files changed, 26 insertions(+), 17 deletions(-)
> 
> diff --git a/run_tests.sh b/run_tests.sh
> index 150a06a91064..a69c3665b7a4 100755
> --- a/run_tests.sh
> +++ b/run_tests.sh
> @@ -10,6 +10,7 @@ if [ ! -f config.mak ]; then
>   fi
>   source config.mak
>   source scripts/common.bash
> +source scripts/vmm.bash
>   
>   function usage()
>   {
> @@ -90,7 +91,7 @@ while [ $# -gt 0 ]; do
>               list_tests="yes"
>               ;;
>           --probe-maxsmp)
> -            probe_maxsmp
> +            ${vmm_opts[$TARGET:probe_maxsmp]}
>               ;;
>           --)
>               ;;
> diff --git a/scripts/runtime.bash b/scripts/runtime.bash
> index 01ec8eae2bba..a802686c511d 100644
> --- a/scripts/runtime.bash
> +++ b/scripts/runtime.bash
> @@ -209,19 +209,3 @@ function run()
>   
>       return $ret
>   }
> -
> -#
> -# Probe for MAX_SMP, in case it's less than the number of host cpus.
> -#
> -function probe_maxsmp()
> -{
> -	local smp
> -
> -	if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'SMP CPUs'); then
> -		smp=${smp##* }
> -		smp=${smp/\(}
> -		smp=${smp/\)}
> -		echo "Restricting MAX_SMP from ($MAX_SMP) to the max supported ($smp)" >&2
> -		MAX_SMP=$smp
> -	fi
> -}
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index a1d50ed51981..ef9819f4132c 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -105,6 +105,22 @@ function qemu_parse_premature_failure()
>   	return 0
>   }
>   
> +#
> +# Probe for MAX_SMP, in case it's less than the number of host cpus.
> +#
> +function qemu_probe_maxsmp()
> +{
> +	local smp
> +
> +	if smp=$($RUNTIME_arch_run _NO_FILE_4Uhere_ -smp $MAX_SMP |& grep 'SMP CPUs'); then
> +		smp=${smp##* }
> +		smp=${smp/\(}
> +		smp=${smp/\)}
> +		echo "Restricting MAX_SMP from ($MAX_SMP) to the max supported ($smp)" >&2
> +		MAX_SMP=$smp
> +	fi
> +}
> +
>   function kvmtool_parse_premature_failure()
>   {
>   	local log="$@"
> @@ -114,6 +130,12 @@ function kvmtool_parse_premature_failure()
>   	return 0
>   }
>   
> +function kvmtool_probe_maxsmp()
> +{
> +	echo "kvmtool automatically limits the number of VCPUs to maximum supported"
> +	echo "The 'smp' test parameter won't be modified"
> +}
> +
>   declare -A vmm_opts=(
>   	[qemu:nr_cpus]='-smp'
>   	[qemu:kernel]='-kernel'
> @@ -122,6 +144,7 @@ declare -A vmm_opts=(
>   	[qemu:default_opts]=''
>   	[qemu:fixup_return_code]=qemu_fixup_return_code
>   	[qemu:parse_premature_failure]=qemu_parse_premature_failure
> +	[qemu:probe_maxsmp]=qemu_probe_maxsmp
>   
>   	[kvmtool:nr_cpus]='--cpus'
>   	[kvmtool:kernel]='--kernel'
> @@ -130,6 +153,7 @@ declare -A vmm_opts=(
>   	[kvmtool:default_opts]="$KVMTOOL_DEFAULT_OPTS"
>   	[kvmtool:fixup_return_code]=kvmtool_fixup_return_code
>   	[kvmtool:parse_premature_failure]=kvmtool_parse_premature_failure
> +	[kvmtool:probe_maxsmp]=kvmtool_probe_maxsmp
>   )
>   
>   function check_vmm_supported()

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 14/16] scripts/mkstandalone: Export $TARGET
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 14/16] scripts/mkstandalone: Export $TARGET Alexandru Elisei
@ 2025-05-21  6:16   ` Shaoqin Huang
  0 siblings, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-21  6:16 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> $TARGET is needed for the test runner to decide if it should use qemu or
> kvmtool, so export it.
> 
> Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   scripts/mkstandalone.sh | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/scripts/mkstandalone.sh b/scripts/mkstandalone.sh
> index 4f666cefe076..3b2caf198b00 100755
> --- a/scripts/mkstandalone.sh
> +++ b/scripts/mkstandalone.sh
> @@ -47,6 +47,7 @@ generate_test ()
>   	config_export ARCH_NAME
>   	config_export TARGET_CPU
>   	config_export DEFAULT_QEMU_CPU
> +	config_export TARGET
>   
>   	echo "echo BUILD_HEAD=$(cat build-head)"
>   

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

* Re: [kvm-unit-tests PATCH v3 16/16] scripts: Enable kvmtool
  2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 16/16] scripts: Enable kvmtool Alexandru Elisei
  2025-05-07 16:59   ` Andrew Jones
@ 2025-05-21  6:20   ` Shaoqin Huang
  1 sibling, 0 replies; 50+ messages in thread
From: Shaoqin Huang @ 2025-05-21  6:20 UTC (permalink / raw)
  To: Alexandru Elisei, andrew.jones, eric.auger, lvivier, thuth,
	frankja, imbrenda, nrb, david, pbonzini
  Cc: kvm, kvmarm, linuxppc-dev, kvm-riscv, linux-s390, will,
	julien.thierry.kdev, maz, oliver.upton, suzuki.poulose, yuzenghui,
	joey.gouly, andre.przywara



On 5/7/25 11:12 PM, Alexandru Elisei wrote:
> Everything is in place to run the tests using kvmtool:
> 
> $ ./configure --target=kvmtool
> $ make clean && make
> $ KVMTOOL=<path/to/kvmtool> ./run_tests.sh
> 
> so enable it, and remove ERRATA_FORCE=y when configuring for kvmtool,
> because the runner will generate and pass the correct environment to
> kvmtool.
> 
> Missing is support for EFI tests. That's because distros don't ship a

Missing should be Nothing?

> EDK2 binary compiled for kvmtool, and on top of that kvm-unit-tests as
> an EFI app hasn't been tested to work with kvmtool.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>

Reviewed-by: Shaoqin Huang <shahuang@redhat.com>

> ---
>   README.md        | 18 +++++++++++++++++-
>   arm/efi/run      |  5 +++++
>   configure        |  1 -
>   scripts/vmm.bash |  2 +-
>   4 files changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/README.md b/README.md
> index be07dc28a094..723ce04cd978 100644
> --- a/README.md
> +++ b/README.md
> @@ -65,6 +65,9 @@ or:
>   
>   to run them all.
>   
> +All tests can be run using QEMU. On arm and arm64, tests can also be run using
> +kvmtool.
> +
>   By default the runner script searches for a suitable QEMU binary in the system.
>   To select a specific QEMU binary though, specify the QEMU=path/to/binary
>   environment variable:
> @@ -78,12 +81,25 @@ ACCEL=name environment variable:
>   
>   For running tests that involve migration from one QEMU instance to another
>   you also need to have the "ncat" binary (from the nmap.org project) installed,
> -otherwise the related tests will be skipped.
> +otherwise the related tests will be skipped. kvmtool does not support migration.
> +
> +As for running a test with kvmtool, please configure kvm-unit-tests accordingly
> +first:
> +
> +   ./configure --arch=arm64 --target=kvmtool
> +
> +then run the test(s) like with QEMU above.
> +
> +To select a kvmtool binary, specify the KVMTOOL=path/to/binary environment
> +variable. kvmtool supports only kvm as the accelerator.
>   
>   ## Running the tests with UEFI
>   
>   Check [x86/efi/README.md](./x86/efi/README.md).
>   
> +On arm and arm64, this is only supported with QEMU; kvmtool cannot run the
> +tests under UEFI.
> +
>   # Tests configuration file
>   
>   The test case may need specific runtime configurations, for
> diff --git a/arm/efi/run b/arm/efi/run
> index 53d71297cc52..0843725ec360 100755
> --- a/arm/efi/run
> +++ b/arm/efi/run
> @@ -15,6 +15,11 @@ source scripts/vmm.bash
>   
>   check_vmm_supported
>   
> +if [[ $TARGET = "kvmtool" ]]; then
> +	echo "kvmtool does not support EFI tests."
> +	exit 2
> +fi
> +
>   if [ -f /usr/share/qemu-efi-aarch64/QEMU_EFI.fd ]; then
>   	DEFAULT_UEFI=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd
>   elif [ -f /usr/share/edk2/aarch64/QEMU_EFI.silent.fd ]; then
> diff --git a/configure b/configure
> index 8c4400db42bc..d5f9995172f8 100755
> --- a/configure
> +++ b/configure
> @@ -392,7 +392,6 @@ elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
>           : "${uart_early_addr:=0x9000000}"
>       elif [ "$target" = "kvmtool" ]; then
>           : "${uart_early_addr:=0x1000000}"
> -        errata_force=1
>       else
>           echo "--target must be one of 'qemu' or 'kvmtool'!"
>           usage
> diff --git a/scripts/vmm.bash b/scripts/vmm.bash
> index ef9819f4132c..4ae60c37a6e8 100644
> --- a/scripts/vmm.bash
> +++ b/scripts/vmm.bash
> @@ -159,7 +159,7 @@ declare -A vmm_opts=(
>   function check_vmm_supported()
>   {
>   	case "$TARGET" in
> -	qemu)
> +	qemu | kvmtool)
>   		return 0
>   		;;
>   	*)

-- 
Shaoqin


-- 
kvm-riscv mailing list
kvm-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kvm-riscv

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

end of thread, other threads:[~2025-05-21  6:22 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-07 15:12 [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Alexandru Elisei
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 01/16] scripts: unittests.cfg: Rename 'extra_params' to 'qemu_params' Alexandru Elisei
2025-05-07 15:40   ` Andrew Jones
2025-05-14  2:57   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 02/16] scripts: Add 'test_args' test definition parameter Alexandru Elisei
2025-05-07 15:58   ` Andrew Jones
2025-05-14  3:16   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 03/16] configure: Export TARGET unconditionally Alexandru Elisei
2025-05-07 16:02   ` Andrew Jones
2025-05-08  8:52     ` Alexandru Elisei
2025-05-08  9:39       ` Andrew Jones
2025-05-08 10:05         ` Alexandru Elisei
2025-05-08 10:17           ` Andrew Jones
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 04/16] run_tests.sh: Document --probe-maxsmp argument Alexandru Elisei
2025-05-14  3:29   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 05/16] scripts: Document environment variables Alexandru Elisei
2025-05-14  3:36   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 06/16] scripts: Refuse to run the tests if not configured for qemu Alexandru Elisei
2025-05-07 16:10   ` Andrew Jones
2025-05-07 16:14     ` Alexandru Elisei
2025-05-14  7:49   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 07/16] scripts: Use an associative array for qemu argument names Alexandru Elisei
2025-05-07 16:17   ` Andrew Jones
2025-05-14  8:02   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 08/16] scripts: Add 'kvmtool_params' to test definition Alexandru Elisei
2025-05-07 16:28   ` Andrew Jones
2025-05-08 15:54     ` Alexandru Elisei
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 09/16] scripts: Add support for kvmtool Alexandru Elisei
2025-05-07 16:38   ` Andrew Jones
2025-05-19  8:55   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 10/16] scripts: Add default arguments " Alexandru Elisei
2025-05-07 16:43   ` Andrew Jones
2025-05-21  3:21   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 11/16] scripts: Add KVMTOOL environment variable for kvmtool binary path Alexandru Elisei
2025-05-07 16:45   ` Andrew Jones
2025-05-19  8:13   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 12/16] scripts: Detect kvmtool failure in premature_failure() Alexandru Elisei
2025-05-07 16:47   ` Andrew Jones
2025-05-21  5:58   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 13/16] scripts: Do not probe for maximum number of VCPUs when using kvmtool Alexandru Elisei
2025-05-07 16:48   ` Andrew Jones
2025-05-21  6:02   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 14/16] scripts/mkstandalone: Export $TARGET Alexandru Elisei
2025-05-21  6:16   ` Shaoqin Huang
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 15/16] scripts: Add 'disabled_if' test definition parameter for kvmtool to use Alexandru Elisei
2025-05-07 16:56   ` Andrew Jones
2025-05-07 15:12 ` [kvm-unit-tests PATCH v3 16/16] scripts: Enable kvmtool Alexandru Elisei
2025-05-07 16:59   ` Andrew Jones
2025-05-21  6:20   ` Shaoqin Huang
2025-05-19  8:56 ` [kvm-unit-tests PATCH v3 00/16] arm/arm64: Add kvmtool to the runner script Shaoqin Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).