cooker.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. import unittest
  16. import tempfile
  17. import os
  18. import bb
  19. import layerindexlib
  20. from layerindexlib.tests.common import LayersTest
  21. import logging
  22. class LayerIndexCookerTest(LayersTest):
  23. def setUp(self):
  24. LayersTest.setUp(self)
  25. # Note this is NOT a comprehensive test of cooker, as we can't easily
  26. # configure the test data. But we can emulate the basics of the layer.conf
  27. # files, so that is what we will do.
  28. new_topdir = os.path.join(os.path.dirname(__file__), "testdata")
  29. new_bbpath = os.path.join(new_topdir, "build")
  30. self.d.setVar('TOPDIR', new_topdir)
  31. self.d.setVar('BBPATH', new_bbpath)
  32. self.d = bb.parse.handle("%s/conf/bblayers.conf" % new_bbpath, self.d, True)
  33. for layer in self.d.getVar('BBLAYERS').split():
  34. self.d = bb.parse.handle("%s/conf/layer.conf" % layer, self.d, True)
  35. self.layerindex = layerindexlib.LayerIndex(self.d)
  36. self.layerindex.load_layerindex('cooker://', load=['layerDependencies'])
  37. def test_layerindex_is_empty(self):
  38. self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is not empty!")
  39. def test_dependency_resolution(self):
  40. # Verify depth first searching...
  41. (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python'])
  42. first = True
  43. for deplayerbranch in dependencies:
  44. layerBranch = dependencies[deplayerbranch][0]
  45. layerDeps = dependencies[deplayerbranch][1:]
  46. if not first:
  47. continue
  48. first = False
  49. # Top of the deps should be openembedded-core, since everything depends on it.
  50. self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='Top dependency not openembedded-core')
  51. # meta-python should cause an openembedded-core dependency, if not assert!
  52. for dep in layerDeps:
  53. if dep.layer.name == 'meta-python':
  54. break
  55. else:
  56. self.assertTrue(False, msg='meta-python was not found')
  57. # Only check the first element...
  58. break
  59. else:
  60. if first:
  61. # Empty list, this is bad.
  62. self.assertTrue(False, msg='Empty list of dependencies')
  63. # Last dep should be the requested item
  64. layerBranch = dependencies[deplayerbranch][0]
  65. self.assertEqual(layerBranch.layer.name, "meta-python", msg='Last dependency not meta-python')
  66. def test_find_collection(self):
  67. def _check(collection, expected):
  68. self.logger.debug(1, "Looking for collection %s..." % collection)
  69. result = self.layerindex.find_collection(collection)
  70. if expected:
  71. self.assertIsNotNone(result, msg="Did not find %s when it shouldn't be there" % collection)
  72. else:
  73. self.assertIsNone(result, msg="Found %s when it should be there" % collection)
  74. tests = [ ('core', True),
  75. ('openembedded-core', False),
  76. ('networking-layer', True),
  77. ('meta-python', True),
  78. ('openembedded-layer', True),
  79. ('notpresent', False) ]
  80. for collection,result in tests:
  81. _check(collection, result)
  82. def test_find_layerbranch(self):
  83. def _check(name, expected):
  84. self.logger.debug(1, "Looking for layerbranch %s..." % name)
  85. result = self.layerindex.find_layerbranch(name)
  86. if expected:
  87. self.assertIsNotNone(result, msg="Did not find %s when it shouldn't be there" % collection)
  88. else:
  89. self.assertIsNone(result, msg="Found %s when it should be there" % collection)
  90. tests = [ ('openembedded-core', True),
  91. ('core', False),
  92. ('networking-layer', True),
  93. ('meta-python', True),
  94. ('openembedded-layer', True),
  95. ('notpresent', False) ]
  96. for collection,result in tests:
  97. _check(collection, result)