tests/qtest/test-x86-cpuid-compat: Check for machines before using them

The user might have disabled the pc-i440fx machine type (or it's older
versions, like done in downstream RHEL) in the QEMU binary, so let's
better check whether the machine types are available before using them.

Message-Id: <20211222153923.1000420-1-thuth@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Thomas Huth 2021-12-22 16:39:23 +01:00
parent 01854af2cf
commit 7539fa0116

View file

@ -302,54 +302,65 @@ int main(int argc, char **argv)
/* Check compatibility of old machine-types that didn't /* Check compatibility of old machine-types that didn't
* auto-increase level/xlevel/xlevel2: */ * auto-increase level/xlevel/xlevel2: */
if (qtest_has_machine("pc-i440fx-2.7")) {
add_cpuid_test("x86/cpuid/auto-level/pc-2.7", add_cpuid_test("x86/cpuid/auto-level/pc-2.7",
"-machine pc-i440fx-2.7 -cpu 486,arat=on,avx512vbmi=on,xsaveopt=on", "-machine pc-i440fx-2.7 -cpu 486,arat=on,avx512vbmi=on,xsaveopt=on",
"level", 1); "level", 1);
add_cpuid_test("x86/cpuid/auto-xlevel/pc-2.7", add_cpuid_test("x86/cpuid/auto-xlevel/pc-2.7",
"-machine pc-i440fx-2.7 -cpu 486,3dnow=on,sse4a=on,invtsc=on,npt=on,svm=on", "-machine pc-i440fx-2.7 -cpu 486,3dnow=on,sse4a=on,invtsc=on,npt=on,svm=on",
"xlevel", 0); "xlevel", 0);
add_cpuid_test("x86/cpuid/auto-xlevel2/pc-2.7", add_cpuid_test("x86/cpuid/auto-xlevel2/pc-2.7",
"-machine pc-i440fx-2.7 -cpu 486,xstore=on", "-machine pc-i440fx-2.7 -cpu 486,xstore=on",
"xlevel2", 0); "xlevel2", 0);
}
/* /*
* QEMU 1.4.0 had auto-level enabled for CPUID[7], already, * QEMU 1.4.0 had auto-level enabled for CPUID[7], already,
* and the compat code that sets default level shouldn't * and the compat code that sets default level shouldn't
* disable the auto-level=7 code: * disable the auto-level=7 code:
*/ */
add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.4/off", if (qtest_has_machine("pc-i440fx-1.4")) {
"-machine pc-i440fx-1.4 -cpu Nehalem", add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.4/off",
"level", 2); "-machine pc-i440fx-1.4 -cpu Nehalem",
add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.5/on", "level", 2);
"-machine pc-i440fx-1.4 -cpu Nehalem,smap=on", add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-1.5/on",
"level", 7); "-machine pc-i440fx-1.4 -cpu Nehalem,smap=on",
add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/off", "level", 7);
"-machine pc-i440fx-2.3 -cpu Penryn", }
"level", 4); if (qtest_has_machine("pc-i440fx-2.3")) {
add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/on", add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/off",
"-machine pc-i440fx-2.3 -cpu Penryn,erms=on", "-machine pc-i440fx-2.3 -cpu Penryn",
"level", 7); "level", 4);
add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/off", add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.3/on",
"-machine pc-i440fx-2.9 -cpu Conroe", "-machine pc-i440fx-2.3 -cpu Penryn,erms=on",
"level", 10); "level", 7);
add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/on", }
"-machine pc-i440fx-2.9 -cpu Conroe,erms=on", if (qtest_has_machine("pc-i440fx-2.9")) {
"level", 10); add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/off",
"-machine pc-i440fx-2.9 -cpu Conroe",
"level", 10);
add_cpuid_test("x86/cpuid/auto-level7/pc-i440fx-2.9/on",
"-machine pc-i440fx-2.9 -cpu Conroe,erms=on",
"level", 10);
}
/* /*
* xlevel doesn't have any feature that triggers auto-level * xlevel doesn't have any feature that triggers auto-level
* code on old machine-types. Just check that the compat code * code on old machine-types. Just check that the compat code
* is working correctly: * is working correctly:
*/ */
add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.3", if (qtest_has_machine("pc-i440fx-2.3")) {
"-machine pc-i440fx-2.3 -cpu SandyBridge", add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.3",
"xlevel", 0x8000000a); "-machine pc-i440fx-2.3 -cpu SandyBridge",
add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-off", "xlevel", 0x8000000a);
"-machine pc-i440fx-2.4 -cpu SandyBridge,", }
"xlevel", 0x80000008); if (qtest_has_machine("pc-i440fx-2.4")) {
add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on", add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-off",
"-machine pc-i440fx-2.4 -cpu SandyBridge,svm=on,npt=on", "-machine pc-i440fx-2.4 -cpu SandyBridge,",
"xlevel", 0x80000008); "xlevel", 0x80000008);
add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on",
"-machine pc-i440fx-2.4 -cpu SandyBridge,svm=on,npt=on",
"xlevel", 0x80000008);
}
/* Test feature parsing */ /* Test feature parsing */
add_feature_test("x86/cpuid/features/plus", add_feature_test("x86/cpuid/features/plus",