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> 174e082566SVictor Kaplansky #include "qemu-common.h" 184e082566SVictor Kaplansky #include "libqtest.h" 194e082566SVictor Kaplansky #include "boot-sector.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", 4945459091SLaurent Vivier "-machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,vsmt=8" }, 50ba3b40deSDavid Gibson { "pseries", "virtio-net-pci", 5145459091SLaurent Vivier "-machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,vsmt=8" }, 521e88989fSDavid Gibson { NULL }, 531e88989fSDavid Gibson }; 541e88989fSDavid Gibson 551e88989fSDavid Gibson static testdef_t ppc64_tests_slow[] = { 56ba3b40deSDavid Gibson { "pseries", "e1000", 5745459091SLaurent Vivier "-machine cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,vsmt=8" }, 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( 77*6f6e1698SPaolo 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 1111e88989fSDavid Gibson testname = g_strdup_printf("pxe/ipv4/%s/%s", 1121e88989fSDavid Gibson test->machine, test->model); 1131e88989fSDavid Gibson qtest_add_data_func(testname, test, test_pxe_ipv4); 1141e88989fSDavid Gibson g_free(testname); 115d23895d9SDavid Gibson 116d23895d9SDavid Gibson if (ipv6) { 117d23895d9SDavid Gibson testname = g_strdup_printf("pxe/ipv6/%s/%s", 118d23895d9SDavid Gibson test->machine, test->model); 119d23895d9SDavid Gibson qtest_add_data_func(testname, test, test_pxe_ipv6); 120d23895d9SDavid Gibson g_free(testname); 121d23895d9SDavid Gibson } 1221e88989fSDavid Gibson } 1231485ef1cSThomas Huth } 1241485ef1cSThomas Huth 1254e082566SVictor Kaplansky int main(int argc, char *argv[]) 1264e082566SVictor Kaplansky { 1274e082566SVictor Kaplansky int ret; 1284e082566SVictor Kaplansky const char *arch = qtest_get_arch(); 1294e082566SVictor Kaplansky 1304e082566SVictor Kaplansky ret = boot_sector_init(disk); 1314e082566SVictor Kaplansky if(ret) 1324e082566SVictor Kaplansky return ret; 1334e082566SVictor Kaplansky 1344e082566SVictor Kaplansky g_test_init(&argc, &argv, NULL); 1354e082566SVictor Kaplansky 1364e082566SVictor Kaplansky if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { 137d23895d9SDavid Gibson test_batch(x86_tests, false); 138ab06ec43SThomas Huth if (g_test_slow()) { 139d23895d9SDavid Gibson test_batch(x86_tests_slow, false); 140ab06ec43SThomas Huth } 1411485ef1cSThomas Huth } else if (strcmp(arch, "ppc64") == 0) { 142d23895d9SDavid Gibson test_batch(ppc64_tests, g_test_slow()); 143ab06ec43SThomas Huth if (g_test_slow()) { 144d23895d9SDavid Gibson test_batch(ppc64_tests_slow, true); 145ab06ec43SThomas Huth } 146b1b2feacSThomas Huth } else if (g_str_equal(arch, "s390x")) { 147d23895d9SDavid Gibson test_batch(s390x_tests, g_test_slow()); 1484e082566SVictor Kaplansky } 1494e082566SVictor Kaplansky ret = g_test_run(); 1504e082566SVictor Kaplansky boot_sector_cleanup(disk); 1514e082566SVictor Kaplansky return ret; 1524e082566SVictor Kaplansky } 153