diff mbox series

[3/4] tests/libqtest: Introduce qtest_get_base_arch()

Message ID 20231010074952.79165-4-philmd@linaro.org
State New
Headers show
Series tests/qtest: Introduce qtest_get_base_arch() and qtest_get_arch_bits() | expand

Commit Message

Philippe Mathieu-Daudé Oct. 10, 2023, 7:49 a.m. UTC
While qtest_get_arch() returns the target architecture name,
such "i386" or "x86_64", qtest_get_base_arch() return the
"base" (or real underlying) architecture, in this example
that is "x86".

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tests/qtest/libqtest.h |  7 +++++++
 tests/qtest/libqtest.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

Comments

Philippe Mathieu-Daudé Oct. 10, 2023, 8:42 a.m. UTC | #1
On 10/10/23 09:49, Philippe Mathieu-Daudé wrote:
> While qtest_get_arch() returns the target architecture name,
> such "i386" or "x86_64", qtest_get_base_arch() return the
> "base" (or real underlying) architecture, in this example
> that is "x86".
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   tests/qtest/libqtest.h |  7 +++++++
>   tests/qtest/libqtest.c | 28 ++++++++++++++++++++++++++++
>   2 files changed, 35 insertions(+)
> 
> diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
> index 1e1b42241d..54071e74ec 100644
> --- a/tests/qtest/libqtest.h
> +++ b/tests/qtest/libqtest.h
> @@ -654,6 +654,13 @@ bool qtest_big_endian(QTestState *s);
>    */
>   const char *qtest_get_arch(void);
>   
> +/**
> + * qtest_get_base_arch:
> + *
> + * Returns: The base architecture for the QEMU executable under test.
> + */
> +const char *qtest_get_base_arch(void);
> +
>   /**
>    * qtest_get_arch_bits:
>    *
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index a643a6309c..51cc92af21 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -925,6 +925,34 @@ const char *qtest_get_arch(void)
>       return end + 1;
>   }
>   
> +const char *qtest_get_base_arch(void)
> +{
> +    static const struct {
> +        const char *const arch;
> +        const char *const base;
> +    } basearch[] = {
> +        { "aarch64", "arm" },
> +        { "i386", "x86" },
> +        { "loongarch64", "loongarch" },
> +        { "mipsel", "mips" },
> +        { "mips64", "mips" },
> +        { "mips64el", "mips" },
> +        { "ppc64", "ppc" },
> +        { "riscv32", "riscv" },
> +        { "riscv64", "riscv" },
> +        { "sparc64", "sparc" },
> +        { "x86_64", "x86" },
> +    };
> +    const char *arch = qtest_get_arch();
> +
> +    for (unsigned i = 0; i < ARRAY_SIZE(basearch); i++) {
> +        if (!strcmp(arch, basearch[i].arch)) {
> +            return basearch[i].base;
> +        }
> +    }
> +    g_assert_not_reached();

Sorry, I forgot to commit this change:

-- >8 --
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -950,7 +950,8 @@ const char *qtest_get_base_arch(void)
              return basearch[i].base;
          }
      }
-    g_assert_not_reached();
+
+    return arch;
  }

---

> +}
> +
>   unsigned qtest_get_arch_bits(void)
>   {
>       static const char *const arch64[] = {
Thomas Huth Oct. 10, 2023, 9:50 a.m. UTC | #2
On 10/10/2023 10.42, Philippe Mathieu-Daudé wrote:
> On 10/10/23 09:49, Philippe Mathieu-Daudé wrote:
>> While qtest_get_arch() returns the target architecture name,
>> such "i386" or "x86_64", qtest_get_base_arch() return the
>> "base" (or real underlying) architecture, in this example
>> that is "x86".
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   tests/qtest/libqtest.h |  7 +++++++
>>   tests/qtest/libqtest.c | 28 ++++++++++++++++++++++++++++
>>   2 files changed, 35 insertions(+)
>>
>> diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
>> index 1e1b42241d..54071e74ec 100644
>> --- a/tests/qtest/libqtest.h
>> +++ b/tests/qtest/libqtest.h
>> @@ -654,6 +654,13 @@ bool qtest_big_endian(QTestState *s);
>>    */
>>   const char *qtest_get_arch(void);
>> +/**
>> + * qtest_get_base_arch:
>> + *
>> + * Returns: The base architecture for the QEMU executable under test.
>> + */
>> +const char *qtest_get_base_arch(void);
>> +
>>   /**
>>    * qtest_get_arch_bits:
>>    *
>> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
>> index a643a6309c..51cc92af21 100644
>> --- a/tests/qtest/libqtest.c
>> +++ b/tests/qtest/libqtest.c
>> @@ -925,6 +925,34 @@ const char *qtest_get_arch(void)
>>       return end + 1;
>>   }
>> +const char *qtest_get_base_arch(void)
>> +{
>> +    static const struct {
>> +        const char *const arch;
>> +        const char *const base;
>> +    } basearch[] = {
>> +        { "aarch64", "arm" },
>> +        { "i386", "x86" },
>> +        { "loongarch64", "loongarch" },
>> +        { "mipsel", "mips" },
>> +        { "mips64", "mips" },
>> +        { "mips64el", "mips" },
>> +        { "ppc64", "ppc" },
>> +        { "riscv32", "riscv" },
>> +        { "riscv64", "riscv" },
>> +        { "sparc64", "sparc" },
>> +        { "x86_64", "x86" },
>> +    };
>> +    const char *arch = qtest_get_arch();
>> +
>> +    for (unsigned i = 0; i < ARRAY_SIZE(basearch); i++) {
>> +        if (!strcmp(arch, basearch[i].arch)) {
>> +            return basearch[i].base;
>> +        }
>> +    }
>> +    g_assert_not_reached();
> 
> Sorry, I forgot to commit this change:
> 
> -- >8 --
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -950,7 +950,8 @@ const char *qtest_get_base_arch(void)
>               return basearch[i].base;
>           }
>       }
> -    g_assert_not_reached();
> +
> +    return arch;
>   }

I'd maybe also do a caching here, as suggested in the first patch.

  Thomas
diff mbox series

Patch

diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h
index 1e1b42241d..54071e74ec 100644
--- a/tests/qtest/libqtest.h
+++ b/tests/qtest/libqtest.h
@@ -654,6 +654,13 @@  bool qtest_big_endian(QTestState *s);
  */
 const char *qtest_get_arch(void);
 
+/**
+ * qtest_get_base_arch:
+ *
+ * Returns: The base architecture for the QEMU executable under test.
+ */
+const char *qtest_get_base_arch(void);
+
 /**
  * qtest_get_arch_bits:
  *
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index a643a6309c..51cc92af21 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -925,6 +925,34 @@  const char *qtest_get_arch(void)
     return end + 1;
 }
 
+const char *qtest_get_base_arch(void)
+{
+    static const struct {
+        const char *const arch;
+        const char *const base;
+    } basearch[] = {
+        { "aarch64", "arm" },
+        { "i386", "x86" },
+        { "loongarch64", "loongarch" },
+        { "mipsel", "mips" },
+        { "mips64", "mips" },
+        { "mips64el", "mips" },
+        { "ppc64", "ppc" },
+        { "riscv32", "riscv" },
+        { "riscv64", "riscv" },
+        { "sparc64", "sparc" },
+        { "x86_64", "x86" },
+    };
+    const char *arch = qtest_get_arch();
+
+    for (unsigned i = 0; i < ARRAY_SIZE(basearch); i++) {
+        if (!strcmp(arch, basearch[i].arch)) {
+            return basearch[i].base;
+        }
+    }
+    g_assert_not_reached();
+}
+
 unsigned qtest_get_arch_bits(void)
 {
     static const char *const arch64[] = {