1# ethtool tests for emulated network devices 2# 3# This test leverages ethtool's --test sequence to validate network 4# device behaviour. 5# 6# SPDX-License-Identifier: GPL-2.0-or-late 7 8from avocado import skip 9from avocado_qemu import QemuSystemTest 10from avocado_qemu import exec_command, exec_command_and_wait_for_pattern 11from avocado_qemu import wait_for_console_pattern 12 13class NetDevEthtool(QemuSystemTest): 14 """ 15 :avocado: tags=arch:x86_64 16 :avocado: tags=machine:q35 17 """ 18 19 # Runs in about 17s under KVM, 19s under TCG, 25s under GCOV 20 timeout = 45 21 22 # Fetch assets from the netdev-ethtool subdir of my shared test 23 # images directory on fileserver.linaro.org. 24 def get_asset(self, name, sha1): 25 base_url = ('https://fileserver.linaro.org/s/' 26 'kE4nCFLdQcoBF9t/download?' 27 'path=%2Fnetdev-ethtool&files=' ) 28 url = base_url + name 29 # use explicit name rather than failing to neatly parse the 30 # URL into a unique one 31 return self.fetch_asset(name=name, locations=(url), asset_hash=sha1) 32 33 def common_test_code(self, netdev, extra_args=None, kvm=False): 34 35 # This custom kernel has drivers for all the supported network 36 # devices we can emulate in QEMU 37 kernel = self.get_asset("bzImage", 38 "33469d7802732d5815226166581442395cb289e2") 39 40 rootfs = self.get_asset("rootfs.squashfs", 41 "9793cea7021414ae844bda51f558bd6565b50cdc") 42 43 append = 'printk.time=0 console=ttyS0 ' 44 append += 'root=/dev/sr0 rootfstype=squashfs ' 45 46 # any additional kernel tweaks for the test 47 if extra_args: 48 append += extra_args 49 50 # finally invoke ethtool directly 51 append += ' init=/usr/sbin/ethtool -- -t eth1 offline' 52 53 # add the rootfs via a readonly cdrom image 54 drive = f"file={rootfs},if=ide,index=0,media=cdrom" 55 56 self.vm.add_args('-kernel', kernel, 57 '-append', append, 58 '-drive', drive, 59 '-device', netdev) 60 61 if kvm: 62 self.vm.add_args('-accel', 'kvm') 63 64 self.vm.set_console(console_index=0) 65 self.vm.launch() 66 67 wait_for_console_pattern(self, 68 "The test result is PASS", 69 "The test result is FAIL", 70 vm=None) 71 # no need to gracefully shutdown, just finish 72 self.vm.kill() 73 74 # Skip testing for MSI for now. Allegedly it was fixed by: 75 # 28e96556ba (igb: Allocate MSI-X vector when testing) 76 # but I'm seeing oops in the kernel 77 @skip("Kernel bug with MSI enabled") 78 def test_igb(self): 79 """ 80 :avocado: tags=device:igb 81 """ 82 self.common_test_code("igb") 83 84 def test_igb_nomsi(self): 85 """ 86 :avocado: tags=device:igb 87 """ 88 self.common_test_code("igb", "pci=nomsi") 89 90 def test_igb_nomsi_kvm(self): 91 """ 92 :avocado: tags=device:igb 93 """ 94 self.require_accelerator('kvm') 95 self.common_test_code("igb", "pci=nomsi", True) 96 97 # It seems the other popular cards we model in QEMU currently fail 98 # the pattern test with: 99 # 100 # pattern test failed (reg 0x00178): got 0x00000000 expected 0x00005A5A 101 # 102 # So for now we skip them. 103 104 @skip("Incomplete reg 0x00178 support") 105 def test_e1000(self): 106 """ 107 :avocado: tags=device:e1000 108 """ 109 self.common_test_code("e1000") 110 111 @skip("Incomplete reg 0x00178 support") 112 def test_i82550(self): 113 """ 114 :avocado: tags=device:i82550 115 """ 116 self.common_test_code("i82550") 117