* [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off)
@ 2016-10-21 19:41 Eduardo Habkost
2016-10-24 11:36 ` Igor Mammedov
2016-10-24 13:36 ` Igor Mammedov
0 siblings, 2 replies; 7+ messages in thread
From: Eduardo Habkost @ 2016-10-21 19:41 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Richard Henderson, Igor Mammedov
Print a warning when mixing [+-]foo and foo=(on|off) in the -cpu
argument in a way that will break in the future.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Coding style fixes
* Print "compatibility won't be kept" warning only once
* Move subprocess test code inside
#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
---
target-i386/cpu.c | 24 ++++++++++++++++++++++++
tests/test-x86-cpuid-compat.c | 26 +++++++++++++++++++++-----
2 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d95514c..dd5b7a7 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1973,6 +1973,11 @@ static const char *x86_cpu_feature_name(FeatureWord w, int bitnr)
*/
static GList *plus_features, *minus_features;
+static gint compare_string(gconstpointer a, gconstpointer b)
+{
+ return g_strcmp0(a, b);
+}
+
/* Parse "+feature,-feature,feature=foo" CPU feature string
*/
static void x86_cpu_parse_featurestr(const char *typename, char *features,
@@ -1981,6 +1986,7 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
char *featurestr; /* Single 'key=value" string being parsed */
Error *local_err = NULL;
static bool cpu_globals_initialized;
+ bool ambiguous = false;
if (cpu_globals_initialized) {
return;
@@ -2022,6 +2028,19 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
feat2prop(featurestr);
name = featurestr;
+ if (g_list_find_custom(plus_features, name, compare_string)) {
+ error_report("warning: Ambiguous CPU model string. "
+ "Don't mix both \"+%s\" and \"%s=%s\"",
+ name, name, val);
+ ambiguous = true;
+ }
+ if (g_list_find_custom(minus_features, name, compare_string)) {
+ error_report("warning: Ambiguous CPU model string. "
+ "Don't mix both \"-%s\" and \"%s=%s\"",
+ name, name, val);
+ ambiguous = true;
+ }
+
/* Special case: */
if (!strcmp(name, "tsc-freq")) {
int64_t tsc_freq;
@@ -2046,6 +2065,11 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
qdev_prop_register_global(prop);
}
+ if (ambiguous) {
+ error_report("warning: Compatibility of ambiguous CPU model "
+ "strings won't be kept on future QEMU versions");
+ }
+
if (local_err) {
error_propagate(errp, local_err);
}
diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c
index 260dd27..df3fc7b 100644
--- a/tests/test-x86-cpuid-compat.c
+++ b/tests/test-x86-cpuid-compat.c
@@ -76,7 +76,7 @@ static void add_cpuid_test(const char *name, const char *cmdline,
qtest_add_data_func(name, args, test_cpuid_prop);
}
-static void test_plus_minus(void)
+static void test_plus_minus_subprocess(void)
{
char *path;
@@ -86,9 +86,8 @@ static void test_plus_minus(void)
* 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.
+ * Note: rules 1 and 2 are planned to be removed soon, and
+ * should generate a warning.
*/
qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
path = get_cpu0_qom_path();
@@ -108,11 +107,28 @@ static void test_plus_minus(void)
g_free(path);
}
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
+static void test_plus_minus(void)
+{
+ g_test_trap_subprocess("/x86/cpuid/parsing-plus-minus/subprocess", 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("*Ambiguous CPU model string. "
+ "Don't mix both \"-mce\" and \"mce=on\"*");
+ g_test_trap_assert_stderr("*Ambiguous CPU model string. "
+ "Don't mix both \"+cx8\" and \"cx8=off\"*");
+ g_test_trap_assert_stdout("");
+}
+#endif
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
- qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus);
+ g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess",
+ test_plus_minus_subprocess);
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
+ g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus);
+#endif
/* Original level values for CPU models: */
add_cpuid_test("x86/cpuid/phenom/level",
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off)
2016-10-21 19:41 [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off) Eduardo Habkost
@ 2016-10-24 11:36 ` Igor Mammedov
2016-10-24 13:14 ` Eduardo Habkost
2016-10-24 13:36 ` Igor Mammedov
1 sibling, 1 reply; 7+ messages in thread
From: Igor Mammedov @ 2016-10-24 11:36 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: qemu-devel, Paolo Bonzini, Richard Henderson
On Fri, 21 Oct 2016 17:41:13 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:
> Print a warning when mixing [+-]foo and foo=(on|off) in the -cpu
> argument in a way that will break in the future.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Changes v1 -> v2:
> * Coding style fixes
> * Print "compatibility won't be kept" warning only once
> * Move subprocess test code inside
> #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> ---
> target-i386/cpu.c | 24 ++++++++++++++++++++++++
> tests/test-x86-cpuid-compat.c | 26 +++++++++++++++++++++-----
> 2 files changed, 45 insertions(+), 5 deletions(-)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index d95514c..dd5b7a7 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1973,6 +1973,11 @@ static const char *x86_cpu_feature_name(FeatureWord w, int bitnr)
> */
> static GList *plus_features, *minus_features;
>
> +static gint compare_string(gconstpointer a, gconstpointer b)
> +{
> + return g_strcmp0(a, b);
> +}
> +
> /* Parse "+feature,-feature,feature=foo" CPU feature string
> */
> static void x86_cpu_parse_featurestr(const char *typename, char *features,
> @@ -1981,6 +1986,7 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
> char *featurestr; /* Single 'key=value" string being parsed */
> Error *local_err = NULL;
> static bool cpu_globals_initialized;
> + bool ambiguous = false;
>
> if (cpu_globals_initialized) {
> return;
> @@ -2022,6 +2028,19 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
> feat2prop(featurestr);
> name = featurestr;
>
> + if (g_list_find_custom(plus_features, name, compare_string)) {
> + error_report("warning: Ambiguous CPU model string. "
> + "Don't mix both \"+%s\" and \"%s=%s\"",
> + name, name, val);
> + ambiguous = true;
> + }
> + if (g_list_find_custom(minus_features, name, compare_string)) {
> + error_report("warning: Ambiguous CPU model string. "
> + "Don't mix both \"-%s\" and \"%s=%s\"",
> + name, name, val);
> + ambiguous = true;
> + }
> +
> /* Special case: */
> if (!strcmp(name, "tsc-freq")) {
> int64_t tsc_freq;
> @@ -2046,6 +2065,11 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
> qdev_prop_register_global(prop);
> }
>
> + if (ambiguous) {
> + error_report("warning: Compatibility of ambiguous CPU model "
> + "strings won't be kept on future QEMU versions");
> + }
> +
> if (local_err) {
> error_propagate(errp, local_err);
> }
> diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c
> index 260dd27..df3fc7b 100644
> --- a/tests/test-x86-cpuid-compat.c
> +++ b/tests/test-x86-cpuid-compat.c
> @@ -76,7 +76,7 @@ static void add_cpuid_test(const char *name, const char *cmdline,
> qtest_add_data_func(name, args, test_cpuid_prop);
> }
>
> -static void test_plus_minus(void)
> +static void test_plus_minus_subprocess(void)
> {
> char *path;
>
> @@ -86,9 +86,8 @@ static void test_plus_minus(void)
> * 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.
> + * Note: rules 1 and 2 are planned to be removed soon, and
> + * should generate a warning.
> */
> qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
> path = get_cpu0_qom_path();
> @@ -108,11 +107,28 @@ static void test_plus_minus(void)
> g_free(path);
> }
>
> +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> +static void test_plus_minus(void)
> +{
> + g_test_trap_subprocess("/x86/cpuid/parsing-plus-minus/subprocess", 0, 0);
> + g_test_trap_assert_passed();
> + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> + "Don't mix both \"-mce\" and \"mce=on\"*");
> + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> + "Don't mix both \"+cx8\" and \"cx8=off\"*");
> + g_test_trap_assert_stdout("");
> +}
> +#endif
Are there any reason to keep both subprocess and inprocess variants?
> +
> int main(int argc, char **argv)
> {
> g_test_init(&argc, &argv, NULL);
>
> - qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus);
> + g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess",
> + test_plus_minus_subprocess);
> +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> + g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus);
> +#endif
>
> /* Original level values for CPU models: */
> add_cpuid_test("x86/cpuid/phenom/level",
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off)
2016-10-24 11:36 ` Igor Mammedov
@ 2016-10-24 13:14 ` Eduardo Habkost
2016-10-24 13:35 ` Igor Mammedov
0 siblings, 1 reply; 7+ messages in thread
From: Eduardo Habkost @ 2016-10-24 13:14 UTC (permalink / raw)
To: Igor Mammedov; +Cc: qemu-devel, Paolo Bonzini, Richard Henderson
On Mon, Oct 24, 2016 at 01:36:16PM +0200, Igor Mammedov wrote:
[...]
> > +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> > +static void test_plus_minus(void)
> > +{
> > + g_test_trap_subprocess("/x86/cpuid/parsing-plus-minus/subprocess", 0, 0);
> > + g_test_trap_assert_passed();
> > + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> > + "Don't mix both \"-mce\" and \"mce=on\"*");
> > + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> > + "Don't mix both \"+cx8\" and \"cx8=off\"*");
> > + g_test_trap_assert_stdout("");
> > +}
> > +#endif
> Are there any reason to keep both subprocess and inprocess variants?
Because g_test_trap_subprocess() needs it. It takes a test path
as argument and runs another test case in a subprocess. Tests
containing "subprocess" as a path component are skipped by
default (so test_plus_minus_subprocess() is only run in a
subprocess).
>
> > +
> > int main(int argc, char **argv)
> > {
> > g_test_init(&argc, &argv, NULL);
> >
> > - qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus);
> > + g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess",
> > + test_plus_minus_subprocess);
> > +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> > + g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus);
> > +#endif
> >
> > /* Original level values for CPU models: */
> > add_cpuid_test("x86/cpuid/phenom/level",
>
--
Eduardo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off)
2016-10-24 13:14 ` Eduardo Habkost
@ 2016-10-24 13:35 ` Igor Mammedov
0 siblings, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2016-10-24 13:35 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: qemu-devel, Paolo Bonzini, Richard Henderson
On Mon, 24 Oct 2016 11:14:24 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:
> On Mon, Oct 24, 2016 at 01:36:16PM +0200, Igor Mammedov wrote:
> [...]
> > > +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> > > +static void test_plus_minus(void)
> > > +{
> > > + g_test_trap_subprocess("/x86/cpuid/parsing-plus-minus/subprocess", 0, 0);
> > > + g_test_trap_assert_passed();
> > > + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> > > + "Don't mix both \"-mce\" and \"mce=on\"*");
> > > + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> > > + "Don't mix both \"+cx8\" and \"cx8=off\"*");
> > > + g_test_trap_assert_stdout("");
> > > +}
> > > +#endif
> > Are there any reason to keep both subprocess and inprocess variants?
>
> Because g_test_trap_subprocess() needs it. It takes a test path
> as argument and runs another test case in a subprocess. Tests
> containing "subprocess" as a path component are skipped by
> default (so test_plus_minus_subprocess() is only run in a
> subprocess).
Ah I see, you are using subprocess to trap warnings on stderr
> >
> > > +
> > > int main(int argc, char **argv)
> > > {
> > > g_test_init(&argc, &argv, NULL);
> > >
> > > - qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus);
> > > + g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess",
> > > + test_plus_minus_subprocess);
> > > +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> > > + g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus);
> > > +#endif
> > >
> > > /* Original level values for CPU models: */
> > > add_cpuid_test("x86/cpuid/phenom/level",
> >
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off)
2016-10-21 19:41 [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off) Eduardo Habkost
2016-10-24 11:36 ` Igor Mammedov
@ 2016-10-24 13:36 ` Igor Mammedov
1 sibling, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2016-10-24 13:36 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: qemu-devel, Paolo Bonzini, Richard Henderson
On Fri, 21 Oct 2016 17:41:13 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:
> Print a warning when mixing [+-]foo and foo=(on|off) in the -cpu
> argument in a way that will break in the future.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> Changes v1 -> v2:
> * Coding style fixes
> * Print "compatibility won't be kept" warning only once
> * Move subprocess test code inside
> #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> ---
> target-i386/cpu.c | 24 ++++++++++++++++++++++++
> tests/test-x86-cpuid-compat.c | 26 +++++++++++++++++++++-----
> 2 files changed, 45 insertions(+), 5 deletions(-)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index d95514c..dd5b7a7 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1973,6 +1973,11 @@ static const char *x86_cpu_feature_name(FeatureWord w, int bitnr)
> */
> static GList *plus_features, *minus_features;
>
> +static gint compare_string(gconstpointer a, gconstpointer b)
> +{
> + return g_strcmp0(a, b);
> +}
> +
> /* Parse "+feature,-feature,feature=foo" CPU feature string
> */
> static void x86_cpu_parse_featurestr(const char *typename, char *features,
> @@ -1981,6 +1986,7 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
> char *featurestr; /* Single 'key=value" string being parsed */
> Error *local_err = NULL;
> static bool cpu_globals_initialized;
> + bool ambiguous = false;
>
> if (cpu_globals_initialized) {
> return;
> @@ -2022,6 +2028,19 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
> feat2prop(featurestr);
> name = featurestr;
>
> + if (g_list_find_custom(plus_features, name, compare_string)) {
> + error_report("warning: Ambiguous CPU model string. "
> + "Don't mix both \"+%s\" and \"%s=%s\"",
> + name, name, val);
> + ambiguous = true;
> + }
> + if (g_list_find_custom(minus_features, name, compare_string)) {
> + error_report("warning: Ambiguous CPU model string. "
> + "Don't mix both \"-%s\" and \"%s=%s\"",
> + name, name, val);
> + ambiguous = true;
> + }
> +
> /* Special case: */
> if (!strcmp(name, "tsc-freq")) {
> int64_t tsc_freq;
> @@ -2046,6 +2065,11 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
> qdev_prop_register_global(prop);
> }
>
> + if (ambiguous) {
> + error_report("warning: Compatibility of ambiguous CPU model "
> + "strings won't be kept on future QEMU versions");
> + }
> +
> if (local_err) {
> error_propagate(errp, local_err);
> }
> diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c
> index 260dd27..df3fc7b 100644
> --- a/tests/test-x86-cpuid-compat.c
> +++ b/tests/test-x86-cpuid-compat.c
> @@ -76,7 +76,7 @@ static void add_cpuid_test(const char *name, const char *cmdline,
> qtest_add_data_func(name, args, test_cpuid_prop);
> }
>
> -static void test_plus_minus(void)
> +static void test_plus_minus_subprocess(void)
> {
> char *path;
>
> @@ -86,9 +86,8 @@ static void test_plus_minus(void)
> * 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.
> + * Note: rules 1 and 2 are planned to be removed soon, and
> + * should generate a warning.
> */
> qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
> path = get_cpu0_qom_path();
> @@ -108,11 +107,28 @@ static void test_plus_minus(void)
> g_free(path);
> }
>
> +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> +static void test_plus_minus(void)
> +{
> + g_test_trap_subprocess("/x86/cpuid/parsing-plus-minus/subprocess", 0, 0);
> + g_test_trap_assert_passed();
> + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> + "Don't mix both \"-mce\" and \"mce=on\"*");
> + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> + "Don't mix both \"+cx8\" and \"cx8=off\"*");
> + g_test_trap_assert_stdout("");
> +}
> +#endif
> +
> int main(int argc, char **argv)
> {
> g_test_init(&argc, &argv, NULL);
>
> - qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus);
> + g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess",
> + test_plus_minus_subprocess);
> +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> + g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus);
> +#endif
>
> /* Original level values for CPU models: */
> add_cpuid_test("x86/cpuid/phenom/level",
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off)
@ 2016-10-24 19:53 Eduardo Habkost
2016-10-25 17:14 ` Igor Mammedov
0 siblings, 1 reply; 7+ messages in thread
From: Eduardo Habkost @ 2016-10-24 19:53 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Richard Henderson, Igor Mammedov
Print a warning when mixing [+-]foo and foo=(on|off) in the -cpu
argument in a way that will break in the future.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v2:
* Put the whole parsing-plus-minus test cases inside
#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS because they would
trigger warnings during "make check"
---
target-i386/cpu.c | 24 ++++++++++++++++++++++++
tests/test-x86-cpuid-compat.c | 28 +++++++++++++++++++++++-----
2 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 83998a8..0f8a8fb 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1973,6 +1973,11 @@ static const char *x86_cpu_feature_name(FeatureWord w, int bitnr)
*/
static GList *plus_features, *minus_features;
+static gint compare_string(gconstpointer a, gconstpointer b)
+{
+ return g_strcmp0(a, b);
+}
+
/* Parse "+feature,-feature,feature=foo" CPU feature string
*/
static void x86_cpu_parse_featurestr(const char *typename, char *features,
@@ -1981,6 +1986,7 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
char *featurestr; /* Single 'key=value" string being parsed */
Error *local_err = NULL;
static bool cpu_globals_initialized;
+ bool ambiguous = false;
if (cpu_globals_initialized) {
return;
@@ -2022,6 +2028,19 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
feat2prop(featurestr);
name = featurestr;
+ if (g_list_find_custom(plus_features, name, compare_string)) {
+ error_report("warning: Ambiguous CPU model string. "
+ "Don't mix both \"+%s\" and \"%s=%s\"",
+ name, name, val);
+ ambiguous = true;
+ }
+ if (g_list_find_custom(minus_features, name, compare_string)) {
+ error_report("warning: Ambiguous CPU model string. "
+ "Don't mix both \"-%s\" and \"%s=%s\"",
+ name, name, val);
+ ambiguous = true;
+ }
+
/* Special case: */
if (!strcmp(name, "tsc-freq")) {
int64_t tsc_freq;
@@ -2046,6 +2065,11 @@ static void x86_cpu_parse_featurestr(const char *typename, char *features,
qdev_prop_register_global(prop);
}
+ if (ambiguous) {
+ error_report("warning: Compatibility of ambiguous CPU model "
+ "strings won't be kept on future QEMU versions");
+ }
+
if (local_err) {
error_propagate(errp, local_err);
}
diff --git a/tests/test-x86-cpuid-compat.c b/tests/test-x86-cpuid-compat.c
index 260dd27..79a2e69 100644
--- a/tests/test-x86-cpuid-compat.c
+++ b/tests/test-x86-cpuid-compat.c
@@ -35,6 +35,7 @@ static QObject *qom_get(const char *path, const char *prop)
return ret;
}
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
static bool qom_get_bool(const char *path, const char *prop)
{
QBool *value = qobject_to_qbool(qom_get(path, prop));
@@ -43,6 +44,7 @@ static bool qom_get_bool(const char *path, const char *prop)
QDECREF(value);
return b;
}
+#endif
typedef struct CpuidTestArgs {
const char *cmdline;
@@ -76,7 +78,8 @@ static void add_cpuid_test(const char *name, const char *cmdline,
qtest_add_data_func(name, args, test_cpuid_prop);
}
-static void test_plus_minus(void)
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
+static void test_plus_minus_subprocess(void)
{
char *path;
@@ -86,9 +89,8 @@ static void test_plus_minus(void)
* 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.
+ * Note: rules 1 and 2 are planned to be removed soon, and
+ * should generate a warning.
*/
qtest_start("-cpu pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on");
path = get_cpu0_qom_path();
@@ -108,11 +110,27 @@ static void test_plus_minus(void)
g_free(path);
}
+static void test_plus_minus(void)
+{
+ g_test_trap_subprocess("/x86/cpuid/parsing-plus-minus/subprocess", 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("*Ambiguous CPU model string. "
+ "Don't mix both \"-mce\" and \"mce=on\"*");
+ g_test_trap_assert_stderr("*Ambiguous CPU model string. "
+ "Don't mix both \"+cx8\" and \"cx8=off\"*");
+ g_test_trap_assert_stdout("");
+}
+#endif
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
- qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus);
+#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
+ g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess",
+ test_plus_minus_subprocess);
+ g_test_add_func("/x86/cpuid/parsing-plus-minus", test_plus_minus);
+#endif
/* Original level values for CPU models: */
add_cpuid_test("x86/cpuid/phenom/level",
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off)
2016-10-24 19:53 Eduardo Habkost
@ 2016-10-25 17:14 ` Igor Mammedov
0 siblings, 0 replies; 7+ messages in thread
From: Igor Mammedov @ 2016-10-25 17:14 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: qemu-devel, Paolo Bonzini, Richard Henderson
On Mon, 24 Oct 2016 17:53:52 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:
> Print a warning when mixing [+-]foo and foo=(on|off) in the -cpu
> argument in a way that will break in the future.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Tested on OSX, there aren't warnings anymore.
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
> ---
> Changes v2:
> * Put the whole parsing-plus-minus test cases inside
> #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS because they would
> trigger warnings during "make check"
> ---
> target-i386/cpu.c | 24 ++++++++++++++++++++++++
> tests/test-x86-cpuid-compat.c | 28 +++++++++++++++++++++++-----
> 2 files changed, 47 insertions(+), 5 deletions(-)
>
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index 83998a8..0f8a8fb 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -1973,6 +1973,11 @@ static const char
> *x86_cpu_feature_name(FeatureWord w, int bitnr) */
> static GList *plus_features, *minus_features;
>
> +static gint compare_string(gconstpointer a, gconstpointer b)
> +{
> + return g_strcmp0(a, b);
> +}
> +
> /* Parse "+feature,-feature,feature=foo" CPU feature string
> */
> static void x86_cpu_parse_featurestr(const char *typename, char
> *features, @@ -1981,6 +1986,7 @@ static void
> x86_cpu_parse_featurestr(const char *typename, char *features, char
> *featurestr; /* Single 'key=value" string being parsed */ Error
> *local_err = NULL; static bool cpu_globals_initialized;
> + bool ambiguous = false;
>
> if (cpu_globals_initialized) {
> return;
> @@ -2022,6 +2028,19 @@ static void x86_cpu_parse_featurestr(const
> char *typename, char *features, feat2prop(featurestr);
> name = featurestr;
>
> + if (g_list_find_custom(plus_features, name, compare_string))
> {
> + error_report("warning: Ambiguous CPU model string. "
> + "Don't mix both \"+%s\" and \"%s=%s\"",
> + name, name, val);
> + ambiguous = true;
> + }
> + if (g_list_find_custom(minus_features, name,
> compare_string)) {
> + error_report("warning: Ambiguous CPU model string. "
> + "Don't mix both \"-%s\" and \"%s=%s\"",
> + name, name, val);
> + ambiguous = true;
> + }
> +
> /* Special case: */
> if (!strcmp(name, "tsc-freq")) {
> int64_t tsc_freq;
> @@ -2046,6 +2065,11 @@ static void x86_cpu_parse_featurestr(const
> char *typename, char *features, qdev_prop_register_global(prop);
> }
>
> + if (ambiguous) {
> + error_report("warning: Compatibility of ambiguous CPU model "
> + "strings won't be kept on future QEMU
> versions");
> + }
> +
> if (local_err) {
> error_propagate(errp, local_err);
> }
> diff --git a/tests/test-x86-cpuid-compat.c
> b/tests/test-x86-cpuid-compat.c index 260dd27..79a2e69 100644
> --- a/tests/test-x86-cpuid-compat.c
> +++ b/tests/test-x86-cpuid-compat.c
> @@ -35,6 +35,7 @@ static QObject *qom_get(const char *path, const
> char *prop) return ret;
> }
>
> +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> static bool qom_get_bool(const char *path, const char *prop)
> {
> QBool *value = qobject_to_qbool(qom_get(path, prop));
> @@ -43,6 +44,7 @@ static bool qom_get_bool(const char *path, const
> char *prop) QDECREF(value);
> return b;
> }
> +#endif
>
> typedef struct CpuidTestArgs {
> const char *cmdline;
> @@ -76,7 +78,8 @@ static void add_cpuid_test(const char *name, const
> char *cmdline, qtest_add_data_func(name, args, test_cpuid_prop);
> }
>
> -static void test_plus_minus(void)
> +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> +static void test_plus_minus_subprocess(void)
> {
> char *path;
>
> @@ -86,9 +89,8 @@ static void test_plus_minus(void)
> * 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.
> + * Note: rules 1 and 2 are planned to be removed soon, and
> + * should generate a warning.
> */
> qtest_start("-cpu
> pentium,-fpu,+fpu,-mce,mce=on,+cx8,cx8=off,+sse4_1,sse4_2=on"); path
> = get_cpu0_qom_path(); @@ -108,11 +110,27 @@ static void
> test_plus_minus(void) g_free(path);
> }
>
> +static void test_plus_minus(void)
> +{
> +
> g_test_trap_subprocess("/x86/cpuid/parsing-plus-minus/subprocess", 0,
> 0);
> + g_test_trap_assert_passed();
> + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> + "Don't mix both \"-mce\" and
> \"mce=on\"*");
> + g_test_trap_assert_stderr("*Ambiguous CPU model string. "
> + "Don't mix both \"+cx8\" and
> \"cx8=off\"*");
> + g_test_trap_assert_stdout("");
> +}
> +#endif
> +
> int main(int argc, char **argv)
> {
> g_test_init(&argc, &argv, NULL);
>
> - qtest_add_func("x86/cpuid/parsing-plus-minus", test_plus_minus);
> +#ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS
> + g_test_add_func("/x86/cpuid/parsing-plus-minus/subprocess",
> + test_plus_minus_subprocess);
> + g_test_add_func("/x86/cpuid/parsing-plus-minus",
> test_plus_minus); +#endif
>
> /* Original level values for CPU models: */
> add_cpuid_test("x86/cpuid/phenom/level",
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-10-25 17:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-21 19:41 [Qemu-devel] [PATCH v2] target-i386: Print warning when mixing [+-]foo and foo=(on|off) Eduardo Habkost
2016-10-24 11:36 ` Igor Mammedov
2016-10-24 13:14 ` Eduardo Habkost
2016-10-24 13:35 ` Igor Mammedov
2016-10-24 13:36 ` Igor Mammedov
-- strict thread matches above, loose matches on Subject: below --
2016-10-24 19:53 Eduardo Habkost
2016-10-25 17:14 ` Igor Mammedov
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).