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