diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2015-02-06 11:28:52 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-02-14 08:41:01 +0000 |
commit | 1920ef31f3ac02692086e2db18dcb59f65bf7ec4 (patch) | |
tree | d4e662d45573d2fef64279a5037837efa6e89c2c /meta | |
parent | cfc12dfc34bdea02af29dda358b7af8a355fe0a4 (diff) | |
download | poky-1920ef31f3ac02692086e2db18dcb59f65bf7ec4.tar.gz |
oe-pkgdata-util: add some QA tests
Test each of the subcommands that this utility provides.
(From OE-Core rev: 725526139debf12d115fada6bd465a297e169080)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/selftest/pkgdata.py | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/pkgdata.py b/meta/lib/oeqa/selftest/pkgdata.py new file mode 100644 index 0000000000..f689bf344e --- /dev/null +++ b/meta/lib/oeqa/selftest/pkgdata.py | |||
@@ -0,0 +1,213 @@ | |||
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 | ||
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('glibc busybox zlib bash') | ||
20 | |||
21 | def test_lookup_pkg(self): | ||
22 | # Forward tests | ||
23 | result = runCmd('oe-pkgdata-util lookup-pkg "glibc busybox"') | ||
24 | self.assertEqual(result.output, 'libc6\nbusybox') | ||
25 | result = runCmd('oe-pkgdata-util lookup-pkg zlib-dev') | ||
26 | self.assertEqual(result.output, 'libz-dev') | ||
27 | result = runCmd('oe-pkgdata-util lookup-pkg nonexistentpkg', ignore_status=True) | ||
28 | self.assertEqual(result.status, 1) | ||
29 | self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg') | ||
30 | # Reverse tests | ||
31 | result = runCmd('oe-pkgdata-util lookup-pkg -r "libc6 busybox"') | ||
32 | self.assertEqual(result.output, 'glibc\nbusybox') | ||
33 | result = runCmd('oe-pkgdata-util lookup-pkg -r libz-dev') | ||
34 | self.assertEqual(result.output, 'zlib-dev') | ||
35 | result = runCmd('oe-pkgdata-util lookup-pkg -r nonexistentpkg', ignore_status=True) | ||
36 | self.assertEqual(result.status, 1) | ||
37 | self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg') | ||
38 | |||
39 | def test_read_value(self): | ||
40 | result = runCmd('oe-pkgdata-util read-value PN libz1') | ||
41 | self.assertEqual(result.output, 'zlib') | ||
42 | result = runCmd('oe-pkgdata-util read-value PKGSIZE bash') | ||
43 | pkgsize = int(result.output.strip()) | ||
44 | self.assertGreater(pkgsize, 1) | ||
45 | |||
46 | def test_find_path(self): | ||
47 | result = runCmd('oe-pkgdata-util find-path /lib/libc.so.6') | ||
48 | self.assertEqual(result.output, 'glibc: /lib/libc.so.6') | ||
49 | result = runCmd('oe-pkgdata-util find-path /bin/bash') | ||
50 | self.assertEqual(result.output, 'bash: /bin/bash') | ||
51 | result = runCmd('oe-pkgdata-util find-path /not/exist', ignore_status=True) | ||
52 | self.assertEqual(result.status, 1) | ||
53 | self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /not/exist') | ||
54 | |||
55 | def test_lookup_recipe(self): | ||
56 | result = runCmd('oe-pkgdata-util lookup-recipe "libc6-staticdev busybox"') | ||
57 | self.assertEqual(result.output, 'glibc\nbusybox') | ||
58 | result = runCmd('oe-pkgdata-util lookup-recipe libz-dbg') | ||
59 | self.assertEqual(result.output, 'zlib') | ||
60 | result = runCmd('oe-pkgdata-util lookup-recipe nonexistentpkg', ignore_status=True) | ||
61 | self.assertEqual(result.status, 1) | ||
62 | self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg') | ||
63 | |||
64 | def test_list_pkgs(self): | ||
65 | # No arguments | ||
66 | result = runCmd('oe-pkgdata-util list-pkgs') | ||
67 | pkglist = result.output.split() | ||
68 | self.assertIn('glibc-utils', pkglist) | ||
69 | self.assertIn('zlib-dev', pkglist) | ||
70 | # No pkgspec, runtime | ||
71 | result = runCmd('oe-pkgdata-util list-pkgs -r') | ||
72 | pkglist = result.output.split() | ||
73 | self.assertIn('libc6-utils', pkglist) | ||
74 | self.assertIn('libz-dev', pkglist) | ||
75 | # With recipe specified | ||
76 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib') | ||
77 | pkglist = sorted(result.output.split()) | ||
78 | try: | ||
79 | pkglist.remove('zlib-ptest') # in case ptest is disabled | ||
80 | except ValueError: | ||
81 | pass | ||
82 | self.assertEqual(pkglist, ['zlib', 'zlib-dbg', 'zlib-dev', 'zlib-doc', 'zlib-staticdev']) | ||
83 | # With recipe specified, runtime | ||
84 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib -r') | ||
85 | pkglist = sorted(result.output.split()) | ||
86 | try: | ||
87 | pkglist.remove('libz-ptest') # in case ptest is disabled | ||
88 | except ValueError: | ||
89 | pass | ||
90 | self.assertEqual(pkglist, ['libz-dbg', 'libz-dev', 'libz-doc', 'libz-staticdev', 'libz1']) | ||
91 | # With recipe specified and unpackaged | ||
92 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib -u') | ||
93 | pkglist = sorted(result.output.split()) | ||
94 | self.assertIn('zlib-locale', pkglist) | ||
95 | # With recipe specified and unpackaged, runtime | ||
96 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib -u -r') | ||
97 | pkglist = sorted(result.output.split()) | ||
98 | self.assertIn('libz-locale', pkglist) | ||
99 | # With recipe specified and pkgspec | ||
100 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib "*-d*"') | ||
101 | pkglist = sorted(result.output.split()) | ||
102 | self.assertEqual(pkglist, ['zlib-dbg', 'zlib-dev', 'zlib-doc']) | ||
103 | # With recipe specified and pkgspec, runtime | ||
104 | result = runCmd('oe-pkgdata-util list-pkgs -p zlib -r "*-d*"') | ||
105 | pkglist = sorted(result.output.split()) | ||
106 | self.assertEqual(pkglist, ['libz-dbg', 'libz-dev', 'libz-doc']) | ||
107 | |||
108 | def test_list_pkg_files(self): | ||
109 | def splitoutput(output): | ||
110 | files = {} | ||
111 | curpkg = None | ||
112 | for line in output.splitlines(): | ||
113 | if line.startswith('\t'): | ||
114 | self.assertTrue(curpkg, 'Unexpected non-package line:\n%s' % line) | ||
115 | files[curpkg].append(line.strip()) | ||
116 | else: | ||
117 | self.assertTrue(line.rstrip().endswith(':'), 'Invalid package line in output:\n%s' % line) | ||
118 | curpkg = line.split(':')[0] | ||
119 | files[curpkg] = [] | ||
120 | return files | ||
121 | base_libdir = get_bb_var('base_libdir') | ||
122 | libdir = get_bb_var('libdir') | ||
123 | includedir = get_bb_var('includedir') | ||
124 | mandir = get_bb_var('mandir') | ||
125 | # Test recipe-space package name | ||
126 | result = runCmd('oe-pkgdata-util list-pkg-files zlib-dev zlib-doc') | ||
127 | files = splitoutput(result.output) | ||
128 | self.assertIn('zlib-dev', files.keys()) | ||
129 | self.assertIn('zlib-doc', files.keys()) | ||
130 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev']) | ||
131 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc']) | ||
132 | # Test runtime package name | ||
133 | result = runCmd('oe-pkgdata-util list-pkg-files -r libz1 libz-dev') | ||
134 | files = splitoutput(result.output) | ||
135 | self.assertIn('libz1', files.keys()) | ||
136 | self.assertIn('libz-dev', files.keys()) | ||
137 | self.assertGreater(len(files['libz1']), 1) | ||
138 | libspec = os.path.join(base_libdir, 'libz.so.1.*') | ||
139 | found = False | ||
140 | for fileitem in files['libz1']: | ||
141 | if fnmatch.fnmatchcase(fileitem, libspec): | ||
142 | found = True | ||
143 | break | ||
144 | self.assertTrue(found, 'Could not find zlib library file %s in libz1 package file list: %s' % (libspec, files['libz1'])) | ||
145 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev']) | ||
146 | # Test recipe | ||
147 | result = runCmd('oe-pkgdata-util list-pkg-files -p zlib') | ||
148 | files = splitoutput(result.output) | ||
149 | self.assertIn('zlib-dbg', files.keys()) | ||
150 | self.assertIn('zlib-doc', files.keys()) | ||
151 | self.assertIn('zlib-dev', files.keys()) | ||
152 | self.assertIn('zlib-staticdev', files.keys()) | ||
153 | self.assertIn('zlib', files.keys()) | ||
154 | self.assertNotIn('zlib-locale', files.keys()) | ||
155 | # (ignore ptest, might not be there depending on config) | ||
156 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev']) | ||
157 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc']) | ||
158 | self.assertIn(os.path.join(libdir, 'libz.a'), files['zlib-staticdev']) | ||
159 | # Test recipe, runtime | ||
160 | result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -r') | ||
161 | files = splitoutput(result.output) | ||
162 | self.assertIn('libz-dbg', files.keys()) | ||
163 | self.assertIn('libz-doc', files.keys()) | ||
164 | self.assertIn('libz-dev', files.keys()) | ||
165 | self.assertIn('libz-staticdev', files.keys()) | ||
166 | self.assertIn('libz1', files.keys()) | ||
167 | self.assertNotIn('libz-locale', files.keys()) | ||
168 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev']) | ||
169 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['libz-doc']) | ||
170 | self.assertIn(os.path.join(libdir, 'libz.a'), files['libz-staticdev']) | ||
171 | # Test recipe, unpackaged | ||
172 | result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -u') | ||
173 | files = splitoutput(result.output) | ||
174 | self.assertIn('zlib-dbg', files.keys()) | ||
175 | self.assertIn('zlib-doc', files.keys()) | ||
176 | self.assertIn('zlib-dev', files.keys()) | ||
177 | self.assertIn('zlib-staticdev', files.keys()) | ||
178 | self.assertIn('zlib', files.keys()) | ||
179 | self.assertIn('zlib-locale', files.keys()) # this is the key one | ||
180 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev']) | ||
181 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc']) | ||
182 | self.assertIn(os.path.join(libdir, 'libz.a'), files['zlib-staticdev']) | ||
183 | # Test recipe, runtime, unpackaged | ||
184 | result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -r -u') | ||
185 | files = splitoutput(result.output) | ||
186 | self.assertIn('libz-dbg', files.keys()) | ||
187 | self.assertIn('libz-doc', files.keys()) | ||
188 | self.assertIn('libz-dev', files.keys()) | ||
189 | self.assertIn('libz-staticdev', files.keys()) | ||
190 | self.assertIn('libz1', files.keys()) | ||
191 | self.assertIn('libz-locale', files.keys()) # this is the key one | ||
192 | self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev']) | ||
193 | self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['libz-doc']) | ||
194 | self.assertIn(os.path.join(libdir, 'libz.a'), files['libz-staticdev']) | ||
195 | |||
196 | def test_glob(self): | ||
197 | tempdir = tempfile.mkdtemp(prefix='pkgdataqa') | ||
198 | self.track_for_cleanup(tempdir) | ||
199 | pkglistfile = os.path.join(tempdir, 'pkglist') | ||
200 | with open(pkglistfile, 'w') as f: | ||
201 | f.write('libc6\n') | ||
202 | f.write('libz1\n') | ||
203 | f.write('busybox\n') | ||
204 | result = runCmd('oe-pkgdata-util glob %s "*-dev"' % pkglistfile) | ||
205 | desiredresult = ['libc6-dev', 'libz-dev', 'busybox-dev'] | ||
206 | self.assertEqual(sorted(result.output.split()), sorted(desiredresult)) | ||
207 | # The following should not error (because when we use this during rootfs construction, sometimes the complementary package won't exist) | ||
208 | result = runCmd('oe-pkgdata-util glob %s "*-nonexistent"' % pkglistfile) | ||
209 | self.assertEqual(result.output, '') | ||
210 | |||
211 | def test_specify_pkgdatadir(self): | ||
212 | result = runCmd('oe-pkgdata-util -p %s lookup-pkg glibc' % get_bb_var('PKGDATA_DIR')) | ||
213 | self.assertEqual(result.output, 'libc6') | ||