qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, Igor Mammedov <imammedo@redhat.com>
Subject: [Qemu-devel] [PATCH v3 7/7] tests: test-x86-cpu: Add KVM feature bit initialization test
Date: Wed, 10 Dec 2014 17:26:50 -0200	[thread overview]
Message-ID: <1418239610-3997-8-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1418239610-3997-1-git-send-email-ehabkost@redhat.com>

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/test-x86-cpu.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tests/test-x86-cpu.c b/tests/test-x86-cpu.c
index fb3de05..20842c5 100644
--- a/tests/test-x86-cpu.c
+++ b/tests/test-x86-cpu.c
@@ -78,6 +78,94 @@ 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;
+        Error *error = NULL;
+        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);
+
+        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] | cpu->filtered_features[w];
+            g_assert_cmpint(actual, ==, expected);
+            /*TODO: test this after moving feature filtering outside realizefn:
+            uint32_t expect_filtered = expected &
+                ~x86_cpu_get_supported_feature_word(w, true);
+            g_assert_cmpint(cpu->filtered_features[w], ==, expect_filtered);
+            */
+        }
+        object_unref(OBJECT(cpu));
+    }
+}
+
+static void test_host_cpu_features_kvm(void)
+{
+    FeatureWord w;
+    ObjectClass *oc;
+    X86CPU *cpu;
+    Error *error = NULL;
+    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: */
+    cpu = X86_CPU(object_new(object_class_get_name(oc)));
+    x86_cpu_parse_featurestr(CPU(cpu), features1, &error);
+
+    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: */
+    all_supported = true;
+    cpu = X86_CPU(object_new(object_class_get_name(oc)));
+    x86_cpu_parse_featurestr(CPU(cpu), features2, &error);
+
+    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_supported = false;
+    all_unsupported = true;
+    cpu = X86_CPU(object_new(object_class_get_name(oc)));
+    x86_cpu_parse_featurestr(CPU(cpu), features3, &error);
+
+    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 +174,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();
 
-- 
1.9.3

      parent reply	other threads:[~2014-12-10 19:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-10 19:26 [Qemu-devel] [PATCH v3 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h Eduardo Habkost
2014-12-10 19:44   ` Peter Maydell
2014-12-12 18:20     ` Eduardo Habkost
2014-12-15  9:30       ` Thomas Huth
2014-12-15 10:17       ` Greg Kurz
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 2/7] tests: Support target-specific unit tests Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 3/7] tests: Make test-x86-cpuid target-specific Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 4/7] tests: Add unit test for X86CPU code Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 5/7] target-i386: Isolate enabled-by-default features to a separate array Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 6/7] tests: test-x86-cpu: Add TCG feature bit initialization test Eduardo Habkost
2014-12-10 19:26 ` Eduardo Habkost [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418239610-3997-8-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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).