2
0

machine-none-test.c 2.6 KB

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