blob: ee1a397bd240b000e901b004e38fe3f054ff57bd [file] [log] [blame]
Thomas Huth4c0a2df2024-08-30 15:38:11 +02001#!/usr/bin/env python3
2#
Alex Bennée9f951112023-03-21 18:05:30 +00003# ethtool tests for emulated network devices
4#
5# This test leverages ethtool's --test sequence to validate network
6# device behaviour.
7#
Philippe Mathieu-Daudé0475d4d2024-09-11 17:12:02 +02008# SPDX-License-Identifier: GPL-2.0-or-later
Alex Bennée9f951112023-03-21 18:05:30 +00009
Thomas Huth4c0a2df2024-08-30 15:38:11 +020010from unittest import skip
11from qemu_test import QemuSystemTest, Asset
12from qemu_test import wait_for_console_pattern
Alex Bennée9f951112023-03-21 18:05:30 +000013
14class NetDevEthtool(QemuSystemTest):
Alex Bennée9f951112023-03-21 18:05:30 +000015
16 # Runs in about 17s under KVM, 19s under TCG, 25s under GCOV
17 timeout = 45
18
19 # Fetch assets from the netdev-ethtool subdir of my shared test
20 # images directory on fileserver.linaro.org.
Thomas Huth4c0a2df2024-08-30 15:38:11 +020021 ASSET_BASEURL = ('https://fileserver.linaro.org/s/kE4nCFLdQcoBF9t/'
22 'download?path=%2Fnetdev-ethtool&files=')
23 ASSET_BZIMAGE = Asset(
24 ASSET_BASEURL + "bzImage",
25 "ed62ee06ea620b1035747f3f66a5e9fc5d3096b29f75562ada888b04cd1c4baf")
26 ASSET_ROOTFS = Asset(
27 ASSET_BASEURL + "rootfs.squashfs",
28 "8f0207e3c4d40832ae73c1a927e42ca30ccb1e71f047acb6ddb161ba422934e6")
Alex Bennée9f951112023-03-21 18:05:30 +000029
Akihiko Odaki1531fb42023-05-23 11:43:03 +090030 def common_test_code(self, netdev, extra_args=None):
Thomas Huth4c0a2df2024-08-30 15:38:11 +020031 self.set_machine('q35')
Alex Bennée9f951112023-03-21 18:05:30 +000032
33 # This custom kernel has drivers for all the supported network
34 # devices we can emulate in QEMU
Thomas Huth4c0a2df2024-08-30 15:38:11 +020035 kernel = self.ASSET_BZIMAGE.fetch()
36 rootfs = self.ASSET_ROOTFS.fetch()
Alex Bennée9f951112023-03-21 18:05:30 +000037
38 append = 'printk.time=0 console=ttyS0 '
39 append += 'root=/dev/sr0 rootfstype=squashfs '
40
41 # any additional kernel tweaks for the test
42 if extra_args:
43 append += extra_args
44
45 # finally invoke ethtool directly
46 append += ' init=/usr/sbin/ethtool -- -t eth1 offline'
47
48 # add the rootfs via a readonly cdrom image
49 drive = f"file={rootfs},if=ide,index=0,media=cdrom"
50
51 self.vm.add_args('-kernel', kernel,
52 '-append', append,
53 '-drive', drive,
54 '-device', netdev)
55
Alex Bennée9f951112023-03-21 18:05:30 +000056 self.vm.set_console(console_index=0)
57 self.vm.launch()
58
59 wait_for_console_pattern(self,
60 "The test result is PASS",
61 "The test result is FAIL",
62 vm=None)
63 # no need to gracefully shutdown, just finish
64 self.vm.kill()
65
Alex Bennée9f951112023-03-21 18:05:30 +000066 def test_igb(self):
Alex Bennée9f951112023-03-21 18:05:30 +000067 self.common_test_code("igb")
68
69 def test_igb_nomsi(self):
Alex Bennée9f951112023-03-21 18:05:30 +000070 self.common_test_code("igb", "pci=nomsi")
71
Alex Bennée9f951112023-03-21 18:05:30 +000072 # It seems the other popular cards we model in QEMU currently fail
73 # the pattern test with:
74 #
75 # pattern test failed (reg 0x00178): got 0x00000000 expected 0x00005A5A
76 #
77 # So for now we skip them.
78
79 @skip("Incomplete reg 0x00178 support")
80 def test_e1000(self):
Alex Bennée9f951112023-03-21 18:05:30 +000081 self.common_test_code("e1000")
82
83 @skip("Incomplete reg 0x00178 support")
84 def test_i82550(self):
Alex Bennée9f951112023-03-21 18:05:30 +000085 self.common_test_code("i82550")
Thomas Huth4c0a2df2024-08-30 15:38:11 +020086
87if __name__ == '__main__':
88 QemuSystemTest.main()