summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/package.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/package.py')
-rw-r--r--meta/lib/oeqa/selftest/cases/package.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/package.py b/meta/lib/oeqa/selftest/cases/package.py
new file mode 100644
index 0000000000..6a8bc9283f
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/package.py
@@ -0,0 +1,80 @@
1from oeqa.selftest.case import OESelftestTestCase
2from oeqa.utils.commands import bitbake, get_bb_vars
3import subprocess, os
4import oe.path
5
6class VersionOrdering(OESelftestTestCase):
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))