summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/manifest.py
diff options
context:
space:
mode:
authorBenjamin Esquivel <benjamin.esquivel@linux.intel.com>2015-10-07 14:41:23 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-10-21 22:56:05 +0100
commit2e91cbd12ddf5f65e914bd7fec36cfee23694a77 (patch)
tree88b392fe64686882a20569f3cfed969f7dc0373b /meta/lib/oeqa/selftest/manifest.py
parentc9bef348302a6af1ca9c2cffd2692d52ceebce88 (diff)
downloadpoky-2e91cbd12ddf5f65e914bd7fec36cfee23694a77.tar.gz
oeqa/selftest/manifest.py: Test support for manifests
adding support for tests to verify that manifest contents contain entries that exist in an specified pkgdata dir tests added: - manifest.VerifyManifest.test_image_manifest_entries - manifest.VerifyManifest.test_SDK_manifest_entries test support written for future tests: -adding a setUpClass that supports other manifest tests -a get dir from bb var function that verifies if the dir exists -a ManifestEntry class defined with missing items list -check for the paths and fail gracefully if not there -debug prints for failure analysis [YOCTO#8028] (From OE-Core rev: aed5b7aef33459f1bb5fa29560920c254a5fd637) Signed-off-by: Benjamin Esquivel <benjamin.esquivel@linux.intel.com> Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/manifest.py')
-rw-r--r--meta/lib/oeqa/selftest/manifest.py163
1 files changed, 163 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/manifest.py b/meta/lib/oeqa/selftest/manifest.py
new file mode 100644
index 0000000000..c813c1d3be
--- /dev/null
+++ b/meta/lib/oeqa/selftest/manifest.py
@@ -0,0 +1,163 @@
1import 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 def test_SDK_manifest_entries(self):
63 '''Verifying the SDK manifest entries exist, this may take a build'''
64
65 # the setup should bitbake core-image-minimal and here it is required
66 # to do an additional setup for the sdk
67 sdktask = '-c populate_sdk'
68 bbargs = sdktask + ' ' + self.buildtarget
69 self.log.debug("{}: doing bitbake {} as a prerequisite of the test"\
70 .format(self.classname, bbargs))
71 if bitbake(bbargs).status:
72 self.log.debug("{} Failed to bitbake {}"\
73 .format(self.classname, bbargs))
74 unittest.SkipTest("{}: Cannot setup testing scenario"\
75 .format(self.classname))
76
77
78 pkgdata_dir = reverse_dir = {}
79 mfilename = mpath = m_entry = {}
80 # get manifest location based on target to query about
81 d_target= dict(target = self.buildtarget,
82 host = 'nativesdk-packagegroup-sdk-host')
83 try:
84 mdir = self.get_dir_from_bb_var('SDK_DEPLOY', self.buildtarget)
85 for k in d_target.keys():
86 mfilename[k] = "{}-toolchain-{}.{}.manifest".format(
87 get_bb_var("SDK_NAME", self.buildtarget),
88 get_bb_var("SDK_VERSION", self.buildtarget),
89 k)
90 mpath[k] = os.path.join(mdir, mfilename[k])
91 if not os.path.isfile(mpath[k]):
92 self.log.debug("{}: {} does not exist".format(
93 self.classname, mpath[k]))
94 raise IOError
95 m_entry[k] = ManifestEntry(mpath[k])
96
97 pkgdata_dir[k] = self.get_dir_from_bb_var('PKGDATA_DIR',
98 d_target[k])
99 reverse_dir[k] = os.path.join(pkgdata_dir[k],
100 'runtime-reverse')
101 if not os.path.exists(reverse_dir[k]):
102 self.log.debug("{}: {} does not exist".format(
103 self.classname, reverse_dir[k]))
104 raise IOError
105 except OSError:
106 raise unittest.SkipTest("{}: Error in obtaining manifest dirs"\
107 .format(self.classname))
108 except IOError:
109 msg = "{}: Error cannot find manifests in the specified dir:\n{}"\
110 .format(self.classname, mdir)
111 self.fail(msg)
112
113 for k in d_target.keys():
114 self.log.debug("{}: Check manifest {}".format(
115 self.classname, m_entry[k].file))
116
117 m_entry[k].missing = self.check_manifest_entries(\
118 m_entry[k].file,reverse_dir[k])
119 if m_entry[k].missing:
120 msg = '{}: {} Error has the following missing entries'\
121 .format(self.classname, m_entry[k].file)
122 logmsg = msg+':\n'+'\n'.join(m_entry[k].missing)
123 self.log.debug(logmsg)
124 self.log.info(msg)
125 self.fail(logmsg)
126
127 def test_image_manifest_entries(self):
128 '''Verifying the image manifest entries exist'''
129
130 # get manifest location based on target to query about
131 try:
132 mdir = self.get_dir_from_bb_var('DEPLOY_DIR_IMAGE',
133 self.buildtarget)
134 mfilename = get_bb_var("IMAGE_LINK_NAME", self.buildtarget)\
135 + ".manifest"
136 mpath = os.path.join(mdir, mfilename)
137 if not os.path.isfile(mpath): raise IOError
138 m_entry = ManifestEntry(mpath)
139
140 pkgdata_dir = {}
141 pkgdata_dir = self.get_dir_from_bb_var('PKGDATA_DIR',
142 self.buildtarget)
143 revdir = os.path.join(pkgdata_dir, 'runtime-reverse')
144 if not os.path.exists(revdir): raise IOError
145 except OSError:
146 raise unittest.SkipTest("{}: Error in obtaining manifest dirs"\
147 .format(self.classname))
148 except IOError:
149 msg = "{}: Error cannot find manifests in dir:\n{}"\
150 .format(self.classname, mdir)
151 self.fail(msg)
152
153 self.log.debug("{}: Check manifest {}"\
154 .format(self.classname, m_entry.file))
155 m_entry.missing = self.check_manifest_entries(\
156 m_entry.file, revdir)
157 if m_entry.missing:
158 msg = '{}: {} Error has the following missing entries'\
159 .format(self.classname, m_entry.file)
160 logmsg = msg+':\n'+'\n'.join(m_entry.missing)
161 self.log.debug(logmsg)
162 self.log.info(msg)
163 self.fail(logmsg)