xref: /openbmc/qemu/tests/qtest/pxe-test.c (revision b23acd3e1fd35a9a8452e793d7a0b0e8cc39714a)
11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth  * PXE test cases.
31e8a1faeSThomas Huth  *
41e8a1faeSThomas Huth  * Copyright (c) 2016, 2017 Red Hat Inc.
51e8a1faeSThomas Huth  *
61e8a1faeSThomas Huth  * Authors:
71e8a1faeSThomas Huth  *  Michael S. Tsirkin <mst@redhat.com>,
81e8a1faeSThomas Huth  *  Victor Kaplansky <victork@redhat.com>
91e8a1faeSThomas Huth  *  Thomas Huth <thuth@redhat.com>
101e8a1faeSThomas Huth  *
111e8a1faeSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
121e8a1faeSThomas Huth  * See the COPYING file in the top-level directory.
131e8a1faeSThomas Huth  */
141e8a1faeSThomas Huth 
151e8a1faeSThomas Huth #include "qemu/osdep.h"
161e8a1faeSThomas Huth #include <glib/gstdio.h>
17907b5105SMarc-André Lureau #include "libqtest.h"
181e8a1faeSThomas Huth #include "boot-sector.h"
19*3e40bdb1SNicholas Piggin #include "ppc-util.h"
201e8a1faeSThomas Huth 
211e8a1faeSThomas Huth #define NETNAME "net0"
221e8a1faeSThomas Huth 
231e8a1faeSThomas Huth static char disk[] = "tests/pxe-test-disk-XXXXXX";
241e8a1faeSThomas Huth 
251e8a1faeSThomas Huth typedef struct testdef {
261e8a1faeSThomas Huth     const char *machine;    /* Machine type */
271e8a1faeSThomas Huth     const char *model;      /* NIC device model */
281e8a1faeSThomas Huth     const char *extra;      /* Any additional parameters */
291e8a1faeSThomas Huth } testdef_t;
301e8a1faeSThomas Huth 
311e8a1faeSThomas Huth static testdef_t x86_tests[] = {
321e8a1faeSThomas Huth     { "pc", "e1000" },
331e8a1faeSThomas Huth     { "pc", "virtio-net-pci" },
341e8a1faeSThomas Huth     { "q35", "e1000e" },
351e8a1faeSThomas Huth     { "q35", "virtio-net-pci", },
361e8a1faeSThomas Huth     { NULL },
371e8a1faeSThomas Huth };
381e8a1faeSThomas Huth 
391e8a1faeSThomas Huth static testdef_t x86_tests_slow[] = {
401e8a1faeSThomas Huth     { "pc", "ne2k_pci", },
411e8a1faeSThomas Huth     { "pc", "i82550", },
421e8a1faeSThomas Huth     { "pc", "rtl8139" },
431e8a1faeSThomas Huth     { "pc", "vmxnet3" },
441e8a1faeSThomas Huth     { NULL },
451e8a1faeSThomas Huth };
461e8a1faeSThomas Huth 
471e8a1faeSThomas Huth static testdef_t ppc64_tests[] = {
481e8a1faeSThomas Huth     { "pseries", "spapr-vlan",
4963d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
501e8a1faeSThomas Huth     { "pseries", "virtio-net-pci",
5163d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
521e8a1faeSThomas Huth     { NULL },
531e8a1faeSThomas Huth };
541e8a1faeSThomas Huth 
551e8a1faeSThomas Huth static testdef_t ppc64_tests_slow[] = {
561e8a1faeSThomas Huth     { "pseries", "e1000",
5763d57c8fSGreg Kurz       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
581e8a1faeSThomas Huth     { NULL },
591e8a1faeSThomas Huth };
601e8a1faeSThomas Huth 
611e8a1faeSThomas Huth static testdef_t s390x_tests[] = {
621e8a1faeSThomas Huth     { "s390-ccw-virtio", "virtio-net-ccw" },
631e8a1faeSThomas Huth     { NULL },
641e8a1faeSThomas Huth };
651e8a1faeSThomas Huth 
test_pxe_one(const testdef_t * test,bool ipv6)661e8a1faeSThomas Huth static void test_pxe_one(const testdef_t *test, bool ipv6)
671e8a1faeSThomas Huth {
681e8a1faeSThomas Huth     QTestState *qts;
691e8a1faeSThomas Huth     char *args;
701e8a1faeSThomas Huth     const char *extra = test->extra;
711e8a1faeSThomas Huth 
721e8a1faeSThomas Huth     if (!extra) {
731e8a1faeSThomas Huth         extra = "";
741e8a1faeSThomas Huth     }
751e8a1faeSThomas Huth 
761e8a1faeSThomas Huth     args = g_strdup_printf(
771e8a1faeSThomas Huth         "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n "
781e8a1faeSThomas Huth         "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
791e8a1faeSThomas Huth         "-device %s,bootindex=1,netdev=" NETNAME " %s",
801e8a1faeSThomas Huth         test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
811e8a1faeSThomas Huth         test->model, extra);
821e8a1faeSThomas Huth 
831e8a1faeSThomas Huth     qts = qtest_init(args);
841e8a1faeSThomas Huth     boot_sector_test(qts);
851e8a1faeSThomas Huth     qtest_quit(qts);
861e8a1faeSThomas Huth     g_free(args);
871e8a1faeSThomas Huth }
881e8a1faeSThomas Huth 
test_pxe_ipv4(gconstpointer data)891e8a1faeSThomas Huth static void test_pxe_ipv4(gconstpointer data)
901e8a1faeSThomas Huth {
911e8a1faeSThomas Huth     const testdef_t *test = data;
921e8a1faeSThomas Huth 
931e8a1faeSThomas Huth     test_pxe_one(test, false);
941e8a1faeSThomas Huth }
951e8a1faeSThomas Huth 
test_pxe_ipv6(gconstpointer data)961e8a1faeSThomas Huth static void test_pxe_ipv6(gconstpointer data)
971e8a1faeSThomas Huth {
981e8a1faeSThomas Huth     const testdef_t *test = data;
991e8a1faeSThomas Huth 
1001e8a1faeSThomas Huth     test_pxe_one(test, true);
1011e8a1faeSThomas Huth }
1021e8a1faeSThomas Huth 
test_batch(const testdef_t * tests,bool ipv6)1031e8a1faeSThomas Huth static void test_batch(const testdef_t *tests, bool ipv6)
1041e8a1faeSThomas Huth {
1051e8a1faeSThomas Huth     int i;
1061e8a1faeSThomas Huth 
1071e8a1faeSThomas Huth     for (i = 0; tests[i].machine; i++) {
1081e8a1faeSThomas Huth         const testdef_t *test = &tests[i];
1091e8a1faeSThomas Huth         char *testname;
1101e8a1faeSThomas Huth 
1118f757034SFabiano Rosas         if (!qtest_has_device(test->model)) {
1128f757034SFabiano Rosas             continue;
1138f757034SFabiano Rosas         }
1148f757034SFabiano Rosas 
1151e8a1faeSThomas Huth         testname = g_strdup_printf("pxe/ipv4/%s/%s",
1161e8a1faeSThomas Huth                                    test->machine, test->model);
1171e8a1faeSThomas Huth         qtest_add_data_func(testname, test, test_pxe_ipv4);
1181e8a1faeSThomas Huth         g_free(testname);
1191e8a1faeSThomas Huth 
1201e8a1faeSThomas Huth         if (ipv6) {
1211e8a1faeSThomas Huth             testname = g_strdup_printf("pxe/ipv6/%s/%s",
1221e8a1faeSThomas Huth                                        test->machine, test->model);
1231e8a1faeSThomas Huth             qtest_add_data_func(testname, test, test_pxe_ipv6);
1241e8a1faeSThomas Huth             g_free(testname);
1251e8a1faeSThomas Huth         }
1261e8a1faeSThomas Huth     }
1271e8a1faeSThomas Huth }
1281e8a1faeSThomas Huth 
main(int argc,char * argv[])1291e8a1faeSThomas Huth int main(int argc, char *argv[])
1301e8a1faeSThomas Huth {
1311e8a1faeSThomas Huth     int ret;
1321e8a1faeSThomas Huth     const char *arch = qtest_get_arch();
1331e8a1faeSThomas Huth 
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 
1411e8a1faeSThomas Huth     ret = boot_sector_init(disk);
1421e8a1faeSThomas Huth     if(ret)
1431e8a1faeSThomas Huth         return ret;
1441e8a1faeSThomas Huth 
1451e8a1faeSThomas Huth 
1461e8a1faeSThomas Huth     if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
1471e8a1faeSThomas Huth         test_batch(x86_tests, false);
1481e8a1faeSThomas Huth         if (g_test_slow()) {
1491e8a1faeSThomas Huth             test_batch(x86_tests_slow, false);
1501e8a1faeSThomas Huth         }
1511e8a1faeSThomas Huth     } else if (strcmp(arch, "ppc64") == 0) {
1521e8a1faeSThomas Huth         test_batch(ppc64_tests, g_test_slow());
1531e8a1faeSThomas Huth         if (g_test_slow()) {
1541e8a1faeSThomas Huth             test_batch(ppc64_tests_slow, true);
1551e8a1faeSThomas Huth         }
1561e8a1faeSThomas Huth     } else if (g_str_equal(arch, "s390x")) {
1571e8a1faeSThomas Huth         test_batch(s390x_tests, g_test_slow());
1581e8a1faeSThomas Huth     }
1591e8a1faeSThomas Huth     ret = g_test_run();
1601e8a1faeSThomas Huth     boot_sector_cleanup(disk);
1611e8a1faeSThomas Huth     return ret;
1621e8a1faeSThomas Huth }
163