Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | from oeqa.selftest.case import OESelftestTestCase |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 8 | from oeqa.utils.commands import bitbake, get_bb_vars, get_bb_var, runqemu |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9 | import subprocess, os |
| 10 | import oe.path |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 11 | import re |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
| 13 | class VersionOrdering(OESelftestTestCase): |
| 14 | # version1, version2, sort order |
| 15 | tests = ( |
| 16 | ("1.0", "1.0", 0), |
| 17 | ("1.0", "2.0", -1), |
| 18 | ("2.0", "1.0", 1), |
| 19 | ("2.0-rc", "2.0", 1), |
| 20 | ("2.0~rc", "2.0", -1), |
| 21 | ("1.2rc2", "1.2.0", -1) |
| 22 | ) |
| 23 | |
| 24 | @classmethod |
| 25 | def setUpClass(cls): |
| 26 | super().setUpClass() |
| 27 | |
| 28 | # Build the tools we need and populate a sysroot |
| 29 | bitbake("dpkg-native opkg-native rpm-native python3-native") |
| 30 | bitbake("build-sysroots -c build_native_sysroot") |
| 31 | |
| 32 | # Get the paths so we can point into the sysroot correctly |
| 33 | vars = get_bb_vars(["STAGING_DIR", "BUILD_ARCH", "bindir_native", "libdir_native"]) |
| 34 | cls.staging = oe.path.join(vars["STAGING_DIR"], vars["BUILD_ARCH"]) |
| 35 | cls.bindir = oe.path.join(cls.staging, vars["bindir_native"]) |
| 36 | cls.libdir = oe.path.join(cls.staging, vars["libdir_native"]) |
| 37 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 38 | def setUpLocal(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 39 | # Just for convenience |
| 40 | self.staging = type(self).staging |
| 41 | self.bindir = type(self).bindir |
| 42 | self.libdir = type(self).libdir |
| 43 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | def test_dpkg(self): |
| 45 | for ver1, ver2, sort in self.tests: |
| 46 | op = { -1: "<<", 0: "=", 1: ">>" }[sort] |
| 47 | status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2)) |
| 48 | self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 49 | |
| 50 | # Now do it again but with incorrect operations |
| 51 | op = { -1: ">>", 0: ">>", 1: "<<" }[sort] |
| 52 | status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2)) |
| 53 | self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 54 | |
| 55 | # Now do it again but with incorrect operations |
| 56 | op = { -1: "=", 0: "<<", 1: "=" }[sort] |
| 57 | status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2)) |
| 58 | self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 59 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 60 | def test_opkg(self): |
| 61 | for ver1, ver2, sort in self.tests: |
| 62 | op = { -1: "<<", 0: "=", 1: ">>" }[sort] |
| 63 | status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2)) |
| 64 | self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 65 | |
| 66 | # Now do it again but with incorrect operations |
| 67 | op = { -1: ">>", 0: ">>", 1: "<<" }[sort] |
| 68 | status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2)) |
| 69 | self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 70 | |
| 71 | # Now do it again but with incorrect operations |
| 72 | op = { -1: "=", 0: "<<", 1: "=" }[sort] |
| 73 | status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2)) |
| 74 | self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 75 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 76 | def test_rpm(self): |
| 77 | # Need to tell the Python bindings where to find its configuration |
| 78 | env = os.environ.copy() |
| 79 | env["RPM_CONFIGDIR"] = oe.path.join(self.libdir, "rpm") |
| 80 | |
| 81 | for ver1, ver2, sort in self.tests: |
| 82 | # The only way to test rpm is via the Python module, so we need to |
| 83 | # execute python3-native. labelCompare returns -1/0/1 (like strcmp) |
| 84 | # so add 100 and use that as the exit code. |
| 85 | command = (oe.path.join(self.bindir, "python3-native", "python3"), "-c", |
| 86 | "import sys, rpm; v1=(None, \"%s\", None); v2=(None, \"%s\", None); sys.exit(rpm.labelCompare(v1, v2) + 100)" % (ver1, ver2)) |
| 87 | status = subprocess.call(command, env=env) |
| 88 | self.assertIn(status, (99, 100, 101)) |
| 89 | self.assertEqual(status - 100, sort, "%s %s (%d) failed" % (ver1, ver2, sort)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 90 | |
| 91 | class PackageTests(OESelftestTestCase): |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 92 | # Verify that a recipe cannot rename a package into an existing one |
| 93 | def test_package_name_conflict(self): |
| 94 | res = bitbake("packagenameconflict", ignore_status=True) |
| 95 | self.assertNotEqual(res.status, 0) |
| 96 | err = "package name already exists" |
| 97 | self.assertTrue(err in res.output) |
| 98 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 99 | # Verify that a recipe which sets up hardlink files has those preserved into split packages |
| 100 | # Also test file sparseness is preserved |
| 101 | def test_preserve_sparse_hardlinks(self): |
| 102 | bitbake("selftest-hardlink -c package") |
| 103 | |
| 104 | dest = get_bb_var('PKGDEST', 'selftest-hardlink') |
| 105 | bindir = get_bb_var('bindir', 'selftest-hardlink') |
| 106 | |
| 107 | def checkfiles(): |
| 108 | # Recipe creates 4 hardlinked files, there is a copy in package/ and a copy in packages-split/ |
| 109 | # so expect 8 in total. |
| 110 | self.assertEqual(os.stat(dest + "/selftest-hardlink" + bindir + "/hello1").st_nlink, 8) |
| 111 | |
| 112 | # Test a sparse file remains sparse |
| 113 | sparsestat = os.stat(dest + "/selftest-hardlink" + bindir + "/sparsetest") |
| 114 | self.assertEqual(sparsestat.st_blocks, 0) |
| 115 | self.assertEqual(sparsestat.st_size, 1048576) |
| 116 | |
| 117 | checkfiles() |
| 118 | |
| 119 | # Clean and reinstall so its now definitely from sstate, then retest. |
| 120 | bitbake("selftest-hardlink -c clean") |
| 121 | bitbake("selftest-hardlink -c package") |
| 122 | |
| 123 | checkfiles() |
| 124 | |
| 125 | # Verify gdb to read symbols from separated debug hardlink file correctly |
| 126 | def test_gdb_hardlink_debug(self): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 127 | features = 'IMAGE_INSTALL:append = " selftest-hardlink"\n' |
| 128 | features += 'IMAGE_INSTALL:append = " selftest-hardlink-dbg"\n' |
| 129 | features += 'IMAGE_INSTALL:append = " selftest-hardlink-gdb"\n' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 130 | self.write_config(features) |
| 131 | bitbake("core-image-minimal") |
| 132 | |
| 133 | def gdbtest(qemu, binary): |
| 134 | """ |
| 135 | Check that gdb ``binary`` to read symbols from separated debug file |
| 136 | """ |
| 137 | self.logger.info("gdbtest %s" % binary) |
| 138 | status, output = qemu.run_serial('/usr/bin/gdb.sh %s' % binary, timeout=60) |
| 139 | for l in output.split('\n'): |
| 140 | # Check debugging symbols exists |
| 141 | if '(no debugging symbols found)' in l: |
| 142 | self.logger.error("No debugging symbols found. GDB result:\n%s" % output) |
| 143 | return False |
| 144 | |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 145 | # Check debugging symbols works correctly. Don't look for a |
| 146 | # source file as optimisation can put the breakpoint inside |
| 147 | # stdio.h. |
| 148 | elif "Breakpoint 1 at" in l: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 149 | return True |
| 150 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 151 | self.logger.error("GDB result:\n%d: %s", status, output) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 152 | return False |
| 153 | |
| 154 | with runqemu('core-image-minimal') as qemu: |
| 155 | for binary in ['/usr/bin/hello1', |
| 156 | '/usr/bin/hello2', |
| 157 | '/usr/libexec/hello3', |
| 158 | '/usr/libexec/hello4']: |
| 159 | if not gdbtest(qemu, binary): |
| 160 | self.fail('GDB %s failed' % binary) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 161 | |
| 162 | def test_preserve_ownership(self): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 163 | features = 'IMAGE_INSTALL:append = " selftest-chown"\n' |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 164 | self.write_config(features) |
| 165 | bitbake("core-image-minimal") |
| 166 | |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 167 | def check_ownership(qemu, expected_gid, expected_uid, path): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 168 | self.logger.info("Check ownership of %s", path) |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 169 | status, output = qemu.run_serial('stat -c "%U %G" ' + path) |
| 170 | self.assertEqual(status, 1, "stat failed: " + output) |
| 171 | try: |
| 172 | uid, gid = output.split() |
| 173 | self.assertEqual(uid, expected_uid) |
| 174 | self.assertEqual(gid, expected_gid) |
| 175 | except ValueError: |
| 176 | self.fail("Cannot parse output: " + output) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 177 | |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 178 | sysconfdir = get_bb_var('sysconfdir', 'selftest-chown') |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 179 | with runqemu('core-image-minimal') as qemu: |
| 180 | for path in [ sysconfdir + "/selftest-chown/file", |
| 181 | sysconfdir + "/selftest-chown/dir", |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 182 | sysconfdir + "/selftest-chown/symlink", |
| 183 | sysconfdir + "/selftest-chown/fifotest/fifo"]: |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 184 | check_ownership(qemu, "test", "test", path) |