Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | from oeqa.selftest.case import OESelftestTestCase |
| 2 | from oeqa.core.decorator.oeid import OETestID |
| 3 | from oeqa.utils.commands import bitbake, get_bb_vars |
| 4 | import subprocess, os |
| 5 | import oe.path |
| 6 | |
| 7 | class VersionOrdering(OESelftestTestCase): |
| 8 | # version1, version2, sort order |
| 9 | tests = ( |
| 10 | ("1.0", "1.0", 0), |
| 11 | ("1.0", "2.0", -1), |
| 12 | ("2.0", "1.0", 1), |
| 13 | ("2.0-rc", "2.0", 1), |
| 14 | ("2.0~rc", "2.0", -1), |
| 15 | ("1.2rc2", "1.2.0", -1) |
| 16 | ) |
| 17 | |
| 18 | @classmethod |
| 19 | def setUpClass(cls): |
| 20 | super().setUpClass() |
| 21 | |
| 22 | # Build the tools we need and populate a sysroot |
| 23 | bitbake("dpkg-native opkg-native rpm-native python3-native") |
| 24 | bitbake("build-sysroots -c build_native_sysroot") |
| 25 | |
| 26 | # Get the paths so we can point into the sysroot correctly |
| 27 | vars = get_bb_vars(["STAGING_DIR", "BUILD_ARCH", "bindir_native", "libdir_native"]) |
| 28 | cls.staging = oe.path.join(vars["STAGING_DIR"], vars["BUILD_ARCH"]) |
| 29 | cls.bindir = oe.path.join(cls.staging, vars["bindir_native"]) |
| 30 | cls.libdir = oe.path.join(cls.staging, vars["libdir_native"]) |
| 31 | |
| 32 | def setUp(self): |
| 33 | # Just for convenience |
| 34 | self.staging = type(self).staging |
| 35 | self.bindir = type(self).bindir |
| 36 | self.libdir = type(self).libdir |
| 37 | |
| 38 | @OETestID(1880) |
| 39 | def test_dpkg(self): |
| 40 | for ver1, ver2, sort in self.tests: |
| 41 | op = { -1: "<<", 0: "=", 1: ">>" }[sort] |
| 42 | status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2)) |
| 43 | self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 44 | |
| 45 | # Now do it again but with incorrect operations |
| 46 | op = { -1: ">>", 0: ">>", 1: "<<" }[sort] |
| 47 | status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2)) |
| 48 | self.assertNotEqual(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 | @OETestID(1881) |
| 56 | def test_opkg(self): |
| 57 | for ver1, ver2, sort in self.tests: |
| 58 | op = { -1: "<<", 0: "=", 1: ">>" }[sort] |
| 59 | status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2)) |
| 60 | self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 61 | |
| 62 | # Now do it again but with incorrect operations |
| 63 | op = { -1: ">>", 0: ">>", 1: "<<" }[sort] |
| 64 | status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2)) |
| 65 | self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 66 | |
| 67 | # Now do it again but with incorrect operations |
| 68 | op = { -1: "=", 0: "<<", 1: "=" }[sort] |
| 69 | status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2)) |
| 70 | self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) |
| 71 | |
| 72 | @OETestID(1882) |
| 73 | def test_rpm(self): |
| 74 | # Need to tell the Python bindings where to find its configuration |
| 75 | env = os.environ.copy() |
| 76 | env["RPM_CONFIGDIR"] = oe.path.join(self.libdir, "rpm") |
| 77 | |
| 78 | for ver1, ver2, sort in self.tests: |
| 79 | # The only way to test rpm is via the Python module, so we need to |
| 80 | # execute python3-native. labelCompare returns -1/0/1 (like strcmp) |
| 81 | # so add 100 and use that as the exit code. |
| 82 | command = (oe.path.join(self.bindir, "python3-native", "python3"), "-c", |
| 83 | "import sys, rpm; v1=(None, \"%s\", None); v2=(None, \"%s\", None); sys.exit(rpm.labelCompare(v1, v2) + 100)" % (ver1, ver2)) |
| 84 | status = subprocess.call(command, env=env) |
| 85 | self.assertIn(status, (99, 100, 101)) |
| 86 | self.assertEqual(status - 100, sort, "%s %s (%d) failed" % (ver1, ver2, sort)) |