xref: /qemu/tests/qtest/pxe-test.c (revision 3e40bdb15e2ba6e55ee92d148b0cefb7050fad20)
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>
17907b5105SMarc-André Lureau #include "libqtest.h"
184e082566SVictor Kaplansky #include "boot-sector.h"
19*3e40bdb1SNicholas Piggin #include "ppc-util.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 */
28ba3b40deSDavid Gibson     const char *extra;      /* Any additional parameters */
291e88989fSDavid Gibson } testdef_t;
301e88989fSDavid Gibson 
311e88989fSDavid Gibson static testdef_t x86_tests[] = {
321e88989fSDavid Gibson     { "pc", "e1000" },
331e88989fSDavid Gibson     { "pc", "virtio-net-pci" },
3418b20bb4SDavid Gibson     { "q35", "e1000e" },
3518b20bb4SDavid Gibson     { "q35", "virtio-net-pci", },
361e88989fSDavid Gibson     { NULL },
371e88989fSDavid Gibson };
381e88989fSDavid Gibson 
391e88989fSDavid Gibson static testdef_t x86_tests_slow[] = {
401e88989fSDavid Gibson     { "pc", "ne2k_pci", },
411e88989fSDavid Gibson     { "pc", "i82550", },
421e88989fSDavid Gibson     { "pc", "rtl8139" },
431e88989fSDavid Gibson     { "pc", "vmxnet3" },
441e88989fSDavid Gibson     { NULL },
451e88989fSDavid Gibson };
461e88989fSDavid Gibson 
471e88989fSDavid Gibson static testdef_t ppc64_tests[] = {
48ba3b40deSDavid Gibson     { "pseries", "spapr-vlan",
4963d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
50ba3b40deSDavid Gibson     { "pseries", "virtio-net-pci",
5163d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
521e88989fSDavid Gibson     { NULL },
531e88989fSDavid Gibson };
541e88989fSDavid Gibson 
551e88989fSDavid Gibson static testdef_t ppc64_tests_slow[] = {
56ba3b40deSDavid Gibson     { "pseries", "e1000",
5763d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
581e88989fSDavid Gibson     { NULL },
591e88989fSDavid Gibson };
601e88989fSDavid Gibson 
611e88989fSDavid Gibson static testdef_t s390x_tests[] = {
621e88989fSDavid Gibson     { "s390-ccw-virtio", "virtio-net-ccw" },
631e88989fSDavid Gibson     { NULL },
641e88989fSDavid Gibson };
651e88989fSDavid Gibson 
test_pxe_one(const testdef_t * test,bool ipv6)661e88989fSDavid Gibson static void test_pxe_one(const testdef_t *test, bool ipv6)
674e082566SVictor Kaplansky {
6843497c43SThomas Huth     QTestState *qts;
694e082566SVictor Kaplansky     char *args;
70ba3b40deSDavid Gibson     const char *extra = test->extra;
71ba3b40deSDavid Gibson 
72ba3b40deSDavid Gibson     if (!extra) {
73ba3b40deSDavid Gibson         extra = "";
74ba3b40deSDavid Gibson     }
754e082566SVictor Kaplansky 
761e88989fSDavid Gibson     args = g_strdup_printf(
776f6e1698SPaolo Bonzini         "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n "
781e88989fSDavid Gibson         "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
79ba3b40deSDavid Gibson         "-device %s,bootindex=1,netdev=" NETNAME " %s",
801e88989fSDavid Gibson         test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
81ba3b40deSDavid Gibson         test->model, extra);
824e082566SVictor Kaplansky 
8343497c43SThomas Huth     qts = qtest_init(args);
8443497c43SThomas Huth     boot_sector_test(qts);
8543497c43SThomas Huth     qtest_quit(qts);
864e082566SVictor Kaplansky     g_free(args);
874e082566SVictor Kaplansky }
884e082566SVictor Kaplansky 
test_pxe_ipv4(gconstpointer data)89ab06ec43SThomas Huth static void test_pxe_ipv4(gconstpointer data)
904e082566SVictor Kaplansky {
911e88989fSDavid Gibson     const testdef_t *test = data;
924e082566SVictor Kaplansky 
931e88989fSDavid Gibson     test_pxe_one(test, false);
941e88989fSDavid Gibson }
951e88989fSDavid Gibson 
test_pxe_ipv6(gconstpointer data)96d23895d9SDavid Gibson static void test_pxe_ipv6(gconstpointer data)
97d23895d9SDavid Gibson {
98d23895d9SDavid Gibson     const testdef_t *test = data;
99d23895d9SDavid Gibson 
100d23895d9SDavid Gibson     test_pxe_one(test, true);
101d23895d9SDavid Gibson }
102d23895d9SDavid Gibson 
test_batch(const testdef_t * tests,bool ipv6)103d23895d9SDavid Gibson static void test_batch(const testdef_t *tests, bool ipv6)
1041e88989fSDavid Gibson {
1051e88989fSDavid Gibson     int i;
1061e88989fSDavid Gibson 
1071e88989fSDavid Gibson     for (i = 0; tests[i].machine; i++) {
1081e88989fSDavid Gibson         const testdef_t *test = &tests[i];
1091e88989fSDavid Gibson         char *testname;
1101e88989fSDavid Gibson 
1118f757034SFabiano Rosas         if (!qtest_has_device(test->model)) {
1128f757034SFabiano Rosas             continue;
1138f757034SFabiano Rosas         }
1148f757034SFabiano Rosas 
1151e88989fSDavid Gibson         testname = g_strdup_printf("pxe/ipv4/%s/%s",
1161e88989fSDavid Gibson                                    test->machine, test->model);
1171e88989fSDavid Gibson         qtest_add_data_func(testname, test, test_pxe_ipv4);
1181e88989fSDavid Gibson         g_free(testname);
119d23895d9SDavid Gibson 
120d23895d9SDavid Gibson         if (ipv6) {
121d23895d9SDavid Gibson             testname = g_strdup_printf("pxe/ipv6/%s/%s",
122d23895d9SDavid Gibson                                        test->machine, test->model);
123d23895d9SDavid Gibson             qtest_add_data_func(testname, test, test_pxe_ipv6);
124d23895d9SDavid Gibson             g_free(testname);
125d23895d9SDavid Gibson         }
1261e88989fSDavid Gibson     }
1271485ef1cSThomas Huth }
1281485ef1cSThomas Huth 
main(int argc,char * argv[])1294e082566SVictor Kaplansky int main(int argc, char *argv[])
1304e082566SVictor Kaplansky {
1314e082566SVictor Kaplansky     int ret;
1324e082566SVictor Kaplansky     const char *arch = qtest_get_arch();
1334e082566SVictor Kaplansky 
1340c1ae3ffSFabiano Rosas     g_test_init(&argc, &argv, NULL);
1350c1ae3ffSFabiano Rosas 
1360c1ae3ffSFabiano Rosas     if (!qtest_has_accel("tcg") && !qtest_has_accel("kvm")) {
1370c1ae3ffSFabiano Rosas         g_test_skip("No KVM or TCG accelerator available");
1380c1ae3ffSFabiano Rosas         return 0;
1390c1ae3ffSFabiano Rosas     }
1400c1ae3ffSFabiano Rosas 
1414e082566SVictor Kaplansky     ret = boot_sector_init(disk);
1424e082566SVictor Kaplansky     if(ret)
1434e082566SVictor Kaplansky         return ret;
1444e082566SVictor Kaplansky 
1454e082566SVictor Kaplansky 
1464e082566SVictor Kaplansky     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
147d23895d9SDavid Gibson         test_batch(x86_tests, false);
148ab06ec43SThomas Huth         if (g_test_slow()) {
149d23895d9SDavid Gibson             test_batch(x86_tests_slow, false);
150ab06ec43SThomas Huth         }
1511485ef1cSThomas Huth     } else if (strcmp(arch, "ppc64") == 0) {
152d23895d9SDavid Gibson         test_batch(ppc64_tests, g_test_slow());
153ab06ec43SThomas Huth         if (g_test_slow()) {
154d23895d9SDavid Gibson             test_batch(ppc64_tests_slow, true);
155ab06ec43SThomas Huth         }
156b1b2feacSThomas Huth     } else if (g_str_equal(arch, "s390x")) {
157d23895d9SDavid Gibson         test_batch(s390x_tests, g_test_slow());
1584e082566SVictor Kaplansky     }
1594e082566SVictor Kaplansky     ret = g_test_run();
1604e082566SVictor Kaplansky     boot_sector_cleanup(disk);
1614e082566SVictor Kaplansky     return ret;
1624e082566SVictor Kaplansky }
163