14e082566SVictor Kaplansky /* 24e082566SVictor Kaplansky * PXE test cases. 34e082566SVictor Kaplansky * 4ab06ec43SThomas Huth * Copyright (c) 2016, 2017 Red Hat Inc. 54e082566SVictor Kaplansky * 64e082566SVictor Kaplansky * Authors: 74e082566SVictor Kaplansky * Michael S. Tsirkin <mst@redhat.com>, 84e082566SVictor Kaplansky * Victor Kaplansky <victork@redhat.com> 9ab06ec43SThomas Huth * Thomas Huth <thuth@redhat.com> 104e082566SVictor Kaplansky * 114e082566SVictor Kaplansky * This work is licensed under the terms of the GNU GPL, version 2 or later. 124e082566SVictor Kaplansky * See the COPYING file in the top-level directory. 134e082566SVictor Kaplansky */ 144e082566SVictor Kaplansky 15974dc73dSPeter Maydell #include "qemu/osdep.h" 164e082566SVictor Kaplansky #include <glib/gstdio.h> 17907b5105SMarc-André Lureau #include "libqtest.h" 184e082566SVictor Kaplansky #include "boot-sector.h" 1963d57c8fSGreg Kurz #include "libqos/libqos-spapr.h" 204e082566SVictor Kaplansky 214e082566SVictor Kaplansky #define NETNAME "net0" 224e082566SVictor Kaplansky 233e353773SThomas Huth static char disk[] = "tests/pxe-test-disk-XXXXXX"; 244e082566SVictor Kaplansky 251e88989fSDavid Gibson typedef struct testdef { 261e88989fSDavid Gibson const char *machine; /* Machine type */ 271e88989fSDavid Gibson const char *model; /* NIC device model */ 28ba3b40deSDavid Gibson const char *extra; /* Any additional parameters */ 291e88989fSDavid Gibson } testdef_t; 301e88989fSDavid Gibson 311e88989fSDavid Gibson static testdef_t x86_tests[] = { 321e88989fSDavid Gibson { "pc", "e1000" }, 331e88989fSDavid Gibson { "pc", "virtio-net-pci" }, 3418b20bb4SDavid Gibson { "q35", "e1000e" }, 3518b20bb4SDavid Gibson { "q35", "virtio-net-pci", }, 361e88989fSDavid Gibson { NULL }, 371e88989fSDavid Gibson }; 381e88989fSDavid Gibson 391e88989fSDavid Gibson static testdef_t x86_tests_slow[] = { 401e88989fSDavid Gibson { "pc", "ne2k_pci", }, 411e88989fSDavid Gibson { "pc", "i82550", }, 421e88989fSDavid Gibson { "pc", "rtl8139" }, 431e88989fSDavid Gibson { "pc", "vmxnet3" }, 441e88989fSDavid Gibson { NULL }, 451e88989fSDavid Gibson }; 461e88989fSDavid Gibson 471e88989fSDavid Gibson static testdef_t ppc64_tests[] = { 48ba3b40deSDavid Gibson { "pseries", "spapr-vlan", 4963d57c8fSGreg Kurz "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, 50ba3b40deSDavid Gibson { "pseries", "virtio-net-pci", 5163d57c8fSGreg Kurz "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, 521e88989fSDavid Gibson { NULL }, 531e88989fSDavid Gibson }; 541e88989fSDavid Gibson 551e88989fSDavid Gibson static testdef_t ppc64_tests_slow[] = { 56ba3b40deSDavid Gibson { "pseries", "e1000", 5763d57c8fSGreg Kurz "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, 581e88989fSDavid Gibson { NULL }, 591e88989fSDavid Gibson }; 601e88989fSDavid Gibson 611e88989fSDavid Gibson static testdef_t s390x_tests[] = { 621e88989fSDavid Gibson { "s390-ccw-virtio", "virtio-net-ccw" }, 631e88989fSDavid Gibson { NULL }, 641e88989fSDavid Gibson }; 651e88989fSDavid Gibson 661e88989fSDavid Gibson static void test_pxe_one(const testdef_t *test, bool ipv6) 674e082566SVictor Kaplansky { 6843497c43SThomas Huth QTestState *qts; 694e082566SVictor Kaplansky char *args; 70ba3b40deSDavid Gibson const char *extra = test->extra; 71ba3b40deSDavid Gibson 72ba3b40deSDavid Gibson if (!extra) { 73ba3b40deSDavid Gibson extra = ""; 74ba3b40deSDavid Gibson } 754e082566SVictor Kaplansky 761e88989fSDavid Gibson args = g_strdup_printf( 776f6e1698SPaolo Bonzini "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n " 781e88989fSDavid Gibson "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s " 79ba3b40deSDavid Gibson "-device %s,bootindex=1,netdev=" NETNAME " %s", 801e88989fSDavid Gibson test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off", 81ba3b40deSDavid Gibson test->model, extra); 824e082566SVictor Kaplansky 8343497c43SThomas Huth qts = qtest_init(args); 8443497c43SThomas Huth boot_sector_test(qts); 8543497c43SThomas Huth qtest_quit(qts); 864e082566SVictor Kaplansky g_free(args); 874e082566SVictor Kaplansky } 884e082566SVictor Kaplansky 89ab06ec43SThomas Huth static void test_pxe_ipv4(gconstpointer data) 904e082566SVictor Kaplansky { 911e88989fSDavid Gibson const testdef_t *test = data; 924e082566SVictor Kaplansky 931e88989fSDavid Gibson test_pxe_one(test, false); 941e88989fSDavid Gibson } 951e88989fSDavid Gibson 96d23895d9SDavid Gibson static void test_pxe_ipv6(gconstpointer data) 97d23895d9SDavid Gibson { 98d23895d9SDavid Gibson const testdef_t *test = data; 99d23895d9SDavid Gibson 100d23895d9SDavid Gibson test_pxe_one(test, true); 101d23895d9SDavid Gibson } 102d23895d9SDavid Gibson 103d23895d9SDavid Gibson static void test_batch(const testdef_t *tests, bool ipv6) 1041e88989fSDavid Gibson { 1051e88989fSDavid Gibson int i; 1061e88989fSDavid Gibson 1071e88989fSDavid Gibson for (i = 0; tests[i].machine; i++) { 1081e88989fSDavid Gibson const testdef_t *test = &tests[i]; 1091e88989fSDavid Gibson char *testname; 1101e88989fSDavid Gibson 111*8f757034SFabiano Rosas if (!qtest_has_device(test->model)) { 112*8f757034SFabiano Rosas continue; 113*8f757034SFabiano Rosas } 114*8f757034SFabiano Rosas 1151e88989fSDavid Gibson testname = g_strdup_printf("pxe/ipv4/%s/%s", 1161e88989fSDavid Gibson test->machine, test->model); 1171e88989fSDavid Gibson qtest_add_data_func(testname, test, test_pxe_ipv4); 1181e88989fSDavid Gibson g_free(testname); 119d23895d9SDavid Gibson 120d23895d9SDavid Gibson if (ipv6) { 121d23895d9SDavid Gibson testname = g_strdup_printf("pxe/ipv6/%s/%s", 122d23895d9SDavid Gibson test->machine, test->model); 123d23895d9SDavid Gibson qtest_add_data_func(testname, test, test_pxe_ipv6); 124d23895d9SDavid Gibson g_free(testname); 125d23895d9SDavid Gibson } 1261e88989fSDavid Gibson } 1271485ef1cSThomas Huth } 1281485ef1cSThomas Huth 1294e082566SVictor Kaplansky int main(int argc, char *argv[]) 1304e082566SVictor Kaplansky { 1314e082566SVictor Kaplansky int ret; 1324e082566SVictor Kaplansky const char *arch = qtest_get_arch(); 1334e082566SVictor Kaplansky 1344e082566SVictor Kaplansky ret = boot_sector_init(disk); 1354e082566SVictor Kaplansky if(ret) 1364e082566SVictor Kaplansky return ret; 1374e082566SVictor Kaplansky 1384e082566SVictor Kaplansky g_test_init(&argc, &argv, NULL); 1394e082566SVictor Kaplansky 1404e082566SVictor Kaplansky if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { 141d23895d9SDavid Gibson test_batch(x86_tests, false); 142ab06ec43SThomas Huth if (g_test_slow()) { 143d23895d9SDavid Gibson test_batch(x86_tests_slow, false); 144ab06ec43SThomas Huth } 1451485ef1cSThomas Huth } else if (strcmp(arch, "ppc64") == 0) { 146d23895d9SDavid Gibson test_batch(ppc64_tests, g_test_slow()); 147ab06ec43SThomas Huth if (g_test_slow()) { 148d23895d9SDavid Gibson test_batch(ppc64_tests_slow, true); 149ab06ec43SThomas Huth } 150b1b2feacSThomas Huth } else if (g_str_equal(arch, "s390x")) { 151d23895d9SDavid Gibson test_batch(s390x_tests, g_test_slow()); 1524e082566SVictor Kaplansky } 1534e082566SVictor Kaplansky ret = g_test_run(); 1544e082566SVictor Kaplansky boot_sector_cleanup(disk); 1554e082566SVictor Kaplansky return ret; 1564e082566SVictor Kaplansky } 157