machine-none-test.c 2.3 KB

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