14c0a2df8SThomas Huth#!/usr/bin/env python3 24c0a2df8SThomas Huth# 39f951114SAlex Bennée# ethtool tests for emulated network devices 49f951114SAlex Bennée# 59f951114SAlex Bennée# This test leverages ethtool's --test sequence to validate network 69f951114SAlex Bennée# device behaviour. 79f951114SAlex Bennée# 8*0475d4ddSPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later 99f951114SAlex Bennée 104c0a2df8SThomas Huthfrom unittest import skip 114c0a2df8SThomas Huthfrom qemu_test import QemuSystemTest, Asset 124c0a2df8SThomas Huthfrom qemu_test import wait_for_console_pattern 139f951114SAlex Bennée 149f951114SAlex Bennéeclass NetDevEthtool(QemuSystemTest): 159f951114SAlex Bennée 169f951114SAlex Bennée # Runs in about 17s under KVM, 19s under TCG, 25s under GCOV 179f951114SAlex Bennée timeout = 45 189f951114SAlex Bennée 199f951114SAlex Bennée # Fetch assets from the netdev-ethtool subdir of my shared test 209f951114SAlex Bennée # 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") 299f951114SAlex Bennée 301531fb4dSAkihiko Odaki def common_test_code(self, netdev, extra_args=None): 314c0a2df8SThomas Huth self.set_machine('q35') 329f951114SAlex Bennée 339f951114SAlex Bennée # This custom kernel has drivers for all the supported network 349f951114SAlex Bennée # devices we can emulate in QEMU 354c0a2df8SThomas Huth kernel = self.ASSET_BZIMAGE.fetch() 364c0a2df8SThomas Huth rootfs = self.ASSET_ROOTFS.fetch() 379f951114SAlex Bennée 389f951114SAlex Bennée append = 'printk.time=0 console=ttyS0 ' 399f951114SAlex Bennée append += 'root=/dev/sr0 rootfstype=squashfs ' 409f951114SAlex Bennée 419f951114SAlex Bennée # any additional kernel tweaks for the test 429f951114SAlex Bennée if extra_args: 439f951114SAlex Bennée append += extra_args 449f951114SAlex Bennée 459f951114SAlex Bennée # finally invoke ethtool directly 469f951114SAlex Bennée append += ' init=/usr/sbin/ethtool -- -t eth1 offline' 479f951114SAlex Bennée 489f951114SAlex Bennée # add the rootfs via a readonly cdrom image 499f951114SAlex Bennée drive = f"file={rootfs},if=ide,index=0,media=cdrom" 509f951114SAlex Bennée 519f951114SAlex Bennée self.vm.add_args('-kernel', kernel, 529f951114SAlex Bennée '-append', append, 539f951114SAlex Bennée '-drive', drive, 549f951114SAlex Bennée '-device', netdev) 559f951114SAlex Bennée 569f951114SAlex Bennée self.vm.set_console(console_index=0) 579f951114SAlex Bennée self.vm.launch() 589f951114SAlex Bennée 599f951114SAlex Bennée wait_for_console_pattern(self, 609f951114SAlex Bennée "The test result is PASS", 619f951114SAlex Bennée "The test result is FAIL", 629f951114SAlex Bennée vm=None) 639f951114SAlex Bennée # no need to gracefully shutdown, just finish 649f951114SAlex Bennée self.vm.kill() 659f951114SAlex Bennée 669f951114SAlex Bennée def test_igb(self): 679f951114SAlex Bennée self.common_test_code("igb") 689f951114SAlex Bennée 699f951114SAlex Bennée def test_igb_nomsi(self): 709f951114SAlex Bennée self.common_test_code("igb", "pci=nomsi") 719f951114SAlex Bennée 729f951114SAlex Bennée # It seems the other popular cards we model in QEMU currently fail 739f951114SAlex Bennée # the pattern test with: 749f951114SAlex Bennée # 759f951114SAlex Bennée # pattern test failed (reg 0x00178): got 0x00000000 expected 0x00005A5A 769f951114SAlex Bennée # 779f951114SAlex Bennée # So for now we skip them. 789f951114SAlex Bennée 799f951114SAlex Bennée @skip("Incomplete reg 0x00178 support") 809f951114SAlex Bennée def test_e1000(self): 819f951114SAlex Bennée self.common_test_code("e1000") 829f951114SAlex Bennée 839f951114SAlex Bennée @skip("Incomplete reg 0x00178 support") 849f951114SAlex Bennée def test_i82550(self): 859f951114SAlex Bennée self.common_test_code("i82550") 864c0a2df8SThomas Huth 874c0a2df8SThomas Huthif __name__ == '__main__': 884c0a2df8SThomas Huth QemuSystemTest.main() 89