* [Buildroot] [RFC v2 1/3] support/testing/run-tests: add try block for indentation
2024-01-03 0:28 [Buildroot] [RFC v2 0/3] Add external test support Colin Foster
@ 2024-01-03 0:28 ` Colin Foster
2024-01-03 0:28 ` [Buildroot] [RFC v2 2/3] support/testing/run-tests: run tests from temp directory Colin Foster
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Colin Foster @ 2024-01-03 0:28 UTC (permalink / raw)
To: buildroot; +Cc: Thomas Petazzoni, Yann E. MORIN, Ricardo Martincoski
Cleanup code for try/finally is necessary for a separate patch. Utilize
a separate patch to add a try block so that the other patches that
actually will change the behavior are much more reviewable.
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
---
v2: New patch, broken out for reviewability
---
support/testing/run-tests | 146 ++++++++++++++++++++------------------
1 file changed, 75 insertions(+), 71 deletions(-)
diff --git a/support/testing/run-tests b/support/testing/run-tests
index 485811b746..9d1174cb3b 100755
--- a/support/testing/run-tests
+++ b/support/testing/run-tests
@@ -42,94 +42,98 @@ def main():
script_path = os.path.realpath(__file__)
test_dir = os.path.dirname(script_path)
- if args.stdout:
- BRConfigTest.logtofile = False
-
- if args.list:
- print("List of tests")
- nose2.discover(argv=[script_path,
- "-s", test_dir,
- "-v",
- "--collect-only"],
- plugins=["nose2.plugins.collect"])
- return 0
-
- if args.download is None:
- args.download = os.getenv("BR2_DL_DIR")
+ try:
+ if args.stdout:
+ BRConfigTest.logtofile = False
+
+ if args.list:
+ print("List of tests")
+ nose2.discover(argv=[script_path,
+ "-s", test_dir,
+ "-v",
+ "--collect-only"],
+ plugins=["nose2.plugins.collect"])
+ return 0
+
if args.download is None:
- print("Missing download directory, please use -d/--download")
+ args.download = os.getenv("BR2_DL_DIR")
+ if args.download is None:
+ print("Missing download directory, please use -d/--download")
+ print("")
+ parser.print_help()
+ return 1
+
+ BRConfigTest.downloaddir = os.path.abspath(args.download)
+
+ if args.prepare_only:
+ emulator_builtin_binaries = ["kernel-vexpress-5.10.202",
+ "vexpress-v2p-ca9-5.10.202.dtb",
+ "kernel-versatile-5.10.202",
+ "versatile-pb-5.10.202.dtb"]
+ print("Downloading emulator builtin binaries")
+ for binary in emulator_builtin_binaries:
+ infra.download(BRConfigTest.downloaddir, binary)
+ return 0
+
+ if args.output is None:
+ print("Missing output directory, please use -o/--output")
print("")
parser.print_help()
return 1
- BRConfigTest.downloaddir = os.path.abspath(args.download)
-
- if args.prepare_only:
- emulator_builtin_binaries = ["kernel-vexpress-5.10.202",
- "vexpress-v2p-ca9-5.10.202.dtb",
- "kernel-versatile-5.10.202",
- "versatile-pb-5.10.202.dtb"]
- print("Downloading emulator builtin binaries")
- for binary in emulator_builtin_binaries:
- infra.download(BRConfigTest.downloaddir, binary)
- return 0
-
- if args.output is None:
- print("Missing output directory, please use -o/--output")
- print("")
- parser.print_help()
- return 1
-
- if not os.path.exists(args.output):
- os.mkdir(args.output)
+ if not os.path.exists(args.output):
+ os.mkdir(args.output)
- BRConfigTest.outputdir = os.path.abspath(args.output)
+ BRConfigTest.outputdir = os.path.abspath(args.output)
- if args.all is False and not args.testname:
- print("No test selected")
- print("")
- parser.print_help()
- return 1
-
- BRConfigTest.keepbuilds = args.keep
-
- if args.testcases != 1:
- if args.testcases < 1:
- print("Invalid number of testcases to run simultaneously")
+ if args.all is False and not args.testname:
+ print("No test selected")
print("")
parser.print_help()
return 1
- # same default BR2_JLEVEL as package/Makefile.in
- br2_jlevel = 1 + multiprocessing.cpu_count()
- each_testcase = int((br2_jlevel + args.testcases) / args.testcases)
- BRConfigTest.jlevel = each_testcase
-
- if args.jlevel:
- if args.jlevel < 0:
- print("Invalid BR2_JLEVEL to use for each testcase")
+
+ BRConfigTest.keepbuilds = args.keep
+
+ if args.testcases != 1:
+ if args.testcases < 1:
+ print("Invalid number of testcases to run simultaneously")
+ print("")
+ parser.print_help()
+ return 1
+ # same default BR2_JLEVEL as package/Makefile.in
+ br2_jlevel = 1 + multiprocessing.cpu_count()
+ each_testcase = int((br2_jlevel + args.testcases) / args.testcases)
+ BRConfigTest.jlevel = each_testcase
+
+ if args.jlevel:
+ if args.jlevel < 0:
+ print("Invalid BR2_JLEVEL to use for each testcase")
+ print("")
+ parser.print_help()
+ return 1
+ # the user can override the auto calculated value
+ BRConfigTest.jlevel = args.jlevel
+
+ if args.timeout_multiplier < 1:
+ print("Invalid multiplier for timeout values")
print("")
parser.print_help()
return 1
- # the user can override the auto calculated value
- BRConfigTest.jlevel = args.jlevel
-
- if args.timeout_multiplier < 1:
- print("Invalid multiplier for timeout values")
- print("")
- parser.print_help()
- return 1
- BRConfigTest.timeout_multiplier = args.timeout_multiplier
+ BRConfigTest.timeout_multiplier = args.timeout_multiplier
- nose2_args = ["-v",
- "-N", str(args.testcases),
- "-s", test_dir,
- "-c", os.path.join(test_dir, "conf/unittest.cfg")]
+ nose2_args = ["-v",
+ "-N", str(args.testcases),
+ "-s", test_dir,
+ "-c", os.path.join(test_dir, "conf/unittest.cfg")]
- if args.testname:
- nose2_args += args.testname
+ if args.testname:
+ nose2_args += args.testname
- nose2.discover(argv=nose2_args)
+ nose2.discover(argv=nose2_args)
+ finally:
+ # Placeholder for try, to be undone shortly
+ pass
if __name__ == "__main__":
sys.exit(main())
--
2.34.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 6+ messages in thread* [Buildroot] [PATCH v3] support/testing/run-tests: add ability to run tests from external
2024-01-03 0:28 [Buildroot] [RFC v2 0/3] Add external test support Colin Foster
` (2 preceding siblings ...)
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
2026-11-23 13:46 ` Colin Foster via buildroot
3 siblings, 1 reply; 6+ messages in thread
From: Angelo Compagnucci @ 2026-11-21 20:37 UTC (permalink / raw)
To: buildroot
Cc: Ricardo Martincoski, Thomas Petazzoni, Yann E . MORIN,
Colin Foster
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
^ permalink raw reply related [flat|nested] 6+ messages in thread