blob: 491a13953c81ef6434f8daab7f35359969e22cd4 [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
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000057 def test_world_inherit_class(self):
58 '''
59 This also does "bitbake -S none world" along with inheriting "yocto-check-layer"
60 class, which can do additional per-recipe test cases.
61 '''
62 msg = []
63 try:
64 get_signatures(self.td['builddir'], failsafe=False, machine=None, extravars='BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS INHERIT" INHERIT="yocto-check-layer"')
65 except RuntimeError as ex:
66 msg.append(str(ex))
67 if msg:
68 msg.insert(0, 'Layer %s failed additional checks from yocto-check-layer.bbclass\nSee below log for specific recipe parsing errors:\n' % \
69 self.tc.layer['name'])
70 self.fail('\n'.join(msg))
71
Brad Bishopd7bf8c12018-02-25 22:55:05 -050072 def test_signatures(self):
73 if self.tc.layer['type'] == LayerType.SOFTWARE and \
74 not self.tc.test_software_layer_signatures:
75 raise unittest.SkipTest("Not testing for signature changes in a software layer %s." \
76 % self.tc.layer['name'])
77
78 curr_sigs, _ = get_signatures(self.td['builddir'], failsafe=True)
79 msg = compare_signatures(self.td['sigs'], curr_sigs)
80 if msg is not None:
81 self.fail('Adding layer %s changed signatures.\n%s' % (self.tc.layer['name'], msg))
Brad Bishop316dfdd2018-06-25 12:45:53 -040082
83 def test_layerseries_compat(self):
84 for collection_name, collection_data in self.tc.layer['collections'].items():
85 self.assertTrue(collection_data['compat'], "Collection %s from layer %s does not set compatible oe-core versions via LAYERSERIES_COMPAT_collection." \
86 % (collection_name, self.tc.layer['name']))