From: Adrian Freihofer <[email protected]>

By default the toolcfg.conf file from build/conf/toolcfg.conf is copied
to build-st/conf/toolcfg.conf. Provide an easy way to add fragments
to the toolcfg.conf file from within oe-selftest test cases.

Signed-off-by: Adrian Freihofer <[email protected]>
---
 meta/lib/oeqa/selftest/case.py    | 28 ++++++++++++++++++++++++++++
 meta/lib/oeqa/selftest/context.py |  1 +
 2 files changed, 29 insertions(+)

diff --git a/meta/lib/oeqa/selftest/case.py b/meta/lib/oeqa/selftest/case.py
index da35b25f68..96898411c3 100644
--- a/meta/lib/oeqa/selftest/case.py
+++ b/meta/lib/oeqa/selftest/case.py
@@ -8,6 +8,7 @@ import sys
 import os
 import glob
 import errno
+import shutil
 from unittest.util import safe_repr
 
 import oeqa.utils.ftools as ftools
@@ -19,6 +20,7 @@ import bb.utils
 class OESelftestTestCase(OETestCase):
     def __init__(self, methodName="runTest"):
         self._extra_tear_down_commands = []
+        self._toolcfgconf_backup = None
         super(OESelftestTestCase, self).__init__(methodName)
 
     @classmethod
@@ -30,6 +32,7 @@ class OESelftestTestCase(OETestCase):
 
         cls.localconf_path = cls.tc.config_paths['localconf']
         cls.local_bblayers_path = cls.tc.config_paths['bblayers']
+        cls.toolcfgconf_path = cls.tc.config_paths['toolcfgconf']
 
         cls.testinc_path = os.path.join(cls.tc.config_paths['builddir'],
                 "conf/selftest.inc")
@@ -137,6 +140,10 @@ class OESelftestTestCase(OETestCase):
                 self.logger.debug("Trying to move on.")
             self._extra_tear_down_commands = []
 
+        # Restore toolcfgconf backup
+        if self._toolcfgconf_backup and 
os.path.exists(self._toolcfgconf_backup):
+            shutil.copy2(self._toolcfgconf_backup, self.toolcfgconf_path)
+
         if self._track_for_cleanup:
             for path in self._track_for_cleanup:
                 if os.path.isdir(path):
@@ -174,6 +181,27 @@ class OESelftestTestCase(OETestCase):
         self.logger.debug("Writing to: %s\n%s\n" % (dest_path, data))
         ftools.write_file(dest_path, data)
 
+    def configure_fragments(self, enable_fragments=None, 
disable_fragments=None):
+        """Configure fragments using bitbake-config-build tool"""
+        existed = os.path.exists(self.toolcfgconf_path)
+        # If there was an existing toolcfg.conf, back it up and restore it in 
tearDown
+        if existed:
+            backup_path = self.toolcfgconf_path + ".oe-selftest-bak"
+            shutil.copy2(self.toolcfgconf_path, backup_path)
+            self._toolcfgconf_backup = backup_path
+            self.track_for_cleanup(backup_path)
+
+        if enable_fragments:
+            cmd = 'bitbake-config-build enable-fragment ' + ' 
'.join(enable_fragments)
+            runCmd(cmd)
+        if disable_fragments:
+            cmd = 'bitbake-config-build disable-fragment ' + ' 
'.join(disable_fragments)
+            runCmd(cmd)
+
+        # If there was no existing toolcfg.conf before, track the new one for 
cleanup
+        if not existed and os.path.exists(self.toolcfgconf_path):
+            self.track_for_cleanup(self.toolcfgconf_path)
+
     def append_config(self, data):
         """Append to <builddir>/conf/selftest.inc"""
         self.logger.debug("Appending to: %s\n%s\n" % (self.testinc_path, data))
diff --git a/meta/lib/oeqa/selftest/context.py 
b/meta/lib/oeqa/selftest/context.py
index c9eb481725..02a4832553 100644
--- a/meta/lib/oeqa/selftest/context.py
+++ b/meta/lib/oeqa/selftest/context.py
@@ -278,6 +278,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
         self.tc_kwargs['init']['config_paths']['builddir'] = builddir
         self.tc_kwargs['init']['config_paths']['localconf'] = 
os.path.join(builddir, "conf/local.conf")
         self.tc_kwargs['init']['config_paths']['bblayers'] = 
os.path.join(builddir, "conf/bblayers.conf")
+        self.tc_kwargs['init']['config_paths']['toolcfgconf'] = 
os.path.join(builddir, "conf/toolcfg.conf")
         self.tc_kwargs['init']['newbuilddir'] = args.newbuilddir
         self.tc_kwargs['init']['keep_builddir'] = args.keep_builddir
 
-- 
2.52.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#228657): 
https://lists.openembedded.org/g/openembedded-core/message/228657
Mute This Topic: https://lists.openembedded.org/mt/116996287/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to