From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq2sr-0002kQ-HG for qemu-devel@nongnu.org; Fri, 30 Sep 2016 14:50:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bq2sp-00033r-1s for qemu-devel@nongnu.org; Fri, 30 Sep 2016 14:50:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42002) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq2so-00033G-PC for qemu-devel@nongnu.org; Fri, 30 Sep 2016 14:50:06 -0400 From: Eduardo Habkost Date: Fri, 30 Sep 2016 15:49:35 -0300 Message-Id: <1475261386-20211-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1475261386-20211-1-git-send-email-ehabkost@redhat.com> References: <1475261386-20211-1-git-send-email-ehabkost@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v5 01/12] tests: Add test case for x86 feature parsing compatibility List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: dahi@linux.vnet.ibm.com, Paolo Bonzini , Igor Mammedov , Jiri Denemark , Markus Armbruster , Richard Henderson , libvir-list@redhat.com Add a new test case to ensure the existing behavior of the feature parsing code will be kept. Signed-off-by: Eduardo Habkost --- Changes series v4 -> v5: * Fix typo on commit message Reported-by: Jonathan Neusch=C3=A4fer * Add comment noting that the "[+-]feature" compatibility mode will be removed soon Changes series v3 -> v4: * New patch added to series --- tests/test-x86-cpuid-compat.c | 44 +++++++++++++++++++++++++++++++++++++= ++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.= c index 83162a4..260dd27 100644 --- a/tests/test-x86-cpuid-compat.c +++ b/tests/test-x86-cpuid-compat.c @@ -3,6 +3,7 @@ #include "qapi/qmp/qlist.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qint.h" +#include "qapi/qmp/qbool.h" #include "libqtest.h" =20 static char *get_cpu0_qom_path(void) @@ -34,6 +35,15 @@ static QObject *qom_get(const char *path, const char *= prop) return ret; } =20 +static bool qom_get_bool(const char *path, const char *prop) +{ + QBool *value =3D qobject_to_qbool(qom_get(path, prop)); + bool b =3D qbool_get_bool(value); + + QDECREF(value); + return b; +} + typedef struct CpuidTestArgs { const char *cmdline; const char *property; @@ -66,10 +76,44 @@ static void add_cpuid_test(const char *name, const ch= ar *cmdline, qtest_add_data_func(name, args, test_cpuid_prop); } =20 +static void test_plus_minus(void) +{ + char *path; + + /* Rules: + * 1)"-foo" overrides "+foo" + * 2) "[+-]foo" overrides "foo=3D..." + * 3) Old feature names with underscores (e.g. "sse4_2") + * should keep working + * + * Note: rules 1 and 2 are planned to be removed soon, but we + * need to keep compatibility for a while until we start + * warning users about it. + */ + qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=3Don,+cx8,cx8=3Doff,+ss= e4_1,sse4_2=3Don"); + path =3D get_cpu0_qom_path(); + + g_assert_false(qom_get_bool(path, "fpu")); + g_assert_false(qom_get_bool(path, "mce")); + g_assert_true(qom_get_bool(path, "cx8")); + + /* Test both the original and the alias feature names: */ + g_assert_true(qom_get_bool(path, "sse4-1")); + g_assert_true(qom_get_bool(path, "sse4.1")); + + g_assert_true(qom_get_bool(path, "sse4-2")); + g_assert_true(qom_get_bool(path, "sse4.2")); + + qtest_end(); + g_free(path); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); =20 + qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus); + /* Original level values for CPU models: */ add_cpuid_test("x86/cpuid/phenom/level", "-cpu phenom", "level", 5); --=20 2.7.4