]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
oeqa/sdk: add helpers to check for and install packages
authorRoss Burton <ross.burton@arm.com>
Sat, 10 May 2025 08:43:41 +0000 (09:43 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 12 May 2025 09:52:52 +0000 (10:52 +0100)
The existing tests simply look at the manifest to determine if a test
should be ran or not based on dependencies. Whilst this works for
Traditional SDKs, it fails for Extensible SDKs if they've been built in
minimal mode, where the manifest will be empty.  However, minimal eSDKs
might well have available sstate to install the missing dependencies.

Add a pair of helper functions to ensure that a package is available, or
skip the test.  This handles nativesdk- vs -native (SDK vs eSDK) and
will try to sdk-install missing dependencies into an eSDK if they're not
already installed.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/sdk/case.py

index 46a3789f5724e55503bbe453e2348f522de5b02e..1fd3b3b5695dd5fac32c7d96e29785fbab467907 100644 (file)
@@ -7,8 +7,10 @@
 import os
 import subprocess
 import shutil
+import unittest
 
 from oeqa.core.case import OETestCase
+from oeqa.sdkext.context import OESDKExtTestContext
 
 class OESDKTestCase(OETestCase):
     def _run(self, cmd):
@@ -16,6 +18,62 @@ class OESDKTestCase(OETestCase):
                 (self.tc.sdk_env, cmd), shell=True, executable="/bin/bash",
                 stderr=subprocess.STDOUT, universal_newlines=True)
 
+    def ensure_host_package(self, *packages, recipe=None):
+        """
+        Check that the host variation of one of the packages listed is available
+        in the SDK (nativesdk-foo for SDK, foo-native for eSDK). The package is
+        a list for the case where debian-renaming may have occured, and the
+        manifest could contain 'foo' or 'libfoo'.
+
+        If testing an eSDK and the package is not found, then try to install the
+        specified recipe to install it from sstate.
+        """
+
+        # In a SDK the manifest is correct. In an eSDK the manifest may be
+        # correct (type=full) or not include packages that exist in sstate but
+        # not installed yet (minimal) so we should try to install the recipe.
+        for package in packages:
+            if isinstance(self.tc, OESDKExtTestContext):
+                package = package + "-native"
+            else:
+                package = "nativesdk-" + package
+
+            if self.tc.hasHostPackage(package):
+                break
+        else:
+            if isinstance(self.tc, OESDKExtTestContext):
+                recipe = (recipe or packages[0]) + "-native"
+                print("Trying to install %s..." % recipe)
+                self._run('devtool sdk-install %s' % recipe)
+            else:
+                raise unittest.SkipTest("Test %s needs one of %s" % (self.id(), ", ".join(packages)))
+
+    def ensure_target_package(self, *packages, multilib=False, recipe=None):
+        """
+        Check that at least one of the packages listed is available in the SDK,
+        adding the multilib prefix if required. The target package is a list for
+        the case where debian-renaming may have occured, and the manifest could
+        contain 'foo' or 'libfoo'.
+
+        If testing an eSDK and the package is not found, then try to install the
+        specified recipe to install it from sstate.
+        """
+
+        # In a SDK the manifest is correct. In an eSDK the manifest may be
+        # correct (type=full) or not include packages that exist in sstate but
+        # not installed yet (minimal) so we should try to install the recipe.
+        for package in packages:
+            if self.tc.hasTargetPackage(package, multilib=multilib):
+                break
+        else:
+            if isinstance(self.tc, OESDKExtTestContext):
+                recipe = recipe or packages[0]
+                print("Trying to install %s..." % recipe)
+                self._run('devtool sdk-install %s' % recipe)
+            else:
+                raise unittest.SkipTest("Test %s needs one of %s" % (self.id(), ", ".join(packages)))
+
+
     def fetch(self, workdir, dl_dir, url, archive=None):
         if not archive:
             from urllib.parse import urlparse