blob: 44d0404c5d435920a8c457536bc3b946cb8329c6 [file] [log] [blame]
Patrick Williamsf1e5d692016-03-30 15:21:19 -05001import unittest
2import os
3
4from oeqa.selftest.base import oeSelfTest
5from oeqa.utils.commands import get_bb_var, bitbake
6from oeqa.utils.decorators import testcase
7
8class ManifestEntry:
9 '''A manifest item of a collection able to list missing packages'''
10 def __init__(self, entry):
11 self.file = entry
12 self.missing = []
13
14class VerifyManifest(oeSelfTest):
15 '''Tests for the manifest files and contents of an image'''
16
17 @classmethod
18 def check_manifest_entries(self, manifest, path):
19 manifest_errors = []
20 try:
21 with open(manifest, "r") as mfile:
22 for line in mfile:
23 manifest_entry = os.path.join(path, line.split()[0])
24 self.log.debug("{}: looking for {}"\
25 .format(self.classname, manifest_entry))
26 if not os.path.isfile(manifest_entry):
27 manifest_errors.append(manifest_entry)
28 self.log.debug("{}: {} not found"\
29 .format(self.classname, manifest_entry))
30 except OSError as e:
31 self.log.debug("{}: checking of {} failed"\
32 .format(self.classname, manifest))
33 raise e
34
35 return manifest_errors
36
37 #this will possibly move from here
38 @classmethod
39 def get_dir_from_bb_var(self, bb_var, target = None):
40 target == self.buildtarget if target == None else target
41 directory = get_bb_var(bb_var, target);
42 if not directory or not os.path.isdir(directory):
43 self.log.debug("{}: {} points to {} when target = {}"\
44 .format(self.classname, bb_var, directory, target))
45 raise OSError
46 return directory
47
48 @classmethod
49 def setUpClass(self):
50
51 self.buildtarget = 'core-image-minimal'
52 self.classname = 'VerifyManifest'
53
54 self.log.info("{}: doing bitbake {} as a prerequisite of the test"\
55 .format(self.classname, self.buildtarget))
56 if bitbake(self.buildtarget).status:
57 self.log.debug("{} Failed to setup {}"\
58 .format(self.classname, self.buildtarget))
59 unittest.SkipTest("{}: Cannot setup testing scenario"\
60 .format(self.classname))
61
62 @testcase(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.log.debug("{}: doing bitbake {} as a prerequisite of the test"\
71 .format(self.classname, bbargs))
72 if bitbake(bbargs).status:
73 self.log.debug("{} Failed to bitbake {}"\
74 .format(self.classname, bbargs))
75 unittest.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 mfilename[k] = "{}-toolchain-{}.{}.manifest".format(
88 get_bb_var("SDK_NAME", self.buildtarget),
89 get_bb_var("SDK_VERSION", self.buildtarget),
90 k)
91 mpath[k] = os.path.join(mdir, mfilename[k])
92 if not os.path.isfile(mpath[k]):
93 self.log.debug("{}: {} does not exist".format(
94 self.classname, mpath[k]))
95 raise IOError
96 m_entry[k] = ManifestEntry(mpath[k])
97
98 pkgdata_dir[k] = self.get_dir_from_bb_var('PKGDATA_DIR',
99 d_target[k])
100 reverse_dir[k] = os.path.join(pkgdata_dir[k],
101 'runtime-reverse')
102 if not os.path.exists(reverse_dir[k]):
103 self.log.debug("{}: {} does not exist".format(
104 self.classname, reverse_dir[k]))
105 raise IOError
106 except OSError:
107 raise unittest.SkipTest("{}: Error in obtaining manifest dirs"\
108 .format(self.classname))
109 except IOError:
110 msg = "{}: Error cannot find manifests in the specified dir:\n{}"\
111 .format(self.classname, mdir)
112 self.fail(msg)
113
114 for k in d_target.keys():
115 self.log.debug("{}: Check manifest {}".format(
116 self.classname, m_entry[k].file))
117
118 m_entry[k].missing = self.check_manifest_entries(\
119 m_entry[k].file,reverse_dir[k])
120 if m_entry[k].missing:
121 msg = '{}: {} Error has the following missing entries'\
122 .format(self.classname, m_entry[k].file)
123 logmsg = msg+':\n'+'\n'.join(m_entry[k].missing)
124 self.log.debug(logmsg)
125 self.log.info(msg)
126 self.fail(logmsg)
127
128 @testcase(1381)
129 def test_image_manifest_entries(self):
130 '''Verifying the image manifest entries exist'''
131
132 # get manifest location based on target to query about
133 try:
134 mdir = self.get_dir_from_bb_var('DEPLOY_DIR_IMAGE',
135 self.buildtarget)
136 mfilename = get_bb_var("IMAGE_LINK_NAME", self.buildtarget)\
137 + ".manifest"
138 mpath = os.path.join(mdir, mfilename)
139 if not os.path.isfile(mpath): raise IOError
140 m_entry = ManifestEntry(mpath)
141
142 pkgdata_dir = {}
143 pkgdata_dir = self.get_dir_from_bb_var('PKGDATA_DIR',
144 self.buildtarget)
145 revdir = os.path.join(pkgdata_dir, 'runtime-reverse')
146 if not os.path.exists(revdir): raise IOError
147 except OSError:
148 raise unittest.SkipTest("{}: Error in obtaining manifest dirs"\
149 .format(self.classname))
150 except IOError:
151 msg = "{}: Error cannot find manifests in dir:\n{}"\
152 .format(self.classname, mdir)
153 self.fail(msg)
154
155 self.log.debug("{}: Check manifest {}"\
156 .format(self.classname, m_entry.file))
157 m_entry.missing = self.check_manifest_entries(\
158 m_entry.file, revdir)
159 if m_entry.missing:
160 msg = '{}: {} Error has the following missing entries'\
161 .format(self.classname, m_entry.file)
162 logmsg = msg+':\n'+'\n'.join(m_entry.missing)
163 self.log.debug(logmsg)
164 self.log.info(msg)
165 self.fail(logmsg)