common.py 3.7 KB

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