Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | # Copyright (C) 2017 Intel Corporation |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | |
| 6 | import glob |
| 7 | import os |
| 8 | import unittest |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 9 | import re |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | from checklayer import get_signatures, LayerType, check_command, get_depgraph, compare_signatures |
| 11 | from checklayer.case import OECheckLayerTestCase |
| 12 | |
| 13 | class CommonCheckLayer(OECheckLayerTestCase): |
| 14 | def test_readme(self): |
| 15 | # The top-level README file may have a suffix (like README.rst or README.txt). |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 16 | readme_files = glob.glob(os.path.join(self.tc.layer['path'], '[Rr][Ee][Aa][Dd][Mm][Ee]*')) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 17 | self.assertTrue(len(readme_files) > 0, |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 18 | msg="Layer doesn't contain a README file.") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | |
| 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 Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 30 | # 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 40 | 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 Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 57 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 72 | 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 Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 82 | |
| 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'])) |