From e06cfae9cb61e049076fa47585f44a9b569a1949 Mon Sep 17 00:00:00 2001 From: Thomas Petazzoni Date: Thu, 27 Aug 2026 11:55:18 +0200 Subject: [PATCH] support/testing: add bpftrace test This commit adds a simple bpftrace test that ensures that not only it builds fine, but it also runs properly on a minimal test scenario. Assisted-by: GPT-5.6 Signed-off-by: Thomas Petazzoni [Julien: - reindent emulator.boot() options - add a call to "bpftrace --version" ] Signed-off-by: Julien Olivain --- DEVELOPERS | 2 + .../testing/tests/package/test_bpftrace.py | 65 +++++++++++++++++++ .../test_bpftrace/linux-bpftrace.fragment | 4 ++ 3 files changed, 71 insertions(+) create mode 100644 support/testing/tests/package/test_bpftrace.py create mode 100644 support/testing/tests/package/test_bpftrace/linux-bpftrace.fragment diff --git a/DEVELOPERS b/DEVELOPERS index 49a72bb69a..53104cc60b 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -3304,6 +3304,8 @@ F: support/testing/tests/package/sample_python_flask_expects_json.py F: support/testing/tests/package/sample_python_git.py F: support/testing/tests/package/sample_python_pyudev.py F: support/testing/tests/package/sample_python_unittest_xml_reporting.py +F: support/testing/tests/package/test_bpftrace.py +F: support/testing/tests/package/test_bpftrace/linux-bpftrace.fragment F: support/testing/tests/package/test_nodejs.py F: support/testing/tests/package/test_python_augeas.py F: support/testing/tests/package/test_python_crccheck.py diff --git a/support/testing/tests/package/test_bpftrace.py b/support/testing/tests/package/test_bpftrace.py new file mode 100644 index 0000000000..83410eea60 --- /dev/null +++ b/support/testing/tests/package/test_bpftrace.py @@ -0,0 +1,65 @@ +import os + +import infra.basetest + + +# gitlab-runner: 2xlarge +class TestBpftrace(infra.basetest.BRTest): + kern_fragment = infra.filepath( + "tests/package/test_bpftrace/linux-bpftrace.fragment" + ) + config = f""" + BR2_aarch64=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" + BR2_LINUX_KERNEL=y + BR2_LINUX_KERNEL_CUSTOM_VERSION=y + BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.6.32" + BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y + BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config" + BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{kern_fragment}" + BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y + BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y + BR2_PACKAGE_BPFTRACE=y + BR2_PACKAGE_TAR=y + BR2_TARGET_ROOTFS_EXT2=y + BR2_TARGET_ROOTFS_EXT2_4=y + BR2_TARGET_ROOTFS_EXT2_SIZE="256M" + # BR2_TARGET_ROOTFS_TAR is not set + """ + + def test_run(self): + drive = os.path.join(self.builddir, "images", "rootfs.ext4") + kern = os.path.join(self.builddir, "images", "Image") + self.emulator.boot( + arch="aarch64", + kernel=kern, + kernel_cmdline=["root=/dev/vda console=ttyAMA0"], + options=[ + "-M", "virt", + "-cpu", "cortex-a57", + "-m", "256M", + "-drive", f"file={drive},if=virtio,format=raw" + ] + ) + self.emulator.login() + + self.assertRunOk("mount -t debugfs none /sys/kernel/debug/") + + # Check the program can run. + self.assertRunOk("bpftrace --version") + + # Check that bpftrace can find a syscall tracepoint. + self.assertRunOk("bpftrace -l 'tracepoint:syscalls:sys_enter_execve'") + + # Compile and attach a tracepoint program, then trigger it with the + # command executed by bpftrace. The marker avoids matching volatile + # fields such as PIDs or command names. + cmd = ( + "bpftrace -e 'tracepoint:syscalls:sys_enter_execve " + '{ printf("buildroot-bpftrace-test\\n"); exit(); }\' ' + "-c /bin/true" + ) + output, ret = self.emulator.run(cmd) + self.assertEqual(ret, 0) + self.assertIn("buildroot-bpftrace-test", "\n".join(output)) diff --git a/support/testing/tests/package/test_bpftrace/linux-bpftrace.fragment b/support/testing/tests/package/test_bpftrace/linux-bpftrace.fragment new file mode 100644 index 0000000000..35359b08f6 --- /dev/null +++ b/support/testing/tests/package/test_bpftrace/linux-bpftrace.fragment @@ -0,0 +1,4 @@ +CONFIG_FTRACE=y +CONFIG_FTRACE_SYSCALLS=y +CONFIG_FUNCTION_TRACER=y +CONFIG_KPROBES=y