test_trace_cmd.py 2.0 KB

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