Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * PXE test cases. |
| 3 | * |
Thomas Huth | ab06ec4 | 2017-09-20 11:02:07 +0200 | [diff] [blame] | 4 | * Copyright (c) 2016, 2017 Red Hat Inc. |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 5 | * |
| 6 | * Authors: |
| 7 | * Michael S. Tsirkin <mst@redhat.com>, |
| 8 | * Victor Kaplansky <victork@redhat.com> |
Thomas Huth | ab06ec4 | 2017-09-20 11:02:07 +0200 | [diff] [blame] | 9 | * Thomas Huth <thuth@redhat.com> |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 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 | |
Peter Maydell | 974dc73 | 2016-02-23 12:00:47 +0000 | [diff] [blame] | 15 | #include "qemu/osdep.h" |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 16 | #include <glib/gstdio.h> |
| 17 | #include "qemu-common.h" |
| 18 | #include "libqtest.h" |
| 19 | #include "boot-sector.h" |
Greg Kurz | 63d57c8 | 2020-02-01 23:46:16 +0100 | [diff] [blame] | 20 | #include "libqos/libqos-spapr.h" |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 21 | |
| 22 | #define NETNAME "net0" |
| 23 | |
Thomas Huth | 3e35377 | 2016-10-11 17:19:36 +0200 | [diff] [blame] | 24 | static char disk[] = "tests/pxe-test-disk-XXXXXX"; |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 25 | |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 26 | typedef struct testdef { |
| 27 | const char *machine; /* Machine type */ |
| 28 | const char *model; /* NIC device model */ |
David Gibson | ba3b40d | 2019-03-12 16:07:14 +1100 | [diff] [blame] | 29 | const char *extra; /* Any additional parameters */ |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 30 | } testdef_t; |
| 31 | |
| 32 | static testdef_t x86_tests[] = { |
| 33 | { "pc", "e1000" }, |
| 34 | { "pc", "virtio-net-pci" }, |
David Gibson | 18b20bb | 2017-12-19 15:45:22 +1100 | [diff] [blame] | 35 | { "q35", "e1000e" }, |
| 36 | { "q35", "virtio-net-pci", }, |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 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[] = { |
David Gibson | ba3b40d | 2019-03-12 16:07:14 +1100 | [diff] [blame] | 49 | { "pseries", "spapr-vlan", |
Greg Kurz | 63d57c8 | 2020-02-01 23:46:16 +0100 | [diff] [blame] | 50 | "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, |
David Gibson | ba3b40d | 2019-03-12 16:07:14 +1100 | [diff] [blame] | 51 | { "pseries", "virtio-net-pci", |
Greg Kurz | 63d57c8 | 2020-02-01 23:46:16 +0100 | [diff] [blame] | 52 | "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 53 | { NULL }, |
| 54 | }; |
| 55 | |
| 56 | static testdef_t ppc64_tests_slow[] = { |
David Gibson | ba3b40d | 2019-03-12 16:07:14 +1100 | [diff] [blame] | 57 | { "pseries", "e1000", |
Greg Kurz | 63d57c8 | 2020-02-01 23:46:16 +0100 | [diff] [blame] | 58 | "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 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) |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 68 | { |
Thomas Huth | 43497c4 | 2018-11-19 16:40:44 +0100 | [diff] [blame] | 69 | QTestState *qts; |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 70 | char *args; |
David Gibson | ba3b40d | 2019-03-12 16:07:14 +1100 | [diff] [blame] | 71 | const char *extra = test->extra; |
| 72 | |
| 73 | if (!extra) { |
| 74 | extra = ""; |
| 75 | } |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 76 | |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 77 | args = g_strdup_printf( |
Paolo Bonzini | 6f6e169 | 2019-11-13 10:10:47 +0100 | [diff] [blame] | 78 | "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n " |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 79 | "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s " |
David Gibson | ba3b40d | 2019-03-12 16:07:14 +1100 | [diff] [blame] | 80 | "-device %s,bootindex=1,netdev=" NETNAME " %s", |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 81 | test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off", |
David Gibson | ba3b40d | 2019-03-12 16:07:14 +1100 | [diff] [blame] | 82 | test->model, extra); |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 83 | |
Thomas Huth | 43497c4 | 2018-11-19 16:40:44 +0100 | [diff] [blame] | 84 | qts = qtest_init(args); |
| 85 | boot_sector_test(qts); |
| 86 | qtest_quit(qts); |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 87 | g_free(args); |
| 88 | } |
| 89 | |
Thomas Huth | ab06ec4 | 2017-09-20 11:02:07 +0200 | [diff] [blame] | 90 | static void test_pxe_ipv4(gconstpointer data) |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 91 | { |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 92 | const testdef_t *test = data; |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 93 | |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 94 | test_pxe_one(test, false); |
| 95 | } |
| 96 | |
David Gibson | d23895d | 2017-12-19 15:45:21 +1100 | [diff] [blame] | 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) |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 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); |
David Gibson | d23895d | 2017-12-19 15:45:21 +1100 | [diff] [blame] | 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 | } |
David Gibson | 1e88989 | 2017-12-19 15:45:20 +1100 | [diff] [blame] | 123 | } |
Thomas Huth | 1485ef1 | 2016-09-26 22:17:46 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 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) { |
David Gibson | d23895d | 2017-12-19 15:45:21 +1100 | [diff] [blame] | 138 | test_batch(x86_tests, false); |
Thomas Huth | ab06ec4 | 2017-09-20 11:02:07 +0200 | [diff] [blame] | 139 | if (g_test_slow()) { |
David Gibson | d23895d | 2017-12-19 15:45:21 +1100 | [diff] [blame] | 140 | test_batch(x86_tests_slow, false); |
Thomas Huth | ab06ec4 | 2017-09-20 11:02:07 +0200 | [diff] [blame] | 141 | } |
Thomas Huth | 1485ef1 | 2016-09-26 22:17:46 +0200 | [diff] [blame] | 142 | } else if (strcmp(arch, "ppc64") == 0) { |
David Gibson | d23895d | 2017-12-19 15:45:21 +1100 | [diff] [blame] | 143 | test_batch(ppc64_tests, g_test_slow()); |
Thomas Huth | ab06ec4 | 2017-09-20 11:02:07 +0200 | [diff] [blame] | 144 | if (g_test_slow()) { |
David Gibson | d23895d | 2017-12-19 15:45:21 +1100 | [diff] [blame] | 145 | test_batch(ppc64_tests_slow, true); |
Thomas Huth | ab06ec4 | 2017-09-20 11:02:07 +0200 | [diff] [blame] | 146 | } |
Thomas Huth | b1b2fea | 2017-08-11 07:57:56 +0200 | [diff] [blame] | 147 | } else if (g_str_equal(arch, "s390x")) { |
David Gibson | d23895d | 2017-12-19 15:45:21 +1100 | [diff] [blame] | 148 | test_batch(s390x_tests, g_test_slow()); |
Victor Kaplansky | 4e08256 | 2016-02-14 18:59:27 +0200 | [diff] [blame] | 149 | } |
| 150 | ret = g_test_run(); |
| 151 | boot_sector_cleanup(disk); |
| 152 | return ret; |
| 153 | } |