blob: 5ddf89aa211ffea5c70b1499e2b7e549026c2a34 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001# Copyright (C) 2018 Wind River Systems, Inc.
2#
Brad Bishopc342db32019-05-15 21:57:59 -04003# SPDX-License-Identifier: GPL-2.0-only
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08006import os
7import bb
8
9import layerindexlib
10from layerindexlib.tests.common import LayersTest
11
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012
13class LayerIndexCookerTest(LayersTest):
14
15 def setUp(self):
16 LayersTest.setUp(self)
17
18 # Note this is NOT a comprehensive test of cooker, as we can't easily
19 # configure the test data. But we can emulate the basics of the layer.conf
20 # files, so that is what we will do.
21
22 new_topdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "testdata")
23 new_bbpath = os.path.join(new_topdir, "build")
24
25 self.d.setVar('TOPDIR', new_topdir)
26 self.d.setVar('BBPATH', new_bbpath)
27
28 self.d = bb.parse.handle("%s/conf/bblayers.conf" % new_bbpath, self.d, True)
29 for layer in self.d.getVar('BBLAYERS').split():
30 self.d = bb.parse.handle("%s/conf/layer.conf" % layer, self.d, True)
31
32 self.layerindex = layerindexlib.LayerIndex(self.d)
33 self.layerindex.load_layerindex('cooker://', load=['layerDependencies'])
34
35 def test_layerindex_is_empty(self):
36 self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is not empty!")
37
38 def test_dependency_resolution(self):
39 # Verify depth first searching...
40 (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python'])
41
42 first = True
43 for deplayerbranch in dependencies:
44 layerBranch = dependencies[deplayerbranch][0]
45 layerDeps = dependencies[deplayerbranch][1:]
46
47 if not first:
48 continue
49
50 first = False
51
52 # Top of the deps should be openembedded-core, since everything depends on it.
53 self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='Top dependency not openembedded-core')
54
55 # meta-python should cause an openembedded-core dependency, if not assert!
56 for dep in layerDeps:
57 if dep.layer.name == 'meta-python':
58 break
59 else:
60 self.assertTrue(False, msg='meta-python was not found')
61
62 # Only check the first element...
63 break
64 else:
65 if first:
66 # Empty list, this is bad.
67 self.assertTrue(False, msg='Empty list of dependencies')
68
69 # Last dep should be the requested item
70 layerBranch = dependencies[deplayerbranch][0]
71 self.assertEqual(layerBranch.layer.name, "meta-python", msg='Last dependency not meta-python')
72
73 def test_find_collection(self):
74 def _check(collection, expected):
Andrew Geisslerd1e89492021-02-12 15:35:20 -060075 self.logger.debug("Looking for collection %s..." % collection)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080076 result = self.layerindex.find_collection(collection)
77 if expected:
78 self.assertIsNotNone(result, msg="Did not find %s when it shouldn't be there" % collection)
79 else:
80 self.assertIsNone(result, msg="Found %s when it should be there" % collection)
81
82 tests = [ ('core', True),
83 ('openembedded-core', False),
84 ('networking-layer', True),
85 ('meta-python', True),
86 ('openembedded-layer', True),
87 ('notpresent', False) ]
88
89 for collection,result in tests:
90 _check(collection, result)
91
92 def test_find_layerbranch(self):
93 def _check(name, expected):
Andrew Geisslerd1e89492021-02-12 15:35:20 -060094 self.logger.debug("Looking for layerbranch %s..." % name)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080095 result = self.layerindex.find_layerbranch(name)
96 if expected:
97 self.assertIsNotNone(result, msg="Did not find %s when it shouldn't be there" % collection)
98 else:
99 self.assertIsNone(result, msg="Found %s when it should be there" % collection)
100
101 tests = [ ('openembedded-core', True),
102 ('core', False),
103 ('networking-layer', True),
104 ('meta-python', True),
105 ('openembedded-layer', True),
106 ('notpresent', False) ]
107
108 for collection,result in tests:
109 _check(collection, result)
110