]> git.proxmox.com Git - mirror_qemu.git/blame - tests/pxe-test.c
Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2018-03-26' into staging
[mirror_qemu.git] / tests / pxe-test.c
CommitLineData
4e082566
VK
1/*
2 * PXE test cases.
3 *
ab06ec43 4 * Copyright (c) 2016, 2017 Red Hat Inc.
4e082566
VK
5 *
6 * Authors:
7 * Michael S. Tsirkin <mst@redhat.com>,
8 * Victor Kaplansky <victork@redhat.com>
ab06ec43 9 * Thomas Huth <thuth@redhat.com>
4e082566
VK
10 *
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.
13 */
14
974dc73d 15#include "qemu/osdep.h"
4e082566
VK
16#include <glib/gstdio.h>
17#include "qemu-common.h"
18#include "libqtest.h"
19#include "boot-sector.h"
20
21#define NETNAME "net0"
22
3e353773 23static char disk[] = "tests/pxe-test-disk-XXXXXX";
4e082566 24
1e88989f
DG
25typedef struct testdef {
26 const char *machine; /* Machine type */
27 const char *model; /* NIC device model */
28} testdef_t;
29
30static testdef_t x86_tests[] = {
31 { "pc", "e1000" },
32 { "pc", "virtio-net-pci" },
18b20bb4
DG
33 { "q35", "e1000e" },
34 { "q35", "virtio-net-pci", },
1e88989f
DG
35 { NULL },
36};
37
38static testdef_t x86_tests_slow[] = {
39 { "pc", "ne2k_pci", },
40 { "pc", "i82550", },
41 { "pc", "rtl8139" },
42 { "pc", "vmxnet3" },
43 { NULL },
44};
45
46static testdef_t ppc64_tests[] = {
47 { "pseries", "spapr-vlan" },
18b20bb4 48 { "pseries", "virtio-net-pci", },
1e88989f
DG
49 { NULL },
50};
51
52static testdef_t ppc64_tests_slow[] = {
1e88989f
DG
53 { "pseries", "e1000" },
54 { NULL },
55};
56
57static testdef_t s390x_tests[] = {
58 { "s390-ccw-virtio", "virtio-net-ccw" },
59 { NULL },
60};
61
62static void test_pxe_one(const testdef_t *test, bool ipv6)
4e082566
VK
63{
64 char *args;
65
1e88989f
DG
66 args = g_strdup_printf(
67 "-machine %s,accel=kvm:tcg -nodefaults -boot order=n "
68 "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
69 "-device %s,bootindex=1,netdev=" NETNAME,
70 test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
71 test->model);
4e082566
VK
72
73 qtest_start(args);
8b19f2b7 74 boot_sector_test(global_qtest);
4e082566
VK
75 qtest_quit(global_qtest);
76 g_free(args);
77}
78
ab06ec43 79static void test_pxe_ipv4(gconstpointer data)
4e082566 80{
1e88989f 81 const testdef_t *test = data;
4e082566 82
1e88989f
DG
83 test_pxe_one(test, false);
84}
85
d23895d9
DG
86static void test_pxe_ipv6(gconstpointer data)
87{
88 const testdef_t *test = data;
89
90 test_pxe_one(test, true);
91}
92
93static void test_batch(const testdef_t *tests, bool ipv6)
1e88989f
DG
94{
95 int i;
96
97 for (i = 0; tests[i].machine; i++) {
98 const testdef_t *test = &tests[i];
99 char *testname;
100
101 testname = g_strdup_printf("pxe/ipv4/%s/%s",
102 test->machine, test->model);
103 qtest_add_data_func(testname, test, test_pxe_ipv4);
104 g_free(testname);
d23895d9
DG
105
106 if (ipv6) {
107 testname = g_strdup_printf("pxe/ipv6/%s/%s",
108 test->machine, test->model);
109 qtest_add_data_func(testname, test, test_pxe_ipv6);
110 g_free(testname);
111 }
1e88989f 112 }
1485ef1c
TH
113}
114
4e082566
VK
115int main(int argc, char *argv[])
116{
117 int ret;
118 const char *arch = qtest_get_arch();
119
120 ret = boot_sector_init(disk);
121 if(ret)
122 return ret;
123
124 g_test_init(&argc, &argv, NULL);
125
126 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
d23895d9 127 test_batch(x86_tests, false);
ab06ec43 128 if (g_test_slow()) {
d23895d9 129 test_batch(x86_tests_slow, false);
ab06ec43 130 }
1485ef1c 131 } else if (strcmp(arch, "ppc64") == 0) {
d23895d9 132 test_batch(ppc64_tests, g_test_slow());
ab06ec43 133 if (g_test_slow()) {
d23895d9 134 test_batch(ppc64_tests_slow, true);
ab06ec43 135 }
b1b2feac 136 } else if (g_str_equal(arch, "s390x")) {
d23895d9 137 test_batch(s390x_tests, g_test_slow());
4e082566
VK
138 }
139 ret = g_test_run();
140 boot_sector_cleanup(disk);
141 return ret;
142}