xref: /qemu/tests/qtest/pxe-test.c (revision 18b20bb43a2f37f0c8ae23a3e9b3d9a4a05b6bd4)
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" },
33*18b20bb4SDavid Gibson     { "q35", "e1000e" },
34*18b20bb4SDavid 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" },
48*18b20bb4SDavid 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 {
644e082566SVictor Kaplansky     char *args;
654e082566SVictor Kaplansky 
661e88989fSDavid Gibson     args = g_strdup_printf(
671e88989fSDavid Gibson         "-machine %s,accel=kvm:tcg -nodefaults -boot order=n "
681e88989fSDavid Gibson         "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
691e88989fSDavid Gibson         "-device %s,bootindex=1,netdev=" NETNAME,
701e88989fSDavid Gibson         test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
711e88989fSDavid Gibson         test->model);
724e082566SVictor Kaplansky 
734e082566SVictor Kaplansky     qtest_start(args);
744e082566SVictor Kaplansky     boot_sector_test();
754e082566SVictor Kaplansky     qtest_quit(global_qtest);
764e082566SVictor Kaplansky     g_free(args);
774e082566SVictor Kaplansky }
784e082566SVictor Kaplansky 
79ab06ec43SThomas Huth static void test_pxe_ipv4(gconstpointer data)
804e082566SVictor Kaplansky {
811e88989fSDavid Gibson     const testdef_t *test = data;
824e082566SVictor Kaplansky 
831e88989fSDavid Gibson     test_pxe_one(test, false);
841e88989fSDavid Gibson }
851e88989fSDavid Gibson 
86d23895d9SDavid Gibson static void test_pxe_ipv6(gconstpointer data)
87d23895d9SDavid Gibson {
88d23895d9SDavid Gibson     const testdef_t *test = data;
89d23895d9SDavid Gibson 
90d23895d9SDavid Gibson     test_pxe_one(test, true);
91d23895d9SDavid Gibson }
92d23895d9SDavid Gibson 
93d23895d9SDavid Gibson static void test_batch(const testdef_t *tests, bool ipv6)
941e88989fSDavid Gibson {
951e88989fSDavid Gibson     int i;
961e88989fSDavid Gibson 
971e88989fSDavid Gibson     for (i = 0; tests[i].machine; i++) {
981e88989fSDavid Gibson         const testdef_t *test = &tests[i];
991e88989fSDavid Gibson         char *testname;
1001e88989fSDavid Gibson 
1011e88989fSDavid Gibson         testname = g_strdup_printf("pxe/ipv4/%s/%s",
1021e88989fSDavid Gibson                                    test->machine, test->model);
1031e88989fSDavid Gibson         qtest_add_data_func(testname, test, test_pxe_ipv4);
1041e88989fSDavid Gibson         g_free(testname);
105d23895d9SDavid Gibson 
106d23895d9SDavid Gibson         if (ipv6) {
107d23895d9SDavid Gibson             testname = g_strdup_printf("pxe/ipv6/%s/%s",
108d23895d9SDavid Gibson                                        test->machine, test->model);
109d23895d9SDavid Gibson             qtest_add_data_func(testname, test, test_pxe_ipv6);
110d23895d9SDavid Gibson             g_free(testname);
111d23895d9SDavid Gibson         }
1121e88989fSDavid Gibson     }
1131485ef1cSThomas Huth }
1141485ef1cSThomas Huth 
1154e082566SVictor Kaplansky int main(int argc, char *argv[])
1164e082566SVictor Kaplansky {
1174e082566SVictor Kaplansky     int ret;
1184e082566SVictor Kaplansky     const char *arch = qtest_get_arch();
1194e082566SVictor Kaplansky 
1204e082566SVictor Kaplansky     ret = boot_sector_init(disk);
1214e082566SVictor Kaplansky     if(ret)
1224e082566SVictor Kaplansky         return ret;
1234e082566SVictor Kaplansky 
1244e082566SVictor Kaplansky     g_test_init(&argc, &argv, NULL);
1254e082566SVictor Kaplansky 
1264e082566SVictor Kaplansky     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
127d23895d9SDavid Gibson         test_batch(x86_tests, false);
128ab06ec43SThomas Huth         if (g_test_slow()) {
129d23895d9SDavid Gibson             test_batch(x86_tests_slow, false);
130ab06ec43SThomas Huth         }
1311485ef1cSThomas Huth     } else if (strcmp(arch, "ppc64") == 0) {
132d23895d9SDavid Gibson         test_batch(ppc64_tests, g_test_slow());
133ab06ec43SThomas Huth         if (g_test_slow()) {
134d23895d9SDavid Gibson             test_batch(ppc64_tests_slow, true);
135ab06ec43SThomas Huth         }
136b1b2feacSThomas Huth     } else if (g_str_equal(arch, "s390x")) {
137d23895d9SDavid Gibson         test_batch(s390x_tests, g_test_slow());
1384e082566SVictor Kaplansky     }
1394e082566SVictor Kaplansky     ret = g_test_run();
1404e082566SVictor Kaplansky     boot_sector_cleanup(disk);
1414e082566SVictor Kaplansky     return ret;
1424e082566SVictor Kaplansky }
143