cooker.py 4.1 KB

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