xref: /qemu/tests/qtest/pxe-test.c (revision d23895d9ba182825b488a37699bae79c70729f5f)
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" },
331e88989fSDavid Gibson     { NULL },
341e88989fSDavid Gibson };
351e88989fSDavid Gibson 
361e88989fSDavid Gibson static testdef_t x86_tests_slow[] = {
371e88989fSDavid Gibson     { "pc", "ne2k_pci", },
381e88989fSDavid Gibson     { "pc", "i82550", },
391e88989fSDavid Gibson     { "pc", "rtl8139" },
401e88989fSDavid Gibson     { "pc", "vmxnet3" },
411e88989fSDavid Gibson     { NULL },
421e88989fSDavid Gibson };
431e88989fSDavid Gibson 
441e88989fSDavid Gibson static testdef_t ppc64_tests[] = {
451e88989fSDavid Gibson     { "pseries", "spapr-vlan" },
461e88989fSDavid Gibson     { NULL },
471e88989fSDavid Gibson };
481e88989fSDavid Gibson 
491e88989fSDavid Gibson static testdef_t ppc64_tests_slow[] = {
501e88989fSDavid Gibson     { "pseries", "virtio-net-pci", },
511e88989fSDavid Gibson     { "pseries", "e1000" },
521e88989fSDavid Gibson     { NULL },
531e88989fSDavid Gibson };
541e88989fSDavid Gibson 
551e88989fSDavid Gibson static testdef_t s390x_tests[] = {
561e88989fSDavid Gibson     { "s390-ccw-virtio", "virtio-net-ccw" },
571e88989fSDavid Gibson     { NULL },
581e88989fSDavid Gibson };
591e88989fSDavid Gibson 
601e88989fSDavid Gibson static void test_pxe_one(const testdef_t *test, bool ipv6)
614e082566SVictor Kaplansky {
624e082566SVictor Kaplansky     char *args;
634e082566SVictor Kaplansky 
641e88989fSDavid Gibson     args = g_strdup_printf(
651e88989fSDavid Gibson         "-machine %s,accel=kvm:tcg -nodefaults -boot order=n "
661e88989fSDavid Gibson         "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
671e88989fSDavid Gibson         "-device %s,bootindex=1,netdev=" NETNAME,
681e88989fSDavid Gibson         test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
691e88989fSDavid 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 {
791e88989fSDavid Gibson     const testdef_t *test = data;
804e082566SVictor Kaplansky 
811e88989fSDavid Gibson     test_pxe_one(test, false);
821e88989fSDavid Gibson }
831e88989fSDavid Gibson 
84*d23895d9SDavid Gibson static void test_pxe_ipv6(gconstpointer data)
85*d23895d9SDavid Gibson {
86*d23895d9SDavid Gibson     const testdef_t *test = data;
87*d23895d9SDavid Gibson 
88*d23895d9SDavid Gibson     test_pxe_one(test, true);
89*d23895d9SDavid Gibson }
90*d23895d9SDavid Gibson 
91*d23895d9SDavid Gibson static void test_batch(const testdef_t *tests, bool ipv6)
921e88989fSDavid Gibson {
931e88989fSDavid Gibson     int i;
941e88989fSDavid Gibson 
951e88989fSDavid Gibson     for (i = 0; tests[i].machine; i++) {
961e88989fSDavid Gibson         const testdef_t *test = &tests[i];
971e88989fSDavid Gibson         char *testname;
981e88989fSDavid Gibson 
991e88989fSDavid Gibson         testname = g_strdup_printf("pxe/ipv4/%s/%s",
1001e88989fSDavid Gibson                                    test->machine, test->model);
1011e88989fSDavid Gibson         qtest_add_data_func(testname, test, test_pxe_ipv4);
1021e88989fSDavid Gibson         g_free(testname);
103*d23895d9SDavid Gibson 
104*d23895d9SDavid Gibson         if (ipv6) {
105*d23895d9SDavid Gibson             testname = g_strdup_printf("pxe/ipv6/%s/%s",
106*d23895d9SDavid Gibson                                        test->machine, test->model);
107*d23895d9SDavid Gibson             qtest_add_data_func(testname, test, test_pxe_ipv6);
108*d23895d9SDavid Gibson             g_free(testname);
109*d23895d9SDavid Gibson         }
1101e88989fSDavid Gibson     }
1111485ef1cSThomas Huth }
1121485ef1cSThomas Huth 
1134e082566SVictor Kaplansky int main(int argc, char *argv[])
1144e082566SVictor Kaplansky {
1154e082566SVictor Kaplansky     int ret;
1164e082566SVictor Kaplansky     const char *arch = qtest_get_arch();
1174e082566SVictor Kaplansky 
1184e082566SVictor Kaplansky     ret = boot_sector_init(disk);
1194e082566SVictor Kaplansky     if(ret)
1204e082566SVictor Kaplansky         return ret;
1214e082566SVictor Kaplansky 
1224e082566SVictor Kaplansky     g_test_init(&argc, &argv, NULL);
1234e082566SVictor Kaplansky 
1244e082566SVictor Kaplansky     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
125*d23895d9SDavid Gibson         test_batch(x86_tests, false);
126ab06ec43SThomas Huth         if (g_test_slow()) {
127*d23895d9SDavid Gibson             test_batch(x86_tests_slow, false);
128ab06ec43SThomas Huth         }
1291485ef1cSThomas Huth     } else if (strcmp(arch, "ppc64") == 0) {
130*d23895d9SDavid Gibson         test_batch(ppc64_tests, g_test_slow());
131ab06ec43SThomas Huth         if (g_test_slow()) {
132*d23895d9SDavid Gibson             test_batch(ppc64_tests_slow, true);
133ab06ec43SThomas Huth         }
134b1b2feacSThomas Huth     } else if (g_str_equal(arch, "s390x")) {
135*d23895d9SDavid Gibson         test_batch(s390x_tests, g_test_slow());
1364e082566SVictor Kaplansky     }
1374e082566SVictor Kaplansky     ret = g_test_run();
1384e082566SVictor Kaplansky     boot_sector_cleanup(disk);
1394e082566SVictor Kaplansky     return ret;
1404e082566SVictor Kaplansky }
141