]> code.ossystems Code Review - openembedded-core.git/commitdiff
selftest/package: Add test to ensure ownership is preserved
authorDaisuke Yamane <daisuke.yamane@cybertrust.co.jp>
Sat, 14 Mar 2020 13:09:42 +0000 (13:09 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 26 Apr 2020 12:58:45 +0000 (13:58 +0100)
Yocto Bug: https://bugzilla.yoctoproject.org/show_bug.cgi?id=13806

Add test_preserve_ownership to selftest/package.
This test creates a file, a directory and a symbolic link and changes ownership,
then compares with them installed in rootfs to ensure ownership is preserved.

[Test without a commit 'bitbake: lib/bb/utils.py: Preserve ownership of symlink']
| 2020-03-14 10:01:14,519 - oe-selftest - INFO - test_preserve_ownership (package.PackageTests)
| 2020-03-14 10:56:44,612 - oe-selftest - INFO - Check ownership of /etc/selftest-chown/file
| 2020-03-14 10:56:44,770 - oe-selftest - INFO - Check ownership of /etc/selftest-chown/dir
| 2020-03-14 10:56:44,822 - oe-selftest - INFO - Check ownership of /etc/selftest-chown/symlink
| 2020-03-14 10:56:44,879 - oe-selftest - ERROR - Incrrect ownership /etc/selftest-chown/symlink [root:root]
| 2020-03-14 10:56:45,884 - oe-selftest - INFO -  ... FAIL

[Test with a commit 'bitbake: lib/bb/utils.py: Preserve ownership of symlink']
| 2020-03-14 10:58:49,599 - oe-selftest - INFO - test_preserve_ownership (package.PackageTests)
| 2020-03-14 11:51:39,947 - oe-selftest - INFO - Check ownership of /etc/selftest-chown/file
| 2020-03-14 11:51:40,013 - oe-selftest - INFO - Check ownership of /etc/selftest-chown/dir
| 2020-03-14 11:51:40,063 - oe-selftest - INFO - Check ownership of /etc/selftest-chown/symlink
| 2020-03-14 11:51:41,118 - oe-selftest - INFO -  ... ok

Signed-off-by: Daisuke Yamane <daisuke.yamane@cybertrust.co.jp>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta-selftest/recipes-test/selftest-chown/selftest-chown.bb [new file with mode: 0644]
meta/lib/oeqa/selftest/cases/package.py

diff --git a/meta-selftest/recipes-test/selftest-chown/selftest-chown.bb b/meta-selftest/recipes-test/selftest-chown/selftest-chown.bb
new file mode 100644 (file)
index 0000000..87bf943
--- /dev/null
@@ -0,0 +1,25 @@
+SUMMARY = "selftest chown"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
+
+LICENSE = "MIT"
+
+S = "${WORKDIR}"
+
+inherit useradd allarch
+
+USERADD_PACKAGES = "${PN}"
+USERADD_PARAM_${PN} = "-u 1234 -M test"
+TESTDIR = "${D}${sysconfdir}/selftest-chown"
+
+do_install() {
+       install -d   ${TESTDIR}
+       install -d   ${TESTDIR}/dir
+       touch        ${TESTDIR}/file
+       ln -s ./file ${TESTDIR}/symlink
+
+       chown    test:test ${TESTDIR}/file
+       chown -R test:test ${TESTDIR}/dir
+       chown -h test:test ${TESTDIR}/symlink
+}
+
+FILES_${PN} = "${sysconfdir}/selftest-chown/*"
index b87f8dc3e2cf3a4e92439a3b3cbc2296d11ac019..3010b1af49ae863c60bb3a52601a3f75ebe37126 100644 (file)
@@ -148,3 +148,26 @@ class PackageTests(OESelftestTestCase):
                            '/usr/libexec/hello4']:
                 if not gdbtest(qemu, binary):
                     self.fail('GDB %s failed' % binary)
+
+    def test_preserve_ownership(self):
+        import os, stat, oe.cachedpath
+        features = 'IMAGE_INSTALL_append = " selftest-chown"\n'
+        self.write_config(features)
+        bitbake("core-image-minimal")
+
+        sysconfdir = get_bb_var('sysconfdir', 'selftest-chown')
+        def check_ownership(qemu, gid, uid, path):
+            self.logger.info("Check ownership of %s", path)
+            status, output = qemu.run_serial(r'/bin/stat -c "%U %G" ' + path, timeout=60)
+            output = output.split(" ")
+            if output[0] != uid or output[1] != gid :
+                self.logger.error("Incrrect ownership %s [%s:%s]", path, output[0], output[1])
+                return False
+            return True
+
+        with runqemu('core-image-minimal') as qemu:
+            for path in [ sysconfdir + "/selftest-chown/file",
+                          sysconfdir + "/selftest-chown/dir",
+                          sysconfdir + "/selftest-chown/symlink"]:
+                if not check_ownership(qemu, "test", "test", path):
+                    self.fail('Test ownership %s failed' % path)