diff options
Diffstat (limited to 'scripts/lib/compatlayer/cases/common.py')
| -rw-r--r-- | scripts/lib/compatlayer/cases/common.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/lib/compatlayer/cases/common.py b/scripts/lib/compatlayer/cases/common.py new file mode 100644 index 0000000000..4d328ec1f1 --- /dev/null +++ b/scripts/lib/compatlayer/cases/common.py | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | # Copyright (C) 2017 Intel Corporation | ||
| 2 | # Released under the MIT license (see COPYING.MIT) | ||
| 3 | |||
| 4 | import os | ||
| 5 | import subprocess | ||
| 6 | import unittest | ||
| 7 | from compatlayer import get_signatures, LayerType | ||
| 8 | from compatlayer.case import OECompatLayerTestCase | ||
| 9 | |||
| 10 | class CommonCompatLayer(OECompatLayerTestCase): | ||
| 11 | def test_readme(self): | ||
| 12 | readme_file = os.path.join(self.tc.layer['path'], 'README') | ||
| 13 | self.assertTrue(os.path.isfile(readme_file), | ||
| 14 | msg="Layer doesn't contains README file.") | ||
| 15 | |||
| 16 | data = '' | ||
| 17 | with open(readme_file, 'r') as f: | ||
| 18 | data = f.read() | ||
| 19 | self.assertTrue(data, | ||
| 20 | msg="Layer contains README file but is empty.") | ||
| 21 | |||
| 22 | def test_parse(self): | ||
| 23 | try: | ||
| 24 | output = subprocess.check_output('bitbake -p', shell=True, | ||
| 25 | stderr=subprocess.PIPE) | ||
| 26 | except subprocess.CalledProcessError as e: | ||
| 27 | import traceback | ||
| 28 | exc = traceback.format_exc() | ||
| 29 | msg = 'Layer %s failed to parse.\n%s\n%s\n' % (self.tc.layer['name'], | ||
| 30 | exc, e.output.decode('utf-8')) | ||
| 31 | raise RuntimeError(msg) | ||
| 32 | |||
| 33 | def test_show_environment(self): | ||
| 34 | try: | ||
| 35 | output = subprocess.check_output('bitbake -e', shell=True, | ||
| 36 | stderr=subprocess.PIPE) | ||
| 37 | except subprocess.CalledProcessError as e: | ||
| 38 | import traceback | ||
| 39 | exc = traceback.format_exc() | ||
| 40 | msg = 'Layer %s failed to show environment.\n%s\n%s\n' % \ | ||
| 41 | (self.tc.layer['name'], exc, e.output.decode('utf-8')) | ||
| 42 | raise RuntimeError(msg) | ||
| 43 | |||
| 44 | def test_signatures(self): | ||
| 45 | if self.tc.layer['type'] == LayerType.SOFTWARE: | ||
| 46 | raise unittest.SkipTest("Layer %s isn't BSP or DISTRO one." \ | ||
| 47 | % self.tc.layer['name']) | ||
| 48 | |||
| 49 | sig_diff = {} | ||
| 50 | |||
| 51 | curr_sigs = get_signatures(self.td['builddir'], failsafe=True) | ||
| 52 | for task in self.td['sigs']: | ||
| 53 | if task not in curr_sigs: | ||
| 54 | continue | ||
| 55 | |||
| 56 | if self.td['sigs'][task] != curr_sigs[task]: | ||
| 57 | sig_diff[task] = '%s -> %s' % \ | ||
| 58 | (self.td['sigs'][task], curr_sigs[task]) | ||
| 59 | |||
| 60 | detail = '' | ||
| 61 | if sig_diff: | ||
| 62 | for task in sig_diff: | ||
| 63 | detail += "%s changed %s\n" % (task, sig_diff[task]) | ||
| 64 | self.assertFalse(bool(sig_diff), "Layer %s changed signatures.\n%s" % \ | ||
| 65 | (self.tc.layer['name'], detail)) | ||
| 66 | |||
