From: Adrian Freihofer <[email protected]>

When writing configuration files during selftests, also handle the
inclusion of fragment files via the toolcfg.conf mechanism.

By default the toolcfg.conf file from build/conf/toolcfg.conf is copied
to build-st/conf/toolcfg.conf. This comes with a risk for using fragments
by accident from the main build in the selftest build. To avoid this,
support writing a reproducible set of fragments per selftest case via
the write_config() method.

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

diff --git a/meta/lib/oeqa/selftest/case.py b/meta/lib/oeqa/selftest/case.py
index da35b25f68..148b120371 100644
--- a/meta/lib/oeqa/selftest/case.py
+++ b/meta/lib/oeqa/selftest/case.py
@@ -30,6 +30,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")
@@ -161,7 +162,7 @@ class OESelftestTestCase(OETestCase):
         self.logger.debug("Adding path '%s' to be cleaned up when test is 
over" % path)
         self._track_for_cleanup.append(path)
 
-    def write_config(self, data, multiconfig=None):
+    def write_config(self, data, multiconfig=None, fragments=None):
         """Write to config file"""
         if multiconfig:
             multiconfigdir = "%s/conf/multiconfig" % self.builddir
@@ -174,6 +175,12 @@ class OESelftestTestCase(OETestCase):
         self.logger.debug("Writing to: %s\n%s\n" % (dest_path, data))
         ftools.write_file(dest_path, data)
 
+        if fragments:
+            toolscfg_str = '# Added by oe-selftest' + os.linesep + \
+                'OE_FRAGMENTS += "' + ' '.join(fragments) + '"' + os.linesep
+            self.logger.debug("Over writing fragments: %s\n%s" % 
(self.toolcfgconf_path, toolscfg_str))
+            ftools.write_file(self.toolcfgconf_path, toolscfg_str)
+
     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 (#228588): 
https://lists.openembedded.org/g/openembedded-core/message/228588
Mute This Topic: https://lists.openembedded.org/mt/116974207/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to