| 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 | 
|  | 9 | from checklayer import get_signatures, LayerType, check_command, get_depgraph, compare_signatures | 
|  | 10 | from checklayer.case import OECheckLayerTestCase | 
|  | 11 |  | 
|  | 12 | class CommonCheckLayer(OECheckLayerTestCase): | 
|  | 13 | def test_readme(self): | 
|  | 14 | # 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] | 15 | 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] | 16 | self.assertTrue(len(readme_files) > 0, | 
|  | 17 | msg="Layer doesn't contains README file.") | 
|  | 18 |  | 
|  | 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 |  | 
|  | 29 | def test_parse(self): | 
|  | 30 | check_command('Layer %s failed to parse.' % self.tc.layer['name'], | 
|  | 31 | 'bitbake -p') | 
|  | 32 |  | 
|  | 33 | def test_show_environment(self): | 
|  | 34 | check_command('Layer %s failed to show environment.' % self.tc.layer['name'], | 
|  | 35 | 'bitbake -e') | 
|  | 36 |  | 
|  | 37 | def test_world(self): | 
|  | 38 | ''' | 
|  | 39 | "bitbake world" is expected to work. test_signatures does not cover that | 
|  | 40 | because it is more lenient and ignores recipes in a world build that | 
|  | 41 | are not actually buildable, so here we fail when "bitbake -S none world" | 
|  | 42 | fails. | 
|  | 43 | ''' | 
|  | 44 | get_signatures(self.td['builddir'], failsafe=False) | 
|  | 45 |  | 
|  | 46 | def test_signatures(self): | 
|  | 47 | if self.tc.layer['type'] == LayerType.SOFTWARE and \ | 
|  | 48 | not self.tc.test_software_layer_signatures: | 
|  | 49 | raise unittest.SkipTest("Not testing for signature changes in a software layer %s." \ | 
|  | 50 | % self.tc.layer['name']) | 
|  | 51 |  | 
|  | 52 | curr_sigs, _ = get_signatures(self.td['builddir'], failsafe=True) | 
|  | 53 | msg = compare_signatures(self.td['sigs'], curr_sigs) | 
|  | 54 | if msg is not None: | 
|  | 55 | 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] | 56 |  | 
|  | 57 | def test_layerseries_compat(self): | 
|  | 58 | for collection_name, collection_data in self.tc.layer['collections'].items(): | 
|  | 59 | self.assertTrue(collection_data['compat'], "Collection %s from layer %s does not set compatible oe-core versions via LAYERSERIES_COMPAT_collection." \ | 
|  | 60 | % (collection_name, self.tc.layer['name'])) |