1import os 2 3import infra.basetest 4 5 6class TestEthtool(infra.basetest.BRTest): 7 # This ethtool test uses an emulated Intel e1000e adapted (which 8 # is well supported by Qemu, the Kernel and ethtool). We are not 9 # using the usual virtio_net because it's not supporting some 10 # ethtool features like adapter testing. For that reason, we need 11 # to compile a Kernel. 12 kernel_fragment = \ 13 infra.filepath("tests/package/test_ethtool/linux-e1000e.fragment") 14 config = \ 15 f""" 16 BR2_aarch64=y 17 BR2_TOOLCHAIN_EXTERNAL=y 18 BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" 19 BR2_LINUX_KERNEL=y 20 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 21 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.6.27" 22 BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y 23 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config" 24 BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{kernel_fragment}" 25 BR2_PACKAGE_ETHTOOL=y 26 BR2_TARGET_ROOTFS_EXT2=y 27 BR2_TARGET_ROOTFS_EXT2_4=y 28 # BR2_TARGET_ROOTFS_TAR is not set 29 """ 30 31 def test_run(self): 32 drive = os.path.join(self.builddir, "images", "rootfs.ext4") 33 kern = os.path.join(self.builddir, "images", "Image") 34 self.emulator.boot(arch="aarch64", 35 kernel=kern, 36 kernel_cmdline=["root=/dev/vda console=ttyAMA0"], 37 options=["-M", "virt", 38 "-cpu", "cortex-a57", 39 "-m", "256M", 40 "-netdev", "user,id=test_net", 41 "-net", "nic,model=e1000e,netdev=test_net", 42 "-drive", f"file={drive},if=virtio,format=raw"]) 43 self.emulator.login() 44 45 # We check the program can run. 46 self.assertRunOk("ethtool --version") 47 48 # We check a simple query runs correctly. 49 self.assertRunOk("ethtool eth0") 50 51 # We query the driver name and check it's the expected e1000e. 52 out, ret = self.emulator.run("ethtool -i eth0") 53 self.assertEqual(ret, 0) 54 self.assertEqual(out[0], "driver: e1000e") 55 56 # We request an adapter online self test. 57 self.assertRunOk("ethtool -t eth0 online", timeout=30) 58 59 # We query offload parameters and check TSO are enabled (this 60 # is the driver default). 61 out, ret = self.emulator.run("ethtool -k eth0") 62 self.assertEqual(ret, 0) 63 self.assertIn("tcp-segmentation-offload: on", out) 64 65 # We request to disable TSO. 66 self.assertRunOk("ethtool -K eth0 tcp-segmentation-offload off") 67 68 # We check again. TSO should now be disabled. 69 out, ret = self.emulator.run("ethtool -k eth0") 70 self.assertEqual(ret, 0) 71 self.assertIn("tcp-segmentation-offload: off", out) 72