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