xref: /qemu/tests/qtest/pxe-test.c (revision 63d57c8f91d0d0e62fc4d91db6340a662b36a3c0)
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"
20*63d57c8fSGreg Kurz #include "libqos/libqos-spapr.h"
214e082566SVictor Kaplansky 
224e082566SVictor Kaplansky #define NETNAME "net0"
234e082566SVictor Kaplansky 
243e353773SThomas Huth static char disk[] = "tests/pxe-test-disk-XXXXXX";
254e082566SVictor Kaplansky 
261e88989fSDavid Gibson typedef struct testdef {
271e88989fSDavid Gibson     const char *machine;    /* Machine type */
281e88989fSDavid Gibson     const char *model;      /* NIC device model */
29ba3b40deSDavid Gibson     const char *extra;      /* Any additional parameters */
301e88989fSDavid Gibson } testdef_t;
311e88989fSDavid Gibson 
321e88989fSDavid Gibson static testdef_t x86_tests[] = {
331e88989fSDavid Gibson     { "pc", "e1000" },
341e88989fSDavid Gibson     { "pc", "virtio-net-pci" },
3518b20bb4SDavid Gibson     { "q35", "e1000e" },
3618b20bb4SDavid Gibson     { "q35", "virtio-net-pci", },
371e88989fSDavid Gibson     { NULL },
381e88989fSDavid Gibson };
391e88989fSDavid Gibson 
401e88989fSDavid Gibson static testdef_t x86_tests_slow[] = {
411e88989fSDavid Gibson     { "pc", "ne2k_pci", },
421e88989fSDavid Gibson     { "pc", "i82550", },
431e88989fSDavid Gibson     { "pc", "rtl8139" },
441e88989fSDavid Gibson     { "pc", "vmxnet3" },
451e88989fSDavid Gibson     { NULL },
461e88989fSDavid Gibson };
471e88989fSDavid Gibson 
481e88989fSDavid Gibson static testdef_t ppc64_tests[] = {
49ba3b40deSDavid Gibson     { "pseries", "spapr-vlan",
50*63d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
51ba3b40deSDavid Gibson     { "pseries", "virtio-net-pci",
52*63d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
531e88989fSDavid Gibson     { NULL },
541e88989fSDavid Gibson };
551e88989fSDavid Gibson 
561e88989fSDavid Gibson static testdef_t ppc64_tests_slow[] = {
57ba3b40deSDavid Gibson     { "pseries", "e1000",
58*63d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
591e88989fSDavid Gibson     { NULL },
601e88989fSDavid Gibson };
611e88989fSDavid Gibson 
621e88989fSDavid Gibson static testdef_t s390x_tests[] = {
631e88989fSDavid Gibson     { "s390-ccw-virtio", "virtio-net-ccw" },
641e88989fSDavid Gibson     { NULL },
651e88989fSDavid Gibson };
661e88989fSDavid Gibson 
671e88989fSDavid Gibson static void test_pxe_one(const testdef_t *test, bool ipv6)
684e082566SVictor Kaplansky {
6943497c43SThomas Huth     QTestState *qts;
704e082566SVictor Kaplansky     char *args;
71ba3b40deSDavid Gibson     const char *extra = test->extra;
72ba3b40deSDavid Gibson 
73ba3b40deSDavid Gibson     if (!extra) {
74ba3b40deSDavid Gibson         extra = "";
75ba3b40deSDavid Gibson     }
764e082566SVictor Kaplansky 
771e88989fSDavid Gibson     args = g_strdup_printf(
786f6e1698SPaolo Bonzini         "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n "
791e88989fSDavid Gibson         "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
80ba3b40deSDavid Gibson         "-device %s,bootindex=1,netdev=" NETNAME " %s",
811e88989fSDavid Gibson         test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
82ba3b40deSDavid Gibson         test->model, extra);
834e082566SVictor Kaplansky 
8443497c43SThomas Huth     qts = qtest_init(args);
8543497c43SThomas Huth     boot_sector_test(qts);
8643497c43SThomas Huth     qtest_quit(qts);
874e082566SVictor Kaplansky     g_free(args);
884e082566SVictor Kaplansky }
894e082566SVictor Kaplansky 
90ab06ec43SThomas Huth static void test_pxe_ipv4(gconstpointer data)
914e082566SVictor Kaplansky {
921e88989fSDavid Gibson     const testdef_t *test = data;
934e082566SVictor Kaplansky 
941e88989fSDavid Gibson     test_pxe_one(test, false);
951e88989fSDavid Gibson }
961e88989fSDavid Gibson 
97d23895d9SDavid Gibson static void test_pxe_ipv6(gconstpointer data)
98d23895d9SDavid Gibson {
99d23895d9SDavid Gibson     const testdef_t *test = data;
100d23895d9SDavid Gibson 
101d23895d9SDavid Gibson     test_pxe_one(test, true);
102d23895d9SDavid Gibson }
103d23895d9SDavid Gibson 
104d23895d9SDavid Gibson static void test_batch(const testdef_t *tests, bool ipv6)
1051e88989fSDavid Gibson {
1061e88989fSDavid Gibson     int i;
1071e88989fSDavid Gibson 
1081e88989fSDavid Gibson     for (i = 0; tests[i].machine; i++) {
1091e88989fSDavid Gibson         const testdef_t *test = &tests[i];
1101e88989fSDavid Gibson         char *testname;
1111e88989fSDavid Gibson 
1121e88989fSDavid Gibson         testname = g_strdup_printf("pxe/ipv4/%s/%s",
1131e88989fSDavid Gibson                                    test->machine, test->model);
1141e88989fSDavid Gibson         qtest_add_data_func(testname, test, test_pxe_ipv4);
1151e88989fSDavid Gibson         g_free(testname);
116d23895d9SDavid Gibson 
117d23895d9SDavid Gibson         if (ipv6) {
118d23895d9SDavid Gibson             testname = g_strdup_printf("pxe/ipv6/%s/%s",
119d23895d9SDavid Gibson                                        test->machine, test->model);
120d23895d9SDavid Gibson             qtest_add_data_func(testname, test, test_pxe_ipv6);
121d23895d9SDavid Gibson             g_free(testname);
122d23895d9SDavid Gibson         }
1231e88989fSDavid Gibson     }
1241485ef1cSThomas Huth }
1251485ef1cSThomas Huth 
1264e082566SVictor Kaplansky int main(int argc, char *argv[])
1274e082566SVictor Kaplansky {
1284e082566SVictor Kaplansky     int ret;
1294e082566SVictor Kaplansky     const char *arch = qtest_get_arch();
1304e082566SVictor Kaplansky 
1314e082566SVictor Kaplansky     ret = boot_sector_init(disk);
1324e082566SVictor Kaplansky     if(ret)
1334e082566SVictor Kaplansky         return ret;
1344e082566SVictor Kaplansky 
1354e082566SVictor Kaplansky     g_test_init(&argc, &argv, NULL);
1364e082566SVictor Kaplansky 
1374e082566SVictor Kaplansky     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
138d23895d9SDavid Gibson         test_batch(x86_tests, false);
139ab06ec43SThomas Huth         if (g_test_slow()) {
140d23895d9SDavid Gibson             test_batch(x86_tests_slow, false);
141ab06ec43SThomas Huth         }
1421485ef1cSThomas Huth     } else if (strcmp(arch, "ppc64") == 0) {
143d23895d9SDavid Gibson         test_batch(ppc64_tests, g_test_slow());
144ab06ec43SThomas Huth         if (g_test_slow()) {
145d23895d9SDavid Gibson             test_batch(ppc64_tests_slow, true);
146ab06ec43SThomas Huth         }
147b1b2feacSThomas Huth     } else if (g_str_equal(arch, "s390x")) {
148d23895d9SDavid Gibson         test_batch(s390x_tests, g_test_slow());
1494e082566SVictor Kaplansky     }
1504e082566SVictor Kaplansky     ret = g_test_run();
1514e082566SVictor Kaplansky     boot_sector_cleanup(disk);
1524e082566SVictor Kaplansky     return ret;
1534e082566SVictor Kaplansky }
154