[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH for-2.4 v5 6/7] tests: test-x86-cpu: Add KVM feature
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PATCH for-2.4 v5 6/7] tests: test-x86-cpu: Add KVM feature bit initialization test |
Date: |
Mon, 23 Mar 2015 16:37:11 -0300 |
Signed-off-by: Eduardo Habkost <address@hidden>
---
tests/test-x86-cpu.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git a/tests/test-x86-cpu.c b/tests/test-x86-cpu.c
index a0923e7..b1b04ea 100644
--- a/tests/test-x86-cpu.c
+++ b/tests/test-x86-cpu.c
@@ -78,6 +78,88 @@ static void test_cpu_features_tcg(void)
}
}
+static void test_cpu_features_kvm(void)
+{
+ int i;
+ kvm_allowed = true;
+
+ for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); ++i) {
+ FeatureWord w;
+ ObjectClass *oc;
+ X86CPU *cpu;
+ X86CPUDefinition *def = &builtin_x86_defs[i];
+ char features[] = "";
+
+ 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);
+
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ uint32_t expected = (def->features[w] | default_features_all[w] |
+ kvm_default_features[w]) &
+ ~kvm_default_unset_features[w];
+ uint32_t actual = cpu->env.features[w];
+ g_assert_cmpint(actual, ==, expected);
+ }
+ object_unref(OBJECT(cpu));
+ }
+}
+
+static void test_host_cpu_features_kvm(void)
+{
+ FeatureWord w;
+ ObjectClass *oc;
+ X86CPU *cpu;
+ char features1[] = "migratable=off";
+ char features2[] = "migratable=off";
+ char features3[] = "migratable=off";
+
+ kvm_allowed = true;
+ oc = x86_cpu_class_by_name("host");
+
+ /* fake_cpuid() test mode: */
+ use_fake_cpuid = true;
+ cpu = X86_CPU(object_new(object_class_get_name(oc)));
+ x86_cpu_parse_featurestr(CPU(cpu), features1, &error_abort);
+
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ FeatureWordInfo *wi = &feature_word_info[w];
+ uint32_t expected = fake_cpuid(wi->cpuid_eax, wi->cpuid_ecx,
+ wi->cpuid_reg);
+ uint32_t actual = cpu->env.features[w];
+ g_assert_cmpint(cpu->filtered_features[w], ==, 0);
+ g_assert_cmpint(actual, ==, expected);
+ }
+ object_unref(OBJECT(cpu));
+
+ /* all-supported test mode: */
+ use_fake_cpuid = false;
+ cpu = X86_CPU(object_new(object_class_get_name(oc)));
+ x86_cpu_parse_featurestr(CPU(cpu), features2, &error_abort);
+
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ uint32_t expected = ~0;
+ uint32_t actual = cpu->env.features[w];
+ g_assert_cmpint(cpu->filtered_features[w], ==, 0);
+ g_assert_cmpint(actual, ==, expected);
+ }
+ object_unref(OBJECT(cpu));
+
+ /* all-unsupported test mode: */
+ all_unsupported = true;
+ cpu = X86_CPU(object_new(object_class_get_name(oc)));
+ x86_cpu_parse_featurestr(CPU(cpu), features3, &error_abort);
+
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ uint32_t expected = 0;
+ uint32_t actual = cpu->env.features[w];
+ g_assert_cmpint(cpu->filtered_features[w], ==, 0);
+ g_assert_cmpint(actual, ==, expected);
+ }
+ object_unref(OBJECT(cpu));
+ all_unsupported = false;
+}
+
int main(int argc, char *argv[])
{
module_call_init(MODULE_INIT_QOM);
@@ -86,6 +168,8 @@ int main(int argc, char *argv[])
g_test_add_func("/cpu/x86/creation", test_cpu_creation);
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_run();
--
2.1.0
- [Qemu-devel] [PATCH for-2.4 v5 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code, Eduardo Habkost, 2015/03/23
- [Qemu-devel] [PATCH for-2.4 v5 1/7] tests: Support target-specific unit tests, Eduardo Habkost, 2015/03/23
- [Qemu-devel] [PATCH for-2.4 v5 2/7] tests: Make test-x86-cpuid target-specific, Eduardo Habkost, 2015/03/23
- [Qemu-devel] [PATCH for-2.4 v5 4/7] target-i386: Isolate enabled-by-default features to a separate array, Eduardo Habkost, 2015/03/23
- [Qemu-devel] [PATCH for-2.4 v5 5/7] tests: test-x86-cpu: Add TCG feature bit initialization test, Eduardo Habkost, 2015/03/23
- [Qemu-devel] [PATCH for-2.4 v5 3/7] tests: Add unit test for X86CPU code, Eduardo Habkost, 2015/03/23
- [Qemu-devel] [PATCH for-2.4 v5 6/7] tests: test-x86-cpu: Add KVM feature bit initialization test,
Eduardo Habkost <=
- [Qemu-devel] [PATCH for-2.4 v5 7/7] tests: test-x86-cpu: Ensure that -cpu override KVM-specific defaults, Eduardo Habkost, 2015/03/23