diff options
author | Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com> | 2017-05-12 14:40:21 -0700 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-06-06 19:02:43 +0100 |
commit | 157c3be2ca93f076033f725ec1ee912df91f7488 (patch) | |
tree | 8ef896ff7adf78d63b34059cd5b017a4f0a3419a /meta/lib/oeqa/selftest/pkgdata.py | |
parent | 10c512b60d1167122b5fe778b93838dca3def717 (diff) | |
download | poky-157c3be2ca93f076033f725ec1ee912df91f7488.tar.gz |
oeqa/selftest/cases: Migrate test cases into the new oe-qa framework
New framework has different classes/decorators so adapt current test cases to
support these. Changes include changes on base classes and decorators.
Also include paths in selftest/__init__.py isn't needed because the
loader is the standard unittest one.
(From OE-Core rev: ddbbefdd124604d10bd47dd0266b55a764fcc0ab)
Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/selftest/pkgdata.py')
-rw-r--r-- | meta/lib/oeqa/selftest/pkgdata.py | 227 |
1 files changed, 0 insertions, 227 deletions
diff --git a/meta/lib/oeqa/selftest/pkgdata.py b/meta/lib/oeqa/selftest/pkgdata.py deleted file mode 100644 index d69c3c800a..0000000000 --- a/meta/lib/oeqa/selftest/pkgdata.py +++ /dev/null | |||
@@ -1,227 +0,0 @@ | |||
1 | import unittest | ||
2 | import os | ||
3 | import tempfile | ||
4 | import logging | ||
5 | import fnmatch | ||
6 | |||
7 | import oeqa.utils.ftools as ftools | ||
8 | from oeqa.selftest.base import oeSelfTest | ||
9 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars | ||
10 | from oeqa.utils.decorators import testcase | ||
11 | |||
12 | class OePkgdataUtilTests(oeSelfTest): | ||
13 | |||
14 | @classmethod | ||
15 | def setUpClass(cls): | ||
16 | # Ensure we have the right data in pkgdata | ||
17 | logger = logging.getLogger("selftest") | ||
18 | logger.info('Running bitbake to generate pkgdata') | ||
19 | bitbake('busybox zlib m4') | ||
20 | |||
21 | @testcase(1203) | ||
22 | def test_lookup_pkg(self): | ||
23 | # Forward tests | ||
24 | result = runCmd('oe-pkgdata-util lookup-pkg "zlib busybox"') | ||
25 | self.assertEqual(result.output, 'libz1\nbusybox') | ||
26 | result = runCmd('oe-pkgdata-util lookup-pkg zlib-dev') | ||
27 | self.assertEqual(result.output, 'libz-dev') | ||
28 | result = runCmd('oe-pkgdata-util lookup-pkg nonexistentpkg', ignore_status=True) | ||
29 | self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) | ||
30 | self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg') | ||
31 | # Reverse tests | ||
32 | result = runCmd('oe-pkgdata-util lookup-pkg -r "libz1 busybox"') | ||
33 | self.assertEqual(result.output, 'zlib\nbusybox') | ||
34 | result = runCmd('oe-pkgdata-util lookup-pkg -r libz-dev') | ||
35 | self.assertEqual(result.output, 'zlib-dev') | ||
36 | result = runCmd('oe-pkgdata-util lookup-pkg -r nonexistentpkg', ignore_status=True) | ||
37 | self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) | ||
38 | self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg') | ||
39 | |||
40 | @testcase(1205) | ||
41 | def test_read_value(self): | ||
42 | result = runCmd('oe-pkgdata-util read-value PN libz1') | ||
43 | self.assertEqual(result.output, 'zlib') | ||
44 | result = runCmd('oe-pkgdata-util read-value PKG libz1') | ||
45 | self.assertEqual(result.output, 'libz1') | ||
46 | result = runCmd('oe-pkgdata-util read-value PKGSIZE m4') | ||
47 | pkgsize = int(result.output.strip()) | ||
48 | self.assertGreater(pkgsize, 1, "Size should be greater than 1. %s" % result.output) | ||
49 | |||
50 | @testcase(1198) | ||
51 | def test_find_path(self): | ||
52 | result = runCmd('oe-pkgdata-util find-path /lib/libz.so.1') | ||
53 | self.assertEqual(result.output, 'zlib: /lib/libz.so.1') | ||
54 | result = runCmd('oe-pkgdata-util find-path /usr/bin/m4') | ||
55 | self.assertEqual(result.output, 'm4: /usr/bin/m4') | ||
56 | result = runCmd('oe-pkgdata-util find-path /not/exist', ignore_status=True) | ||
57 | self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) | ||
58 | self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /not/exist') | ||
59 | |||
60 | @testcase(1204) | ||
61 | def test_lookup_recipe(self): | ||
62 | result = runCmd('oe-pkgdata-util lookup-recipe "libz-staticdev busybox"') | ||
63 | self.assertEqual(result.output, 'zlib\nbusybox') | ||
64 | result = runCmd('oe-pkgdata-util lookup-recipe libz-dbg') | ||
65 | self.assertEqual(result.output, 'zlib') | ||
66 | result = runCmd('oe-pkgdata-util lookup-recipe nonexistentpkg', ignore_status=True) | ||
67 | self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output) | ||
68 | self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg') | ||
69 | |||
70 | @testcase(1202) | ||
71 | def test_list_pkgs(self): | ||
72 | # No arguments | ||
73 | result = runCmd('oe-pkgdata-util list-pkgs') | ||
74 | pkglist = result.output.split() | ||
75 | self.assertIn('zlib', pkglist, "Listed packages: %s" % result.output) | ||
76 | self.assertIn('zlib-dev', pkglist, "Listed packages: %s" % result.output) | ||
77 | # No pkgspec, runtime | ||
78 | result = runCmd('oe-pkgdata-util list-pkgs -r') | ||
79 | pkglist = result.output.split() | ||
80 | self.assertIn('libz-dev', pkglist, "Listed packages: %s" % result.output) | ||
81 | # With recipe specified | ||
82 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib') | ||
83 | pkglist = sorted(result.output.split()) | ||
84 | try: | ||
85 | pkglist.remove('zlib-ptest') # in case ptest is disabled | ||
86 | except ValueError: | ||
87 | pass | ||
88 | self.assertEqual(pkglist, ['zlib', 'zlib-dbg', 'zlib-dev', 'zlib-doc', 'zlib-staticdev'], "Packages listed after remove: %s" % result.output) | ||
89 | # With recipe specified, runtime | ||
90 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib -r') | ||
91 | pkglist = sorted(result.output.split()) | ||
92 | try: | ||
93 | pkglist.remove('libz-ptest') # in case ptest is disabled | ||
94 | except ValueError: | ||
95 | pass | ||
96 | self.assertEqual(pkglist, ['libz-dbg', 'libz-dev', 'libz-doc', 'libz-staticdev', 'libz1'], "Packages listed after remove: %s" % result.output) | ||
97 | # With recipe specified and unpackaged | ||
98 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib -u') | ||
99 | pkglist = sorted(result.output.split()) | ||
100 | self.assertIn('zlib-locale', pkglist, "Listed packages: %s" % result.output) | ||
101 | # With recipe specified and unpackaged, runtime | ||
102 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib -u -r') | ||
103 | pkglist = sorted(result.output.split()) | ||
104 | self.assertIn('libz-locale', pkglist, "Listed packages: %s" % result.output) | ||
105 | # With recipe specified and pkgspec | ||
106 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib "*-d*"') | ||
107 | pkglist = sorted(result.output.split()) | ||
108 | self.assertEqual(pkglist, ['zlib-dbg', 'zlib-dev', 'zlib-doc'], "Packages listed: %s" % result.output) | ||
109 | # With recipe specified and pkgspec, runtime | ||
110 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib -r "*-d*"') | ||
111 | pkglist = sorted(result.output.split()) | ||
112 | self.assertEqual(pkglist, ['libz-dbg', 'libz-dev', 'libz-doc'], "Packages listed: %s" % result.output) | ||
113 | |||
114 | @testcase(1201) | ||
115 | def test_list_pkg_files(self): | ||
116 | def splitoutput(output): | ||
117 | files = {} | ||
118 | curpkg = None | ||
119 | for line in output.splitlines(): | ||
120 | if line.startswith('\t'): | ||
121 | self.assertTrue(curpkg, 'Unexpected non-package line:\n%s' % line) | ||
122 | files[curpkg].append(line.strip()) | ||
123 | else: | ||
124 | self.assertTrue(line.rstrip().endswith(':'), 'Invalid package line in output:\n%s' % line) | ||
125 | curpkg = line.split(':')[0] | ||
126 | files[curpkg] = [] | ||
127 | return files | ||
128 | bb_vars = get_bb_vars(['base_libdir', 'libdir', 'includedir', 'mandir']) | ||
129 | base_libdir = bb_vars['base_libdir'] | ||
130 | libdir = bb_vars['libdir'] | ||
131 | includedir = bb_vars['includedir'] | ||
132 | mandir = bb_vars['mandir'] | ||
133 | # Test recipe-space package name | ||
134 | result = runCmd('oe-pkgdata-util list-pkg-files zlib-dev zlib-doc') | ||
135 | files = splitoutput(result.output) | ||
136 | self.assertIn('zlib-dev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
137 | self.assertIn('zlib-doc', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
138 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev']) | ||
139 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc']) | ||
140 | # Test runtime package name | ||
141 | result = runCmd('oe-pkgdata-util list-pkg-files -r libz1 libz-dev') | ||
142 | files = splitoutput(result.output) | ||
143 | self.assertIn('libz1', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
144 | self.assertIn('libz-dev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
145 | self.assertGreater(len(files['libz1']), 1) | ||
146 | libspec = os.path.join(base_libdir, 'libz.so.1.*') | ||
147 | found = False | ||
148 | for fileitem in files['libz1']: | ||
149 | if fnmatch.fnmatchcase(fileitem, libspec): | ||
150 | found = True | ||
151 | break | ||
152 | self.assertTrue(found, 'Could not find zlib library file %s in libz1 package file list: %s' % (libspec, files['libz1'])) | ||
153 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev']) | ||
154 | # Test recipe | ||
155 | result = runCmd('oe-pkgdata-util list-pkg-files -p zlib') | ||
156 | files = splitoutput(result.output) | ||
157 | self.assertIn('zlib-dbg', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
158 | self.assertIn('zlib-doc', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
159 | self.assertIn('zlib-dev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
160 | self.assertIn('zlib-staticdev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
161 | self.assertIn('zlib', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
162 | self.assertNotIn('zlib-locale', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
163 | # (ignore ptest, might not be there depending on config) | ||
164 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev']) | ||
165 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc']) | ||
166 | self.assertIn(os.path.join(libdir, 'libz.a'), files['zlib-staticdev']) | ||
167 | # Test recipe, runtime | ||
168 | result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -r') | ||
169 | files = splitoutput(result.output) | ||
170 | self.assertIn('libz-dbg', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
171 | self.assertIn('libz-doc', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
172 | self.assertIn('libz-dev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
173 | self.assertIn('libz-staticdev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
174 | self.assertIn('libz1', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
175 | self.assertNotIn('libz-locale', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
176 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev']) | ||
177 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['libz-doc']) | ||
178 | self.assertIn(os.path.join(libdir, 'libz.a'), files['libz-staticdev']) | ||
179 | # Test recipe, unpackaged | ||
180 | result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -u') | ||
181 | files = splitoutput(result.output) | ||
182 | self.assertIn('zlib-dbg', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
183 | self.assertIn('zlib-doc', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
184 | self.assertIn('zlib-dev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
185 | self.assertIn('zlib-staticdev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
186 | self.assertIn('zlib', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
187 | self.assertIn('zlib-locale', list(files.keys()), "listed pkgs. files: %s" %result.output) # this is the key one | ||
188 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev']) | ||
189 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc']) | ||
190 | self.assertIn(os.path.join(libdir, 'libz.a'), files['zlib-staticdev']) | ||
191 | # Test recipe, runtime, unpackaged | ||
192 | result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -r -u') | ||
193 | files = splitoutput(result.output) | ||
194 | self.assertIn('libz-dbg', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
195 | self.assertIn('libz-doc', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
196 | self.assertIn('libz-dev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
197 | self.assertIn('libz-staticdev', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
198 | self.assertIn('libz1', list(files.keys()), "listed pkgs. files: %s" %result.output) | ||
199 | self.assertIn('libz-locale', list(files.keys()), "listed pkgs. files: %s" %result.output) # this is the key one | ||
200 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev']) | ||
201 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['libz-doc']) | ||
202 | self.assertIn(os.path.join(libdir, 'libz.a'), files['libz-staticdev']) | ||
203 | |||
204 | @testcase(1200) | ||
205 | def test_glob(self): | ||
206 | tempdir = tempfile.mkdtemp(prefix='pkgdataqa') | ||
207 | self.track_for_cleanup(tempdir) | ||
208 | pkglistfile = os.path.join(tempdir, 'pkglist') | ||
209 | with open(pkglistfile, 'w') as f: | ||
210 | f.write('libz1\n') | ||
211 | f.write('busybox\n') | ||
212 | result = runCmd('oe-pkgdata-util glob %s "*-dev"' % pkglistfile) | ||
213 | desiredresult = ['libz-dev', 'busybox-dev'] | ||
214 | self.assertEqual(sorted(result.output.split()), sorted(desiredresult)) | ||
215 | # The following should not error (because when we use this during rootfs construction, sometimes the complementary package won't exist) | ||
216 | result = runCmd('oe-pkgdata-util glob %s "*-nonexistent"' % pkglistfile) | ||
217 | self.assertEqual(result.output, '') | ||
218 | # Test exclude option | ||
219 | result = runCmd('oe-pkgdata-util glob %s "*-dev *-dbg" -x "^libz"' % pkglistfile) | ||
220 | resultlist = result.output.split() | ||
221 | self.assertNotIn('libz-dev', resultlist) | ||
222 | self.assertNotIn('libz-dbg', resultlist) | ||
223 | |||
224 | @testcase(1206) | ||
225 | def test_specify_pkgdatadir(self): | ||
226 | result = runCmd('oe-pkgdata-util -p %s lookup-pkg zlib' % get_bb_var('PKGDATA_DIR')) | ||
227 | self.assertEqual(result.output, 'libz1') | ||