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