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 25*1e88989fSDavid Gibson typedef struct testdef { 26*1e88989fSDavid Gibson const char *machine; /* Machine type */ 27*1e88989fSDavid Gibson const char *model; /* NIC device model */ 28*1e88989fSDavid Gibson } testdef_t; 29*1e88989fSDavid Gibson 30*1e88989fSDavid Gibson static testdef_t x86_tests[] = { 31*1e88989fSDavid Gibson { "pc", "e1000" }, 32*1e88989fSDavid Gibson { "pc", "virtio-net-pci" }, 33*1e88989fSDavid Gibson { NULL }, 34*1e88989fSDavid Gibson }; 35*1e88989fSDavid Gibson 36*1e88989fSDavid Gibson static testdef_t x86_tests_slow[] = { 37*1e88989fSDavid Gibson { "pc", "ne2k_pci", }, 38*1e88989fSDavid Gibson { "pc", "i82550", }, 39*1e88989fSDavid Gibson { "pc", "rtl8139" }, 40*1e88989fSDavid Gibson { "pc", "vmxnet3" }, 41*1e88989fSDavid Gibson { NULL }, 42*1e88989fSDavid Gibson }; 43*1e88989fSDavid Gibson 44*1e88989fSDavid Gibson static testdef_t ppc64_tests[] = { 45*1e88989fSDavid Gibson { "pseries", "spapr-vlan" }, 46*1e88989fSDavid Gibson { NULL }, 47*1e88989fSDavid Gibson }; 48*1e88989fSDavid Gibson 49*1e88989fSDavid Gibson static testdef_t ppc64_tests_slow[] = { 50*1e88989fSDavid Gibson { "pseries", "virtio-net-pci", }, 51*1e88989fSDavid Gibson { "pseries", "e1000" }, 52*1e88989fSDavid Gibson { NULL }, 53*1e88989fSDavid Gibson }; 54*1e88989fSDavid Gibson 55*1e88989fSDavid Gibson static testdef_t s390x_tests[] = { 56*1e88989fSDavid Gibson { "s390-ccw-virtio", "virtio-net-ccw" }, 57*1e88989fSDavid Gibson { NULL }, 58*1e88989fSDavid Gibson }; 59*1e88989fSDavid Gibson 60*1e88989fSDavid Gibson static void test_pxe_one(const testdef_t *test, bool ipv6) 614e082566SVictor Kaplansky { 624e082566SVictor Kaplansky char *args; 634e082566SVictor Kaplansky 64*1e88989fSDavid Gibson args = g_strdup_printf( 65*1e88989fSDavid Gibson "-machine %s,accel=kvm:tcg -nodefaults -boot order=n " 66*1e88989fSDavid Gibson "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s " 67*1e88989fSDavid Gibson "-device %s,bootindex=1,netdev=" NETNAME, 68*1e88989fSDavid Gibson test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off", 69*1e88989fSDavid Gibson test->model); 704e082566SVictor Kaplansky 714e082566SVictor Kaplansky qtest_start(args); 724e082566SVictor Kaplansky boot_sector_test(); 734e082566SVictor Kaplansky qtest_quit(global_qtest); 744e082566SVictor Kaplansky g_free(args); 754e082566SVictor Kaplansky } 764e082566SVictor Kaplansky 77ab06ec43SThomas Huth static void test_pxe_ipv4(gconstpointer data) 784e082566SVictor Kaplansky { 79*1e88989fSDavid Gibson const testdef_t *test = data; 804e082566SVictor Kaplansky 81*1e88989fSDavid Gibson test_pxe_one(test, false); 82*1e88989fSDavid Gibson } 83*1e88989fSDavid Gibson 84*1e88989fSDavid Gibson static void test_batch(const testdef_t *tests) 85*1e88989fSDavid Gibson { 86*1e88989fSDavid Gibson int i; 87*1e88989fSDavid Gibson 88*1e88989fSDavid Gibson for (i = 0; tests[i].machine; i++) { 89*1e88989fSDavid Gibson const testdef_t *test = &tests[i]; 90*1e88989fSDavid Gibson char *testname; 91*1e88989fSDavid Gibson 92*1e88989fSDavid Gibson testname = g_strdup_printf("pxe/ipv4/%s/%s", 93*1e88989fSDavid Gibson test->machine, test->model); 94*1e88989fSDavid Gibson qtest_add_data_func(testname, test, test_pxe_ipv4); 95*1e88989fSDavid Gibson g_free(testname); 96*1e88989fSDavid Gibson } 971485ef1cSThomas Huth } 981485ef1cSThomas Huth 994e082566SVictor Kaplansky int main(int argc, char *argv[]) 1004e082566SVictor Kaplansky { 1014e082566SVictor Kaplansky int ret; 1024e082566SVictor Kaplansky const char *arch = qtest_get_arch(); 1034e082566SVictor Kaplansky 1044e082566SVictor Kaplansky ret = boot_sector_init(disk); 1054e082566SVictor Kaplansky if(ret) 1064e082566SVictor Kaplansky return ret; 1074e082566SVictor Kaplansky 1084e082566SVictor Kaplansky g_test_init(&argc, &argv, NULL); 1094e082566SVictor Kaplansky 1104e082566SVictor Kaplansky if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { 111*1e88989fSDavid Gibson test_batch(x86_tests); 112ab06ec43SThomas Huth if (g_test_slow()) { 113*1e88989fSDavid Gibson test_batch(x86_tests_slow); 114ab06ec43SThomas Huth } 1151485ef1cSThomas Huth } else if (strcmp(arch, "ppc64") == 0) { 116*1e88989fSDavid Gibson test_batch(ppc64_tests); 117ab06ec43SThomas Huth if (g_test_slow()) { 118*1e88989fSDavid Gibson test_batch(ppc64_tests_slow); 119ab06ec43SThomas Huth } 120b1b2feacSThomas Huth } else if (g_str_equal(arch, "s390x")) { 121*1e88989fSDavid Gibson test_batch(s390x_tests); 1224e082566SVictor Kaplansky } 1234e082566SVictor Kaplansky ret = g_test_run(); 1244e082566SVictor Kaplansky boot_sector_cleanup(disk); 1254e082566SVictor Kaplansky return ret; 1264e082566SVictor Kaplansky } 127