]> Git Repo - buildroot-mgba.git/commitdiff
support/testing: add bcc runtime test
authorJulien Olivain <[email protected]>
Sat, 1 Jun 2024 21:01:04 +0000 (23:01 +0200)
committerThomas Petazzoni <[email protected]>
Fri, 12 Jul 2024 14:40:23 +0000 (16:40 +0200)
Signed-off-by: Julien Olivain <[email protected]>
Signed-off-by: Thomas Petazzoni <[email protected]>
DEVELOPERS
support/testing/tests/package/test_bcc.py [new file with mode: 0644]
support/testing/tests/package/test_bcc/linux-bcc.fragment [new file with mode: 0644]

index aeae27eb46ffcb6340880591ff834d7d07a84e93..b0c5cc02d74e6238546f4ad5f9a35b44a485080d 100644 (file)
@@ -1807,6 +1807,8 @@ F:        support/testing/tests/package/test_acpica.py
 F:     support/testing/tests/package/test_acpica/
 F:     support/testing/tests/package/test_apache.py
 F:     support/testing/tests/package/test_bc.py
+F:     support/testing/tests/package/test_bcc.py
+F:     support/testing/tests/package/test_bcc/
 F:     support/testing/tests/package/test_bitcoin.py
 F:     support/testing/tests/package/test_brotli.py
 F:     support/testing/tests/package/test_bzip2.py
diff --git a/support/testing/tests/package/test_bcc.py b/support/testing/tests/package/test_bcc.py
new file mode 100644 (file)
index 0000000..51f175a
--- /dev/null
@@ -0,0 +1,84 @@
+import os
+import time
+
+import infra.basetest
+
+
+class TestBcc(infra.basetest.BRTest):
+    # This test is using a Kernel >= 5.2, so it will use
+    # CONFIG_IKHEADERS. Those Kernel headers are unpacked from
+    # "/sys/kernel/kheaders.tar.xz" with a "tar" invocation. The
+    # Busybox "tar" command invoked by bcc fails to unpack the Kernel
+    # tar archive. We need the GNU Tar package. The Kernel also needs
+    # few extra config options, for running execsnoop.
+    kern_fragment = \
+        infra.filepath("tests/package/test_bcc/linux-bcc.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_BCC=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()
+
+        log = "/root/execsnoop.log"
+        test_cmd = "/bin/sleep 1"
+
+        # bcc needs debugs to be mounted.
+        self.assertRunOk("mount -t debugfs none /sys/kernel/debug/")
+
+        # Generate some exec()s activity in background. We explicitly
+        # call for "/bin/sleep" rather than just "sleep" to avoid
+        # using any shell builtin and make sure we will exec() the
+        # binary.
+        cmd = f"while true ; do {test_cmd} ; done &"
+        self.assertRunOk(cmd)
+
+        # Run execsnoop, also in background...
+        cmd = f"/usr/share/bcc/tools/execsnoop > {log} &"
+        self.assertRunOk(cmd)
+
+        for attempt in range(3):
+            # Wait a bit, to let execsnoop to start and log some data.
+            time.sleep(40 * self.timeout_multiplier)
+
+            # We check that the log file contains some data.
+            cmd = f"test -s {log}"
+            _, ret = self.emulator.run(cmd)
+            if ret == 0:
+                break
+        else:
+            self.fail(f"Timeout while waiting for data in {log}.")
+
+        # Kill our background execsnoop execution.
+        self.assertRunOk("kill $!")
+
+        # Check we have captured execution occurrences of out test
+        # command.
+        cmd = f"grep -Foc '{test_cmd}' {log}"
+        out, ret = self.emulator.run(cmd)
+        self.assertEqual(ret, 0)
+        self.assertGreater(int(out[0]), 0)
diff --git a/support/testing/tests/package/test_bcc/linux-bcc.fragment b/support/testing/tests/package/test_bcc/linux-bcc.fragment
new file mode 100644 (file)
index 0000000..35359b0
--- /dev/null
@@ -0,0 +1,4 @@
+CONFIG_FTRACE=y
+CONFIG_FTRACE_SYSCALLS=y
+CONFIG_FUNCTION_TRACER=y
+CONFIG_KPROBES=y
This page took 0.039917 seconds and 4 git commands to generate.