11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * Machine 'none' tests.
31e8a1faeSThomas Huth *
41e8a1faeSThomas Huth * Copyright (c) 2018 Red Hat Inc.
51e8a1faeSThomas Huth *
61e8a1faeSThomas Huth * Authors:
71e8a1faeSThomas Huth * Igor Mammedov <imammedo@redhat.com>,
81e8a1faeSThomas Huth *
91e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later.
101e8a1faeSThomas Huth * See the COPYING file in the top-level directory.
111e8a1faeSThomas Huth */
121e8a1faeSThomas Huth
131e8a1faeSThomas Huth #include "qemu/osdep.h"
141e8a1faeSThomas Huth
151e8a1faeSThomas Huth #include "qemu/cutils.h"
16907b5105SMarc-André Lureau #include "libqtest.h"
171e8a1faeSThomas Huth #include "qapi/qmp/qdict.h"
181e8a1faeSThomas Huth
191e8a1faeSThomas Huth
201e8a1faeSThomas Huth struct arch2cpu {
211e8a1faeSThomas Huth const char *arch;
221e8a1faeSThomas Huth const char *cpu_model;
231e8a1faeSThomas Huth };
241e8a1faeSThomas Huth
251e8a1faeSThomas Huth static struct arch2cpu cpus_map[] = {
261e8a1faeSThomas Huth /* tested targets list */
271e8a1faeSThomas Huth { "arm", "cortex-a15" },
281e8a1faeSThomas Huth { "aarch64", "cortex-a57" },
29754cea8cSMichael Rolnik { "avr", "avr6-avr-cpu" },
301e8a1faeSThomas Huth { "x86_64", "qemu64,apic-id=0" },
311e8a1faeSThomas Huth { "i386", "qemu32,apic-id=0" },
321e8a1faeSThomas Huth { "alpha", "ev67" },
331e8a1faeSThomas Huth { "m68k", "m5206" },
34bbad173cSEdgar E. Iglesias { "microblaze", "any" },
35bbad173cSEdgar E. Iglesias { "microblazeel", "any" },
361e8a1faeSThomas Huth { "mips", "4Kc" },
371e8a1faeSThomas Huth { "mipsel", "I7200" },
381e8a1faeSThomas Huth { "mips64", "20Kc" },
391e8a1faeSThomas Huth { "mips64el", "I6500" },
401e8a1faeSThomas Huth { "or1k", "or1200" },
411e8a1faeSThomas Huth { "ppc", "604" },
421e8a1faeSThomas Huth { "ppc64", "power8e_v2.1" },
431e8a1faeSThomas Huth { "s390x", "qemu" },
441e8a1faeSThomas Huth { "sh4", "sh7750r" },
45*51cdb680SThomas Huth { "sh4eb", "sh7751r" },
461e8a1faeSThomas Huth { "sparc", "LEON2" },
471e8a1faeSThomas Huth { "sparc64", "Fujitsu Sparc64" },
481e8a1faeSThomas Huth { "tricore", "tc1796" },
491e8a1faeSThomas Huth { "xtensa", "dc233c" },
501e8a1faeSThomas Huth { "xtensaeb", "fsf" },
511e8a1faeSThomas Huth { "hppa", "hppa" },
5265a117daSAlistair Francis { "riscv64", "rv64" },
5365a117daSAlistair Francis { "riscv32", "rv32" },
54c8c35e5fSYoshinori Sato { "rx", "rx62n" },
55e18f27d9SSong Gao { "loongarch64", "la464"},
561e8a1faeSThomas Huth };
571e8a1faeSThomas Huth
get_cpu_model_by_arch(const char * arch)581e8a1faeSThomas Huth static const char *get_cpu_model_by_arch(const char *arch)
591e8a1faeSThomas Huth {
601e8a1faeSThomas Huth int i;
611e8a1faeSThomas Huth
621e8a1faeSThomas Huth for (i = 0; i < ARRAY_SIZE(cpus_map); i++) {
631e8a1faeSThomas Huth if (!strcmp(arch, cpus_map[i].arch)) {
641e8a1faeSThomas Huth return cpus_map[i].cpu_model;
651e8a1faeSThomas Huth }
661e8a1faeSThomas Huth }
671e8a1faeSThomas Huth return NULL;
681e8a1faeSThomas Huth }
691e8a1faeSThomas Huth
test_machine_cpu_cli(void)701e8a1faeSThomas Huth static void test_machine_cpu_cli(void)
711e8a1faeSThomas Huth {
721e8a1faeSThomas Huth QDict *response;
731e8a1faeSThomas Huth const char *arch = qtest_get_arch();
741e8a1faeSThomas Huth const char *cpu_model = get_cpu_model_by_arch(arch);
751e8a1faeSThomas Huth QTestState *qts;
761e8a1faeSThomas Huth
771e8a1faeSThomas Huth if (!cpu_model) {
781e8a1faeSThomas Huth fprintf(stderr, "WARNING: cpu name for target '%s' isn't defined,"
791e8a1faeSThomas Huth " add it to cpus_map\n", arch);
801e8a1faeSThomas Huth return; /* TODO: die here to force all targets have a test */
811e8a1faeSThomas Huth }
82de56338eSBin Meng qts = qtest_initf("-machine none -cpu \"%s\"", cpu_model);
831e8a1faeSThomas Huth
841e8a1faeSThomas Huth response = qtest_qmp(qts, "{ 'execute': 'quit' }");
851e8a1faeSThomas Huth g_assert(qdict_haskey(response, "return"));
861e8a1faeSThomas Huth qobject_unref(response);
871e8a1faeSThomas Huth
881e8a1faeSThomas Huth qtest_quit(qts);
891e8a1faeSThomas Huth }
901e8a1faeSThomas Huth
main(int argc,char ** argv)911e8a1faeSThomas Huth int main(int argc, char **argv)
921e8a1faeSThomas Huth {
931e8a1faeSThomas Huth g_test_init(&argc, &argv, NULL);
941e8a1faeSThomas Huth
951e8a1faeSThomas Huth qtest_add_func("machine/none/cpu_option", test_machine_cpu_cli);
961e8a1faeSThomas Huth
971e8a1faeSThomas Huth return g_test_run();
981e8a1faeSThomas Huth }
99