package.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. from oeqa.selftest.case import OESelftestTestCase
  2. from oeqa.utils.commands import bitbake, get_bb_vars, get_bb_var, runqemu
  3. import stat
  4. import subprocess, os
  5. import oe.path
  6. class 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. @classmethod
  17. def setUpClass(cls):
  18. super().setUpClass()
  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. # Get the paths so we can point into the sysroot correctly
  23. vars = get_bb_vars(["STAGING_DIR", "BUILD_ARCH", "bindir_native", "libdir_native"])
  24. cls.staging = oe.path.join(vars["STAGING_DIR"], vars["BUILD_ARCH"])
  25. cls.bindir = oe.path.join(cls.staging, vars["bindir_native"])
  26. cls.libdir = oe.path.join(cls.staging, vars["libdir_native"])
  27. def setUpLocal(self):
  28. # Just for convenience
  29. self.staging = type(self).staging
  30. self.bindir = type(self).bindir
  31. self.libdir = type(self).libdir
  32. def test_dpkg(self):
  33. for ver1, ver2, sort in self.tests:
  34. op = { -1: "<<", 0: "=", 1: ">>" }[sort]
  35. status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2))
  36. self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  37. # Now do it again but with incorrect operations
  38. op = { -1: ">>", 0: ">>", 1: "<<" }[sort]
  39. status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2))
  40. self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  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. def test_opkg(self):
  46. for ver1, ver2, sort in self.tests:
  47. op = { -1: "<<", 0: "=", 1: ">>" }[sort]
  48. status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2))
  49. self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  50. # Now do it again but with incorrect operations
  51. op = { -1: ">>", 0: ">>", 1: "<<" }[sort]
  52. status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2))
  53. self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  54. # Now do it again but with incorrect operations
  55. op = { -1: "=", 0: "<<", 1: "=" }[sort]
  56. status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2))
  57. self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  58. def test_rpm(self):
  59. # Need to tell the Python bindings where to find its configuration
  60. env = os.environ.copy()
  61. env["RPM_CONFIGDIR"] = oe.path.join(self.libdir, "rpm")
  62. for ver1, ver2, sort in self.tests:
  63. # The only way to test rpm is via the Python module, so we need to
  64. # execute python3-native. labelCompare returns -1/0/1 (like strcmp)
  65. # so add 100 and use that as the exit code.
  66. command = (oe.path.join(self.bindir, "python3-native", "python3"), "-c",
  67. "import sys, rpm; v1=(None, \"%s\", None); v2=(None, \"%s\", None); sys.exit(rpm.labelCompare(v1, v2) + 100)" % (ver1, ver2))
  68. status = subprocess.call(command, env=env)
  69. self.assertIn(status, (99, 100, 101))
  70. self.assertEqual(status - 100, sort, "%s %s (%d) failed" % (ver1, ver2, sort))
  71. class PackageTests(OESelftestTestCase):
  72. # Verify that a recipe which sets up hardlink files has those preserved into split packages
  73. # Also test file sparseness is preserved
  74. def test_preserve_sparse_hardlinks(self):
  75. bitbake("selftest-hardlink -c package")
  76. dest = get_bb_var('PKGDEST', 'selftest-hardlink')
  77. bindir = get_bb_var('bindir', 'selftest-hardlink')
  78. def checkfiles():
  79. # Recipe creates 4 hardlinked files, there is a copy in package/ and a copy in packages-split/
  80. # so expect 8 in total.
  81. self.assertEqual(os.stat(dest + "/selftest-hardlink" + bindir + "/hello1").st_nlink, 8)
  82. # Test a sparse file remains sparse
  83. sparsestat = os.stat(dest + "/selftest-hardlink" + bindir + "/sparsetest")
  84. self.assertEqual(sparsestat.st_blocks, 0)
  85. self.assertEqual(sparsestat.st_size, 1048576)
  86. checkfiles()
  87. # Clean and reinstall so its now definitely from sstate, then retest.
  88. bitbake("selftest-hardlink -c clean")
  89. bitbake("selftest-hardlink -c package")
  90. checkfiles()
  91. # Verify gdb to read symbols from separated debug hardlink file correctly
  92. def test_gdb_hardlink_debug(self):
  93. features = 'IMAGE_INSTALL_append = " selftest-hardlink"\n'
  94. features += 'IMAGE_INSTALL_append = " selftest-hardlink-dbg"\n'
  95. features += 'IMAGE_INSTALL_append = " selftest-hardlink-gdb"\n'
  96. self.write_config(features)
  97. bitbake("core-image-minimal")
  98. def gdbtest(qemu, binary):
  99. """
  100. Check that gdb ``binary`` to read symbols from separated debug file
  101. """
  102. self.logger.info("gdbtest %s" % binary)
  103. status, output = qemu.run_serial('/usr/bin/gdb.sh %s' % binary, timeout=60)
  104. for l in output.split('\n'):
  105. # Check debugging symbols exists
  106. if '(no debugging symbols found)' in l:
  107. self.logger.error("No debugging symbols found. GDB result:\n%s" % output)
  108. return False
  109. # Check debugging symbols works correctly
  110. elif "Breakpoint 1, main () at hello.c:4" in l:
  111. return True
  112. self.logger.error("GDB result:\n%d: %s", status, output)
  113. return False
  114. with runqemu('core-image-minimal') as qemu:
  115. for binary in ['/usr/bin/hello1',
  116. '/usr/bin/hello2',
  117. '/usr/libexec/hello3',
  118. '/usr/libexec/hello4']:
  119. if not gdbtest(qemu, binary):
  120. self.fail('GDB %s failed' % binary)