diff options
Diffstat (limited to 'scripts/lib/checklayer/cases')
-rw-r--r-- | scripts/lib/checklayer/cases/bsp.py | 4 | ||||
-rw-r--r-- | scripts/lib/checklayer/cases/common.py | 79 | ||||
-rw-r--r-- | scripts/lib/checklayer/cases/distro.py | 2 |
3 files changed, 80 insertions, 5 deletions
diff --git a/scripts/lib/checklayer/cases/bsp.py b/scripts/lib/checklayer/cases/bsp.py index 7fd56f5d36..b76163fb56 100644 --- a/scripts/lib/checklayer/cases/bsp.py +++ b/scripts/lib/checklayer/cases/bsp.py | |||
@@ -11,7 +11,7 @@ from checklayer.case import OECheckLayerTestCase | |||
11 | class BSPCheckLayer(OECheckLayerTestCase): | 11 | class BSPCheckLayer(OECheckLayerTestCase): |
12 | @classmethod | 12 | @classmethod |
13 | def setUpClass(self): | 13 | def setUpClass(self): |
14 | if self.tc.layer['type'] != LayerType.BSP: | 14 | if self.tc.layer['type'] not in (LayerType.BSP, LayerType.CORE): |
15 | raise unittest.SkipTest("BSPCheckLayer: Layer %s isn't BSP one." %\ | 15 | raise unittest.SkipTest("BSPCheckLayer: Layer %s isn't BSP one." %\ |
16 | self.tc.layer['name']) | 16 | self.tc.layer['name']) |
17 | 17 | ||
@@ -153,7 +153,7 @@ class BSPCheckLayer(OECheckLayerTestCase): | |||
153 | # do_build can be ignored: it is know to have | 153 | # do_build can be ignored: it is know to have |
154 | # different signatures in some cases, for example in | 154 | # different signatures in some cases, for example in |
155 | # the allarch ca-certificates due to RDEPENDS=openssl. | 155 | # the allarch ca-certificates due to RDEPENDS=openssl. |
156 | # That particular dependency is whitelisted via | 156 | # That particular dependency is marked via |
157 | # SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, but still shows up | 157 | # SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS, but still shows up |
158 | # in the sstate signature hash because filtering it | 158 | # in the sstate signature hash because filtering it |
159 | # out would be hard and running do_build multiple | 159 | # out would be hard and running do_build multiple |
diff --git a/scripts/lib/checklayer/cases/common.py b/scripts/lib/checklayer/cases/common.py index b82304e361..ddead69a7b 100644 --- a/scripts/lib/checklayer/cases/common.py +++ b/scripts/lib/checklayer/cases/common.py | |||
@@ -6,15 +6,19 @@ | |||
6 | import glob | 6 | import glob |
7 | import os | 7 | import os |
8 | import unittest | 8 | import unittest |
9 | from checklayer import get_signatures, LayerType, check_command, get_depgraph, compare_signatures | 9 | import re |
10 | from checklayer import get_signatures, LayerType, check_command, compare_signatures, get_git_toplevel | ||
10 | from checklayer.case import OECheckLayerTestCase | 11 | from checklayer.case import OECheckLayerTestCase |
11 | 12 | ||
12 | class CommonCheckLayer(OECheckLayerTestCase): | 13 | class CommonCheckLayer(OECheckLayerTestCase): |
13 | def test_readme(self): | 14 | def test_readme(self): |
15 | if self.tc.layer['type'] == LayerType.CORE: | ||
16 | raise unittest.SkipTest("Core layer's README is top level") | ||
17 | |||
14 | # The top-level README file may have a suffix (like README.rst or README.txt). | 18 | # The top-level README file may have a suffix (like README.rst or README.txt). |
15 | readme_files = glob.glob(os.path.join(self.tc.layer['path'], '[Rr][Ee][Aa][Dd][Mm][Ee]*')) | 19 | readme_files = glob.glob(os.path.join(self.tc.layer['path'], '[Rr][Ee][Aa][Dd][Mm][Ee]*')) |
16 | self.assertTrue(len(readme_files) > 0, | 20 | self.assertTrue(len(readme_files) > 0, |
17 | msg="Layer doesn't contains README file.") | 21 | msg="Layer doesn't contain a README file.") |
18 | 22 | ||
19 | # There might be more than one file matching the file pattern above | 23 | # 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 | 24 | # (for example, README.rst and README-COPYING.rst). The one with the shortest |
@@ -26,6 +30,48 @@ class CommonCheckLayer(OECheckLayerTestCase): | |||
26 | self.assertTrue(data, | 30 | self.assertTrue(data, |
27 | msg="Layer contains a README file but it is empty.") | 31 | msg="Layer contains a README file but it is empty.") |
28 | 32 | ||
33 | # If a layer's README references another README, then the checks below are not valid | ||
34 | if re.search('README', data, re.IGNORECASE): | ||
35 | return | ||
36 | |||
37 | self.assertIn('maintainer', data.lower()) | ||
38 | self.assertIn('patch', data.lower()) | ||
39 | # Check that there is an email address in the README | ||
40 | email_regex = re.compile(r"[^@]+@[^@]+") | ||
41 | self.assertTrue(email_regex.match(data)) | ||
42 | |||
43 | def find_file_by_name(self, globs): | ||
44 | """ | ||
45 | Utility function to find a file that matches the specified list of | ||
46 | globs, in either the layer directory itself or the repository top-level | ||
47 | directory. | ||
48 | """ | ||
49 | directories = [self.tc.layer["path"]] | ||
50 | toplevel = get_git_toplevel(directories[0]) | ||
51 | if toplevel: | ||
52 | directories.append(toplevel) | ||
53 | |||
54 | for path in directories: | ||
55 | for name in globs: | ||
56 | files = glob.glob(os.path.join(path, name)) | ||
57 | if files: | ||
58 | return sorted(files)[0] | ||
59 | return None | ||
60 | |||
61 | def test_security(self): | ||
62 | """ | ||
63 | Test that the layer has a SECURITY.md (or similar) file, either in the | ||
64 | layer itself or at the top of the containing git repository. | ||
65 | """ | ||
66 | if self.tc.layer["type"] == LayerType.CORE: | ||
67 | raise unittest.SkipTest("Core layer's SECURITY is top level") | ||
68 | |||
69 | filename = self.find_file_by_name(("SECURITY", "SECURITY.*")) | ||
70 | self.assertTrue(filename, msg="Layer doesn't contain a SECURITY.md file.") | ||
71 | |||
72 | size = os.path.getsize(filename) | ||
73 | self.assertGreater(size, 0, msg=f"{filename} has no content.") | ||
74 | |||
29 | def test_parse(self): | 75 | def test_parse(self): |
30 | check_command('Layer %s failed to parse.' % self.tc.layer['name'], | 76 | check_command('Layer %s failed to parse.' % self.tc.layer['name'], |
31 | 'bitbake -p') | 77 | 'bitbake -p') |
@@ -43,6 +89,35 @@ class CommonCheckLayer(OECheckLayerTestCase): | |||
43 | ''' | 89 | ''' |
44 | get_signatures(self.td['builddir'], failsafe=False) | 90 | get_signatures(self.td['builddir'], failsafe=False) |
45 | 91 | ||
92 | def test_world_inherit_class(self): | ||
93 | ''' | ||
94 | This also does "bitbake -S none world" along with inheriting "yocto-check-layer" | ||
95 | class, which can do additional per-recipe test cases. | ||
96 | ''' | ||
97 | msg = [] | ||
98 | try: | ||
99 | get_signatures(self.td['builddir'], failsafe=False, machine=None, extravars='BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS INHERIT" INHERIT="yocto-check-layer"') | ||
100 | except RuntimeError as ex: | ||
101 | msg.append(str(ex)) | ||
102 | if msg: | ||
103 | msg.insert(0, 'Layer %s failed additional checks from yocto-check-layer.bbclass\nSee below log for specific recipe parsing errors:\n' % \ | ||
104 | self.tc.layer['name']) | ||
105 | self.fail('\n'.join(msg)) | ||
106 | |||
107 | def test_patches_upstream_status(self): | ||
108 | import sys | ||
109 | sys.path.append(os.path.join(sys.path[0], '../../../../meta/lib/')) | ||
110 | import oe.qa | ||
111 | patches = [] | ||
112 | for dirpath, dirs, files in os.walk(self.tc.layer['path']): | ||
113 | for filename in files: | ||
114 | if filename.endswith(".patch"): | ||
115 | ppath = os.path.join(dirpath, filename) | ||
116 | if oe.qa.check_upstream_status(ppath): | ||
117 | patches.append(ppath) | ||
118 | self.assertEqual(len(patches), 0 , \ | ||
119 | msg="Found following patches with malformed or missing upstream status:\n%s" % '\n'.join([str(patch) for patch in patches])) | ||
120 | |||
46 | def test_signatures(self): | 121 | def test_signatures(self): |
47 | if self.tc.layer['type'] == LayerType.SOFTWARE and \ | 122 | if self.tc.layer['type'] == LayerType.SOFTWARE and \ |
48 | not self.tc.test_software_layer_signatures: | 123 | not self.tc.test_software_layer_signatures: |
diff --git a/scripts/lib/checklayer/cases/distro.py b/scripts/lib/checklayer/cases/distro.py index f0bee5493c..a35332451c 100644 --- a/scripts/lib/checklayer/cases/distro.py +++ b/scripts/lib/checklayer/cases/distro.py | |||
@@ -11,7 +11,7 @@ from checklayer.case import OECheckLayerTestCase | |||
11 | class DistroCheckLayer(OECheckLayerTestCase): | 11 | class DistroCheckLayer(OECheckLayerTestCase): |
12 | @classmethod | 12 | @classmethod |
13 | def setUpClass(self): | 13 | def setUpClass(self): |
14 | if self.tc.layer['type'] != LayerType.DISTRO: | 14 | if self.tc.layer['type'] not in (LayerType.DISTRO, LayerType.CORE): |
15 | raise unittest.SkipTest("DistroCheckLayer: Layer %s isn't Distro one." %\ | 15 | raise unittest.SkipTest("DistroCheckLayer: Layer %s isn't Distro one." %\ |
16 | self.tc.layer['name']) | 16 | self.tc.layer['name']) |
17 | 17 | ||