summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/spdx.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/spdx.py')
-rw-r--r--meta/lib/oeqa/selftest/cases/spdx.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/spdx.py b/meta/lib/oeqa/selftest/cases/spdx.py
new file mode 100644
index 0000000000..05fc4e390b
--- /dev/null
+++ b/meta/lib/oeqa/selftest/cases/spdx.py
@@ -0,0 +1,54 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7import json
8import os
9from oeqa.selftest.case import OESelftestTestCase
10from oeqa.utils.commands import bitbake, get_bb_var, runCmd
11
12class SPDXCheck(OESelftestTestCase):
13
14 @classmethod
15 def setUpClass(cls):
16 super(SPDXCheck, cls).setUpClass()
17 bitbake("python3-spdx-tools-native")
18 bitbake("-c addto_recipe_sysroot python3-spdx-tools-native")
19
20 def check_recipe_spdx(self, high_level_dir, spdx_file, target_name):
21 config = """
22INHERIT += "create-spdx"
23"""
24 self.write_config(config)
25
26 deploy_dir = get_bb_var("DEPLOY_DIR")
27 machine_var = get_bb_var("MACHINE")
28 # qemux86-64 creates the directory qemux86_64
29 machine_dir = machine_var.replace("-", "_")
30
31 full_file_path = os.path.join(deploy_dir, "spdx", machine_dir, high_level_dir, spdx_file)
32
33 try:
34 os.remove(full_file_path)
35 except FileNotFoundError:
36 pass
37
38 bitbake("%s -c create_spdx" % target_name)
39
40 def check_spdx_json(filename):
41 with open(filename) as f:
42 report = json.load(f)
43 self.assertNotEqual(report, None)
44 self.assertNotEqual(report["SPDXID"], None)
45
46 python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-spdx-tools-native'), 'nativepython3')
47 validator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-spdx-tools-native'), 'pyspdxtools')
48 result = runCmd("{} {} -i {}".format(python, validator, filename))
49
50 self.assertExists(full_file_path)
51 result = check_spdx_json(full_file_path)
52
53 def test_spdx_base_files(self):
54 self.check_recipe_spdx("packages", "base-files.spdx.json", "base-files")