blob: 6596dabc322da785a1654ed110eadaee54799033 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001from oeqa.selftest.case import OESelftestTestCase
2from oeqa.core.decorator.oeid import OETestID
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003from oeqa.utils.commands import bitbake, get_bb_vars, get_bb_var, runqemu
4import stat
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005import subprocess, os
6import oe.path
7
8class VersionOrdering(OESelftestTestCase):
9 # version1, version2, sort order
10 tests = (
11 ("1.0", "1.0", 0),
12 ("1.0", "2.0", -1),
13 ("2.0", "1.0", 1),
14 ("2.0-rc", "2.0", 1),
15 ("2.0~rc", "2.0", -1),
16 ("1.2rc2", "1.2.0", -1)
17 )
18
19 @classmethod
20 def setUpClass(cls):
21 super().setUpClass()
22
23 # Build the tools we need and populate a sysroot
24 bitbake("dpkg-native opkg-native rpm-native python3-native")
25 bitbake("build-sysroots -c build_native_sysroot")
26
27 # Get the paths so we can point into the sysroot correctly
28 vars = get_bb_vars(["STAGING_DIR", "BUILD_ARCH", "bindir_native", "libdir_native"])
29 cls.staging = oe.path.join(vars["STAGING_DIR"], vars["BUILD_ARCH"])
30 cls.bindir = oe.path.join(cls.staging, vars["bindir_native"])
31 cls.libdir = oe.path.join(cls.staging, vars["libdir_native"])
32
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080033 def setUpLocal(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034 # Just for convenience
35 self.staging = type(self).staging
36 self.bindir = type(self).bindir
37 self.libdir = type(self).libdir
38
39 @OETestID(1880)
40 def test_dpkg(self):
41 for ver1, ver2, sort in self.tests:
42 op = { -1: "<<", 0: "=", 1: ">>" }[sort]
43 status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2))
44 self.assertEqual(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 # Now do it again but with incorrect operations
52 op = { -1: "=", 0: "<<", 1: "=" }[sort]
53 status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2))
54 self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
55
56 @OETestID(1881)
57 def test_opkg(self):
58 for ver1, ver2, sort in self.tests:
59 op = { -1: "<<", 0: "=", 1: ">>" }[sort]
60 status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2))
61 self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
62
63 # Now do it again but with incorrect operations
64 op = { -1: ">>", 0: ">>", 1: "<<" }[sort]
65 status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2))
66 self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
67
68 # Now do it again but with incorrect operations
69 op = { -1: "=", 0: "<<", 1: "=" }[sort]
70 status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2))
71 self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
72
73 @OETestID(1882)
74 def test_rpm(self):
75 # Need to tell the Python bindings where to find its configuration
76 env = os.environ.copy()
77 env["RPM_CONFIGDIR"] = oe.path.join(self.libdir, "rpm")
78
79 for ver1, ver2, sort in self.tests:
80 # The only way to test rpm is via the Python module, so we need to
81 # execute python3-native. labelCompare returns -1/0/1 (like strcmp)
82 # so add 100 and use that as the exit code.
83 command = (oe.path.join(self.bindir, "python3-native", "python3"), "-c",
84 "import sys, rpm; v1=(None, \"%s\", None); v2=(None, \"%s\", None); sys.exit(rpm.labelCompare(v1, v2) + 100)" % (ver1, ver2))
85 status = subprocess.call(command, env=env)
86 self.assertIn(status, (99, 100, 101))
87 self.assertEqual(status - 100, sort, "%s %s (%d) failed" % (ver1, ver2, sort))
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080088
89class PackageTests(OESelftestTestCase):
90 # Verify that a recipe which sets up hardlink files has those preserved into split packages
91 # Also test file sparseness is preserved
92 def test_preserve_sparse_hardlinks(self):
93 bitbake("selftest-hardlink -c package")
94
95 dest = get_bb_var('PKGDEST', 'selftest-hardlink')
96 bindir = get_bb_var('bindir', 'selftest-hardlink')
97
98 def checkfiles():
99 # Recipe creates 4 hardlinked files, there is a copy in package/ and a copy in packages-split/
100 # so expect 8 in total.
101 self.assertEqual(os.stat(dest + "/selftest-hardlink" + bindir + "/hello1").st_nlink, 8)
102
103 # Test a sparse file remains sparse
104 sparsestat = os.stat(dest + "/selftest-hardlink" + bindir + "/sparsetest")
105 self.assertEqual(sparsestat.st_blocks, 0)
106 self.assertEqual(sparsestat.st_size, 1048576)
107
108 checkfiles()
109
110 # Clean and reinstall so its now definitely from sstate, then retest.
111 bitbake("selftest-hardlink -c clean")
112 bitbake("selftest-hardlink -c package")
113
114 checkfiles()
115
116 # Verify gdb to read symbols from separated debug hardlink file correctly
117 def test_gdb_hardlink_debug(self):
118 features = 'IMAGE_INSTALL_append = " selftest-hardlink"\n'
119 features += 'IMAGE_INSTALL_append = " selftest-hardlink-dbg"\n'
120 features += 'IMAGE_INSTALL_append = " selftest-hardlink-gdb"\n'
121 self.write_config(features)
122 bitbake("core-image-minimal")
123
124 def gdbtest(qemu, binary):
125 """
126 Check that gdb ``binary`` to read symbols from separated debug file
127 """
128 self.logger.info("gdbtest %s" % binary)
129 status, output = qemu.run_serial('/usr/bin/gdb.sh %s' % binary, timeout=60)
130 for l in output.split('\n'):
131 # Check debugging symbols exists
132 if '(no debugging symbols found)' in l:
133 self.logger.error("No debugging symbols found. GDB result:\n%s" % output)
134 return False
135
136 # Check debugging symbols works correctly
137 elif "Breakpoint 1, main () at hello.c:4" in l:
138 return True
139
Brad Bishop19323692019-04-05 15:28:33 -0400140 self.logger.error("GDB result:\n%d: %s", status, output)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800141 return False
142
143 with runqemu('core-image-minimal') as qemu:
144 for binary in ['/usr/bin/hello1',
145 '/usr/bin/hello2',
146 '/usr/libexec/hello3',
147 '/usr/libexec/hello4']:
148 if not gdbtest(qemu, binary):
149 self.fail('GDB %s failed' % binary)