xref: /qemu/tests/qtest/pxe-test.c (revision ab06ec43577177a442e8e5ca28d0154efe4ff60f)
14e082566SVictor Kaplansky /*
24e082566SVictor Kaplansky  * PXE test cases.
34e082566SVictor Kaplansky  *
4*ab06ec43SThomas 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>
9*ab06ec43SThomas 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 
251485ef1cSThomas Huth static void test_pxe_one(const char *params, bool ipv6)
264e082566SVictor Kaplansky {
274e082566SVictor Kaplansky     char *args;
284e082566SVictor Kaplansky 
292cef91cfSMichael S. Tsirkin     args = g_strdup_printf("-machine accel=kvm:tcg -nodefaults -boot order=n "
301485ef1cSThomas Huth                            "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,"
311485ef1cSThomas Huth                            "ipv4=%s,ipv6=%s %s", disk, ipv6 ? "off" : "on",
321485ef1cSThomas Huth                            ipv6 ? "on" : "off", params);
334e082566SVictor Kaplansky 
344e082566SVictor Kaplansky     qtest_start(args);
354e082566SVictor Kaplansky     boot_sector_test();
364e082566SVictor Kaplansky     qtest_quit(global_qtest);
374e082566SVictor Kaplansky     g_free(args);
384e082566SVictor Kaplansky }
394e082566SVictor Kaplansky 
40*ab06ec43SThomas Huth static void test_pxe_ipv4(gconstpointer data)
414e082566SVictor Kaplansky {
42*ab06ec43SThomas Huth     const char *model = data;
43*ab06ec43SThomas Huth     char *dev_arg;
444e082566SVictor Kaplansky 
45*ab06ec43SThomas Huth     dev_arg = g_strdup_printf("-device %s,netdev=" NETNAME, model);
46*ab06ec43SThomas Huth     test_pxe_one(dev_arg, false);
47*ab06ec43SThomas Huth     g_free(dev_arg);
481485ef1cSThomas Huth }
491485ef1cSThomas Huth 
501485ef1cSThomas Huth static void test_pxe_spapr_vlan(void)
511485ef1cSThomas Huth {
52ef6c47f1SThomas Huth     test_pxe_one("-device spapr-vlan,netdev=" NETNAME, true);
534e082566SVictor Kaplansky }
544e082566SVictor Kaplansky 
55b1b2feacSThomas Huth static void test_pxe_virtio_ccw(void)
56b1b2feacSThomas Huth {
57b1b2feacSThomas Huth     test_pxe_one("-device virtio-net-ccw,bootindex=1,netdev=" NETNAME, false);
58b1b2feacSThomas Huth }
59b1b2feacSThomas Huth 
604e082566SVictor Kaplansky int main(int argc, char *argv[])
614e082566SVictor Kaplansky {
624e082566SVictor Kaplansky     int ret;
634e082566SVictor Kaplansky     const char *arch = qtest_get_arch();
644e082566SVictor Kaplansky 
654e082566SVictor Kaplansky     ret = boot_sector_init(disk);
664e082566SVictor Kaplansky     if(ret)
674e082566SVictor Kaplansky         return ret;
684e082566SVictor Kaplansky 
694e082566SVictor Kaplansky     g_test_init(&argc, &argv, NULL);
704e082566SVictor Kaplansky 
714e082566SVictor Kaplansky     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
72*ab06ec43SThomas Huth         qtest_add_data_func("pxe/e1000", "e1000", test_pxe_ipv4);
73*ab06ec43SThomas Huth         qtest_add_data_func("pxe/virtio", "virtio-net-pci", test_pxe_ipv4);
74*ab06ec43SThomas Huth         if (g_test_slow()) {
75*ab06ec43SThomas Huth             qtest_add_data_func("pxe/ne2000", "ne2k_pci", test_pxe_ipv4);
76*ab06ec43SThomas Huth             qtest_add_data_func("pxe/eepro100", "i82550", test_pxe_ipv4);
77*ab06ec43SThomas Huth             qtest_add_data_func("pxe/pcnet", "pcnet", test_pxe_ipv4);
78*ab06ec43SThomas Huth             qtest_add_data_func("pxe/rtl8139", "rtl8139", test_pxe_ipv4);
79*ab06ec43SThomas Huth             qtest_add_data_func("pxe/vmxnet3", "vmxnet3", test_pxe_ipv4);
80*ab06ec43SThomas Huth         }
811485ef1cSThomas Huth     } else if (strcmp(arch, "ppc64") == 0) {
821485ef1cSThomas Huth         qtest_add_func("pxe/spapr-vlan", test_pxe_spapr_vlan);
83*ab06ec43SThomas Huth         if (g_test_slow()) {
84*ab06ec43SThomas Huth             qtest_add_data_func("pxe/virtio", "virtio-net-pci", test_pxe_ipv4);
85*ab06ec43SThomas Huth             qtest_add_data_func("pxe/e1000", "e1000", test_pxe_ipv4);
86*ab06ec43SThomas Huth         }
87b1b2feacSThomas Huth     } else if (g_str_equal(arch, "s390x")) {
88b1b2feacSThomas Huth         qtest_add_func("pxe/virtio-ccw", test_pxe_virtio_ccw);
894e082566SVictor Kaplansky     }
904e082566SVictor Kaplansky     ret = g_test_run();
914e082566SVictor Kaplansky     boot_sector_cleanup(disk);
924e082566SVictor Kaplansky     return ret;
934e082566SVictor Kaplansky }
94