xref: /openbmc/qemu/tests/qtest/pxe-test.c (revision 6016b7b4)
1 /*
2  * PXE test cases.
3  *
4  * Copyright (c) 2016, 2017 Red Hat Inc.
5  *
6  * Authors:
7  *  Michael S. Tsirkin <mst@redhat.com>,
8  *  Victor Kaplansky <victork@redhat.com>
9  *  Thomas Huth <thuth@redhat.com>
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 
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"
21 
22 #define NETNAME "net0"
23 
24 static char disk[] = "tests/pxe-test-disk-XXXXXX";
25 
26 typedef struct testdef {
27     const char *machine;    /* Machine type */
28     const char *model;      /* NIC device model */
29     const char *extra;      /* Any additional parameters */
30 } testdef_t;
31 
32 static testdef_t x86_tests[] = {
33     { "pc", "e1000" },
34     { "pc", "virtio-net-pci" },
35     { "q35", "e1000e" },
36     { "q35", "virtio-net-pci", },
37     { NULL },
38 };
39 
40 static testdef_t x86_tests_slow[] = {
41     { "pc", "ne2k_pci", },
42     { "pc", "i82550", },
43     { "pc", "rtl8139" },
44     { "pc", "vmxnet3" },
45     { NULL },
46 };
47 
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 },
53     { NULL },
54 };
55 
56 static testdef_t ppc64_tests_slow[] = {
57     { "pseries", "e1000",
58       "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES },
59     { NULL },
60 };
61 
62 static testdef_t s390x_tests[] = {
63     { "s390-ccw-virtio", "virtio-net-ccw" },
64     { NULL },
65 };
66 
67 static void test_pxe_one(const testdef_t *test, bool ipv6)
68 {
69     QTestState *qts;
70     char *args;
71     const char *extra = test->extra;
72 
73     if (!extra) {
74         extra = "";
75     }
76 
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",
82         test->model, extra);
83 
84     qts = qtest_init(args);
85     boot_sector_test(qts);
86     qtest_quit(qts);
87     g_free(args);
88 }
89 
90 static void test_pxe_ipv4(gconstpointer data)
91 {
92     const testdef_t *test = data;
93 
94     test_pxe_one(test, false);
95 }
96 
97 static void test_pxe_ipv6(gconstpointer data)
98 {
99     const testdef_t *test = data;
100 
101     test_pxe_one(test, true);
102 }
103 
104 static void test_batch(const testdef_t *tests, bool ipv6)
105 {
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);
116 
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         }
123     }
124 }
125 
126 int 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) {
138         test_batch(x86_tests, false);
139         if (g_test_slow()) {
140             test_batch(x86_tests_slow, false);
141         }
142     } else if (strcmp(arch, "ppc64") == 0) {
143         test_batch(ppc64_tests, g_test_slow());
144         if (g_test_slow()) {
145             test_batch(ppc64_tests_slow, true);
146         }
147     } else if (g_str_equal(arch, "s390x")) {
148         test_batch(s390x_tests, g_test_slow());
149     }
150     ret = g_test_run();
151     boot_sector_cleanup(disk);
152     return ret;
153 }
154