blob: 9f15e05be9b9d942e69b3dffa1ce2d0bfba2b8ba [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001# Copyright (C) 2017 Intel Corporation
Brad Bishopc342db32019-05-15 21:57:59 -04002#
3# SPDX-License-Identifier: MIT
4#
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005
6import glob
7import os
8import unittest
Andrew Geissler595f6302022-01-24 19:11:47 +00009import re
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010from checklayer import get_signatures, LayerType, check_command, get_depgraph, compare_signatures
11from checklayer.case import OECheckLayerTestCase
12
13class CommonCheckLayer(OECheckLayerTestCase):
14 def test_readme(self):
15 # The top-level README file may have a suffix (like README.rst or README.txt).
Brad Bishop79641f22019-09-10 07:20:22 -040016 readme_files = glob.glob(os.path.join(self.tc.layer['path'], '[Rr][Ee][Aa][Dd][Mm][Ee]*'))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017 self.assertTrue(len(readme_files) > 0,
Andrew Geissler595f6302022-01-24 19:11:47 +000018 msg="Layer doesn't contain a README file.")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019
20 # There might be more than one file matching the file pattern above
21 # (for example, README.rst and README-COPYING.rst). The one with the shortest
22 # name is considered the "main" one.
23 readme_file = sorted(readme_files)[0]
24 data = ''
25 with open(readme_file, 'r') as f:
26 data = f.read()
27 self.assertTrue(data,
28 msg="Layer contains a README file but it is empty.")
29
Andrew Geissler595f6302022-01-24 19:11:47 +000030 # If a layer's README references another README, then the checks below are not valid
31 if re.search('README', data, re.IGNORECASE):
32 return
33
34 self.assertIn('maintainer', data.lower())
35 self.assertIn('patch', data.lower())
36 # Check that there is an email address in the README
37 email_regex = re.compile(r"[^@]+@[^@]+")
38 self.assertTrue(email_regex.match(data))
39
Brad Bishopd7bf8c12018-02-25 22:55:05 -050040 def test_parse(self):
41 check_command('Layer %s failed to parse.' % self.tc.layer['name'],
42 'bitbake -p')
43
44 def test_show_environment(self):
45 check_command('Layer %s failed to show environment.' % self.tc.layer['name'],
46 'bitbake -e')
47
48 def test_world(self):
49 '''
50 "bitbake world" is expected to work. test_signatures does not cover that
51 because it is more lenient and ignores recipes in a world build that
52 are not actually buildable, so here we fail when "bitbake -S none world"
53 fails.
54 '''
55 get_signatures(self.td['builddir'], failsafe=False)
56
57 def test_signatures(self):
58 if self.tc.layer['type'] == LayerType.SOFTWARE and \
59 not self.tc.test_software_layer_signatures:
60 raise unittest.SkipTest("Not testing for signature changes in a software layer %s." \
61 % self.tc.layer['name'])
62
63 curr_sigs, _ = get_signatures(self.td['builddir'], failsafe=True)
64 msg = compare_signatures(self.td['sigs'], curr_sigs)
65 if msg is not None:
66 self.fail('Adding layer %s changed signatures.\n%s' % (self.tc.layer['name'], msg))
Brad Bishop316dfdd2018-06-25 12:45:53 -040067
68 def test_layerseries_compat(self):
69 for collection_name, collection_data in self.tc.layer['collections'].items():
70 self.assertTrue(collection_data['compat'], "Collection %s from layer %s does not set compatible oe-core versions via LAYERSERIES_COMPAT_collection." \
71 % (collection_name, self.tc.layer['name']))