| 1 | /* |
| 2 | * Machine 'none' tests. |
| 3 | * |
| 4 | * Copyright (c) 2018 Red Hat Inc. |
| 5 | * |
| 6 | * Authors: |
| 7 | * Igor Mammedov <imammedo@redhat.com>, |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 10 | * See the COPYING file in the top-level directory. |
| 11 | */ |
| 12 | |
| 13 | #include "qemu/osdep.h" |
| 14 | |
| 15 | #include "qemu/cutils.h" |
| 16 | #include "libqtest.h" |
| 17 | #include "qobject/qdict.h" |
| 18 | |
| 19 | |
| 20 | struct arch2cpu { |
| 21 | const char *arch; |
| 22 | const char *cpu_model; |
| 23 | }; |
| 24 | |
| 25 | static struct arch2cpu cpus_map[] = { |
| 26 | /* tested targets list */ |
| 27 | { "arm", "cortex-a15" }, |
| 28 | { "aarch64", "cortex-a57" }, |
| 29 | { "avr", "avr6-avr-cpu" }, |
| 30 | { "x86_64", "qemu64,apic-id=0" }, |
| 31 | { "i386", "qemu32,apic-id=0" }, |
| 32 | { "alpha", "ev67" }, |
| 33 | { "m68k", "m5206" }, |
| 34 | { "microblaze", "any" }, |
| 35 | { "mips", "4Kc" }, |
| 36 | { "mipsel", "I7200" }, |
| 37 | { "mips64", "20Kc" }, |
| 38 | { "mips64el", "I6500" }, |
| 39 | { "or1k", "or1200" }, |
| 40 | { "ppc", "604" }, |
| 41 | { "ppc64", "power11_v2.0" }, |
| 42 | { "s390x", "qemu" }, |
| 43 | { "sh4", "sh7750r" }, |
| 44 | { "sh4eb", "sh7751r" }, |
| 45 | { "sparc", "LEON2" }, |
| 46 | { "sparc64", "Fujitsu Sparc64" }, |
| 47 | { "tricore", "tc1796" }, |
| 48 | { "xtensa", "dc233c" }, |
| 49 | { "xtensaeb", "fsf" }, |
| 50 | { "hppa", "pa-7300lc" }, |
| 51 | { "riscv64", "rv64" }, |
| 52 | { "riscv32", "rv32" }, |
| 53 | { "rx", "rx62n" }, |
| 54 | { "loongarch64", "la464"}, |
| 55 | }; |
| 56 | |
| 57 | static const char *get_cpu_model_by_arch(const char *arch) |
| 58 | { |
| 59 | int i; |
| 60 | |
| 61 | for (i = 0; i < ARRAY_SIZE(cpus_map); i++) { |
| 62 | if (!strcmp(arch, cpus_map[i].arch)) { |
| 63 | return cpus_map[i].cpu_model; |
| 64 | } |
| 65 | } |
| 66 | return NULL; |
| 67 | } |
| 68 | |
| 69 | static void test_machine_cpu_cli(void) |
| 70 | { |
| 71 | QDict *response; |
| 72 | const char *arch = qtest_get_arch(); |
| 73 | const char *cpu_model = get_cpu_model_by_arch(arch); |
| 74 | QTestState *qts; |
| 75 | |
| 76 | if (!cpu_model) { |
| 77 | fprintf(stderr, "WARNING: cpu name for target '%s' isn't defined," |
| 78 | " add it to cpus_map\n", arch); |
| 79 | return; /* TODO: die here to force all targets have a test */ |
| 80 | } |
| 81 | qts = qtest_initf("-machine none -cpu \"%s\"", cpu_model); |
| 82 | |
| 83 | response = qtest_qmp(qts, "{ 'execute': 'quit' }"); |
| 84 | g_assert(qdict_haskey(response, "return")); |
| 85 | qobject_unref(response); |
| 86 | |
| 87 | qtest_quit(qts); |
| 88 | } |
| 89 | |
| 90 | int main(int argc, char **argv) |
| 91 | { |
| 92 | g_test_init(&argc, &argv, NULL); |
| 93 | |
| 94 | qtest_add_func("machine/none/cpu_option", test_machine_cpu_cli); |
| 95 | |
| 96 | return g_test_run(); |
| 97 | } |