diff mbox series

[RFC,v4,07/15] tests/qtest: Adjust qom-test to always set a -cpu option

Message ID 20230119135424.5417-8-farosas@suse.de (mailing list archive)
State New, archived
Headers show
Series target/arm: Allow CONFIG_TCG=n builds | expand

Commit Message

Fabiano Rosas Jan. 19, 2023, 1:54 p.m. UTC
Start using the qtest_get_machine_args function, which explicitly
sets the -cpu option according to the machine default.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 tests/qtest/qom-test.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Comments

Richard Henderson Jan. 19, 2023, 7 p.m. UTC | #1
On 1/19/23 03:54, Fabiano Rosas wrote:
> Start using the qtest_get_machine_args function, which explicitly
> sets the -cpu option according to the machine default.
> 
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
>   tests/qtest/qom-test.c | 19 +++++++++++++++++--
>   1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c
> index d380261f8f..462e3c4281 100644
> --- a/tests/qtest/qom-test.c
> +++ b/tests/qtest/qom-test.c
> @@ -78,14 +78,28 @@ static void test_properties(QTestState *qts, const char *path, bool recurse)
>       qobject_unref(response);
>   }
>   
> +static const char *arch_get_cpu(const char *machine)
> +{
> +    const char *arch = qtest_get_arch();
> +
> +    if (g_str_equal(arch, "aarch64")) {
> +        if (!strncmp(machine, "virt", 4)) {
> +            return "cortex-a57";

I'm not keen on hard-coding cortex-a57 instead of max, even if they happen to evaluate to 
mostly the same thing currently for -accel qtest.

Nor am I keen on replicating this N times across N qtest files.
Better perhaps in libqtest.c, or something?
Or even directly in qtest_get_machine_args()?


r~
Fabiano Rosas Jan. 19, 2023, 7:12 p.m. UTC | #2
Richard Henderson <richard.henderson@linaro.org> writes:

> On 1/19/23 03:54, Fabiano Rosas wrote:
>> Start using the qtest_get_machine_args function, which explicitly
>> sets the -cpu option according to the machine default.
>> 
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>> ---
>>   tests/qtest/qom-test.c | 19 +++++++++++++++++--
>>   1 file changed, 17 insertions(+), 2 deletions(-)
>> 
>> diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c
>> index d380261f8f..462e3c4281 100644
>> --- a/tests/qtest/qom-test.c
>> +++ b/tests/qtest/qom-test.c
>> @@ -78,14 +78,28 @@ static void test_properties(QTestState *qts, const char *path, bool recurse)
>>       qobject_unref(response);
>>   }
>>   
>> +static const char *arch_get_cpu(const char *machine)
>> +{
>> +    const char *arch = qtest_get_arch();
>> +
>> +    if (g_str_equal(arch, "aarch64")) {
>> +        if (!strncmp(machine, "virt", 4)) {
>> +            return "cortex-a57";
>
> I'm not keen on hard-coding cortex-a57 instead of max, even if they happen to evaluate to 
> mostly the same thing currently for -accel qtest.

Ok.

> Nor am I keen on replicating this N times across N qtest files.
> Better perhaps in libqtest.c, or something?
> Or even directly in qtest_get_machine_args()?

Ah right, this was a callback in a previous version so there was no
"cpu" parameter to qtest_get_machine_args. Now I could indeed move
arch_get_cpu into libqtest.c somewhere.
diff mbox series

Patch

diff --git a/tests/qtest/qom-test.c b/tests/qtest/qom-test.c
index d380261f8f..462e3c4281 100644
--- a/tests/qtest/qom-test.c
+++ b/tests/qtest/qom-test.c
@@ -78,14 +78,28 @@  static void test_properties(QTestState *qts, const char *path, bool recurse)
     qobject_unref(response);
 }
 
+static const char *arch_get_cpu(const char *machine)
+{
+    const char *arch = qtest_get_arch();
+
+    if (g_str_equal(arch, "aarch64")) {
+        if (!strncmp(machine, "virt", 4)) {
+            return "cortex-a57";
+        }
+    }
+
+    return NULL;
+}
+
 static void test_machine(gconstpointer data)
 {
     const char *machine = data;
+    char *args;
     QDict *response;
     QTestState *qts;
 
-    qts = qtest_initf("-machine %s", machine);
-
+    args = qtest_get_machine_args(machine, arch_get_cpu(machine), NULL);
+    qts = qtest_init(args);
     test_properties(qts, "/machine", true);
 
     response = qtest_qmp(qts, "{ 'execute': 'quit' }");
@@ -94,6 +108,7 @@  static void test_machine(gconstpointer data)
 
     qtest_quit(qts);
     g_free((void *)machine);
+    g_free((void *)args);
 }
 
 static void add_machine_test_case(const char *mname)