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 "qapi/qmp/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     { "microblazeel", "any" },
36     { "mips", "4Kc" },
37     { "mipsel", "I7200" },
38     { "mips64", "20Kc" },
39     { "mips64el", "I6500" },
40     { "or1k", "or1200" },
41     { "ppc", "604" },
42     { "ppc64", "power8e_v2.1" },
43     { "s390x", "qemu" },
44     { "sh4", "sh7750r" },
45     { "sh4eb", "sh7751r" },
46     { "sparc", "LEON2" },
47     { "sparc64", "Fujitsu Sparc64" },
48     { "tricore", "tc1796" },
49     { "xtensa", "dc233c" },
50     { "xtensaeb", "fsf" },
51     { "hppa", "hppa" },
52     { "riscv64", "rv64" },
53     { "riscv32", "rv32" },
54     { "rx", "rx62n" },
55     { "loongarch64", "la464"},
56 };
57 
58 static const char *get_cpu_model_by_arch(const char *arch)
59 {
60     int i;
61 
62     for (i = 0; i < ARRAY_SIZE(cpus_map); i++) {
63         if (!strcmp(arch, cpus_map[i].arch)) {
64             return cpus_map[i].cpu_model;
65         }
66     }
67     return NULL;
68 }
69 
70 static void test_machine_cpu_cli(void)
71 {
72     QDict *response;
73     const char *arch = qtest_get_arch();
74     const char *cpu_model = get_cpu_model_by_arch(arch);
75     QTestState *qts;
76 
77     if (!cpu_model) {
78         fprintf(stderr, "WARNING: cpu name for target '%s' isn't defined,"
79                 " add it to cpus_map\n", arch);
80         return; /* TODO: die here to force all targets have a test */
81     }
82     qts = qtest_initf("-machine none -cpu \"%s\"", cpu_model);
83 
84     response = qtest_qmp(qts, "{ 'execute': 'quit' }");
85     g_assert(qdict_haskey(response, "return"));
86     qobject_unref(response);
87 
88     qtest_quit(qts);
89 }
90 
91 int main(int argc, char **argv)
92 {
93     g_test_init(&argc, &argv, NULL);
94 
95     qtest_add_func("machine/none/cpu_option", test_machine_cpu_cli);
96 
97     return g_test_run();
98 }
99