diff options
author | Ross Burton <ross.burton@intel.com> | 2017-05-02 13:42:08 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-05-16 14:08:28 +0100 |
commit | ad2778693eaa19f591dca5795ed77f3f878546de (patch) | |
tree | 31b5b41da24cae4e7cd82844c36ec9c1134d4e05 /meta | |
parent | 37c1dd150c8eeb741462e852907df85f48980014 (diff) | |
download | poky-ad2778693eaa19f591dca5795ed77f3f878546de.tar.gz |
oeqa/selftest: add test for package manager version comparison
This test case verifies that opkg, dpkg, and rpm all have the same behaviour for
version ordering, specifically the behaviour of ~ which should be sorting
*before* nothing:
1.0 < 2.0~pre < 2.0 < 2.0-fix
(From OE-Core rev: 0bf875ea234bb9ff50d347345782e14d6b7d3ff9)
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/selftest/package.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/package.py b/meta/lib/oeqa/selftest/package.py new file mode 100644 index 0000000000..95125f220d --- /dev/null +++ b/meta/lib/oeqa/selftest/package.py | |||
@@ -0,0 +1,80 @@ | |||
1 | from oeqa.selftest.base import oeSelfTest | ||
2 | from oeqa.utils.commands import bitbake, get_bb_vars | ||
3 | import subprocess, os | ||
4 | import oe.path | ||
5 | |||
6 | class VersionOrdering(oeSelfTest): | ||
7 | # version1, version2, sort order | ||
8 | tests = ( | ||
9 | ("1.0", "1.0", 0), | ||
10 | ("1.0", "2.0", -1), | ||
11 | ("2.0", "1.0", 1), | ||
12 | ("2.0-rc", "2.0", 1), | ||
13 | ("2.0~rc", "2.0", -1), | ||
14 | ("1.2rc2", "1.2.0", -1) | ||
15 | ) | ||
16 | |||
17 | @classmethod | ||
18 | def setUpClass(cls): | ||
19 | # Build the tools we need and populate a sysroot | ||
20 | bitbake("dpkg-native opkg-native rpm-native python3-native") | ||
21 | bitbake("build-sysroots -c build_native_sysroot") | ||
22 | |||
23 | # Get the paths so we can point into the sysroot correctly | ||
24 | vars = get_bb_vars(["STAGING_DIR", "BUILD_ARCH", "bindir_native", "libdir_native"]) | ||
25 | cls.staging = oe.path.join(vars["STAGING_DIR"], vars["BUILD_ARCH"]) | ||
26 | cls.bindir = oe.path.join(cls.staging, vars["bindir_native"]) | ||
27 | cls.libdir = oe.path.join(cls.staging, vars["libdir_native"]) | ||
28 | |||
29 | def setUp(self): | ||
30 | # Just for convenience | ||
31 | self.staging = type(self).staging | ||
32 | self.bindir = type(self).bindir | ||
33 | self.libdir = type(self).libdir | ||
34 | |||
35 | def test_dpkg(self): | ||
36 | for ver1, ver2, sort in self.tests: | ||
37 | op = { -1: "<<", 0: "=", 1: ">>" }[sort] | ||
38 | status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2)) | ||
39 | self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) | ||
40 | |||
41 | # Now do it again but with incorrect operations | ||
42 | op = { -1: ">>", 0: ">>", 1: "<<" }[sort] | ||
43 | status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2)) | ||
44 | self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) | ||
45 | |||
46 | # Now do it again but with incorrect operations | ||
47 | op = { -1: "=", 0: "<<", 1: "=" }[sort] | ||
48 | status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2)) | ||
49 | self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) | ||
50 | |||
51 | def test_opkg(self): | ||
52 | for ver1, ver2, sort in self.tests: | ||
53 | op = { -1: "<<", 0: "=", 1: ">>" }[sort] | ||
54 | status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2)) | ||
55 | self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2)) | ||
56 | |||
57 | # Now do it again but with incorrect operations | ||
58 | op = { -1: ">>", 0: ">>", 1: "<<" }[sort] | ||
59 | status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2)) | ||
60 | self.assertNotEqual(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 | def test_rpm(self): | ||
68 | # Need to tell the Python bindings where to find its configuration | ||
69 | env = os.environ.copy() | ||
70 | env["RPM_CONFIGDIR"] = oe.path.join(self.libdir, "rpm") | ||
71 | |||
72 | for ver1, ver2, sort in self.tests: | ||
73 | # The only way to test rpm is via the Python module, so we need to | ||
74 | # execute python3-native. labelCompare returns -1/0/1 (like strcmp) | ||
75 | # so add 100 and use that as the exit code. | ||
76 | command = (oe.path.join(self.bindir, "python3-native", "python3"), "-c", | ||
77 | "import sys, rpm; v1=(None, \"%s\", None); v2=(None, \"%s\", None); sys.exit(rpm.labelCompare(v1, v2) + 100)" % (ver1, ver2)) | ||
78 | status = subprocess.call(command, env=env) | ||
79 | self.assertIn(status, (99, 100, 101)) | ||
80 | self.assertEqual(status - 100, sort, "%s %s (%d) failed" % (ver1, ver2, sort)) | ||