[Buildroot] [PATCH 1/1] support/testing: new acl runtime test
Peter Korsgaard
peter at korsgaard.com
Tue Feb 6 21:48:51 UTC 2024
>>>>> "Julien" == Julien Olivain <ju.o at free.fr> writes:
> Signed-off-by: Julien Olivain <ju.o at free.fr>
> ---
> DEVELOPERS | 1 +
> support/testing/tests/package/test_acl.py | 87 +++++++++++++++++++++++
> 2 files changed, 88 insertions(+)
> create mode 100644 support/testing/tests/package/test_acl.py
> diff --git a/DEVELOPERS b/DEVELOPERS
> index 4b8d195f9f..ce248e8706 100644
> --- a/DEVELOPERS
> +++ b/DEVELOPERS
> @@ -1762,6 +1762,7 @@ F: support/testing/tests/package/sample_python_midiutil.py
> F: support/testing/tests/package/sample_python_ml_dtypes.py
> F: support/testing/tests/package/sample_python_pyalsa.py
> F: support/testing/tests/package/sample_python_spake2.py
> +F: support/testing/tests/package/test_acl.py
> F: support/testing/tests/package/test_acpica.py
> F: support/testing/tests/package/test_acpica/
> F: support/testing/tests/package/test_apache.py
> diff --git a/support/testing/tests/package/test_acl.py b/support/testing/tests/package/test_acl.py
> new file mode 100644
> index 0000000000..e4827c7bec
> --- /dev/null
> +++ b/support/testing/tests/package/test_acl.py
> @@ -0,0 +1,87 @@
> +import os
> +
> +import infra.basetest
> +
> +
> +class TestAcl(infra.basetest.BRTest):
> + # Note: this test requires a Kernel with a filesystem on /tmp
> + # supporting ACLs. This is the case for the basetest reference
> + # config. Kernel has CONFIG_TMPFS_POSIX_ACL=y, and /tmp is tmpfs
> + # in the default Buildroot config.
> + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
> + """
> + BR2_PACKAGE_ACL=y
> + BR2_TARGET_ROOTFS_CPIO=y
> + # BR2_TARGET_ROOTFS_TAR is not set
> + """
> +
> + def test_run(self):
> + cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
> + self.emulator.boot(arch="armv5",
> + kernel="builtin",
> + options=["-initrd", cpio_file])
> + self.emulator.login()
> +
> + # Check the programs can execute.
> + self.assertRunOk("getfacl --version")
> + self.assertRunOk("setfacl --version")
> +
> + # Constants used in this test.
> + test_user = "acltest"
> + test_data = "Hello Buildroot!"
> + test_file = "/tmp/file.txt"
> +
> + # Create a test user:
> + # -D don't set a password
> + # -h set home directory
> + # -H don't create home directory
> + # -s set shell to /bin/sh
> + self.assertRunOk(f"adduser -D -h /tmp -H -s /bin/sh {test_user}")
> +
> + # Create a test file, and make sure the owner is "root" with
> + # standard Unix permissions to read/write only for the owner.
> + self.assertRunOk(f"echo '{test_data}' > {test_file}")
> + self.assertRunOk(f"chown root:root {test_file}")
> + self.assertRunOk(f"chmod 0600 {test_file}")
> +
> + # Check we have no ACL for the test user.
> + getacl_cmd = f"getfacl -c -p {test_file}"
> + out, ret = self.emulator.run(getacl_cmd)
> + self.assertEqual(ret, 0)
NIT: Maybe we should consider making assertRunOk() return the stdout
output so we don't need to open code the exit code check every time that
we also need stdout?
Committed, thanks.
--
Bye, Peter Korsgaard
More information about the buildroot
mailing list