diff mbox series

[13/14] oe-selftest devtool: ide tests

Message ID 20230821161120.171956-14-adrian.freihofer@siemens.com
State New
Headers show
Series devtool ide plugin | expand

Commit Message

Adrian Freihofer Aug. 21, 2023, 4:07 p.m. UTC
Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/lib/oeqa/selftest/cases/devtool.py | 133 ++++++++++++++++++++++++
 1 file changed, 133 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py
index 14a80d5ff4c..083ecd4acfb 100644
--- a/meta/lib/oeqa/selftest/cases/devtool.py
+++ b/meta/lib/oeqa/selftest/cases/devtool.py
@@ -11,6 +11,7 @@  import tempfile
 import glob
 import fnmatch
 import unittest
+import json
 
 from oeqa.selftest.case import OESelftestTestCase
 from oeqa.utils.commands import runCmd, bitbake, get_bb_var, create_temp_layer
@@ -2192,3 +2193,135 @@  class DevtoolUpgradeTests(DevtoolBase):
 
         #Step 4.5
         runCmd("grep %s %s" % (modconfopt, codeconfigfile))
+
+
+class DevtoolIdeTests(DevtoolBase):
+
+    def __devtool_ide_recipe(self):
+        tempdir = tempfile.mkdtemp(prefix='devtoolqa')
+        self.track_for_cleanup(tempdir)
+        self.track_for_cleanup(self.workspacedir)
+        self.add_command_to_tearDown('bitbake -c clean %s' % self.recipe_name)
+        self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
+
+        conf_lines = [
+            'IMAGE_FEATURES += "ssh-server-openssh"',
+            'IMAGE_CLASSES += "image-combined-dbg"',
+            'IMAGE_GEN_DEBUGFS = "1"',
+            'IMAGE_INSTALL += "gdbserver %s-ptest"' % self.recipe_name
+        ]
+        self.write_config("\n".join(conf_lines))
+
+        result = runCmd('devtool modify %s -x %s' % (self.recipe_name, tempdir))
+        self.assertExists(os.path.join(tempdir, self.build_file),
+                          'Extracted source could not be found')
+        self.assertExists(os.path.join(self.workspacedir, 'conf',
+                          'layer.conf'), 'Workspace directory not created')
+        matches = glob.glob(os.path.join(self.workspacedir,
+                            'appends', self.recipe_name + '.bbappend'))
+        self.assertTrue(matches, 'bbappend not created %s' % result.output)
+
+        # Test devtool status
+        result = runCmd('devtool status')
+        self.assertIn(self.recipe_name, result.output)
+        self.assertIn(tempdir, result.output)
+        self._check_src_repo(tempdir)
+
+        result = runCmd('devtool ide %s core-image-minimal -c' % self.recipe_name)
+        return tempdir
+
+    def __devtool_ide_qemu(self):
+        # Verify do_install works
+        with open(os.path.join(self.tempdir, '.vscode', 'tasks.json')) as tasks_j:
+            tasks_d = json.load(tasks_j)
+        tasks = tasks_d["tasks"]
+        task_install = next((task for task in tasks if task["label"] == "install && deploy-target %s"  % self.recipe_name), None)
+        self.assertIsNot(task_install, None)
+        install_deploy_cmd = task_install["command"]
+        # execute only the bb_run_do_install script since the deploy would require e.g. Qemu running.
+        install_cmd = install_deploy_cmd.replace("install_and_deploy", "bb_run_do_install")
+        runCmd(install_cmd, cwd=self.tempdir)
+
+        # Verify if re-building the SDK still works and the deploy and install script gets generated
+        runCmd('devtool ide %s core-image-minimal -c' % self.recipe_name)
+        self.assertExists(install_deploy_cmd, 'install_and_deploy script not found')
+
+        # Verify deployment to Qemu works
+        with runqemu("core-image-minimal", runqemuparams = "nographic") as qemu:
+            MAGIC_STRING_ORIG = "Magic: 123456789"
+            MAGIC_STRING_NEW = "Magic: 987654321"
+
+            # Verify the unmodified example prints the magic string
+            status, output = qemu.run(self.example_exe)
+            self.assertEqual(status, 0)
+            self.assertIn(MAGIC_STRING_ORIG, output)
+
+            # Verify the unmodified ptests work
+            status, output = qemu.run("ptest-runner " + self.recipe_name)
+            self.assertEqual(status, 0, msg=output)
+            self.assertIn("PASS: cpp-example-lib", output)
+
+            # Replace the Magic String in the code, compile and deploy to Qemu
+            cpp_example_lib_hpp = os.path.join(self.tempdir, 'cpp-example-lib.hpp')
+            with open(cpp_example_lib_hpp, 'r') as file:
+                cpp_code = file.read()
+                cpp_code = cpp_code.replace(MAGIC_STRING_ORIG, MAGIC_STRING_NEW)
+            with open(cpp_example_lib_hpp, 'w') as file:
+                file.write(cpp_code)
+            runCmd(install_deploy_cmd, cwd=self.tempdir)
+
+            # Verify the modified example prints the modified magic string
+            status, output = qemu.run(self.example_exe)
+            self.assertEqual(status, 0)
+            self.assertNotIn(MAGIC_STRING_ORIG, output)
+            self.assertIn(MAGIC_STRING_NEW, output)
+
+            # Verify the modified example ptests work
+            status, output = qemu.run("ptest-runner " + self.recipe_name)
+            self.assertEqual(status, 0, msg=output)
+            self.assertIn("PASS: cpp-example-lib", output)
+
+    def test_devtool_ide_recipe_cmake(self):
+        self.recipe_name = "cmake-example"
+        self.example_exe = "cmake-example"
+        self.build_file = "CMakeLists.txt"
+        self.tempdir = self.__devtool_ide_recipe()
+
+        with open(os.path.join(self.tempdir, 'CMakeUserPresets.json')) as cmake_preset_j:
+            cmake_preset_d = json.load(cmake_preset_j)
+        config_presets = cmake_preset_d["configurePresets"]
+        self.assertEqual(len(config_presets), 1)
+        cmake_exe = config_presets[0]["cmakeExecutable"]
+        preset_name = config_presets[0]["name"]
+
+        # Verify the cmake preset generated by devtool ide is available
+        result = runCmd('%s --list-presets' % cmake_exe, cwd=self.tempdir)
+        self.assertIn(preset_name, result.output)
+
+        # Verify cmake re-uses the o files compiled by bitbake
+        result = runCmd('%s --build --preset %s' % (cmake_exe, preset_name), cwd=self.tempdir)
+        self.assertIn("ninja: no work to do.", result.output)
+
+        # Verify the unit tests work (in Qemu)
+        result = runCmd('%s --build --preset %s --target test' % (cmake_exe, preset_name), cwd=self.tempdir)
+        self.assertIn("100% tests passed", result.output)
+
+        # Verify re-building and testing works again
+        result = runCmd('%s --build --preset %s --target clean' % (cmake_exe, preset_name), cwd=self.tempdir)
+        self.assertIn("Cleaning all built files...", result.output)
+        result = runCmd('%s --build --preset %s' % (cmake_exe, preset_name), cwd=self.tempdir)
+        self.assertIn("Building", result.output)
+        self.assertIn("Linking", result.output)
+        result = runCmd('%s --build --preset %s --target test' % (cmake_exe, preset_name), cwd=self.tempdir)
+        self.assertIn("Running tests...", result.output)
+        self.assertIn("100% tests passed", result.output)
+
+        self.__devtool_ide_qemu()
+
+    def test_devtool_ide_recipe_meson(self):
+        self.recipe_name = "meson-example"
+        self.example_exe = "mesonex"
+        self.build_file = "meson.build"
+        self.tempdir = self.__devtool_ide_recipe()
+
+        self.__devtool_ide_qemu()