1import os 2 3import infra.basetest 4 5 6class TestTraceCmd(infra.basetest.BRTest): 7 # A specific configuration is needed for testing trace-cmd. 8 # The function tracer need to be enabled in the Kernel. 9 kern_fragment = \ 10 infra.filepath("tests/package/test_trace_cmd/linux-ftrace.fragment") 11 config = \ 12 f""" 13 BR2_aarch64=y 14 BR2_TOOLCHAIN_EXTERNAL=y 15 BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" 16 BR2_LINUX_KERNEL=y 17 BR2_LINUX_KERNEL_CUSTOM_VERSION=y 18 BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.74" 19 BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y 20 BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config" 21 BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{kern_fragment}" 22 BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y 23 BR2_PACKAGE_TRACE_CMD=y 24 BR2_TARGET_ROOTFS_CPIO=y 25 BR2_TARGET_ROOTFS_CPIO_GZIP=y 26 # BR2_TARGET_ROOTFS_TAR is not set 27 """ 28 29 def test_run(self): 30 img = os.path.join(self.builddir, "images", "rootfs.cpio.gz") 31 kern = os.path.join(self.builddir, "images", "Image") 32 self.emulator.boot(arch="aarch64", 33 kernel=kern, 34 kernel_cmdline=["console=ttyAMA0"], 35 options=["-M", "virt", 36 "-cpu", "cortex-a57", 37 "-m", "256M", 38 "-initrd", img]) 39 self.emulator.login() 40 41 # Record calls to kmalloc() from a simple command. 42 self.assertRunOk("trace-cmd record -e kmalloc ls -l /") 43 44 # Show information about the trace.dat file. 45 self.assertRunOk("trace-cmd dump") 46 47 # Generate a text report of the trace. 48 self.assertRunOk("trace-cmd report > trace.txt") 49 50 # Check we have occurrences of "kmalloc:" in the trace report. 51 cmd = "grep -Fc kmalloc: trace.txt" 52 output, exit_code = self.emulator.run(cmd) 53 self.assertEqual(exit_code, 0) 54 self.assertTrue(int(output[0]) > 0) 55