| 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 "libqtest.h" |
| 18 | #include "boot-sector.h" |
| 19 | #include "ppc-util.h" |
| 20 | |
| 21 | #define NETNAME "net0" |
| 22 | |
| 23 | static char disk[] = "tests/pxe-test-disk-XXXXXX"; |
| 24 | |
| 25 | typedef struct testdef { |
| 26 | const char *machine; /* Machine type */ |
| 27 | const char *model; /* NIC device model */ |
| 28 | const char *extra; /* Any additional parameters */ |
| 29 | } testdef_t; |
| 30 | |
| 31 | static testdef_t x86_tests[] = { |
| 32 | { "pc", "e1000" }, |
| 33 | { "pc", "virtio-net-pci" }, |
| 34 | { "q35", "e1000e" }, |
| 35 | { "q35", "virtio-net-pci", }, |
| 36 | { NULL }, |
| 37 | }; |
| 38 | |
| 39 | static testdef_t x86_tests_slow[] = { |
| 40 | { "pc", "ne2k_pci", }, |
| 41 | { "pc", "i82550", }, |
| 42 | { "pc", "rtl8139" }, |
| 43 | { "pc", "vmxnet3" }, |
| 44 | { NULL }, |
| 45 | }; |
| 46 | |
| 47 | static testdef_t ppc64_tests[] = { |
| 48 | { "pseries", "spapr-vlan", |
| 49 | "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, |
| 50 | { "pseries", "virtio-net-pci", |
| 51 | "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, |
| 52 | { NULL }, |
| 53 | }; |
| 54 | |
| 55 | static testdef_t ppc64_tests_slow[] = { |
| 56 | { "pseries", "e1000", |
| 57 | "-machine vsmt=8," PSERIES_DEFAULT_CAPABILITIES }, |
| 58 | { NULL }, |
| 59 | }; |
| 60 | |
| 61 | static testdef_t s390x_tests[] = { |
| 62 | { "s390-ccw-virtio", "virtio-net-ccw" }, |
| 63 | { NULL }, |
| 64 | }; |
| 65 | |
| 66 | static void test_pxe_one(const testdef_t *test, bool ipv6) |
| 67 | { |
| 68 | QTestState *qts; |
| 69 | char *args; |
| 70 | const char *extra = test->extra; |
| 71 | |
| 72 | if (!extra) { |
| 73 | extra = ""; |
| 74 | } |
| 75 | |
| 76 | args = g_strdup_printf( |
| 77 | "-accel kvm -accel tcg -machine %s -nodefaults -boot order=n " |
| 78 | "-netdev user,id=" NETNAME ",tftp=./,bootfile=%s,ipv4=%s,ipv6=%s " |
| 79 | "-device %s,bootindex=1,netdev=" NETNAME " %s", |
| 80 | test->machine, disk, ipv6 ? "off" : "on", ipv6 ? "on" : "off", |
| 81 | test->model, extra); |
| 82 | |
| 83 | qts = qtest_init(args); |
| 84 | boot_sector_test(qts); |
| 85 | qtest_quit(qts); |
| 86 | g_free(args); |
| 87 | } |
| 88 | |
| 89 | static void test_pxe_ipv4(gconstpointer data) |
| 90 | { |
| 91 | const testdef_t *test = data; |
| 92 | |
| 93 | test_pxe_one(test, false); |
| 94 | } |
| 95 | |
| 96 | static void test_pxe_ipv6(gconstpointer data) |
| 97 | { |
| 98 | const testdef_t *test = data; |
| 99 | |
| 100 | test_pxe_one(test, true); |
| 101 | } |
| 102 | |
| 103 | static void test_batch(const testdef_t *tests, bool ipv6) |
| 104 | { |
| 105 | int i; |
| 106 | |
| 107 | for (i = 0; tests[i].machine; i++) { |
| 108 | const testdef_t *test = &tests[i]; |
| 109 | char *testname; |
| 110 | |
| 111 | if (!qtest_has_machine(test->machine)) { |
| 112 | continue; |
| 113 | } |
| 114 | |
| 115 | if (!qtest_has_device(test->model)) { |
| 116 | continue; |
| 117 | } |
| 118 | |
| 119 | testname = g_strdup_printf("pxe/ipv4/%s/%s", |
| 120 | test->machine, test->model); |
| 121 | qtest_add_data_func(testname, test, test_pxe_ipv4); |
| 122 | g_free(testname); |
| 123 | |
| 124 | if (ipv6) { |
| 125 | testname = g_strdup_printf("pxe/ipv6/%s/%s", |
| 126 | test->machine, test->model); |
| 127 | qtest_add_data_func(testname, test, test_pxe_ipv6); |
| 128 | g_free(testname); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | int main(int argc, char *argv[]) |
| 134 | { |
| 135 | int ret; |
| 136 | const char *arch = qtest_get_arch(); |
| 137 | |
| 138 | g_test_init(&argc, &argv, NULL); |
| 139 | |
| 140 | if (!qtest_has_accel("tcg") && !qtest_has_accel("kvm")) { |
| 141 | g_test_skip("No KVM or TCG accelerator available"); |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | ret = boot_sector_init(disk); |
| 146 | if(ret) |
| 147 | return ret; |
| 148 | |
| 149 | |
| 150 | if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { |
| 151 | test_batch(x86_tests, false); |
| 152 | if (g_test_slow()) { |
| 153 | test_batch(x86_tests_slow, false); |
| 154 | } |
| 155 | } else if (strcmp(arch, "ppc64") == 0) { |
| 156 | test_batch(ppc64_tests, g_test_slow()); |
| 157 | if (g_test_slow()) { |
| 158 | test_batch(ppc64_tests_slow, true); |
| 159 | } |
| 160 | } else if (g_str_equal(arch, "s390x")) { |
| 161 | test_batch(s390x_tests, g_test_slow()); |
| 162 | } |
| 163 | ret = g_test_run(); |
| 164 | boot_sector_cleanup(disk); |
| 165 | return ret; |
| 166 | } |