diff mbox series

[16/17] qa: Add selftest for python3-spdx-tools

Message ID 20230922144628.2495839-17-samantha.jalabert@syslinbit.com
State Accepted, archived
Commit e766fe7a9391cc9348d92ab704ec58c4806e38c6
Headers show
Series python3-spdx-tools implementation | expand

Commit Message

Samantha Jalabert Sept. 22, 2023, 2:46 p.m. UTC
From: Samantha Jalabert <samantha.jalabert@syslinbit.com>

Signed-off-by: Marta Rybczynska <mrybczynska@syslinbit.com>
Signed-off-by: Samantha Jalabert <samantha.jalabert@syslinbit.com>
---
 meta/lib/oeqa/selftest/cases/spdx.py | 54 ++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 meta/lib/oeqa/selftest/cases/spdx.py
diff mbox series

Patch

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 @@ 
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+import json
+import os
+from oeqa.selftest.case import OESelftestTestCase
+from oeqa.utils.commands import bitbake, get_bb_var, runCmd
+
+class SPDXCheck(OESelftestTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        super(SPDXCheck, cls).setUpClass()
+        bitbake("python3-spdx-tools-native")
+        bitbake("-c addto_recipe_sysroot python3-spdx-tools-native")
+
+    def check_recipe_spdx(self, high_level_dir, spdx_file, target_name):
+        config = """
+INHERIT += "create-spdx"
+"""
+        self.write_config(config)
+
+        deploy_dir = get_bb_var("DEPLOY_DIR")
+        machine_var = get_bb_var("MACHINE")
+        # qemux86-64 creates the directory qemux86_64
+        machine_dir = machine_var.replace("-", "_")
+
+        full_file_path = os.path.join(deploy_dir, "spdx", machine_dir, high_level_dir, spdx_file)
+
+        try:
+            os.remove(full_file_path)
+        except FileNotFoundError:
+            pass
+
+        bitbake("%s -c create_spdx" % target_name)
+
+        def check_spdx_json(filename):
+            with open(filename) as f:
+                report = json.load(f)
+                self.assertNotEqual(report, None)
+                self.assertNotEqual(report["SPDXID"], None)
+
+            python = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-spdx-tools-native'), 'nativepython3')
+            validator = os.path.join(get_bb_var('STAGING_BINDIR', 'python3-spdx-tools-native'), 'pyspdxtools')
+            result = runCmd("{} {} -i {}".format(python, validator, filename))
+
+        self.assertExists(full_file_path)
+        result = check_spdx_json(full_file_path)
+
+    def test_spdx_base_files(self):
+        self.check_recipe_spdx("packages", "base-files.spdx.json", "base-files")