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-common.h"
16 #include "qemu/cutils.h"
17 #include "libqtest.h"
18 #include "qapi/qmp/qdict.h"
19 
20 
21 struct arch2cpu {
22     const char *arch;
23     const char *cpu_model;
24 };
25 
26 static struct arch2cpu cpus_map[] = {
27     /* tested targets list */
28     { "arm", "cortex-a15" },
29     { "aarch64", "cortex-a57" },
30     { "x86_64", "qemu64,apic-id=0" },
31     { "i386", "qemu32,apic-id=0" },
32     { "alpha", "ev67" },
33     { "cris", "crisv32" },
34     { "lm32", "lm32-full" },
35     { "m68k", "m5206" },
36     /* FIXME: { "microblaze", "any" }, doesn't work with -M none -cpu any */
37     /* FIXME: { "microblazeel", "any" }, doesn't work with -M none -cpu any */
38     { "mips", "4Kc" },
39     { "mipsel", "I7200" },
40     { "mips64", "20Kc" },
41     { "mips64el", "I6500" },
42     { "moxie", "MoxieLite" },
43     { "nios2", "FIXME" },
44     { "or1k", "or1200" },
45     { "ppc", "604" },
46     { "ppc64", "power8e_v2.1" },
47     { "s390x", "qemu" },
48     { "sh4", "sh7750r" },
49     { "sh4eb", "sh7751r" },
50     { "sparc", "LEON2" },
51     { "sparc64", "Fujitsu Sparc64" },
52     { "tricore", "tc1796" },
53     { "unicore32", "UniCore-II" },
54     { "xtensa", "dc233c" },
55     { "xtensaeb", "fsf" },
56     { "hppa", "hppa" },
57     { "riscv64", "rv64gcsu-v1.10.0" },
58     { "riscv32", "rv32gcsu-v1.9.1" },
59     { "rx", "rx62n" },
60 };
61 
62 static const char *get_cpu_model_by_arch(const char *arch)
63 {
64     int i;
65 
66     for (i = 0; i < ARRAY_SIZE(cpus_map); i++) {
67         if (!strcmp(arch, cpus_map[i].arch)) {
68             return cpus_map[i].cpu_model;
69         }
70     }
71     return NULL;
72 }
73 
74 static void test_machine_cpu_cli(void)
75 {
76     QDict *response;
77     const char *arch = qtest_get_arch();
78     const char *cpu_model = get_cpu_model_by_arch(arch);
79     QTestState *qts;
80 
81     if (!cpu_model) {
82         if (!(!strcmp(arch, "microblaze") || !strcmp(arch, "microblazeel"))) {
83             fprintf(stderr, "WARNING: cpu name for target '%s' isn't defined,"
84                     " add it to cpus_map\n", arch);
85         }
86         return; /* TODO: die here to force all targets have a test */
87     }
88     qts = qtest_initf("-machine none -cpu '%s'", cpu_model);
89 
90     response = qtest_qmp(qts, "{ 'execute': 'quit' }");
91     g_assert(qdict_haskey(response, "return"));
92     qobject_unref(response);
93 
94     qtest_quit(qts);
95 }
96 
97 int main(int argc, char **argv)
98 {
99     g_test_init(&argc, &argv, NULL);
100 
101     qtest_add_func("machine/none/cpu_option", test_machine_cpu_cli);
102 
103     return g_test_run();
104 }
105