From: Angelo Compagnucci <angelo.compagnucci@gmail.com>
To: buildroot@buildroot.org
Cc: Ricardo Martincoski <ricardo.martincoski@datacom.com.br>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
"Yann E . MORIN" <yann.morin@orange.com>,
Colin Foster <colin.foster@in-advantage.com>
Subject: [Buildroot] [PATCH v3] support/testing/run-tests: add ability to run tests from external
Date: Sat, 21 Nov 2026 21:37:26 +0100 [thread overview]
Message-ID: <20261121203726.3858693-1-angelo.compagnucci@gmail.com> (raw)
In-Reply-To: <20240103002810.1055951-1-colin.foster@in-advantage.com>
From: Colin Foster <colin.foster@in-advantage.com>
The BR2_EXTERNAL variable can be used to keep customizations outside of
Buildroot. There was no support for writing tests in those external
environments.
When the BR2_EXTERNAL environment variable is set, run-tests now also
finds the tests in the support/testing/tests folder of each
br2-external:
- The support/testing folders of the br2-externals are added to the
Python path, and the tests package of Buildroot and its subpackages
use pkgutil.extend_path(). So the tests of the br2-externals merge in
the tests package: they are named and run like the Buildroot ones,
e.g. tests.package.test_foo.TestFoo.
- PYTHONPATH passes these folders to the nose2 workers.
- nose2 only discovers the tests of one folder, so run-tests gives the
names of the external tests to nose2, for -l and for --all.
Document it in the manual, with the two things to know:
infra.filepath() points to the Buildroot tree, and the build of a test
case does not use the BR2_EXTERNAL environment variable. So a test case
that builds packages of its br2-external lists it in its br2_external
member.
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
Co-authored-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
---
Changes v2 -> v3:
- new approach: instead of copying all the tests to a temporary
folder, merge the tests of the br2-externals in the tests package
with pkgutil.extend_path(). Nothing is copied, and infra stays the
one of Buildroot.
- drop patch 1/3 (try block) and patch 2/3 (temporary folder), not
needed anymore
- list and run the external tests with -l and --all too: nose2 only
discovers the tests of one folder
- the build failure in the v2 cover letter came from the build of the
test case: it does not use the BR2_EXTERNAL environment variable.
Document the br2_external member of the test class, which does it.
- document the feature in the manual
- rebase on master, drop RFC
Supersedes v2:
https://patchwork.buildroot.org/project/buildroot/patch/20240103002810.1055951-2-colin.foster@in-advantage.com/
https://patchwork.buildroot.org/project/buildroot/patch/20240103002810.1055951-3-colin.foster@in-advantage.com/
https://patchwork.buildroot.org/project/buildroot/patch/20240103002810.1055951-4-colin.foster@in-advantage.com/
docs/manual/contribute.adoc | 29 +++++++++++++++
support/testing/run-tests | 39 ++++++++++++++++++++-
support/testing/tests/__init__.py | 2 ++
support/testing/tests/boot/__init__.py | 2 ++
support/testing/tests/core/__init__.py | 2 ++
support/testing/tests/download/__init__.py | 2 ++
support/testing/tests/fs/__init__.py | 2 ++
support/testing/tests/init/__init__.py | 2 ++
support/testing/tests/package/__init__.py | 2 ++
support/testing/tests/toolchain/__init__.py | 2 ++
support/testing/tests/utils/__init__.py | 2 ++
11 files changed, 85 insertions(+), 1 deletion(-)
diff --git a/docs/manual/contribute.adoc b/docs/manual/contribute.adoc
index 6ac75fb66a..653be26543 100644
--- a/docs/manual/contribute.adoc
+++ b/docs/manual/contribute.adoc
@@ -683,6 +683,35 @@ Creating a basic test case involves:
After creating the test script, add yourself to the +DEVELOPERS+ file to
be the maintainer of that test case.
+==== Test cases in a br2-external
+
+Test cases can also live in a br2-external tree, in its
++support/testing/tests/+ folder, organized like the one of Buildroot,
+e.g. +support/testing/tests/package/test_foo.py+.
+
+When the +BR2_EXTERNAL+ environment variable is set, +run-tests+ finds
+these test cases too: +run-tests -l+ lists them, and they run like the
+Buildroot ones:
+
+----
+$ BR2_EXTERNAL=/path/to/my-external support/testing/run-tests -d dl -o output_folder tests.package.test_foo.TestFoo
+----
+
+These test cases use the +infra+ of Buildroot, so:
+
+* +infra.filepath()+ points to the Buildroot tree. To find its own
+ files, a test case uses paths relative to its own file, e.g.
+ +os.path.dirname(__file__)+.
+
+* The build of a test case does not use the +BR2_EXTERNAL+ environment
+ variable. To build the packages of its br2-external, the test class
+ lists it in its +br2_external+ member:
+
+----
+class TestFoo(infra.basetest.BRTest):
+ br2_external = [os.path.join(os.path.dirname(__file__), "../../../..")]
+----
+
==== Debugging a test case
When a test case runs, the +output_folder+ will contain the following:
diff --git a/support/testing/run-tests b/support/testing/run-tests
index f0c1cc782a..90f564da0a 100755
--- a/support/testing/run-tests
+++ b/support/testing/run-tests
@@ -11,6 +11,30 @@ from infra.basetest import BRTestSettings
import infra
+def external_tests():
+ """Find the tests of the br2-externals, in their support/testing/tests
+
+ The directories are added to the Python path, so that their tests merge
+ in the tests package. PYTHONPATH passes them to the nose2 workers.
+ nose2 only discovers the tests of one directory, so return the names
+ of the external tests, to give them to nose2.
+ """
+ tests = []
+ for external in os.getenv("BR2_EXTERNAL", "").replace(":", " ").split():
+ testing_dir = os.path.join(os.path.abspath(external), "support", "testing")
+ if not os.path.isdir(os.path.join(testing_dir, "tests")):
+ continue
+ sys.path.append(testing_dir)
+ os.environ["PYTHONPATH"] = os.pathsep.join(
+ filter(None, [os.getenv("PYTHONPATH"), testing_dir]))
+ for root, _, files in os.walk(os.path.join(testing_dir, "tests")):
+ for f in sorted(files):
+ if f.startswith("test_") and f.endswith(".py"):
+ module = os.path.relpath(os.path.join(root, f[:-3]), testing_dir)
+ tests.append(module.replace(os.sep, "."))
+ return tests
+
+
def main():
parser = argparse.ArgumentParser(description='Run Buildroot tests')
parser.add_argument('testname', nargs='*',
@@ -43,6 +67,7 @@ def main():
script_path = os.path.realpath(__file__)
test_dir = os.path.dirname(script_path)
+ ext_tests = external_tests()
if args.list:
print("List of tests")
@@ -55,7 +80,12 @@ def main():
if args.debug:
nose2_args += ["--log-level", "debug"]
nose2.discover(argv=nose2_args,
- plugins=["nose2.plugins.collect"])
+ plugins=["nose2.plugins.collect"],
+ exit=False)
+ if ext_tests:
+ nose2.discover(argv=nose2_args + ext_tests,
+ plugins=["nose2.plugins.collect"],
+ exit=False)
return 0
if args.download is None:
@@ -140,6 +170,13 @@ def main():
if args.testname:
nose2_args += args.testname
+ elif ext_tests:
+ # Run all the tests: first the ones of Buildroot, then the ones of
+ # the br2-externals
+ ok = nose2.discover(argv=nose2_args, exit=False).result.wasSuccessful()
+ ok &= nose2.discover(argv=nose2_args + ext_tests,
+ exit=False).result.wasSuccessful()
+ return 0 if ok else 1
nose2.discover(argv=nose2_args)
diff --git a/support/testing/tests/__init__.py b/support/testing/tests/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/__init__.py
+++ b/support/testing/tests/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/support/testing/tests/boot/__init__.py b/support/testing/tests/boot/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/boot/__init__.py
+++ b/support/testing/tests/boot/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/support/testing/tests/core/__init__.py b/support/testing/tests/core/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/core/__init__.py
+++ b/support/testing/tests/core/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/support/testing/tests/download/__init__.py b/support/testing/tests/download/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/download/__init__.py
+++ b/support/testing/tests/download/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/support/testing/tests/fs/__init__.py b/support/testing/tests/fs/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/fs/__init__.py
+++ b/support/testing/tests/fs/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/support/testing/tests/init/__init__.py b/support/testing/tests/init/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/init/__init__.py
+++ b/support/testing/tests/init/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/support/testing/tests/package/__init__.py b/support/testing/tests/package/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/package/__init__.py
+++ b/support/testing/tests/package/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/support/testing/tests/toolchain/__init__.py b/support/testing/tests/toolchain/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/toolchain/__init__.py
+++ b/support/testing/tests/toolchain/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
diff --git a/support/testing/tests/utils/__init__.py b/support/testing/tests/utils/__init__.py
index e69de29bb2..a220f8c5ba 100644
--- a/support/testing/tests/utils/__init__.py
+++ b/support/testing/tests/utils/__init__.py
@@ -0,0 +1,2 @@
+# Merge the tests of the br2-externals in this package, see run-tests
+__path__ = __import__("pkgutil").extend_path(__path__, __name__)
--
2.53.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2026-11-21 20:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-03 0:28 [Buildroot] [RFC v2 0/3] Add external test support Colin Foster
2024-01-03 0:28 ` [Buildroot] [RFC v2 1/3] support/testing/run-tests: add try block for indentation Colin Foster
2024-01-03 0:28 ` [Buildroot] [RFC v2 2/3] support/testing/run-tests: run tests from temp directory Colin Foster
2024-01-03 0:28 ` [Buildroot] [RFC v2 3/3] support/testing/run-tests: add ability to run tests from external Colin Foster
2026-11-21 20:37 ` Angelo Compagnucci [this message]
2026-11-23 13:46 ` [Buildroot] [PATCH v3] " Colin Foster via buildroot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121203726.3858693-1-angelo.compagnucci@gmail.com \
--to=angelo.compagnucci@gmail.com \
--cc=buildroot@buildroot.org \
--cc=colin.foster@in-advantage.com \
--cc=ricardo.martincoski@datacom.com.br \
--cc=thomas.petazzoni@bootlin.com \
--cc=yann.morin@orange.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox