14c0a2df8SThomas Huth#!/usr/bin/env python3 24c0a2df8SThomas Huth# 34c0a2df8SThomas Huth# ethtool tests for emulated network devices 44c0a2df8SThomas Huth# 54c0a2df8SThomas Huth# This test leverages ethtool's --test sequence to validate network 64c0a2df8SThomas Huth# device behaviour. 74c0a2df8SThomas Huth# 8*0475d4ddSPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later 94c0a2df8SThomas Huth 104c0a2df8SThomas Huthfrom unittest import skip 114c0a2df8SThomas Huthfrom qemu_test import QemuSystemTest, Asset 124c0a2df8SThomas Huthfrom qemu_test import wait_for_console_pattern 134c0a2df8SThomas Huth 144c0a2df8SThomas Huthclass NetDevEthtool(QemuSystemTest): 154c0a2df8SThomas Huth 164c0a2df8SThomas Huth # Runs in about 17s under KVM, 19s under TCG, 25s under GCOV 174c0a2df8SThomas Huth timeout = 45 184c0a2df8SThomas Huth 194c0a2df8SThomas Huth # Fetch assets from the netdev-ethtool subdir of my shared test 204c0a2df8SThomas Huth # images directory on fileserver.linaro.org. 214c0a2df8SThomas Huth ASSET_BASEURL = ('https://fileserver.linaro.org/s/kE4nCFLdQcoBF9t/' 224c0a2df8SThomas Huth 'download?path=%2Fnetdev-ethtool&files=') 234c0a2df8SThomas Huth ASSET_BZIMAGE = Asset( 244c0a2df8SThomas Huth ASSET_BASEURL + "bzImage", 254c0a2df8SThomas Huth "ed62ee06ea620b1035747f3f66a5e9fc5d3096b29f75562ada888b04cd1c4baf") 264c0a2df8SThomas Huth ASSET_ROOTFS = Asset( 274c0a2df8SThomas Huth ASSET_BASEURL + "rootfs.squashfs", 284c0a2df8SThomas Huth "8f0207e3c4d40832ae73c1a927e42ca30ccb1e71f047acb6ddb161ba422934e6") 294c0a2df8SThomas Huth 304c0a2df8SThomas Huth def common_test_code(self, netdev, extra_args=None): 314c0a2df8SThomas Huth self.set_machine('q35') 324c0a2df8SThomas Huth 334c0a2df8SThomas Huth # This custom kernel has drivers for all the supported network 344c0a2df8SThomas Huth # devices we can emulate in QEMU 354c0a2df8SThomas Huth kernel = self.ASSET_BZIMAGE.fetch() 364c0a2df8SThomas Huth rootfs = self.ASSET_ROOTFS.fetch() 374c0a2df8SThomas Huth 384c0a2df8SThomas Huth append = 'printk.time=0 console=ttyS0 ' 394c0a2df8SThomas Huth append += 'root=/dev/sr0 rootfstype=squashfs ' 404c0a2df8SThomas Huth 414c0a2df8SThomas Huth # any additional kernel tweaks for the test 424c0a2df8SThomas Huth if extra_args: 434c0a2df8SThomas Huth append += extra_args 444c0a2df8SThomas Huth 454c0a2df8SThomas Huth # finally invoke ethtool directly 464c0a2df8SThomas Huth append += ' init=/usr/sbin/ethtool -- -t eth1 offline' 474c0a2df8SThomas Huth 484c0a2df8SThomas Huth # add the rootfs via a readonly cdrom image 494c0a2df8SThomas Huth drive = f"file={rootfs},if=ide,index=0,media=cdrom" 504c0a2df8SThomas Huth 514c0a2df8SThomas Huth self.vm.add_args('-kernel', kernel, 524c0a2df8SThomas Huth '-append', append, 534c0a2df8SThomas Huth '-drive', drive, 544c0a2df8SThomas Huth '-device', netdev) 554c0a2df8SThomas Huth 564c0a2df8SThomas Huth self.vm.set_console(console_index=0) 574c0a2df8SThomas Huth self.vm.launch() 584c0a2df8SThomas Huth 594c0a2df8SThomas Huth wait_for_console_pattern(self, 604c0a2df8SThomas Huth "The test result is PASS", 614c0a2df8SThomas Huth "The test result is FAIL", 624c0a2df8SThomas Huth vm=None) 634c0a2df8SThomas Huth # no need to gracefully shutdown, just finish 644c0a2df8SThomas Huth self.vm.kill() 654c0a2df8SThomas Huth 664c0a2df8SThomas Huth def test_igb(self): 674c0a2df8SThomas Huth self.common_test_code("igb") 684c0a2df8SThomas Huth 694c0a2df8SThomas Huth def test_igb_nomsi(self): 704c0a2df8SThomas Huth self.common_test_code("igb", "pci=nomsi") 714c0a2df8SThomas Huth 724c0a2df8SThomas Huth # It seems the other popular cards we model in QEMU currently fail 734c0a2df8SThomas Huth # the pattern test with: 744c0a2df8SThomas Huth # 754c0a2df8SThomas Huth # pattern test failed (reg 0x00178): got 0x00000000 expected 0x00005A5A 764c0a2df8SThomas Huth # 774c0a2df8SThomas Huth # So for now we skip them. 784c0a2df8SThomas Huth 794c0a2df8SThomas Huth @skip("Incomplete reg 0x00178 support") 804c0a2df8SThomas Huth def test_e1000(self): 814c0a2df8SThomas Huth self.common_test_code("e1000") 824c0a2df8SThomas Huth 834c0a2df8SThomas Huth @skip("Incomplete reg 0x00178 support") 844c0a2df8SThomas Huth def test_i82550(self): 854c0a2df8SThomas Huth self.common_test_code("i82550") 864c0a2df8SThomas Huth 874c0a2df8SThomas Huthif __name__ == '__main__': 884c0a2df8SThomas Huth QemuSystemTest.main() 89