From: Fabiano Rosas <farosas@suse.de>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Laurent Vivier <lvivier@redhat.com>
Subject: Re: [PATCH 2/2] tests/qtest/test-x86-cpuid-compat: Switch test_feature_flag to data-driven
Date: Tue, 10 Mar 2026 17:18:32 -0300 [thread overview]
Message-ID: <87qzprzbdz.fsf@suse.de> (raw)
In-Reply-To: <20260308185421.972734-3-peter.maydell@linaro.org>
Peter Maydell <peter.maydell@linaro.org> writes:
> As with add_cpuid_test(), the add_feature_test() function also
> allocates memory that is leaked if the test case is not run. Fix
> this in the same way, by moving all the allocations into
> test_feature_flag() and passing it a pointer to a struct with the
> necessary parameters which is a compile-time constant.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> tests/qtest/test-x86-cpuid-compat.c | 134 +++++++++++++++-------------
> 1 file changed, 72 insertions(+), 62 deletions(-)
>
> diff --git a/tests/qtest/test-x86-cpuid-compat.c b/tests/qtest/test-x86-cpuid-compat.c
> index fc90a46d37..17c0965827 100644
> --- a/tests/qtest/test-x86-cpuid-compat.c
> +++ b/tests/qtest/test-x86-cpuid-compat.c
> @@ -94,8 +94,12 @@ static void test_cpuid_prop(const void *data)
>
> /* Parameters to a add_feature_test() test case */
> typedef struct FeatureTestArgs {
> - /* cmdline to start QEMU */
> - const char *cmdline;
> + /* Test name */
> + const char *name;
> + /* CPU type */
> + const char *cpu;
> + /* CPU features, may be NULL */
> + const char *cpufeat;
> /*
> * cpuid-input-eax and cpuid-input-ecx values to look for,
> * in "feature-words" and "filtered-features" properties.
> @@ -140,10 +144,17 @@ static void test_feature_flag(const void *data)
> {
> const FeatureTestArgs *args = data;
> char *path;
> + char *cmdline;
> QList *present, *filtered;
> uint32_t value;
>
> - qtest_start(args->cmdline);
> + if (args->cpufeat) {
> + cmdline = g_strdup_printf("-cpu %s,%s", args->cpu, args->cpufeat);
> + } else {
> + cmdline = g_strdup_printf("-cpu %s", args->cpu);
> + }
> +
> + qtest_start(cmdline);
> path = get_cpu0_qom_path();
> present = qobject_to(QList, qom_get(path, "feature-words"));
> filtered = qobject_to(QList, qom_get(path, "filtered-features"));
> @@ -156,40 +167,7 @@ static void test_feature_flag(const void *data)
> qobject_unref(present);
> qobject_unref(filtered);
> g_free(path);
> - g_free((void *)args->cmdline);
> - g_free((void *)data);
> -}
> -
> -/*
> - * 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 void add_feature_test(const char *name, const char *cpu,
> - const char *cpufeat, uint32_t eax,
> - uint32_t ecx, const char *reg,
> - int bitnr, bool expected_value)
> -{
> - FeatureTestArgs *args = g_new0(FeatureTestArgs, 1);
> - char *cmdline;
> -
> - if (!qtest_has_cpu_model(cpu)) {
> - return;
> - }
> -
> - if (cpufeat) {
> - cmdline = g_strdup_printf("-cpu %s,%s", cpu, cpufeat);
> - } else {
> - cmdline = g_strdup_printf("-cpu %s", cpu);
> - }
> -
> - args->cmdline = cmdline;
> - args->in_eax = eax;
> - args->in_ecx = ecx;
> - args->reg = reg;
> - args->bitnr = bitnr;
> - args->expected_value = expected_value;
> - qtest_add_data_func(name, args, test_feature_flag);
> + g_free(cmdline);
> }
>
> static void test_plus_minus_subprocess(void)
> @@ -381,6 +359,56 @@ static const CpuidTestArgs cpuid_tests[] = {
> },
> };
>
> +/*
> + * Test cases to ensure that a given feature flag is set in
> + * either "feature-words" or "filtered-features", when running QEMU
> + * using cmdline
> + */
> +static const FeatureTestArgs feature_tests[] = {
> + /* Test feature parsing */
> + {
> + "x86/cpuid/features/plus",
> + "486", "+arat",
> + 6, 0, "EAX", 2, true,
> + },
> + {
> + "x86/cpuid/features/minus",
> + "pentium", "-mmx",
> + 1, 0, "EDX", 23, false,
> + },
> + {
> + "x86/cpuid/features/on",
> + "486", "arat=on",
> + 6, 0, "EAX", 2, true,
> + },
> + {
> + "x86/cpuid/features/off",
> + "pentium", "mmx=off",
> + 1, 0, "EDX", 23, false,
> + },
> +
> + {
> + "x86/cpuid/features/max-plus-invtsc",
> + "max" , "+invtsc",
> + 0x80000007, 0, "EDX", 8, true,
> + },
> + {
> + "x86/cpuid/features/max-invtsc-on",
> + "max", "invtsc=on",
> + 0x80000007, 0, "EDX", 8, true,
> + },
> + {
> + "x86/cpuid/features/max-minus-mmx",
> + "max", "-mmx",
> + 1, 0, "EDX", 23, false,
> + },
> + {
> + "x86/cpuid/features/max-invtsc-on,mmx=off",
> + "max", "mmx=off",
> + 1, 0, "EDX", 23, false,
> + },
> +};
> +
> int main(int argc, char **argv)
> {
> g_test_init(&argc, &argv, NULL);
> @@ -397,32 +425,14 @@ int main(int argc, char **argv)
> &cpuid_tests[i], test_cpuid_prop);
> }
>
> - /* Test feature parsing */
> - add_feature_test("x86/cpuid/features/plus",
> - "486", "+arat",
> - 6, 0, "EAX", 2, true);
> - add_feature_test("x86/cpuid/features/minus",
> - "pentium", "-mmx",
> - 1, 0, "EDX", 23, false);
> - add_feature_test("x86/cpuid/features/on",
> - "486", "arat=on",
> - 6, 0, "EAX", 2, true);
> - add_feature_test("x86/cpuid/features/off",
> - "pentium", "mmx=off",
> - 1, 0, "EDX", 23, false);
>
> - add_feature_test("x86/cpuid/features/max-plus-invtsc",
> - "max" , "+invtsc",
> - 0x80000007, 0, "EDX", 8, true);
> - add_feature_test("x86/cpuid/features/max-invtsc-on",
> - "max", "invtsc=on",
> - 0x80000007, 0, "EDX", 8, true);
> - add_feature_test("x86/cpuid/features/max-minus-mmx",
> - "max", "-mmx",
> - 1, 0, "EDX", 23, false);
> - add_feature_test("x86/cpuid/features/max-invtsc-on,mmx=off",
> - "max", "mmx=off",
> - 1, 0, "EDX", 23, false);
> + for (int i = 0; i < ARRAY_SIZE(feature_tests); i++) {
> + if (!qtest_has_cpu_model(feature_tests[i].cpu)) {
> + continue;
> + }
> + qtest_add_data_func(feature_tests[i].name,
> + &feature_tests[i], test_feature_flag);
> + }
>
> return g_test_run();
> }
Reviewed-by: Fabiano Rosas <farosas@suse.de>
prev parent reply other threads:[~2026-03-10 20:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-08 18:54 [PATCH 0/2] tests/qtest/test-x86-cpuid-compat: fix leaks Peter Maydell
2026-03-08 18:54 ` [PATCH 1/2] tests/qtest/test-x86-cpuid-compat: Switch test_cpuid_prop to data-driven Peter Maydell
2026-03-10 20:18 ` Fabiano Rosas
2026-03-08 18:54 ` [PATCH 2/2] tests/qtest/test-x86-cpuid-compat: Switch test_feature_flag " Peter Maydell
2026-03-10 20:18 ` Fabiano Rosas [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=87qzprzbdz.fsf@suse.de \
--to=farosas@suse.de \
--cc=lvivier@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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