Skip to contentSkip to conversation

oe-selftest improvements

PATCH New Paul Barker 1 participant 4 messages Jun 3, 2020

lore
Share & tools
lore
#0 lore raw

cover oe-selftest improvements

These patches add some extra options to oe-selftest and fix the test case patching logic discussed with RP on IRC.

The last patch may fix [1] but further confirmation is needed.

[1]: https://bugzilla.yoctoproject.org/show_bug.cgi?id=13815

Paul Barker (3):
oe-selftest: Allow overriding the build directory used for tests
oe-selftest: Support verbose log output
oe-selftest: Recursively patch test case paths

 meta/lib/oeqa/core/context.py     |  2 ++
 meta/lib/oeqa/selftest/context.py | 25 +++++++++++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/3 oe-selftest: Allow overriding the build directory used for tests

This may be useful if the parent directory of the original builddir is not writable, on a lower performance drive, etc.

---
 meta/lib/oeqa/selftest/context.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
meta/lib/oeqa/selftest/context.py +8 -2
index 48ec5d419c..17f2a0cf6b 100644
@@ -22,18 +22,22 @@ from oeqa.core.exception import OEQAPreRun, OEQATestNotFound
 from oeqa.utils.commands import runCmd, get_bb_vars, get_test_layer
 
 class OESelftestTestContext(OETestContext):
-    def __init__(self, td=None, logger=None, machines=None, config_paths=None):
+    def __init__(self, td=None, logger=None, machines=None, config_paths=None, newbuilddir=None):
         super(OESelftestTestContext, self).__init__(td, logger)
 
         self.machines = machines
         self.custommachine = None
         self.config_paths = config_paths
+        self.newbuilddir = newbuilddir
 
     def setup_builddir(self, suffix, selftestdir, suite):
         builddir = os.environ['BUILDDIR']
         if not selftestdir:
             selftestdir = get_test_layer()
-        newbuilddir = builddir + suffix
+        if self.newbuilddir:
+            newbuilddir = os.path.join(self.newbuilddir, 'build' + suffix)
+        else:
+            newbuilddir = builddir + suffix
         newselftestdir = newbuilddir + "/meta-selftest"
 
         if os.path.exists(newbuilddir):
@@ -133,6 +137,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
                 action='append', default=None,
                 help='Exclude all (unhidden) tests that match any of the specified tag(s). (exclude applies before select)')
 
+        parser.add_argument('-B', '--newbuilddir', help='New build directory to use for tests.')
         parser.set_defaults(func=self.run)
 
     def _get_available_machines(self):
@@ -187,6 +192,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']['newbuilddir'] = args.newbuilddir
 
         def tag_filter(tags):
             if args.exclude_tags:
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/3 oe-selftest: Support verbose log output

In reply to Paul Barker
---
 meta/lib/oeqa/core/context.py     | 2 ++
 meta/lib/oeqa/selftest/context.py | 1 +
 2 files changed, 3 insertions(+)
meta/lib/oeqa/core/context.py +2 -0
index 4705d608ac..7d3fa3b84a 100644
@@ -156,6 +156,8 @@ class OETestContextExecutor(object):
         fh = logging.FileHandler(args.output_log)
         fh.setFormatter(formatter)
         logger.addHandler(fh)
+        if getattr(args, 'verbose', False):
+            logger.setLevel('DEBUG')
 
         return logger
 
meta/lib/oeqa/selftest/context.py +1 -0
index 17f2a0cf6b..7589ca3c1f 100644
@@ -138,6 +138,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor):
                 help='Exclude all (unhidden) tests that match any of the specified tag(s). (exclude applies before select)')
 
         parser.add_argument('-B', '--newbuilddir', help='New build directory to use for tests.')
+        parser.add_argument('-v', '--verbose', action='store_true')
         parser.set_defaults(func=self.run)
 
     def _get_available_machines(self):
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/3 oe-selftest: Recursively patch test case paths

In reply to Paul Barker

This ensures that builddir is updated correctly to point to the new selftest build directory when we're given a list of test suites instead of a list of test cases.

---
 meta/lib/oeqa/selftest/context.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
meta/lib/oeqa/selftest/context.py +12 -2
index 7589ca3c1f..494e9dbd1e 100644
@@ -10,6 +10,7 @@ import glob
 import sys
 import importlib
 import subprocess
+import unittest
 from random import choice
 
 import oeqa
@@ -60,9 +61,9 @@ class OESelftestTestContext(OETestContext):
 
         os.chdir(newbuilddir)
 
-        for t in suite:
+        def patch_test(t):
             if not hasattr(t, "tc"):
-                continue
+                return
             cp = t.tc.config_paths
             for p in cp:
                 if selftestdir in cp[p] and newselftestdir not in cp[p]:
@@ -70,6 +71,15 @@ class OESelftestTestContext(OETestContext):
                 if builddir in cp[p] and newbuilddir not in cp[p]:
                     cp[p] = cp[p].replace(builddir, newbuilddir)
 
+        def patch_suite(s):
+            for x in s:
+                if isinstance(x, unittest.TestSuite):
+                    patch_suite(x)
+                else:
+                    patch_test(x)
+
+        patch_suite(suite)
+
         return (builddir, newbuilddir)
 
     def prepareSuite(self, suites, processes):
Signature · 1 line
2.26.2