common.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (C) 2017 Intel Corporation
  2. #
  3. # SPDX-License-Identifier: MIT
  4. #
  5. import glob
  6. import os
  7. import unittest
  8. import re
  9. from checklayer import get_signatures, LayerType, check_command, get_depgraph, compare_signatures
  10. from checklayer.case import OECheckLayerTestCase
  11. class CommonCheckLayer(OECheckLayerTestCase):
  12. def test_readme(self):
  13. if self.tc.layer['type'] == LayerType.CORE:
  14. raise unittest.SkipTest("Core layer's README is top level")
  15. # The top-level README file may have a suffix (like README.rst or README.txt).
  16. readme_files = glob.glob(os.path.join(self.tc.layer['path'], '[Rr][Ee][Aa][Dd][Mm][Ee]*'))
  17. self.assertTrue(len(readme_files) > 0,
  18. msg="Layer doesn't contain a README file.")
  19. # There might be more than one file matching the file pattern above
  20. # (for example, README.rst and README-COPYING.rst). The one with the shortest
  21. # name is considered the "main" one.
  22. readme_file = sorted(readme_files)[0]
  23. data = ''
  24. with open(readme_file, 'r') as f:
  25. data = f.read()
  26. self.assertTrue(data,
  27. msg="Layer contains a README file but it is empty.")
  28. # If a layer's README references another README, then the checks below are not valid
  29. if re.search('README', data, re.IGNORECASE):
  30. return
  31. self.assertIn('maintainer', data.lower())
  32. self.assertIn('patch', data.lower())
  33. # Check that there is an email address in the README
  34. email_regex = re.compile(r"[^@]+@[^@]+")
  35. self.assertTrue(email_regex.match(data))
  36. def test_parse(self):
  37. check_command('Layer %s failed to parse.' % self.tc.layer['name'],
  38. 'bitbake -p')
  39. def test_show_environment(self):
  40. check_command('Layer %s failed to show environment.' % self.tc.layer['name'],
  41. 'bitbake -e')
  42. def test_world(self):
  43. '''
  44. "bitbake world" is expected to work. test_signatures does not cover that
  45. because it is more lenient and ignores recipes in a world build that
  46. are not actually buildable, so here we fail when "bitbake -S none world"
  47. fails.
  48. '''
  49. get_signatures(self.td['builddir'], failsafe=False)
  50. def test_world_inherit_class(self):
  51. '''
  52. This also does "bitbake -S none world" along with inheriting "yocto-check-layer"
  53. class, which can do additional per-recipe test cases.
  54. '''
  55. msg = []
  56. try:
  57. get_signatures(self.td['builddir'], failsafe=False, machine=None, extravars='BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS INHERIT" INHERIT="yocto-check-layer"')
  58. except RuntimeError as ex:
  59. msg.append(str(ex))
  60. if msg:
  61. msg.insert(0, 'Layer %s failed additional checks from yocto-check-layer.bbclass\nSee below log for specific recipe parsing errors:\n' % \
  62. self.tc.layer['name'])
  63. self.fail('\n'.join(msg))
  64. def test_signatures(self):
  65. if self.tc.layer['type'] == LayerType.SOFTWARE and \
  66. not self.tc.test_software_layer_signatures:
  67. raise unittest.SkipTest("Not testing for signature changes in a software layer %s." \
  68. % self.tc.layer['name'])
  69. curr_sigs, _ = get_signatures(self.td['builddir'], failsafe=True)
  70. msg = compare_signatures(self.td['sigs'], curr_sigs)
  71. if msg is not None:
  72. self.fail('Adding layer %s changed signatures.\n%s' % (self.tc.layer['name'], msg))
  73. def test_layerseries_compat(self):
  74. for collection_name, collection_data in self.tc.layer['collections'].items():
  75. self.assertTrue(collection_data['compat'], "Collection %s from layer %s does not set compatible oe-core versions via LAYERSERIES_COMPAT_collection." \
  76. % (collection_name, self.tc.layer['name']))