manifest.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import os
  2. from oeqa.selftest.case import OESelftestTestCase
  3. from oeqa.utils.commands import get_bb_var, get_bb_vars, bitbake
  4. class ManifestEntry:
  5. '''A manifest item of a collection able to list missing packages'''
  6. def __init__(self, entry):
  7. self.file = entry
  8. self.missing = []
  9. class VerifyManifest(OESelftestTestCase):
  10. '''Tests for the manifest files and contents of an image'''
  11. @classmethod
  12. def check_manifest_entries(self, manifest, path):
  13. manifest_errors = []
  14. try:
  15. with open(manifest, "r") as mfile:
  16. for line in mfile:
  17. manifest_entry = os.path.join(path, line.split()[0])
  18. self.logger.debug("{}: looking for {}"\
  19. .format(self.classname, manifest_entry))
  20. if not os.path.isfile(manifest_entry):
  21. manifest_errors.append(manifest_entry)
  22. self.logger.debug("{}: {} not found"\
  23. .format(self.classname, manifest_entry))
  24. except OSError as e:
  25. self.logger.debug("{}: checking of {} failed"\
  26. .format(self.classname, manifest))
  27. raise e
  28. return manifest_errors
  29. #this will possibly move from here
  30. @classmethod
  31. def get_dir_from_bb_var(self, bb_var, target = None):
  32. target == self.buildtarget if target == None else target
  33. directory = get_bb_var(bb_var, target);
  34. if not directory or not os.path.isdir(directory):
  35. self.logger.debug("{}: {} points to {} when target = {}"\
  36. .format(self.classname, bb_var, directory, target))
  37. raise OSError
  38. return directory
  39. @classmethod
  40. def setUpClass(self):
  41. super(VerifyManifest, self).setUpClass()
  42. self.buildtarget = 'core-image-minimal'
  43. self.classname = 'VerifyManifest'
  44. self.logger.info("{}: doing bitbake {} as a prerequisite of the test"\
  45. .format(self.classname, self.buildtarget))
  46. if bitbake(self.buildtarget).status:
  47. self.logger.debug("{} Failed to setup {}"\
  48. .format(self.classname, self.buildtarget))
  49. self.skipTest("{}: Cannot setup testing scenario"\
  50. .format(self.classname))
  51. def test_SDK_manifest_entries(self):
  52. '''Verifying the SDK manifest entries exist, this may take a build'''
  53. # the setup should bitbake core-image-minimal and here it is required
  54. # to do an additional setup for the sdk
  55. sdktask = '-c populate_sdk'
  56. bbargs = sdktask + ' ' + self.buildtarget
  57. self.logger.debug("{}: doing bitbake {} as a prerequisite of the test"\
  58. .format(self.classname, bbargs))
  59. if bitbake(bbargs).status:
  60. self.logger.debug("{} Failed to bitbake {}"\
  61. .format(self.classname, bbargs))
  62. self.skipTest("{}: Cannot setup testing scenario"\
  63. .format(self.classname))
  64. pkgdata_dir = reverse_dir = {}
  65. mfilename = mpath = m_entry = {}
  66. # get manifest location based on target to query about
  67. d_target= dict(target = self.buildtarget,
  68. host = 'nativesdk-packagegroup-sdk-host')
  69. try:
  70. mdir = self.get_dir_from_bb_var('SDK_DEPLOY', self.buildtarget)
  71. for k in d_target.keys():
  72. bb_vars = get_bb_vars(['SDK_NAME', 'SDK_VERSION'], self.buildtarget)
  73. mfilename[k] = "{}-toolchain-{}.{}.manifest".format(
  74. bb_vars['SDK_NAME'],
  75. bb_vars['SDK_VERSION'],
  76. k)
  77. mpath[k] = os.path.join(mdir, mfilename[k])
  78. if not os.path.isfile(mpath[k]):
  79. self.logger.debug("{}: {} does not exist".format(
  80. self.classname, mpath[k]))
  81. raise IOError
  82. m_entry[k] = ManifestEntry(mpath[k])
  83. pkgdata_dir[k] = self.get_dir_from_bb_var('PKGDATA_DIR',
  84. d_target[k])
  85. reverse_dir[k] = os.path.join(pkgdata_dir[k],
  86. 'runtime-reverse')
  87. if not os.path.exists(reverse_dir[k]):
  88. self.logger.debug("{}: {} does not exist".format(
  89. self.classname, reverse_dir[k]))
  90. raise IOError
  91. except OSError:
  92. raise self.skipTest("{}: Error in obtaining manifest dirs"\
  93. .format(self.classname))
  94. except IOError:
  95. msg = "{}: Error cannot find manifests in the specified dir:\n{}"\
  96. .format(self.classname, mdir)
  97. self.fail(msg)
  98. for k in d_target.keys():
  99. self.logger.debug("{}: Check manifest {}".format(
  100. self.classname, m_entry[k].file))
  101. m_entry[k].missing = self.check_manifest_entries(\
  102. m_entry[k].file,reverse_dir[k])
  103. if m_entry[k].missing:
  104. msg = '{}: {} Error has the following missing entries'\
  105. .format(self.classname, m_entry[k].file)
  106. logmsg = msg+':\n'+'\n'.join(m_entry[k].missing)
  107. self.logger.debug(logmsg)
  108. self.logger.info(msg)
  109. self.fail(logmsg)
  110. def test_image_manifest_entries(self):
  111. '''Verifying the image manifest entries exist'''
  112. # get manifest location based on target to query about
  113. try:
  114. mdir = self.get_dir_from_bb_var('DEPLOY_DIR_IMAGE',
  115. self.buildtarget)
  116. mfilename = get_bb_var("IMAGE_LINK_NAME", self.buildtarget)\
  117. + ".manifest"
  118. mpath = os.path.join(mdir, mfilename)
  119. if not os.path.isfile(mpath): raise IOError
  120. m_entry = ManifestEntry(mpath)
  121. pkgdata_dir = {}
  122. pkgdata_dir = self.get_dir_from_bb_var('PKGDATA_DIR',
  123. self.buildtarget)
  124. revdir = os.path.join(pkgdata_dir, 'runtime-reverse')
  125. if not os.path.exists(revdir): raise IOError
  126. except OSError:
  127. raise self.skipTest("{}: Error in obtaining manifest dirs"\
  128. .format(self.classname))
  129. except IOError:
  130. msg = "{}: Error cannot find manifests in dir:\n{}"\
  131. .format(self.classname, mdir)
  132. self.fail(msg)
  133. self.logger.debug("{}: Check manifest {}"\
  134. .format(self.classname, m_entry.file))
  135. m_entry.missing = self.check_manifest_entries(\
  136. m_entry.file, revdir)
  137. if m_entry.missing:
  138. msg = '{}: {} Error has the following missing entries'\
  139. .format(self.classname, m_entry.file)
  140. logmsg = msg+':\n'+'\n'.join(m_entry.missing)
  141. self.logger.debug(logmsg)
  142. self.logger.info(msg)
  143. self.fail(logmsg)