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 */ 281e88989fSDavid Gibson } testdef_t; 291e88989fSDavid Gibson 301e88989fSDavid Gibson static testdef_t x86_tests[] = { 311e88989fSDavid Gibson { "pc", "e1000" }, 321e88989fSDavid Gibson { "pc", "virtio-net-pci" }, 3318b20bb4SDavid Gibson { "q35", "e1000e" }, 3418b20bb4SDavid Gibson { "q35", "virtio-net-pci", }, 351e88989fSDavid Gibson { NULL }, 361e88989fSDavid Gibson }; 371e88989fSDavid Gibson 381e88989fSDavid Gibson static testdef_t x86_tests_slow[] = { 391e88989fSDavid Gibson { "pc", "ne2k_pci", }, 401e88989fSDavid Gibson { "pc", "i82550", }, 411e88989fSDavid Gibson { "pc", "rtl8139" }, 421e88989fSDavid Gibson { "pc", "vmxnet3" }, 431e88989fSDavid Gibson { NULL }, 441e88989fSDavid Gibson }; 451e88989fSDavid Gibson 461e88989fSDavid Gibson static testdef_t ppc64_tests[] = { 471e88989fSDavid Gibson { "pseries", "spapr-vlan" }, 4818b20bb4SDavid Gibson { "pseries", "virtio-net-pci", }, 491e88989fSDavid Gibson { NULL }, 501e88989fSDavid Gibson }; 511e88989fSDavid Gibson 521e88989fSDavid Gibson static testdef_t ppc64_tests_slow[] = { 531e88989fSDavid Gibson { "pseries", "e1000" }, 541e88989fSDavid Gibson { NULL }, 551e88989fSDavid Gibson }; 561e88989fSDavid Gibson 571e88989fSDavid Gibson static testdef_t s390x_tests[] = { 581e88989fSDavid Gibson { "s390-ccw-virtio", "virtio-net-ccw" }, 591e88989fSDavid Gibson { NULL }, 601e88989fSDavid Gibson }; 611e88989fSDavid Gibson 621e88989fSDavid Gibson static void test_pxe_one(const testdef_t *test, bool ipv6) 634e082566SVictor Kaplansky { 64*43497c43SThomas Huth QTestState *qts; 654e082566SVictor Kaplansky char *args; 664e082566SVictor Kaplansky 671e88989fSDavid Gibson args = g_strdup_printf( 681e88989fSDavid Gibson "-machine %s,accel=kvm:tcg -nodefaults -boot order=n " 691e88989fSDavid Gibson "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s " 701e88989fSDavid Gibson "-device %s,bootindex=1,netdev=" NETNAME, 711e88989fSDavid Gibson test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off", 721e88989fSDavid Gibson test->model); 734e082566SVictor Kaplansky 74*43497c43SThomas Huth qts = qtest_init(args); 75*43497c43SThomas Huth boot_sector_test(qts); 76*43497c43SThomas Huth qtest_quit(qts); 774e082566SVictor Kaplansky g_free(args); 784e082566SVictor Kaplansky } 794e082566SVictor Kaplansky 80ab06ec43SThomas Huth static void test_pxe_ipv4(gconstpointer data) 814e082566SVictor Kaplansky { 821e88989fSDavid Gibson const testdef_t *test = data; 834e082566SVictor Kaplansky 841e88989fSDavid Gibson test_pxe_one(test, false); 851e88989fSDavid Gibson } 861e88989fSDavid Gibson 87d23895d9SDavid Gibson static void test_pxe_ipv6(gconstpointer data) 88d23895d9SDavid Gibson { 89d23895d9SDavid Gibson const testdef_t *test = data; 90d23895d9SDavid Gibson 91d23895d9SDavid Gibson test_pxe_one(test, true); 92d23895d9SDavid Gibson } 93d23895d9SDavid Gibson 94d23895d9SDavid Gibson static void test_batch(const testdef_t *tests, bool ipv6) 951e88989fSDavid Gibson { 961e88989fSDavid Gibson int i; 971e88989fSDavid Gibson 981e88989fSDavid Gibson for (i = 0; tests[i].machine; i++) { 991e88989fSDavid Gibson const testdef_t *test = &tests[i]; 1001e88989fSDavid Gibson char *testname; 1011e88989fSDavid Gibson 1021e88989fSDavid Gibson testname = g_strdup_printf("pxe/ipv4/%s/%s", 1031e88989fSDavid Gibson test->machine, test->model); 1041e88989fSDavid Gibson qtest_add_data_func(testname, test, test_pxe_ipv4); 1051e88989fSDavid Gibson g_free(testname); 106d23895d9SDavid Gibson 107d23895d9SDavid Gibson if (ipv6) { 108d23895d9SDavid Gibson testname = g_strdup_printf("pxe/ipv6/%s/%s", 109d23895d9SDavid Gibson test->machine, test->model); 110d23895d9SDavid Gibson qtest_add_data_func(testname, test, test_pxe_ipv6); 111d23895d9SDavid Gibson g_free(testname); 112d23895d9SDavid Gibson } 1131e88989fSDavid Gibson } 1141485ef1cSThomas Huth } 1151485ef1cSThomas Huth 1164e082566SVictor Kaplansky int main(int argc, char *argv[]) 1174e082566SVictor Kaplansky { 1184e082566SVictor Kaplansky int ret; 1194e082566SVictor Kaplansky const char *arch = qtest_get_arch(); 1204e082566SVictor Kaplansky 1214e082566SVictor Kaplansky ret = boot_sector_init(disk); 1224e082566SVictor Kaplansky if(ret) 1234e082566SVictor Kaplansky return ret; 1244e082566SVictor Kaplansky 1254e082566SVictor Kaplansky g_test_init(&argc, &argv, NULL); 1264e082566SVictor Kaplansky 1274e082566SVictor Kaplansky if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { 128d23895d9SDavid Gibson test_batch(x86_tests, false); 129ab06ec43SThomas Huth if (g_test_slow()) { 130d23895d9SDavid Gibson test_batch(x86_tests_slow, false); 131ab06ec43SThomas Huth } 1321485ef1cSThomas Huth } else if (strcmp(arch, "ppc64") == 0) { 133d23895d9SDavid Gibson test_batch(ppc64_tests, g_test_slow()); 134ab06ec43SThomas Huth if (g_test_slow()) { 135d23895d9SDavid Gibson test_batch(ppc64_tests_slow, true); 136ab06ec43SThomas Huth } 137b1b2feacSThomas Huth } else if (g_str_equal(arch, "s390x")) { 138d23895d9SDavid Gibson test_batch(s390x_tests, g_test_slow()); 1394e082566SVictor Kaplansky } 1404e082566SVictor Kaplansky ret = g_test_run(); 1414e082566SVictor Kaplansky boot_sector_cleanup(disk); 1424e082566SVictor Kaplansky return ret; 1434e082566SVictor Kaplansky } 144