tests/pxe-test: Test net booting over IPv6 in some cases
[qemu/kevin.git] / tests / pxe-test.c
blob5689c7d7ee887920ba3cd90040d95949d837dc98
1 /*
2 * PXE test cases.
4 * Copyright (c) 2016, 2017 Red Hat Inc.
6 * Authors:
7 * Michael S. Tsirkin <mst@redhat.com>,
8 * Victor Kaplansky <victork@redhat.com>
9 * Thomas Huth <thuth@redhat.com>
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 "libqtest.h"
19 #include "boot-sector.h"
21 #define NETNAME "net0"
23 static char disk[] = "tests/pxe-test-disk-XXXXXX";
25 typedef struct testdef {
26 const char *machine; /* Machine type */
27 const char *model; /* NIC device model */
28 } testdef_t;
30 static testdef_t x86_tests[] = {
31 { "pc", "e1000" },
32 { "pc", "virtio-net-pci" },
33 { NULL },
36 static testdef_t x86_tests_slow[] = {
37 { "pc", "ne2k_pci", },
38 { "pc", "i82550", },
39 { "pc", "rtl8139" },
40 { "pc", "vmxnet3" },
41 { NULL },
44 static testdef_t ppc64_tests[] = {
45 { "pseries", "spapr-vlan" },
46 { NULL },
49 static testdef_t ppc64_tests_slow[] = {
50 { "pseries", "virtio-net-pci", },
51 { "pseries", "e1000" },
52 { NULL },
55 static testdef_t s390x_tests[] = {
56 { "s390-ccw-virtio", "virtio-net-ccw" },
57 { NULL },
60 static void test_pxe_one(const testdef_t *test, bool ipv6)
62 char *args;
64 args = g_strdup_printf(
65 "-machine %s,accel=kvm:tcg -nodefaults -boot order=n "
66 "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
67 "-device %s,bootindex=1,netdev=" NETNAME,
68 test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
69 test->model);
71 qtest_start(args);
72 boot_sector_test();
73 qtest_quit(global_qtest);
74 g_free(args);
77 static void test_pxe_ipv4(gconstpointer data)
79 const testdef_t *test = data;
81 test_pxe_one(test, false);
84 static void test_pxe_ipv6(gconstpointer data)
86 const testdef_t *test = data;
88 test_pxe_one(test, true);
91 static void test_batch(const testdef_t *tests, bool ipv6)
93 int i;
95 for (i = 0; tests[i].machine; i++) {
96 const testdef_t *test = &tests[i];
97 char *testname;
99 testname = g_strdup_printf("pxe/ipv4/%s/%s",
100 test->machine, test->model);
101 qtest_add_data_func(testname, test, test_pxe_ipv4);
102 g_free(testname);
104 if (ipv6) {
105 testname = g_strdup_printf("pxe/ipv6/%s/%s",
106 test->machine, test->model);
107 qtest_add_data_func(testname, test, test_pxe_ipv6);
108 g_free(testname);
113 int main(int argc, char *argv[])
115 int ret;
116 const char *arch = qtest_get_arch();
118 ret = boot_sector_init(disk);
119 if(ret)
120 return ret;
122 g_test_init(&argc, &argv, NULL);
124 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
125 test_batch(x86_tests, false);
126 if (g_test_slow()) {
127 test_batch(x86_tests_slow, false);
129 } else if (strcmp(arch, "ppc64") == 0) {
130 test_batch(ppc64_tests, g_test_slow());
131 if (g_test_slow()) {
132 test_batch(ppc64_tests_slow, true);
134 } else if (g_str_equal(arch, "s390x")) {
135 test_batch(s390x_tests, g_test_slow());
137 ret = g_test_run();
138 boot_sector_cleanup(disk);
139 return ret;