2
0

pxe-test.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * PXE test cases.
  3. *
  4. * Copyright (c) 2016, 2017 Red Hat Inc.
  5. *
  6. * Authors:
  7. * Michael S. Tsirkin <mst@redhat.com>,
  8. * Victor Kaplansky <victork@redhat.com>
  9. * Thomas Huth <thuth@redhat.com>
  10. *
  11. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  12. * See the COPYING file in the top-level directory.
  13. */
  14. #include "qemu/osdep.h"
  15. #include <glib/gstdio.h>
  16. #include "qemu-common.h"
  17. #include "libqtest.h"
  18. #include "boot-sector.h"
  19. #define NETNAME "net0"
  20. static char disk[] = "tests/pxe-test-disk-XXXXXX";
  21. typedef struct testdef {
  22. const char *machine; /* Machine type */
  23. const char *model; /* NIC device model */
  24. const char *extra; /* Any additional parameters */
  25. } testdef_t;
  26. static testdef_t x86_tests[] = {
  27. { "pc", "e1000" },
  28. { "pc", "virtio-net-pci" },
  29. { "q35", "e1000e" },
  30. { "q35", "virtio-net-pci", },
  31. { NULL },
  32. };
  33. static testdef_t x86_tests_slow[] = {
  34. { "pc", "ne2k_pci", },
  35. { "pc", "i82550", },
  36. { "pc", "rtl8139" },
  37. { "pc", "vmxnet3" },
  38. { NULL },
  39. };
  40. static testdef_t ppc64_tests[] = {
  41. { "pseries", "spapr-vlan",
  42. "-machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,vsmt=8" },
  43. { "pseries", "virtio-net-pci",
  44. "-machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,vsmt=8" },
  45. { NULL },
  46. };
  47. static testdef_t ppc64_tests_slow[] = {
  48. { "pseries", "e1000",
  49. "-machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,vsmt=8" },
  50. { NULL },
  51. };
  52. static testdef_t s390x_tests[] = {
  53. { "s390-ccw-virtio", "virtio-net-ccw" },
  54. { NULL },
  55. };
  56. static void test_pxe_one(const testdef_t *test, bool ipv6)
  57. {
  58. QTestState *qts;
  59. char *args;
  60. const char *extra = test->extra;
  61. if (!extra) {
  62. extra = "";
  63. }
  64. args = g_strdup_printf(
  65. "-machine %s,accel=kvm:tcg -nodefaults -boot order=n "
  66. "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
  67. "-device %s,bootindex=1,netdev=" NETNAME " %s",
  68. test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
  69. test->model, extra);
  70. qts = qtest_init(args);
  71. boot_sector_test(qts);
  72. qtest_quit(qts);
  73. g_free(args);
  74. }
  75. static void test_pxe_ipv4(gconstpointer data)
  76. {
  77. const testdef_t *test = data;
  78. test_pxe_one(test, false);
  79. }
  80. static void test_pxe_ipv6(gconstpointer data)
  81. {
  82. const testdef_t *test = data;
  83. test_pxe_one(test, true);
  84. }
  85. static void test_batch(const testdef_t *tests, bool ipv6)
  86. {
  87. int i;
  88. for (i = 0; tests[i].machine; i++) {
  89. const testdef_t *test = &tests[i];
  90. char *testname;
  91. testname = g_strdup_printf("pxe/ipv4/%s/%s",
  92. test->machine, test->model);
  93. qtest_add_data_func(testname, test, test_pxe_ipv4);
  94. g_free(testname);
  95. if (ipv6) {
  96. testname = g_strdup_printf("pxe/ipv6/%s/%s",
  97. test->machine, test->model);
  98. qtest_add_data_func(testname, test, test_pxe_ipv6);
  99. g_free(testname);
  100. }
  101. }
  102. }
  103. int main(int argc, char *argv[])
  104. {
  105. int ret;
  106. const char *arch = qtest_get_arch();
  107. ret = boot_sector_init(disk);
  108. if(ret)
  109. return ret;
  110. g_test_init(&argc, &argv, NULL);
  111. if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
  112. test_batch(x86_tests, false);
  113. if (g_test_slow()) {
  114. test_batch(x86_tests_slow, false);
  115. }
  116. } else if (strcmp(arch, "ppc64") == 0) {
  117. test_batch(ppc64_tests, g_test_slow());
  118. if (g_test_slow()) {
  119. test_batch(ppc64_tests_slow, true);
  120. }
  121. } else if (g_str_equal(arch, "s390x")) {
  122. test_batch(s390x_tests, g_test_slow());
  123. }
  124. ret = g_test_run();
  125. boot_sector_cleanup(disk);
  126. return ret;
  127. }