blob: 1161a773a4a77b429c8887dc913d731e4cf2cda9 [file] [log] [blame]
Victor Kaplansky4e082562016-02-14 18:59:27 +02001/*
2 * PXE test cases.
3 *
Thomas Huthab06ec42017-09-20 11:02:07 +02004 * Copyright (c) 2016, 2017 Red Hat Inc.
Victor Kaplansky4e082562016-02-14 18:59:27 +02005 *
6 * Authors:
7 * Michael S. Tsirkin <mst@redhat.com>,
8 * Victor Kaplansky <victork@redhat.com>
Thomas Huthab06ec42017-09-20 11:02:07 +02009 * Thomas Huth <thuth@redhat.com>
Victor Kaplansky4e082562016-02-14 18:59:27 +020010 *
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
Peter Maydell974dc732016-02-23 12:00:47 +000015#include "qemu/osdep.h"
Victor Kaplansky4e082562016-02-14 18:59:27 +020016#include <glib/gstdio.h>
17#include "qemu-common.h"
18#include "libqtest.h"
19#include "boot-sector.h"
Greg Kurz63d57c82020-02-01 23:46:16 +010020#include "libqos/libqos-spapr.h"
Victor Kaplansky4e082562016-02-14 18:59:27 +020021
22#define NETNAME "net0"
23
Thomas Huth3e353772016-10-11 17:19:36 +020024static char disk[] = "tests/pxe-test-disk-XXXXXX";
Victor Kaplansky4e082562016-02-14 18:59:27 +020025
David Gibson1e889892017-12-19 15:45:20 +110026typedef struct testdef {
27 const char *machine; /* Machine type */
28 const char *model; /* NIC device model */
David Gibsonba3b40d2019-03-12 16:07:14 +110029 const char *extra; /* Any additional parameters */
David Gibson1e889892017-12-19 15:45:20 +110030} testdef_t;
31
32static testdef_t x86_tests[] = {
33 { "pc", "e1000" },
34 { "pc", "virtio-net-pci" },
David Gibson18b20bb2017-12-19 15:45:22 +110035 { "q35", "e1000e" },
36 { "q35", "virtio-net-pci", },
David Gibson1e889892017-12-19 15:45:20 +110037 { NULL },
38};
39
40static testdef_t x86_tests_slow[] = {
41 { "pc", "ne2k_pci", },
42 { "pc", "i82550", },
43 { "pc", "rtl8139" },
44 { "pc", "vmxnet3" },
45 { NULL },
46};
47
48static testdef_t ppc64_tests[] = {
David Gibsonba3b40d2019-03-12 16:07:14 +110049 { "pseries", "spapr-vlan",
Greg Kurz63d57c82020-02-01 23:46:16 +010050 "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
David Gibsonba3b40d2019-03-12 16:07:14 +110051 { "pseries", "virtio-net-pci",
Greg Kurz63d57c82020-02-01 23:46:16 +010052 "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
David Gibson1e889892017-12-19 15:45:20 +110053 { NULL },
54};
55
56static testdef_t ppc64_tests_slow[] = {
David Gibsonba3b40d2019-03-12 16:07:14 +110057 { "pseries", "e1000",
Greg Kurz63d57c82020-02-01 23:46:16 +010058 "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
David Gibson1e889892017-12-19 15:45:20 +110059 { NULL },
60};
61
62static testdef_t s390x_tests[] = {
63 { "s390-ccw-virtio", "virtio-net-ccw" },
64 { NULL },
65};
66
67static void test_pxe_one(const testdef_t *test, bool ipv6)
Victor Kaplansky4e082562016-02-14 18:59:27 +020068{
Thomas Huth43497c42018-11-19 16:40:44 +010069 QTestState *qts;
Victor Kaplansky4e082562016-02-14 18:59:27 +020070 char *args;
David Gibsonba3b40d2019-03-12 16:07:14 +110071 const char *extra = test->extra;
72
73 if (!extra) {
74 extra = "";
75 }
Victor Kaplansky4e082562016-02-14 18:59:27 +020076
David Gibson1e889892017-12-19 15:45:20 +110077 args = g_strdup_printf(
Paolo Bonzini6f6e1692019-11-13 10:10:47 +010078 "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n "
David Gibson1e889892017-12-19 15:45:20 +110079 "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s "
David Gibsonba3b40d2019-03-12 16:07:14 +110080 "-device %s,bootindex=1,netdev=" NETNAME " %s",
David Gibson1e889892017-12-19 15:45:20 +110081 test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off",
David Gibsonba3b40d2019-03-12 16:07:14 +110082 test->model, extra);
Victor Kaplansky4e082562016-02-14 18:59:27 +020083
Thomas Huth43497c42018-11-19 16:40:44 +010084 qts = qtest_init(args);
85 boot_sector_test(qts);
86 qtest_quit(qts);
Victor Kaplansky4e082562016-02-14 18:59:27 +020087 g_free(args);
88}
89
Thomas Huthab06ec42017-09-20 11:02:07 +020090static void test_pxe_ipv4(gconstpointer data)
Victor Kaplansky4e082562016-02-14 18:59:27 +020091{
David Gibson1e889892017-12-19 15:45:20 +110092 const testdef_t *test = data;
Victor Kaplansky4e082562016-02-14 18:59:27 +020093
David Gibson1e889892017-12-19 15:45:20 +110094 test_pxe_one(test, false);
95}
96
David Gibsond23895d2017-12-19 15:45:21 +110097static void test_pxe_ipv6(gconstpointer data)
98{
99 const testdef_t *test = data;
100
101 test_pxe_one(test, true);
102}
103
104static void test_batch(const testdef_t *tests, bool ipv6)
David Gibson1e889892017-12-19 15:45:20 +1100105{
106 int i;
107
108 for (i = 0; tests[i].machine; i++) {
109 const testdef_t *test = &tests[i];
110 char *testname;
111
112 testname = g_strdup_printf("pxe/ipv4/%s/%s",
113 test->machine, test->model);
114 qtest_add_data_func(testname, test, test_pxe_ipv4);
115 g_free(testname);
David Gibsond23895d2017-12-19 15:45:21 +1100116
117 if (ipv6) {
118 testname = g_strdup_printf("pxe/ipv6/%s/%s",
119 test->machine, test->model);
120 qtest_add_data_func(testname, test, test_pxe_ipv6);
121 g_free(testname);
122 }
David Gibson1e889892017-12-19 15:45:20 +1100123 }
Thomas Huth1485ef12016-09-26 22:17:46 +0200124}
125
Victor Kaplansky4e082562016-02-14 18:59:27 +0200126int main(int argc, char *argv[])
127{
128 int ret;
129 const char *arch = qtest_get_arch();
130
131 ret = boot_sector_init(disk);
132 if(ret)
133 return ret;
134
135 g_test_init(&argc, &argv, NULL);
136
137 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
David Gibsond23895d2017-12-19 15:45:21 +1100138 test_batch(x86_tests, false);
Thomas Huthab06ec42017-09-20 11:02:07 +0200139 if (g_test_slow()) {
David Gibsond23895d2017-12-19 15:45:21 +1100140 test_batch(x86_tests_slow, false);
Thomas Huthab06ec42017-09-20 11:02:07 +0200141 }
Thomas Huth1485ef12016-09-26 22:17:46 +0200142 } else if (strcmp(arch, "ppc64") == 0) {
David Gibsond23895d2017-12-19 15:45:21 +1100143 test_batch(ppc64_tests, g_test_slow());
Thomas Huthab06ec42017-09-20 11:02:07 +0200144 if (g_test_slow()) {
David Gibsond23895d2017-12-19 15:45:21 +1100145 test_batch(ppc64_tests_slow, true);
Thomas Huthab06ec42017-09-20 11:02:07 +0200146 }
Thomas Huthb1b2fea2017-08-11 07:57:56 +0200147 } else if (g_str_equal(arch, "s390x")) {
David Gibsond23895d2017-12-19 15:45:21 +1100148 test_batch(s390x_tests, g_test_slow());
Victor Kaplansky4e082562016-02-14 18:59:27 +0200149 }
150 ret = g_test_run();
151 boot_sector_cleanup(disk);
152 return ret;
153}