1#!/usr/bin/env python3 2# 3# ethtool tests for emulated network devices 4# 5# This test leverages ethtool's --test sequence to validate network 6# device behaviour. 7# 8# SPDX-License-Identifier: GPL-2.0-or-later 9 10from unittest import skip 11from qemu_test import QemuSystemTest, Asset 12from qemu_test import wait_for_console_pattern 13 14class NetDevEthtool(QemuSystemTest): 15 16 # Runs in about 17s under KVM, 19s under TCG, 25s under GCOV 17 timeout = 45 18 19 ASSET_BZIMAGE = Asset("https://share.linaro.org/downloadFile?id=QD37GYYAJhGOgVe", 20 "ed62ee06ea620b1035747f3f66a5e9fc5d3096b29f75562ada888b04cd1c4baf") 21 ASSET_ROOTFS = Asset("https://share.linaro.org/downloadFile?id=YAqnr0W8fruDh3f", 22 "8f0207e3c4d40832ae73c1a927e42ca30ccb1e71f047acb6ddb161ba422934e6") 23 24 def common_test_code(self, netdev, extra_args=None): 25 self.set_machine('q35') 26 27 # This custom kernel has drivers for all the supported network 28 # devices we can emulate in QEMU 29 kernel = self.ASSET_BZIMAGE.fetch() 30 rootfs = self.ASSET_ROOTFS.fetch() 31 32 append = 'printk.time=0 console=ttyS0 ' 33 append += 'root=/dev/sr0 rootfstype=squashfs ' 34 35 # any additional kernel tweaks for the test 36 if extra_args: 37 append += extra_args 38 39 # finally invoke ethtool directly 40 append += ' init=/usr/sbin/ethtool -- -t eth1 offline' 41 42 # add the rootfs via a readonly cdrom image 43 drive = f"file={rootfs},if=ide,index=0,media=cdrom" 44 45 self.vm.add_args('-kernel', kernel, 46 '-append', append, 47 '-drive', drive, 48 '-device', netdev) 49 50 self.vm.set_console(console_index=0) 51 self.vm.launch() 52 53 wait_for_console_pattern(self, 54 "The test result is PASS", 55 "The test result is FAIL", 56 vm=None) 57 # no need to gracefully shutdown, just finish 58 self.vm.kill() 59 60 def test_igb(self): 61 self.common_test_code("igb") 62 63 def test_igb_nomsi(self): 64 self.common_test_code("igb", "pci=nomsi") 65 66 # It seems the other popular cards we model in QEMU currently fail 67 # the pattern test with: 68 # 69 # pattern test failed (reg 0x00178): got 0x00000000 expected 0x00005A5A 70 # 71 # So for now we skip them. 72 73 @skip("Incomplete reg 0x00178 support") 74 def test_e1000(self): 75 self.common_test_code("e1000") 76 77 @skip("Incomplete reg 0x00178 support") 78 def test_i82550(self): 79 self.common_test_code("i82550") 80 81if __name__ == '__main__': 82 QemuSystemTest.main() 83