From nobody Thu May 2 17:27:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1494268387394887.3897981438703; Mon, 8 May 2017 11:33:07 -0700 (PDT) Received: from localhost ([::1]:60888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7nSz-0004BM-Nf for importer@patchew.org; Mon, 08 May 2017 14:33:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7nS8-0003Pa-4J for qemu-devel@nongnu.org; Mon, 08 May 2017 14:32:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d7nS4-0005A2-Um for qemu-devel@nongnu.org; Mon, 08 May 2017 14:32:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d7nS4-00059t-Lv for qemu-devel@nongnu.org; Mon, 08 May 2017 14:32:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7120680F97 for ; Mon, 8 May 2017 18:32:07 +0000 (UTC) Received: from localhost (ovpn-116-2.gru2.redhat.com [10.97.116.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 071D6176A4; Mon, 8 May 2017 18:32:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7120680F97 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ehabkost@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7120680F97 From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Mon, 8 May 2017 15:32:05 -0300 Message-Id: <20170508183205.10884-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 08 May 2017 18:32:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] tests: Add [+-]feature and feature=on|off test cases X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add test code to ensure features are enabled/disabled correctly in the command-line. The test case use the "feature-words" and "filtered-features" properties to check if the features were enabled/disabled correctly. Signed-off-by: Eduardo Habkost Reviewed-by: Igor Mammedov --- Changes v1 -> v2: * Remove explicit "accel=3D" option to avoid triggering warnings on "make check" * Use qdict_get_*() helpers to make code shorter * Rename input_eax, input_ecx to in_eax, in_ecx to make lines fit in the coding style width limit * v1 was submitted as part of the series: Subject: [PATCH 0/4] x86: Support "-cpu feature=3Dforce" * Coding style: split lines * Style changes on code comments --- tests/test-x86-cpuid-compat.c | 111 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 111 insertions(+) diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c index 79a2e69a28..6c71e46391 100644 --- a/tests/test-x86-cpuid-compat.c +++ b/tests/test-x86-cpuid-compat.c @@ -1,6 +1,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qapi/qmp/qlist.h" +#include "qapi/qmp/qstring.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qint.h" #include "qapi/qmp/qbool.h" @@ -78,6 +79,90 @@ static void add_cpuid_test(const char *name, const char = *cmdline, qtest_add_data_func(name, args, test_cpuid_prop); } =20 + +/* Parameters to a add_feature_test() test case */ +typedef struct FeatureTestArgs { + /* cmdline to start QEMU */ + const char *cmdline; + /* + * cpuid-input-eax and cpuid-input-ecx values to look for, + * in "feature-words" and "filtered-features" properties. + */ + uint32_t in_eax, in_ecx; + /* The register name to look for, in the X86CPUFeatureWordInfo array */ + const char *reg; + /* The bit to check in X86CPUFeatureWordInfo.features */ + int bitnr; + /* The expected value for the bit in (X86CPUFeatureWordInfo.features) = */ + bool expected_value; +} FeatureTestArgs; + +/* Get the value for a feature word in a X86CPUFeatureWordInfo list */ +static uint32_t get_feature_word(QList *features, uint32_t eax, uint32_t e= cx, + const char *reg) +{ + const QListEntry *e; + + for (e =3D qlist_first(features); e; e =3D qlist_next(e)) { + QDict *w =3D qobject_to_qdict(qlist_entry_obj(e)); + const char *rreg =3D qdict_get_str(w, "cpuid-register"); + uint32_t reax =3D qdict_get_int(w, "cpuid-input-eax"); + bool has_ecx =3D qdict_haskey(w, "cpuid-input-ecx"); + uint32_t recx =3D 0; + + if (has_ecx) { + recx =3D qdict_get_int(w, "cpuid-input-ecx"); + } + if (eax =3D=3D reax && (!has_ecx || ecx =3D=3D recx) && !strcmp(rr= eg, reg)) { + return qint_get_int(qobject_to_qint(qdict_get(w, "features"))); + } + } + return 0; +} + +static void test_feature_flag(const void *data) +{ + const FeatureTestArgs *args =3D data; + char *path; + QList *present, *filtered; + uint32_t value; + + qtest_start(args->cmdline); + path =3D get_cpu0_qom_path(); + present =3D qobject_to_qlist(qom_get(path, "feature-words")); + filtered =3D qobject_to_qlist(qom_get(path, "filtered-features")); + value =3D get_feature_word(present, args->in_eax, args->in_ecx, args->= reg); + value |=3D get_feature_word(filtered, args->in_eax, args->in_ecx, args= ->reg); + qtest_end(); + + g_assert(!!(value & (1U << args->bitnr)) =3D=3D args->expected_value); + + QDECREF(present); + QDECREF(filtered); + g_free(path); +} + +/* + * Add test case to ensure that a given feature flag is set in + * either "feature-words" or "filtered-features", when running QEMU + * using cmdline + */ +static FeatureTestArgs *add_feature_test(const char *name, const char *cmd= line, + uint32_t eax, uint32_t ecx, + const char *reg, int bitnr, + bool expected_value) +{ + FeatureTestArgs *args =3D g_new0(FeatureTestArgs, 1); + args->cmdline =3D cmdline; + args->in_eax =3D eax; + args->in_ecx =3D ecx; + args->reg =3D reg; + args->bitnr =3D bitnr; + args->expected_value =3D expected_value; + qtest_add_data_func(name, args, test_feature_flag); + return args; +} + #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS static void test_plus_minus_subprocess(void) { @@ -229,5 +314,31 @@ int main(int argc, char **argv) "-machine pc-i440fx-2.7 -cpu 486,+xstore", "xlevel2", 0); =20 + /* Test feature parsing */ + add_feature_test("x86/cpuid/features/plus", + "-cpu 486,+arat", + 6, 0, "EAX", 2, true); + add_feature_test("x86/cpuid/features/minus", + "-cpu pentium,-mmx", + 1, 0, "EDX", 23, false); + add_feature_test("x86/cpuid/features/on", + "-cpu 486,arat=3Don", + 6, 0, "EAX", 2, true); + add_feature_test("x86/cpuid/features/off", + "-cpu pentium,mmx=3Doff", + 1, 0, "EDX", 23, false); + add_feature_test("x86/cpuid/features/max-plus-invtsc", + "-cpu max,+invtsc", + 0x80000007, 0, "EDX", 8, true); + add_feature_test("x86/cpuid/features/max-invtsc-on", + "-cpu max,invtsc=3Don", + 0x80000007, 0, "EDX", 8, true); + add_feature_test("x86/cpuid/features/max-minus-mmx", + "-cpu max,-mmx", + 1, 0, "EDX", 23, false); + add_feature_test("x86/cpuid/features/max-invtsc-on,mmx=3Doff", + "-cpu max,mmx=3Doff", + 1, 0, "EDX", 23, false); + return g_test_run(); } --=20 2.11.0.259.g40922b1