diff options
author | Mark Hatle <mark.hatle@windriver.com> | 2018-07-23 22:29:11 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-08-02 10:18:27 +0100 |
commit | 1ac19d1bf111a4836625f5cbb28a751d5c427395 (patch) | |
tree | ae9fa1448b425522952cbc8af90cf79912c746b1 /bitbake/lib/layerindexlib/tests | |
parent | 0dea95093115acc08f6ad19dc931d532a601cbec (diff) | |
download | poky-1ac19d1bf111a4836625f5cbb28a751d5c427395.tar.gz |
bitbake: layerindexlib: Initial layer index processing module implementation
The layer index module is expected to be used by various parts of the system
in order to access a layerindex-web (such as layers.openembedded.org) and
perform basic processing on the information, such as dependency scanning.
Along with the layerindex implementation are associated tests. The tests
properly honor BB_SKIP_NETTESTS='yes' to prevent test failures.
Tests Implemented:
- Branch, LayerItem, LayerBranch, LayerDependency, Recipe, Machine and
Distro objects
- LayerIndex setup using the layers.openembedded.org restapi
- LayerIndex storing and retrieving from a file
- LayerIndex verify dependency resolution ordering
- LayerIndex setup using simulated cooker data
(Bitbake rev: fd0ee6c10dbb5592731e56f4c592fe687682a3e6)
Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/layerindexlib/tests')
11 files changed, 670 insertions, 0 deletions
diff --git a/bitbake/lib/layerindexlib/tests/__init__.py b/bitbake/lib/layerindexlib/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/__init__.py | |||
diff --git a/bitbake/lib/layerindexlib/tests/common.py b/bitbake/lib/layerindexlib/tests/common.py new file mode 100644 index 0000000000..22a54585c8 --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/common.py | |||
@@ -0,0 +1,43 @@ | |||
1 | # Copyright (C) 2017-2018 Wind River Systems, Inc. | ||
2 | # | ||
3 | # This program is free software; you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License version 2 as | ||
5 | # published by the Free Software Foundation. | ||
6 | # | ||
7 | # This program is distributed in the hope that it will be useful, | ||
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
10 | # See the GNU General Public License for more details. | ||
11 | # | ||
12 | # You should have received a copy of the GNU General Public License | ||
13 | # along with this program; if not, write to the Free Software | ||
14 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | |||
16 | import unittest | ||
17 | import tempfile | ||
18 | import os | ||
19 | import bb | ||
20 | |||
21 | import logging | ||
22 | |||
23 | class LayersTest(unittest.TestCase): | ||
24 | |||
25 | def setUp(self): | ||
26 | self.origdir = os.getcwd() | ||
27 | self.d = bb.data.init() | ||
28 | # At least one variable needs to be set | ||
29 | self.d.setVar('DL_DIR', os.getcwd()) | ||
30 | |||
31 | if os.environ.get("BB_SKIP_NETTESTS") == "yes": | ||
32 | self.d.setVar('BB_NO_NETWORK', '1') | ||
33 | |||
34 | self.tempdir = tempfile.mkdtemp() | ||
35 | self.logger = logging.getLogger("BitBake") | ||
36 | |||
37 | def tearDown(self): | ||
38 | os.chdir(self.origdir) | ||
39 | if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes": | ||
40 | print("Not cleaning up %s. Please remove manually." % self.tempdir) | ||
41 | else: | ||
42 | bb.utils.prunedir(self.tempdir) | ||
43 | |||
diff --git a/bitbake/lib/layerindexlib/tests/cooker.py b/bitbake/lib/layerindexlib/tests/cooker.py new file mode 100644 index 0000000000..9ce6e8c3ae --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/cooker.py | |||
@@ -0,0 +1,123 @@ | |||
1 | # Copyright (C) 2018 Wind River Systems, Inc. | ||
2 | # | ||
3 | # This program is free software; you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License version 2 as | ||
5 | # published by the Free Software Foundation. | ||
6 | # | ||
7 | # This program is distributed in the hope that it will be useful, | ||
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
10 | # See the GNU General Public License for more details. | ||
11 | # | ||
12 | # You should have received a copy of the GNU General Public License | ||
13 | # along with this program; if not, write to the Free Software | ||
14 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | |||
16 | import unittest | ||
17 | import tempfile | ||
18 | import os | ||
19 | import bb | ||
20 | |||
21 | import layerindexlib | ||
22 | from layerindexlib.tests.common import LayersTest | ||
23 | |||
24 | import logging | ||
25 | |||
26 | class LayerIndexCookerTest(LayersTest): | ||
27 | |||
28 | def setUp(self): | ||
29 | LayersTest.setUp(self) | ||
30 | |||
31 | # Note this is NOT a comprehensive test of cooker, as we can't easily | ||
32 | # configure the test data. But we can emulate the basics of the layer.conf | ||
33 | # files, so that is what we will do. | ||
34 | |||
35 | new_topdir = os.path.join(os.path.dirname(__file__), "testdata") | ||
36 | new_bbpath = os.path.join(new_topdir, "build") | ||
37 | |||
38 | self.d.setVar('TOPDIR', new_topdir) | ||
39 | self.d.setVar('BBPATH', new_bbpath) | ||
40 | |||
41 | self.d = bb.parse.handle("%s/conf/bblayers.conf" % new_bbpath, self.d, True) | ||
42 | for layer in self.d.getVar('BBLAYERS').split(): | ||
43 | self.d = bb.parse.handle("%s/conf/layer.conf" % layer, self.d, True) | ||
44 | |||
45 | self.layerindex = layerindexlib.LayerIndex(self.d) | ||
46 | self.layerindex.load_layerindex('cooker://', load=['layerDependencies']) | ||
47 | |||
48 | def test_layerindex_is_empty(self): | ||
49 | self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is not empty!") | ||
50 | |||
51 | def test_dependency_resolution(self): | ||
52 | # Verify depth first searching... | ||
53 | (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python']) | ||
54 | |||
55 | first = True | ||
56 | for deplayerbranch in dependencies: | ||
57 | layerBranch = dependencies[deplayerbranch][0] | ||
58 | layerDeps = dependencies[deplayerbranch][1:] | ||
59 | |||
60 | if not first: | ||
61 | continue | ||
62 | |||
63 | first = False | ||
64 | |||
65 | # Top of the deps should be openembedded-core, since everything depends on it. | ||
66 | self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='Top dependency not openembedded-core') | ||
67 | |||
68 | # meta-python should cause an openembedded-core dependency, if not assert! | ||
69 | for dep in layerDeps: | ||
70 | if dep.layer.name == 'meta-python': | ||
71 | break | ||
72 | else: | ||
73 | self.assertTrue(False, msg='meta-python was not found') | ||
74 | |||
75 | # Only check the first element... | ||
76 | break | ||
77 | else: | ||
78 | if first: | ||
79 | # Empty list, this is bad. | ||
80 | self.assertTrue(False, msg='Empty list of dependencies') | ||
81 | |||
82 | # Last dep should be the requested item | ||
83 | layerBranch = dependencies[deplayerbranch][0] | ||
84 | self.assertEqual(layerBranch.layer.name, "meta-python", msg='Last dependency not meta-python') | ||
85 | |||
86 | def test_find_collection(self): | ||
87 | def _check(collection, expected): | ||
88 | self.logger.debug(1, "Looking for collection %s..." % collection) | ||
89 | result = self.layerindex.find_collection(collection) | ||
90 | if expected: | ||
91 | self.assertIsNotNone(result, msg="Did not find %s when it shouldn't be there" % collection) | ||
92 | else: | ||
93 | self.assertIsNone(result, msg="Found %s when it should be there" % collection) | ||
94 | |||
95 | tests = [ ('core', True), | ||
96 | ('openembedded-core', False), | ||
97 | ('networking-layer', True), | ||
98 | ('meta-python', True), | ||
99 | ('openembedded-layer', True), | ||
100 | ('notpresent', False) ] | ||
101 | |||
102 | for collection,result in tests: | ||
103 | _check(collection, result) | ||
104 | |||
105 | def test_find_layerbranch(self): | ||
106 | def _check(name, expected): | ||
107 | self.logger.debug(1, "Looking for layerbranch %s..." % name) | ||
108 | result = self.layerindex.find_layerbranch(name) | ||
109 | if expected: | ||
110 | self.assertIsNotNone(result, msg="Did not find %s when it shouldn't be there" % collection) | ||
111 | else: | ||
112 | self.assertIsNone(result, msg="Found %s when it should be there" % collection) | ||
113 | |||
114 | tests = [ ('openembedded-core', True), | ||
115 | ('core', False), | ||
116 | ('networking-layer', True), | ||
117 | ('meta-python', True), | ||
118 | ('openembedded-layer', True), | ||
119 | ('notpresent', False) ] | ||
120 | |||
121 | for collection,result in tests: | ||
122 | _check(collection, result) | ||
123 | |||
diff --git a/bitbake/lib/layerindexlib/tests/layerindexobj.py b/bitbake/lib/layerindexlib/tests/layerindexobj.py new file mode 100644 index 0000000000..e2fbb950b0 --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/layerindexobj.py | |||
@@ -0,0 +1,226 @@ | |||
1 | # Copyright (C) 2017-2018 Wind River Systems, Inc. | ||
2 | # | ||
3 | # This program is free software; you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License version 2 as | ||
5 | # published by the Free Software Foundation. | ||
6 | # | ||
7 | # This program is distributed in the hope that it will be useful, | ||
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
10 | # See the GNU General Public License for more details. | ||
11 | # | ||
12 | # You should have received a copy of the GNU General Public License | ||
13 | # along with this program; if not, write to the Free Software | ||
14 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | |||
16 | import unittest | ||
17 | import tempfile | ||
18 | import os | ||
19 | import bb | ||
20 | |||
21 | from layerindexlib.tests.common import LayersTest | ||
22 | |||
23 | import logging | ||
24 | |||
25 | class LayerIndexObjectsTest(LayersTest): | ||
26 | def setUp(self): | ||
27 | from layerindexlib import LayerIndexObj, Branch, LayerItem, LayerBranch, LayerDependency, Recipe, Machine, Distro | ||
28 | |||
29 | LayersTest.setUp(self) | ||
30 | |||
31 | self.index = LayerIndexObj() | ||
32 | |||
33 | branchId = 0 | ||
34 | layerItemId = 0 | ||
35 | layerBranchId = 0 | ||
36 | layerDependencyId = 0 | ||
37 | recipeId = 0 | ||
38 | machineId = 0 | ||
39 | distroId = 0 | ||
40 | |||
41 | self.index.branches = {} | ||
42 | self.index.layerItems = {} | ||
43 | self.index.layerBranches = {} | ||
44 | self.index.layerDependencies = {} | ||
45 | self.index.recipes = {} | ||
46 | self.index.machines = {} | ||
47 | self.index.distros = {} | ||
48 | |||
49 | branchId += 1 | ||
50 | self.index.branches[branchId] = Branch(self.index) | ||
51 | self.index.branches[branchId].define_data(branchId, | ||
52 | 'test_branch', 'bb_test_branch') | ||
53 | self.index.branches[branchId].lockData() | ||
54 | |||
55 | layerItemId +=1 | ||
56 | self.index.layerItems[layerItemId] = LayerItem(self.index) | ||
57 | self.index.layerItems[layerItemId].define_data(layerItemId, | ||
58 | 'test_layerItem', vcs_url='git://git_test_url/test_layerItem') | ||
59 | self.index.layerItems[layerItemId].lockData() | ||
60 | |||
61 | layerBranchId +=1 | ||
62 | self.index.layerBranches[layerBranchId] = LayerBranch(self.index) | ||
63 | self.index.layerBranches[layerBranchId].define_data(layerBranchId, | ||
64 | 'test_collection', '99', layerItemId, | ||
65 | branchId) | ||
66 | |||
67 | recipeId += 1 | ||
68 | self.index.recipes[recipeId] = Recipe(self.index) | ||
69 | self.index.recipes[recipeId].define_data(recipeId, 'test_git.bb', | ||
70 | 'recipes-test', 'test', 'git', | ||
71 | layerBranchId) | ||
72 | |||
73 | machineId += 1 | ||
74 | self.index.machines[machineId] = Machine(self.index) | ||
75 | self.index.machines[machineId].define_data(machineId, | ||
76 | 'test_machine', 'test_machine', | ||
77 | layerBranchId) | ||
78 | |||
79 | distroId += 1 | ||
80 | self.index.distros[distroId] = Distro(self.index) | ||
81 | self.index.distros[distroId].define_data(distroId, | ||
82 | 'test_distro', 'test_distro', | ||
83 | layerBranchId) | ||
84 | |||
85 | layerItemId +=1 | ||
86 | self.index.layerItems[layerItemId] = LayerItem(self.index) | ||
87 | self.index.layerItems[layerItemId].define_data(layerItemId, 'test_layerItem 2', | ||
88 | vcs_url='git://git_test_url/test_layerItem') | ||
89 | |||
90 | layerBranchId +=1 | ||
91 | self.index.layerBranches[layerBranchId] = LayerBranch(self.index) | ||
92 | self.index.layerBranches[layerBranchId].define_data(layerBranchId, | ||
93 | 'test_collection_2', '72', layerItemId, | ||
94 | branchId, actual_branch='some_other_branch') | ||
95 | |||
96 | layerDependencyId += 1 | ||
97 | self.index.layerDependencies[layerDependencyId] = LayerDependency(self.index) | ||
98 | self.index.layerDependencies[layerDependencyId].define_data(layerDependencyId, | ||
99 | layerBranchId, 1) | ||
100 | |||
101 | layerDependencyId += 1 | ||
102 | self.index.layerDependencies[layerDependencyId] = LayerDependency(self.index) | ||
103 | self.index.layerDependencies[layerDependencyId].define_data(layerDependencyId, | ||
104 | layerBranchId, 1, required=False) | ||
105 | |||
106 | def test_branch(self): | ||
107 | branch = self.index.branches[1] | ||
108 | self.assertEqual(branch.id, 1) | ||
109 | self.assertEqual(branch.name, 'test_branch') | ||
110 | self.assertEqual(branch.short_description, 'test_branch') | ||
111 | self.assertEqual(branch.bitbake_branch, 'bb_test_branch') | ||
112 | |||
113 | def test_layerItem(self): | ||
114 | layerItem = self.index.layerItems[1] | ||
115 | self.assertEqual(layerItem.id, 1) | ||
116 | self.assertEqual(layerItem.name, 'test_layerItem') | ||
117 | self.assertEqual(layerItem.summary, 'test_layerItem') | ||
118 | self.assertEqual(layerItem.description, 'test_layerItem') | ||
119 | self.assertEqual(layerItem.vcs_url, 'git://git_test_url/test_layerItem') | ||
120 | self.assertEqual(layerItem.vcs_web_url, None) | ||
121 | self.assertIsNone(layerItem.vcs_web_tree_base_url) | ||
122 | self.assertIsNone(layerItem.vcs_web_file_base_url) | ||
123 | self.assertIsNotNone(layerItem.updated) | ||
124 | |||
125 | layerItem = self.index.layerItems[2] | ||
126 | self.assertEqual(layerItem.id, 2) | ||
127 | self.assertEqual(layerItem.name, 'test_layerItem 2') | ||
128 | self.assertEqual(layerItem.summary, 'test_layerItem 2') | ||
129 | self.assertEqual(layerItem.description, 'test_layerItem 2') | ||
130 | self.assertEqual(layerItem.vcs_url, 'git://git_test_url/test_layerItem') | ||
131 | self.assertIsNone(layerItem.vcs_web_url) | ||
132 | self.assertIsNone(layerItem.vcs_web_tree_base_url) | ||
133 | self.assertIsNone(layerItem.vcs_web_file_base_url) | ||
134 | self.assertIsNotNone(layerItem.updated) | ||
135 | |||
136 | def test_layerBranch(self): | ||
137 | layerBranch = self.index.layerBranches[1] | ||
138 | self.assertEqual(layerBranch.id, 1) | ||
139 | self.assertEqual(layerBranch.collection, 'test_collection') | ||
140 | self.assertEqual(layerBranch.version, '99') | ||
141 | self.assertEqual(layerBranch.vcs_subdir, '') | ||
142 | self.assertEqual(layerBranch.actual_branch, 'test_branch') | ||
143 | self.assertIsNotNone(layerBranch.updated) | ||
144 | self.assertEqual(layerBranch.layer_id, 1) | ||
145 | self.assertEqual(layerBranch.branch_id, 1) | ||
146 | self.assertEqual(layerBranch.layer, self.index.layerItems[1]) | ||
147 | self.assertEqual(layerBranch.branch, self.index.branches[1]) | ||
148 | |||
149 | layerBranch = self.index.layerBranches[2] | ||
150 | self.assertEqual(layerBranch.id, 2) | ||
151 | self.assertEqual(layerBranch.collection, 'test_collection_2') | ||
152 | self.assertEqual(layerBranch.version, '72') | ||
153 | self.assertEqual(layerBranch.vcs_subdir, '') | ||
154 | self.assertEqual(layerBranch.actual_branch, 'some_other_branch') | ||
155 | self.assertIsNotNone(layerBranch.updated) | ||
156 | self.assertEqual(layerBranch.layer_id, 2) | ||
157 | self.assertEqual(layerBranch.branch_id, 1) | ||
158 | self.assertEqual(layerBranch.layer, self.index.layerItems[2]) | ||
159 | self.assertEqual(layerBranch.branch, self.index.branches[1]) | ||
160 | |||
161 | def test_layerDependency(self): | ||
162 | layerDependency = self.index.layerDependencies[1] | ||
163 | self.assertEqual(layerDependency.id, 1) | ||
164 | self.assertEqual(layerDependency.layerbranch_id, 2) | ||
165 | self.assertEqual(layerDependency.layerbranch, self.index.layerBranches[2]) | ||
166 | self.assertEqual(layerDependency.layer_id, 2) | ||
167 | self.assertEqual(layerDependency.layer, self.index.layerItems[2]) | ||
168 | self.assertTrue(layerDependency.required) | ||
169 | self.assertEqual(layerDependency.dependency_id, 1) | ||
170 | self.assertEqual(layerDependency.dependency, self.index.layerItems[1]) | ||
171 | self.assertEqual(layerDependency.dependency_layerBranch, self.index.layerBranches[1]) | ||
172 | |||
173 | layerDependency = self.index.layerDependencies[2] | ||
174 | self.assertEqual(layerDependency.id, 2) | ||
175 | self.assertEqual(layerDependency.layerbranch_id, 2) | ||
176 | self.assertEqual(layerDependency.layerbranch, self.index.layerBranches[2]) | ||
177 | self.assertEqual(layerDependency.layer_id, 2) | ||
178 | self.assertEqual(layerDependency.layer, self.index.layerItems[2]) | ||
179 | self.assertFalse(layerDependency.required) | ||
180 | self.assertEqual(layerDependency.dependency_id, 1) | ||
181 | self.assertEqual(layerDependency.dependency, self.index.layerItems[1]) | ||
182 | self.assertEqual(layerDependency.dependency_layerBranch, self.index.layerBranches[1]) | ||
183 | |||
184 | def test_recipe(self): | ||
185 | recipe = self.index.recipes[1] | ||
186 | self.assertEqual(recipe.id, 1) | ||
187 | self.assertEqual(recipe.layerbranch_id, 1) | ||
188 | self.assertEqual(recipe.layerbranch, self.index.layerBranches[1]) | ||
189 | self.assertEqual(recipe.layer_id, 1) | ||
190 | self.assertEqual(recipe.layer, self.index.layerItems[1]) | ||
191 | self.assertEqual(recipe.filename, 'test_git.bb') | ||
192 | self.assertEqual(recipe.filepath, 'recipes-test') | ||
193 | self.assertEqual(recipe.fullpath, 'recipes-test/test_git.bb') | ||
194 | self.assertEqual(recipe.summary, "") | ||
195 | self.assertEqual(recipe.description, "") | ||
196 | self.assertEqual(recipe.section, "") | ||
197 | self.assertEqual(recipe.pn, 'test') | ||
198 | self.assertEqual(recipe.pv, 'git') | ||
199 | self.assertEqual(recipe.license, "") | ||
200 | self.assertEqual(recipe.homepage, "") | ||
201 | self.assertEqual(recipe.bugtracker, "") | ||
202 | self.assertEqual(recipe.provides, "") | ||
203 | self.assertIsNotNone(recipe.updated) | ||
204 | self.assertEqual(recipe.inherits, "") | ||
205 | |||
206 | def test_machine(self): | ||
207 | machine = self.index.machines[1] | ||
208 | self.assertEqual(machine.id, 1) | ||
209 | self.assertEqual(machine.layerbranch_id, 1) | ||
210 | self.assertEqual(machine.layerbranch, self.index.layerBranches[1]) | ||
211 | self.assertEqual(machine.layer_id, 1) | ||
212 | self.assertEqual(machine.layer, self.index.layerItems[1]) | ||
213 | self.assertEqual(machine.name, 'test_machine') | ||
214 | self.assertEqual(machine.description, 'test_machine') | ||
215 | self.assertIsNotNone(machine.updated) | ||
216 | |||
217 | def test_distro(self): | ||
218 | distro = self.index.distros[1] | ||
219 | self.assertEqual(distro.id, 1) | ||
220 | self.assertEqual(distro.layerbranch_id, 1) | ||
221 | self.assertEqual(distro.layerbranch, self.index.layerBranches[1]) | ||
222 | self.assertEqual(distro.layer_id, 1) | ||
223 | self.assertEqual(distro.layer, self.index.layerItems[1]) | ||
224 | self.assertEqual(distro.name, 'test_distro') | ||
225 | self.assertEqual(distro.description, 'test_distro') | ||
226 | self.assertIsNotNone(distro.updated) | ||
diff --git a/bitbake/lib/layerindexlib/tests/restapi.py b/bitbake/lib/layerindexlib/tests/restapi.py new file mode 100644 index 0000000000..bfaac43db4 --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/restapi.py | |||
@@ -0,0 +1,174 @@ | |||
1 | # Copyright (C) 2017-2018 Wind River Systems, Inc. | ||
2 | # | ||
3 | # This program is free software; you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License version 2 as | ||
5 | # published by the Free Software Foundation. | ||
6 | # | ||
7 | # This program is distributed in the hope that it will be useful, | ||
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
10 | # See the GNU General Public License for more details. | ||
11 | # | ||
12 | # You should have received a copy of the GNU General Public License | ||
13 | # along with this program; if not, write to the Free Software | ||
14 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | |||
16 | import unittest | ||
17 | import tempfile | ||
18 | import os | ||
19 | import bb | ||
20 | |||
21 | import layerindexlib | ||
22 | from layerindexlib.tests.common import LayersTest | ||
23 | |||
24 | import logging | ||
25 | |||
26 | class LayerIndexWebRestApiTest(LayersTest): | ||
27 | |||
28 | if os.environ.get("BB_SKIP_NETTESTS") == "yes": | ||
29 | print("Unset BB_SKIP_NETTESTS to run network tests") | ||
30 | else: | ||
31 | def setUp(self): | ||
32 | LayersTest.setUp(self) | ||
33 | self.layerindex = layerindexlib.LayerIndex(self.d) | ||
34 | self.layerindex.load_layerindex('http://layers.openembedded.org/layerindex/api/;branch=sumo', load=['layerDependencies']) | ||
35 | |||
36 | def test_layerindex_is_empty(self): | ||
37 | self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is empty") | ||
38 | |||
39 | def test_layerindex_store_file(self): | ||
40 | self.layerindex.store_layerindex('file://%s/file.json' % self.tempdir, self.layerindex.indexes[0]) | ||
41 | |||
42 | self.assertTrue(os.path.isfile('%s/file.json' % self.tempdir), msg="Temporary file was not created by store_layerindex") | ||
43 | |||
44 | reload = layerindexlib.LayerIndex(self.d) | ||
45 | reload.load_layerindex('file://%s/file.json' % self.tempdir) | ||
46 | |||
47 | self.assertFalse(reload.is_empty(), msg="Layerindex is empty") | ||
48 | |||
49 | # Calculate layerItems in original index that should NOT be in reload | ||
50 | layerItemNames = [] | ||
51 | for itemId in self.layerindex.indexes[0].layerItems: | ||
52 | layerItemNames.append(self.layerindex.indexes[0].layerItems[itemId].name) | ||
53 | |||
54 | for layerBranchId in self.layerindex.indexes[0].layerBranches: | ||
55 | layerItemNames.remove(self.layerindex.indexes[0].layerBranches[layerBranchId].layer.name) | ||
56 | |||
57 | for itemId in reload.indexes[0].layerItems: | ||
58 | self.assertFalse(reload.indexes[0].layerItems[itemId].name in layerItemNames, msg="Item reloaded when it shouldn't have been") | ||
59 | |||
60 | # Compare the original to what we wrote... | ||
61 | for type in self.layerindex.indexes[0]._index: | ||
62 | if type == 'apilinks' or \ | ||
63 | type == 'layerItems' or \ | ||
64 | type in self.layerindex.indexes[0].config['local']: | ||
65 | continue | ||
66 | for id in getattr(self.layerindex.indexes[0], type): | ||
67 | self.logger.debug(1, "type %s" % (type)) | ||
68 | |||
69 | self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number not in reloaded index") | ||
70 | |||
71 | self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id])) | ||
72 | |||
73 | self.assertEqual(getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id], msg="Reloaded contents different") | ||
74 | |||
75 | def test_layerindex_store_split(self): | ||
76 | self.layerindex.store_layerindex('file://%s' % self.tempdir, self.layerindex.indexes[0]) | ||
77 | |||
78 | reload = layerindexlib.LayerIndex(self.d) | ||
79 | reload.load_layerindex('file://%s' % self.tempdir) | ||
80 | |||
81 | self.assertFalse(reload.is_empty(), msg="Layer index is empty") | ||
82 | |||
83 | for type in self.layerindex.indexes[0]._index: | ||
84 | if type == 'apilinks' or \ | ||
85 | type == 'layerItems' or \ | ||
86 | type in self.layerindex.indexes[0].config['local']: | ||
87 | continue | ||
88 | for id in getattr(self.layerindex.indexes[0] ,type): | ||
89 | self.logger.debug(1, "type %s" % (type)) | ||
90 | |||
91 | self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number missing from reloaded data") | ||
92 | |||
93 | self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id])) | ||
94 | |||
95 | self.assertEqual(getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id], msg="reloaded data does not match original") | ||
96 | |||
97 | def test_dependency_resolution(self): | ||
98 | # Verify depth first searching... | ||
99 | (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python']) | ||
100 | |||
101 | first = True | ||
102 | for deplayerbranch in dependencies: | ||
103 | layerBranch = dependencies[deplayerbranch][0] | ||
104 | layerDeps = dependencies[deplayerbranch][1:] | ||
105 | |||
106 | if not first: | ||
107 | continue | ||
108 | |||
109 | first = False | ||
110 | |||
111 | # Top of the deps should be openembedded-core, since everything depends on it. | ||
112 | self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='OpenEmbedded-Core is no the first dependency') | ||
113 | |||
114 | # meta-python should cause an openembedded-core dependency, if not assert! | ||
115 | for dep in layerDeps: | ||
116 | if dep.layer.name == 'meta-python': | ||
117 | break | ||
118 | else: | ||
119 | self.logger.debug(1, "meta-python was not found") | ||
120 | self.assetTrue(False) | ||
121 | |||
122 | # Only check the first element... | ||
123 | break | ||
124 | else: | ||
125 | # Empty list, this is bad. | ||
126 | self.logger.debug(1, "Empty list of dependencies") | ||
127 | self.assertIsNotNone(first, msg="Empty list of dependencies") | ||
128 | |||
129 | # Last dep should be the requested item | ||
130 | layerBranch = dependencies[deplayerbranch][0] | ||
131 | self.assertEqual(layerBranch.layer.name, "meta-python", msg="Last dependency not meta-python") | ||
132 | |||
133 | def test_find_collection(self): | ||
134 | def _check(collection, expected): | ||
135 | self.logger.debug(1, "Looking for collection %s..." % collection) | ||
136 | result = self.layerindex.find_collection(collection) | ||
137 | if expected: | ||
138 | self.assertIsNotNone(result, msg="Did not find %s when it should be there" % collection) | ||
139 | else: | ||
140 | self.assertIsNone(result, msg="Found %s when it shouldn't be there" % collection) | ||
141 | |||
142 | tests = [ ('core', True), | ||
143 | ('openembedded-core', False), | ||
144 | ('networking-layer', True), | ||
145 | ('meta-python', True), | ||
146 | ('openembedded-layer', True), | ||
147 | ('notpresent', False) ] | ||
148 | |||
149 | for collection,result in tests: | ||
150 | _check(collection, result) | ||
151 | |||
152 | def test_find_layerbranch(self): | ||
153 | def _check(name, expected): | ||
154 | self.logger.debug(1, "Looking for layerbranch %s..." % name) | ||
155 | |||
156 | for index in self.layerindex.indexes: | ||
157 | for layerbranchid in index.layerBranches: | ||
158 | self.logger.debug(1, "Present: %s" % index.layerBranches[layerbranchid].layer.name) | ||
159 | result = self.layerindex.find_layerbranch(name) | ||
160 | if expected: | ||
161 | self.assertIsNotNone(result, msg="Did not find %s when it should be there" % collection) | ||
162 | else: | ||
163 | self.assertIsNone(result, msg="Found %s when it shouldn't be there" % collection) | ||
164 | |||
165 | tests = [ ('openembedded-core', True), | ||
166 | ('core', False), | ||
167 | ('meta-networking', True), | ||
168 | ('meta-python', True), | ||
169 | ('meta-oe', True), | ||
170 | ('notpresent', False) ] | ||
171 | |||
172 | for collection,result in tests: | ||
173 | _check(collection, result) | ||
174 | |||
diff --git a/bitbake/lib/layerindexlib/tests/testdata/README b/bitbake/lib/layerindexlib/tests/testdata/README new file mode 100644 index 0000000000..36ab40bebe --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/testdata/README | |||
@@ -0,0 +1,11 @@ | |||
1 | This test data is used to verify the 'cooker' module of the layerindex. | ||
2 | |||
3 | The module consists of a faux project bblayers.conf with four layers defined. | ||
4 | |||
5 | layer1 - openembedded-core | ||
6 | layer2 - networking-layer | ||
7 | layer3 - meta-python | ||
8 | layer4 - openembedded-layer (meta-oe) | ||
9 | |||
10 | Since we do not have a fully populated cooker, we use this to test the | ||
11 | basic index generation, and not any deep recipe based contents. | ||
diff --git a/bitbake/lib/layerindexlib/tests/testdata/build/conf/bblayers.conf b/bitbake/lib/layerindexlib/tests/testdata/build/conf/bblayers.conf new file mode 100644 index 0000000000..40429b2f66 --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/testdata/build/conf/bblayers.conf | |||
@@ -0,0 +1,15 @@ | |||
1 | LAYERSERIES_CORENAMES = "sumo" | ||
2 | |||
3 | # LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf | ||
4 | # changes incompatibly | ||
5 | LCONF_VERSION = "7" | ||
6 | |||
7 | BBPATH = "${TOPDIR}" | ||
8 | BBFILES ?= "" | ||
9 | |||
10 | BBLAYERS ?= " \ | ||
11 | ${TOPDIR}/layer1 \ | ||
12 | ${TOPDIR}/layer2 \ | ||
13 | ${TOPDIR}/layer3 \ | ||
14 | ${TOPDIR}/layer4 \ | ||
15 | " | ||
diff --git a/bitbake/lib/layerindexlib/tests/testdata/layer1/conf/layer.conf b/bitbake/lib/layerindexlib/tests/testdata/layer1/conf/layer.conf new file mode 100644 index 0000000000..966d531959 --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/testdata/layer1/conf/layer.conf | |||
@@ -0,0 +1,17 @@ | |||
1 | # We have a conf and classes directory, add to BBPATH | ||
2 | BBPATH .= ":${LAYERDIR}" | ||
3 | # We have recipes-* directories, add to BBFILES | ||
4 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb" | ||
5 | |||
6 | BBFILE_COLLECTIONS += "core" | ||
7 | BBFILE_PATTERN_core = "^${LAYERDIR}/" | ||
8 | BBFILE_PRIORITY_core = "5" | ||
9 | |||
10 | LAYERSERIES_CORENAMES = "sumo" | ||
11 | |||
12 | # This should only be incremented on significant changes that will | ||
13 | # cause compatibility issues with other layers | ||
14 | LAYERVERSION_core = "11" | ||
15 | LAYERSERIES_COMPAT_core = "sumo" | ||
16 | |||
17 | BBLAYERS_LAYERINDEX_NAME_core = "openembedded-core" | ||
diff --git a/bitbake/lib/layerindexlib/tests/testdata/layer2/conf/layer.conf b/bitbake/lib/layerindexlib/tests/testdata/layer2/conf/layer.conf new file mode 100644 index 0000000000..7569d1c217 --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/testdata/layer2/conf/layer.conf | |||
@@ -0,0 +1,20 @@ | |||
1 | # We have a conf and classes directory, add to BBPATH | ||
2 | BBPATH .= ":${LAYERDIR}" | ||
3 | |||
4 | # We have a packages directory, add to BBFILES | ||
5 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ | ||
6 | ${LAYERDIR}/recipes-*/*/*.bbappend" | ||
7 | |||
8 | BBFILE_COLLECTIONS += "networking-layer" | ||
9 | BBFILE_PATTERN_networking-layer := "^${LAYERDIR}/" | ||
10 | BBFILE_PRIORITY_networking-layer = "5" | ||
11 | |||
12 | # This should only be incremented on significant changes that will | ||
13 | # cause compatibility issues with other layers | ||
14 | LAYERVERSION_networking-layer = "1" | ||
15 | |||
16 | LAYERDEPENDS_networking-layer = "core" | ||
17 | LAYERDEPENDS_networking-layer += "openembedded-layer" | ||
18 | LAYERDEPENDS_networking-layer += "meta-python" | ||
19 | |||
20 | LAYERSERIES_COMPAT_networking-layer = "sumo" | ||
diff --git a/bitbake/lib/layerindexlib/tests/testdata/layer3/conf/layer.conf b/bitbake/lib/layerindexlib/tests/testdata/layer3/conf/layer.conf new file mode 100644 index 0000000000..7089071faf --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/testdata/layer3/conf/layer.conf | |||
@@ -0,0 +1,19 @@ | |||
1 | # We might have a conf and classes directory, append to BBPATH | ||
2 | BBPATH .= ":${LAYERDIR}" | ||
3 | |||
4 | # We have recipes directories, add to BBFILES | ||
5 | BBFILES += "${LAYERDIR}/recipes*/*/*.bb ${LAYERDIR}/recipes*/*/*.bbappend" | ||
6 | |||
7 | BBFILE_COLLECTIONS += "meta-python" | ||
8 | BBFILE_PATTERN_meta-python := "^${LAYERDIR}/" | ||
9 | BBFILE_PRIORITY_meta-python = "7" | ||
10 | |||
11 | # This should only be incremented on significant changes that will | ||
12 | # cause compatibility issues with other layers | ||
13 | LAYERVERSION_meta-python = "1" | ||
14 | |||
15 | LAYERDEPENDS_meta-python = "core openembedded-layer" | ||
16 | |||
17 | LAYERSERIES_COMPAT_meta-python = "sumo" | ||
18 | |||
19 | LICENSE_PATH += "${LAYERDIR}/licenses" | ||
diff --git a/bitbake/lib/layerindexlib/tests/testdata/layer4/conf/layer.conf b/bitbake/lib/layerindexlib/tests/testdata/layer4/conf/layer.conf new file mode 100644 index 0000000000..6649ee0208 --- /dev/null +++ b/bitbake/lib/layerindexlib/tests/testdata/layer4/conf/layer.conf | |||
@@ -0,0 +1,22 @@ | |||
1 | # We have a conf and classes directory, append to BBPATH | ||
2 | BBPATH .= ":${LAYERDIR}" | ||
3 | |||
4 | # We have a recipes directory, add to BBFILES | ||
5 | BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend" | ||
6 | |||
7 | BBFILE_COLLECTIONS += "openembedded-layer" | ||
8 | BBFILE_PATTERN_openembedded-layer := "^${LAYERDIR}/" | ||
9 | |||
10 | # Define the priority for recipes (.bb files) from this layer, | ||
11 | # choosing carefully how this layer interacts with all of the | ||
12 | # other layers. | ||
13 | |||
14 | BBFILE_PRIORITY_openembedded-layer = "6" | ||
15 | |||
16 | # This should only be incremented on significant changes that will | ||
17 | # cause compatibility issues with other layers | ||
18 | LAYERVERSION_openembedded-layer = "1" | ||
19 | |||
20 | LAYERDEPENDS_openembedded-layer = "core" | ||
21 | |||
22 | LAYERSERIES_COMPAT_openembedded-layer = "sumo" | ||