1import os
2
3import infra.basetest
4
5
6class TestStrace(infra.basetest.BRTest):
7    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
8        """
9        BR2_PACKAGE_STRACE=y
10        BR2_TARGET_ROOTFS_CPIO=y
11        # BR2_TARGET_ROOTFS_TAR is not set
12        """
13
14    def test_run(self):
15        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
16        self.emulator.boot(arch="armv5",
17                           kernel="builtin",
18                           options=["-initrd", cpio_file])
19        self.emulator.login()
20
21        # Check the program can execute.
22        self.assertRunOk("strace --version")
23
24        test_file = "buildroot-strace-test.txt"
25        test_file_mode = "0600"
26        strace_log = "strace.log"
27
28        # Create a test file.
29        self.assertRunOk(f"touch {test_file}")
30
31        # Run strace on a chmod
32        cmd = f"strace -o {strace_log} chmod {test_file_mode} {test_file}"
33        self.assertRunOk(cmd)
34
35        # Check the strace log contain a call to chmod()
36        expected_str = f"chmod(\"{test_file}\", {test_file_mode}) = 0"
37        self.assertRunOk(f"grep -F '{expected_str}' {strace_log}")
38