Add a test case to ensure reordering the feature handling code won't make accelerator-specific defaults override explicit command-line options. Explicit command-line options should always override the CPU model defaults.
Signed-off-by: Eduardo Habkost <ehabk...@redhat.com> --- tests/test-x86-cpu.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test-x86-cpu.c b/tests/test-x86-cpu.c index b1b04ea..618624b 100644 --- a/tests/test-x86-cpu.c +++ b/tests/test-x86-cpu.c @@ -160,6 +160,36 @@ static void test_host_cpu_features_kvm(void) all_unsupported = false; } +/* Ensure that explicit CPU options always override KVM-specific defaults */ +static void test_kvm_override(void) +{ + int i; + kvm_allowed = true; + + /* Even KVM defaults change on cpu.c, this test relies on x2apic being + * always enabled, and monitor being always disabled by KVM: + */ + kvm_default_features[FEAT_1_ECX] |= CPUID_EXT_X2APIC; + kvm_default_unset_features[FEAT_1_ECX] |= CPUID_EXT_MONITOR; + + for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); ++i) { + ObjectClass *oc; + X86CPU *cpu; + X86CPUDefinition *def = &builtin_x86_defs[i]; + char features[] = "-x2apic,+monitor"; + + oc = x86_cpu_class_by_name(def->name); + cpu = X86_CPU(object_new(object_class_get_name(oc))); + x86_cpu_parse_featurestr(CPU(cpu), features, &error_abort); + + g_assert_cmpint(cpu->env.features[FEAT_1_ECX] & CPUID_EXT_MONITOR, ==, + CPUID_EXT_MONITOR); + g_assert_cmpint(cpu->env.features[FEAT_1_ECX] & CPUID_EXT_X2APIC, ==, + 0); + object_unref(OBJECT(cpu)); + } +} + int main(int argc, char *argv[]) { module_call_init(MODULE_INIT_QOM); @@ -170,6 +200,7 @@ int main(int argc, char *argv[]) g_test_add_func("/cpu/x86/features/tcg", test_cpu_features_tcg); g_test_add_func("/cpu/x86/features/kvm", test_cpu_features_kvm); g_test_add_func("/cpu/x86/features/host", test_host_cpu_features_kvm); + g_test_add_func("/cpu/x86/features/kvm-override", test_kvm_override); g_test_run(); -- 2.1.0