From patchwork Wed Dec 10 19:26:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 419830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 152C71400D5 for ; Thu, 11 Dec 2014 06:28:04 +1100 (AEDT) Received: from localhost ([::1]:47549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XymvZ-0001r4-Kj for incoming@patchwork.ozlabs.org; Wed, 10 Dec 2014 14:28:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xymuq-0000XI-2b for qemu-devel@nongnu.org; Wed, 10 Dec 2014 14:27:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xymuj-0007nt-4p for qemu-devel@nongnu.org; Wed, 10 Dec 2014 14:27:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xymui-0007ne-TF for qemu-devel@nongnu.org; Wed, 10 Dec 2014 14:27:09 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBAJR81M026196 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 10 Dec 2014 14:27:08 -0500 Received: from localhost (ovpn-113-88.phx2.redhat.com [10.3.113.88]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBAJR7rs027300; Wed, 10 Dec 2014 14:27:07 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Wed, 10 Dec 2014 17:26:50 -0200 Message-Id: <1418239610-3997-8-git-send-email-ehabkost@redhat.com> In-Reply-To: <1418239610-3997-1-git-send-email-ehabkost@redhat.com> References: <1418239610-3997-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Igor Mammedov Subject: [Qemu-devel] [PATCH v3 7/7] tests: test-x86-cpu: Add KVM feature bit initialization test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Eduardo Habkost --- 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();