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