blob: aa05f40d6ac6c775109a8d72bbff26fc771961ba [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001import os
2import tempfile
3import fnmatch
4
5from oeqa.selftest.case import OESelftestTestCase
6from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars
7from oeqa.core.decorator.oeid import OETestID
8
9class OePkgdataUtilTests(OESelftestTestCase):
10
11 @classmethod
12 def setUpClass(cls):
13 super(OePkgdataUtilTests, cls).setUpClass()
14 # Ensure we have the right data in pkgdata
15 cls.logger.info('Running bitbake to generate pkgdata')
Brad Bishop19323692019-04-05 15:28:33 -040016 bitbake('target-sdk-provides-dummy -c clean')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017 bitbake('busybox zlib m4')
18
19 @OETestID(1203)
20 def test_lookup_pkg(self):
21 # Forward tests
22 result = runCmd('oe-pkgdata-util lookup-pkg "zlib busybox"')
23 self.assertEqual(result.output, 'libz1\nbusybox')
24 result = runCmd('oe-pkgdata-util lookup-pkg zlib-dev')
25 self.assertEqual(result.output, 'libz-dev')
26 result = runCmd('oe-pkgdata-util lookup-pkg nonexistentpkg', ignore_status=True)
27 self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output)
28 self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg')
29 # Reverse tests
30 result = runCmd('oe-pkgdata-util lookup-pkg -r "libz1 busybox"')
31 self.assertEqual(result.output, 'zlib\nbusybox')
32 result = runCmd('oe-pkgdata-util lookup-pkg -r libz-dev')
33 self.assertEqual(result.output, 'zlib-dev')
34 result = runCmd('oe-pkgdata-util lookup-pkg -r nonexistentpkg', ignore_status=True)
35 self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output)
36 self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg')
37
38 @OETestID(1205)
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 PKG libz1')
43 self.assertEqual(result.output, 'libz1')
44 result = runCmd('oe-pkgdata-util read-value PKGSIZE m4')
45 pkgsize = int(result.output.strip())
46 self.assertGreater(pkgsize, 1, "Size should be greater than 1. %s" % result.output)
47
48 @OETestID(1198)
49 def test_find_path(self):
50 result = runCmd('oe-pkgdata-util find-path /lib/libz.so.1')
51 self.assertEqual(result.output, 'zlib: /lib/libz.so.1')
52 result = runCmd('oe-pkgdata-util find-path /usr/bin/m4')
53 self.assertEqual(result.output, 'm4: /usr/bin/m4')
54 result = runCmd('oe-pkgdata-util find-path /not/exist', ignore_status=True)
55 self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output)
56 self.assertEqual(result.output, 'ERROR: Unable to find any package producing path /not/exist')
57
58 @OETestID(1204)
59 def test_lookup_recipe(self):
60 result = runCmd('oe-pkgdata-util lookup-recipe "libz-staticdev busybox"')
61 self.assertEqual(result.output, 'zlib\nbusybox')
62 result = runCmd('oe-pkgdata-util lookup-recipe libz-dbg')
63 self.assertEqual(result.output, 'zlib')
64 result = runCmd('oe-pkgdata-util lookup-recipe nonexistentpkg', ignore_status=True)
65 self.assertEqual(result.status, 1, "Status different than 1. output: %s" % result.output)
66 self.assertEqual(result.output, 'ERROR: The following packages could not be found: nonexistentpkg')
67
68 @OETestID(1202)
69 def test_list_pkgs(self):
70 # No arguments
71 result = runCmd('oe-pkgdata-util list-pkgs')
72 pkglist = result.output.split()
73 self.assertIn('zlib', pkglist, "Listed packages: %s" % result.output)
74 self.assertIn('zlib-dev', pkglist, "Listed packages: %s" % result.output)
75 # No pkgspec, runtime
76 result = runCmd('oe-pkgdata-util list-pkgs -r')
77 pkglist = result.output.split()
78 self.assertIn('libz-dev', pkglist, "Listed packages: %s" % result.output)
79 # With recipe specified
80 result = runCmd('oe-pkgdata-util list-pkgs -p zlib')
81 pkglist = sorted(result.output.split())
82 try:
83 pkglist.remove('zlib-ptest') # in case ptest is disabled
84 except ValueError:
85 pass
Brad Bishop19323692019-04-05 15:28:33 -040086 self.assertEqual(pkglist, ['zlib', 'zlib-dbg', 'zlib-dev', 'zlib-doc', 'zlib-src', 'zlib-staticdev'], "Packages listed after remove: %s" % result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050087 # With recipe specified, runtime
88 result = runCmd('oe-pkgdata-util list-pkgs -p zlib -r')
89 pkglist = sorted(result.output.split())
90 try:
91 pkglist.remove('libz-ptest') # in case ptest is disabled
92 except ValueError:
93 pass
Brad Bishop19323692019-04-05 15:28:33 -040094 self.assertEqual(pkglist, ['libz-dbg', 'libz-dev', 'libz-doc', 'libz-src', 'libz-staticdev', 'libz1'], "Packages listed after remove: %s" % result.output)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050095 # With recipe specified and unpackaged
96 result = runCmd('oe-pkgdata-util list-pkgs -p zlib -u')
97 pkglist = sorted(result.output.split())
98 self.assertIn('zlib-locale', pkglist, "Listed packages: %s" % result.output)
99 # With recipe specified and unpackaged, runtime
100 result = runCmd('oe-pkgdata-util list-pkgs -p zlib -u -r')
101 pkglist = sorted(result.output.split())
102 self.assertIn('libz-locale', pkglist, "Listed packages: %s" % result.output)
103 # With recipe specified and pkgspec
104 result = runCmd('oe-pkgdata-util list-pkgs -p zlib "*-d*"')
105 pkglist = sorted(result.output.split())
106 self.assertEqual(pkglist, ['zlib-dbg', 'zlib-dev', 'zlib-doc'], "Packages listed: %s" % result.output)
107 # With recipe specified and pkgspec, runtime
108 result = runCmd('oe-pkgdata-util list-pkgs -p zlib -r "*-d*"')
109 pkglist = sorted(result.output.split())
110 self.assertEqual(pkglist, ['libz-dbg', 'libz-dev', 'libz-doc'], "Packages listed: %s" % result.output)
111
112 @OETestID(1201)
113 def test_list_pkg_files(self):
114 def splitoutput(output):
115 files = {}
116 curpkg = None
117 for line in output.splitlines():
118 if line.startswith('\t'):
119 self.assertTrue(curpkg, 'Unexpected non-package line:\n%s' % line)
120 files[curpkg].append(line.strip())
121 else:
122 self.assertTrue(line.rstrip().endswith(':'), 'Invalid package line in output:\n%s' % line)
123 curpkg = line.split(':')[0]
124 files[curpkg] = []
125 return files
126 bb_vars = get_bb_vars(['base_libdir', 'libdir', 'includedir', 'mandir'])
127 base_libdir = bb_vars['base_libdir']
128 libdir = bb_vars['libdir']
129 includedir = bb_vars['includedir']
130 mandir = bb_vars['mandir']
131 # Test recipe-space package name
132 result = runCmd('oe-pkgdata-util list-pkg-files zlib-dev zlib-doc')
133 files = splitoutput(result.output)
134 self.assertIn('zlib-dev', list(files.keys()), "listed pkgs. files: %s" %result.output)
135 self.assertIn('zlib-doc', list(files.keys()), "listed pkgs. files: %s" %result.output)
136 self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev'])
137 self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc'])
138 # Test runtime package name
139 result = runCmd('oe-pkgdata-util list-pkg-files -r libz1 libz-dev')
140 files = splitoutput(result.output)
141 self.assertIn('libz1', list(files.keys()), "listed pkgs. files: %s" %result.output)
142 self.assertIn('libz-dev', list(files.keys()), "listed pkgs. files: %s" %result.output)
143 self.assertGreater(len(files['libz1']), 1)
144 libspec = os.path.join(base_libdir, 'libz.so.1.*')
145 found = False
146 for fileitem in files['libz1']:
147 if fnmatch.fnmatchcase(fileitem, libspec):
148 found = True
149 break
150 self.assertTrue(found, 'Could not find zlib library file %s in libz1 package file list: %s' % (libspec, files['libz1']))
151 self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev'])
152 # Test recipe
153 result = runCmd('oe-pkgdata-util list-pkg-files -p zlib')
154 files = splitoutput(result.output)
155 self.assertIn('zlib-dbg', list(files.keys()), "listed pkgs. files: %s" %result.output)
156 self.assertIn('zlib-doc', list(files.keys()), "listed pkgs. files: %s" %result.output)
157 self.assertIn('zlib-dev', list(files.keys()), "listed pkgs. files: %s" %result.output)
158 self.assertIn('zlib-staticdev', list(files.keys()), "listed pkgs. files: %s" %result.output)
159 self.assertIn('zlib', list(files.keys()), "listed pkgs. files: %s" %result.output)
160 self.assertNotIn('zlib-locale', list(files.keys()), "listed pkgs. files: %s" %result.output)
161 # (ignore ptest, might not be there depending on config)
162 self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev'])
163 self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc'])
164 self.assertIn(os.path.join(libdir, 'libz.a'), files['zlib-staticdev'])
165 # Test recipe, runtime
166 result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -r')
167 files = splitoutput(result.output)
168 self.assertIn('libz-dbg', list(files.keys()), "listed pkgs. files: %s" %result.output)
169 self.assertIn('libz-doc', list(files.keys()), "listed pkgs. files: %s" %result.output)
170 self.assertIn('libz-dev', list(files.keys()), "listed pkgs. files: %s" %result.output)
171 self.assertIn('libz-staticdev', list(files.keys()), "listed pkgs. files: %s" %result.output)
172 self.assertIn('libz1', list(files.keys()), "listed pkgs. files: %s" %result.output)
173 self.assertNotIn('libz-locale', list(files.keys()), "listed pkgs. files: %s" %result.output)
174 self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev'])
175 self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['libz-doc'])
176 self.assertIn(os.path.join(libdir, 'libz.a'), files['libz-staticdev'])
177 # Test recipe, unpackaged
178 result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -u')
179 files = splitoutput(result.output)
180 self.assertIn('zlib-dbg', list(files.keys()), "listed pkgs. files: %s" %result.output)
181 self.assertIn('zlib-doc', list(files.keys()), "listed pkgs. files: %s" %result.output)
182 self.assertIn('zlib-dev', list(files.keys()), "listed pkgs. files: %s" %result.output)
183 self.assertIn('zlib-staticdev', list(files.keys()), "listed pkgs. files: %s" %result.output)
184 self.assertIn('zlib', list(files.keys()), "listed pkgs. files: %s" %result.output)
185 self.assertIn('zlib-locale', list(files.keys()), "listed pkgs. files: %s" %result.output) # this is the key one
186 self.assertIn(os.path.join(includedir, 'zlib.h'), files['zlib-dev'])
187 self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['zlib-doc'])
188 self.assertIn(os.path.join(libdir, 'libz.a'), files['zlib-staticdev'])
189 # Test recipe, runtime, unpackaged
190 result = runCmd('oe-pkgdata-util list-pkg-files -p zlib -r -u')
191 files = splitoutput(result.output)
192 self.assertIn('libz-dbg', list(files.keys()), "listed pkgs. files: %s" %result.output)
193 self.assertIn('libz-doc', list(files.keys()), "listed pkgs. files: %s" %result.output)
194 self.assertIn('libz-dev', list(files.keys()), "listed pkgs. files: %s" %result.output)
195 self.assertIn('libz-staticdev', list(files.keys()), "listed pkgs. files: %s" %result.output)
196 self.assertIn('libz1', list(files.keys()), "listed pkgs. files: %s" %result.output)
197 self.assertIn('libz-locale', list(files.keys()), "listed pkgs. files: %s" %result.output) # this is the key one
198 self.assertIn(os.path.join(includedir, 'zlib.h'), files['libz-dev'])
199 self.assertIn(os.path.join(mandir, 'man3/zlib.3'), files['libz-doc'])
200 self.assertIn(os.path.join(libdir, 'libz.a'), files['libz-staticdev'])
201
202 @OETestID(1200)
203 def test_glob(self):
204 tempdir = tempfile.mkdtemp(prefix='pkgdataqa')
205 self.track_for_cleanup(tempdir)
206 pkglistfile = os.path.join(tempdir, 'pkglist')
207 with open(pkglistfile, 'w') as f:
208 f.write('libz1\n')
209 f.write('busybox\n')
210 result = runCmd('oe-pkgdata-util glob %s "*-dev"' % pkglistfile)
211 desiredresult = ['libz-dev', 'busybox-dev']
212 self.assertEqual(sorted(result.output.split()), sorted(desiredresult))
213 # The following should not error (because when we use this during rootfs construction, sometimes the complementary package won't exist)
214 result = runCmd('oe-pkgdata-util glob %s "*-nonexistent"' % pkglistfile)
215 self.assertEqual(result.output, '')
216 # Test exclude option
217 result = runCmd('oe-pkgdata-util glob %s "*-dev *-dbg" -x "^libz"' % pkglistfile)
218 resultlist = result.output.split()
219 self.assertNotIn('libz-dev', resultlist)
220 self.assertNotIn('libz-dbg', resultlist)
221
222 @OETestID(1206)
223 def test_specify_pkgdatadir(self):
224 result = runCmd('oe-pkgdata-util -p %s lookup-pkg zlib' % get_bb_var('PKGDATA_DIR'))
225 self.assertEqual(result.output, 'libz1')