package.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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, get_bb_var
  4. import stat
  5. import subprocess, os
  6. import oe.path
  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. @classmethod
  18. def setUpClass(cls):
  19. super().setUpClass()
  20. # Build the tools we need and populate a sysroot
  21. bitbake("dpkg-native opkg-native rpm-native python3-native")
  22. bitbake("build-sysroots -c build_native_sysroot")
  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. def setUpLocal(self):
  29. # Just for convenience
  30. self.staging = type(self).staging
  31. self.bindir = type(self).bindir
  32. self.libdir = type(self).libdir
  33. @OETestID(1880)
  34. def test_dpkg(self):
  35. for ver1, ver2, sort in self.tests:
  36. op = { -1: "<<", 0: "=", 1: ">>" }[sort]
  37. status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2))
  38. self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  39. # Now do it again but with incorrect operations
  40. op = { -1: ">>", 0: ">>", 1: "<<" }[sort]
  41. status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2))
  42. self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  43. # Now do it again but with incorrect operations
  44. op = { -1: "=", 0: "<<", 1: "=" }[sort]
  45. status = subprocess.call((oe.path.join(self.bindir, "dpkg"), "--compare-versions", ver1, op, ver2))
  46. self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  47. @OETestID(1881)
  48. def test_opkg(self):
  49. for ver1, ver2, sort in self.tests:
  50. op = { -1: "<<", 0: "=", 1: ">>" }[sort]
  51. status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2))
  52. self.assertEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  53. # Now do it again but with incorrect operations
  54. op = { -1: ">>", 0: ">>", 1: "<<" }[sort]
  55. status = subprocess.call((oe.path.join(self.bindir, "opkg"), "compare-versions", ver1, op, ver2))
  56. self.assertNotEqual(status, 0, "%s %s %s failed" % (ver1, op, ver2))
  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. @OETestID(1882)
  62. def test_rpm(self):
  63. # Need to tell the Python bindings where to find its configuration
  64. env = os.environ.copy()
  65. env["RPM_CONFIGDIR"] = oe.path.join(self.libdir, "rpm")
  66. for ver1, ver2, sort in self.tests:
  67. # The only way to test rpm is via the Python module, so we need to
  68. # execute python3-native. labelCompare returns -1/0/1 (like strcmp)
  69. # so add 100 and use that as the exit code.
  70. command = (oe.path.join(self.bindir, "python3-native", "python3"), "-c",
  71. "import sys, rpm; v1=(None, \"%s\", None); v2=(None, \"%s\", None); sys.exit(rpm.labelCompare(v1, v2) + 100)" % (ver1, ver2))
  72. status = subprocess.call(command, env=env)
  73. self.assertIn(status, (99, 100, 101))
  74. self.assertEqual(status - 100, sort, "%s %s (%d) failed" % (ver1, ver2, sort))
  75. class PackageTests(OESelftestTestCase):
  76. # Verify that a recipe which sets up hardlink files has those preserved into split packages
  77. def test_preserve_hardlinks(self):
  78. result = bitbake("selftest-hardlink -c package")
  79. dest = get_bb_var('PKGDEST', 'selftest-hardlink')
  80. bindir = get_bb_var('bindir', 'selftest-hardlink')
  81. # Recipe creates 4 hardlinked files, there is a copy in package/ and a copy in packages-split/
  82. # so expect 8 in total.
  83. self.assertEqual(os.stat(dest + "/selftest-hardlink" + bindir + "/hello").st_nlink, 8)