4 * Copyright (c) 2016, 2017 Red Hat Inc.
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
15 #include "qemu/osdep.h"
16 #include <glib/gstdio.h>
17 #include "qemu-common.h"
18 #include "libqos/libqtest.h"
19 #include "boot-sector.h"
20 #include "libqos/libqos-spapr.h"
22 #define NETNAME "net0"
24 static char disk[] = "tests/pxe-test-disk-XXXXXX";
26 typedef struct testdef {
27 const char *machine; /* Machine type */
28 const char *model; /* NIC device model */
29 const char *extra; /* Any additional parameters */
32 static testdef_t x86_tests[] = {
34 { "pc", "virtio-net-pci" },
36 { "q35", "virtio-net-pci", },
40 static testdef_t x86_tests_slow[] = {
41 { "pc", "ne2k_pci", },
48 static testdef_t ppc64_tests[] = {
49 { "pseries", "spapr-vlan",
50 "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
51 { "pseries", "virtio-net-pci",
52 "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
56 static testdef_t ppc64_tests_slow[] = {
58 "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
62 static testdef_t s390x_tests[] = {
63 { "s390-ccw-virtio", "virtio-net-ccw" },
67 static void test_pxe_one(const testdef_t *test, bool ipv6)
71 const char *extra = test->extra;
77 args = g_strdup_printf(
78 "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n "
79 "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
80 "-device %s,bootindex=1,netdev=" NETNAME " %s",
81 test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
84 qts = qtest_init(args);
85 boot_sector_test(qts);
90 static void test_pxe_ipv4(gconstpointer data)
92 const testdef_t *test = data;
94 test_pxe_one(test, false);
97 static void test_pxe_ipv6(gconstpointer data)
99 const testdef_t *test = data;
101 test_pxe_one(test, true);
104 static void test_batch(const testdef_t *tests, bool ipv6)
108 for (i = 0; tests[i].machine; i++) {
109 const testdef_t *test = &tests[i];
112 testname = g_strdup_printf("pxe/ipv4/%s/%s",
113 test->machine, test->model);
114 qtest_add_data_func(testname, test, test_pxe_ipv4);
118 testname = g_strdup_printf("pxe/ipv6/%s/%s",
119 test->machine, test->model);
120 qtest_add_data_func(testname, test, test_pxe_ipv6);
126 int main(int argc, char *argv[])
129 const char *arch = qtest_get_arch();
131 ret = boot_sector_init(disk);
135 g_test_init(&argc, &argv, NULL);
137 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
138 test_batch(x86_tests, false);
140 test_batch(x86_tests_slow, false);
142 } else if (strcmp(arch, "ppc64") == 0) {
143 test_batch(ppc64_tests, g_test_slow());
145 test_batch(ppc64_tests_slow, true);
147 } else if (g_str_equal(arch, "s390x")) {
148 test_batch(s390x_tests, g_test_slow());
151 boot_sector_cleanup(disk);