2 * QTest testcase for e1000e NIC
4 * Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
5 * Developed by Daynix Computing LTD (http://www.daynix.com)
8 * Dmitry Fleytman <dmitry@daynix.com>
9 * Leonid Bloch <leonid@daynix.com>
10 * Yan Vugenfirer <yan@daynix.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 #include "qemu/osdep.h"
28 #include "qemu-common.h"
29 #include "libqtest-single.h"
30 #include "qemu-common.h"
31 #include "libqos/pci-pc.h"
32 #include "qemu/sockets.h"
34 #include "qemu/module.h"
35 #include "qemu/bitops.h"
36 #include "libqos/malloc.h"
37 #include "libqos/e1000e.h"
39 static void e1000e_send_verify(QE1000E
*d
, int *test_sockets
, QGuestAllocator
*alloc
)
61 static const uint32_t dtyp_data
= BIT(20);
62 static const uint32_t dtyp_ext
= BIT(29);
63 static const uint32_t dcmd_rs
= BIT(27);
64 static const uint32_t dcmd_eop
= BIT(24);
65 static const uint32_t dsta_dd
= BIT(0);
66 static const int data_len
= 64;
71 /* Prepare test data buffer */
72 uint64_t data
= guest_alloc(alloc
, data_len
);
73 memwrite(data
, "TEST", 5);
75 /* Prepare TX descriptor */
76 memset(&descr
, 0, sizeof(descr
));
77 descr
.buffer_addr
= cpu_to_le64(data
);
78 descr
.lower
.data
= cpu_to_le32(dcmd_rs
|
84 /* Put descriptor to the ring */
85 e1000e_tx_ring_push(d
, &descr
);
87 /* Wait for TX WB interrupt */
88 e1000e_wait_isr(d
, E1000E_TX0_MSG_ID
);
91 g_assert_cmphex(le32_to_cpu(descr
.upper
.data
) & dsta_dd
, ==, dsta_dd
);
93 /* Check data sent to the backend */
94 ret
= qemu_recv(test_sockets
[0], &recv_len
, sizeof(recv_len
), 0);
95 g_assert_cmpint(ret
, == , sizeof(recv_len
));
96 qemu_recv(test_sockets
[0], buffer
, 64, 0);
97 g_assert_cmpstr(buffer
, == , "TEST");
99 /* Free test data buffer */
100 guest_free(alloc
, data
);
103 static void e1000e_receive_verify(QE1000E
*d
, int *test_sockets
, QGuestAllocator
*alloc
)
107 uint64_t buffer_addr
;
122 uint32_t status_error
;
129 static const uint32_t esta_dd
= BIT(0);
131 char test
[] = "TEST";
132 int len
= htonl(sizeof(test
));
133 struct iovec iov
[] = {
136 .iov_len
= sizeof(len
),
139 .iov_len
= sizeof(test
),
143 static const int data_len
= 64;
147 /* Send a dummy packet to device's socket*/
148 ret
= iov_send(test_sockets
[0], iov
, 2, 0, sizeof(len
) + sizeof(test
));
149 g_assert_cmpint(ret
, == , sizeof(test
) + sizeof(len
));
151 /* Prepare test data buffer */
152 uint64_t data
= guest_alloc(alloc
, data_len
);
154 /* Prepare RX descriptor */
155 memset(&descr
, 0, sizeof(descr
));
156 descr
.read
.buffer_addr
= cpu_to_le64(data
);
158 /* Put descriptor to the ring */
159 e1000e_rx_ring_push(d
, &descr
);
161 /* Wait for TX WB interrupt */
162 e1000e_wait_isr(d
, E1000E_RX0_MSG_ID
);
165 g_assert_cmphex(le32_to_cpu(descr
.wb
.upper
.status_error
) &
166 esta_dd
, ==, esta_dd
);
168 /* Check data sent to the backend */
169 memread(data
, buffer
, sizeof(buffer
));
170 g_assert_cmpstr(buffer
, == , "TEST");
172 /* Free test data buffer */
173 guest_free(alloc
, data
);
176 static void test_e1000e_init(void *obj
, void *data
, QGuestAllocator
* alloc
)
178 /* init does nothing */
181 static void test_e1000e_tx(void *obj
, void *data
, QGuestAllocator
* alloc
)
183 QE1000E_PCI
*e1000e
= obj
;
184 QE1000E
*d
= &e1000e
->e1000e
;
185 QOSGraphObject
*e_object
= obj
;
186 QPCIDevice
*dev
= e_object
->get_driver(e_object
, "pci-device");
188 /* FIXME: add spapr support */
189 if (qpci_check_buggy_msi(dev
)) {
193 e1000e_send_verify(d
, data
, alloc
);
196 static void test_e1000e_rx(void *obj
, void *data
, QGuestAllocator
* alloc
)
198 QE1000E_PCI
*e1000e
= obj
;
199 QE1000E
*d
= &e1000e
->e1000e
;
200 QOSGraphObject
*e_object
= obj
;
201 QPCIDevice
*dev
= e_object
->get_driver(e_object
, "pci-device");
203 /* FIXME: add spapr support */
204 if (qpci_check_buggy_msi(dev
)) {
208 e1000e_receive_verify(d
, data
, alloc
);
211 static void test_e1000e_multiple_transfers(void *obj
, void *data
,
212 QGuestAllocator
*alloc
)
214 static const long iterations
= 4 * 1024;
217 QE1000E_PCI
*e1000e
= obj
;
218 QE1000E
*d
= &e1000e
->e1000e
;
219 QOSGraphObject
*e_object
= obj
;
220 QPCIDevice
*dev
= e_object
->get_driver(e_object
, "pci-device");
222 /* FIXME: add spapr support */
223 if (qpci_check_buggy_msi(dev
)) {
227 for (i
= 0; i
< iterations
; i
++) {
228 e1000e_send_verify(d
, data
, alloc
);
229 e1000e_receive_verify(d
, data
, alloc
);
234 static void test_e1000e_hotplug(void *obj
, void *data
, QGuestAllocator
* alloc
)
236 QTestState
*qts
= global_qtest
; /* TODO: get rid of global_qtest here */
238 qtest_qmp_device_add(qts
, "e1000e", "e1000e_net", "{'addr': '0x06'}");
239 qpci_unplug_acpi_device_test(qts
, "e1000e_net", 0x06);
242 static void data_test_clear(void *sockets
)
244 int *test_sockets
= sockets
;
246 close(test_sockets
[0]);
247 qos_invalidate_command_line();
248 close(test_sockets
[1]);
249 g_free(test_sockets
);
252 static void *data_test_init(GString
*cmd_line
, void *arg
)
254 int *test_sockets
= g_new(int, 2);
255 int ret
= socketpair(PF_UNIX
, SOCK_STREAM
, 0, test_sockets
);
256 g_assert_cmpint(ret
, != , -1);
258 g_string_append_printf(cmd_line
, " -netdev socket,fd=%d,id=hs0 ",
261 g_test_queue_destroy(data_test_clear
, test_sockets
);
265 static void register_e1000e_test(void)
267 QOSGraphTestOptions opts
= {
268 .before
= data_test_init
,
271 qos_add_test("init", "e1000e", test_e1000e_init
, &opts
);
272 qos_add_test("tx", "e1000e", test_e1000e_tx
, &opts
);
273 qos_add_test("rx", "e1000e", test_e1000e_rx
, &opts
);
274 qos_add_test("multiple_transfers", "e1000e",
275 test_e1000e_multiple_transfers
, &opts
);
276 qos_add_test("hotplug", "e1000e", test_e1000e_hotplug
, &opts
);
279 libqos_init(register_e1000e_test
);