Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

build-system: add capability to execute scripts with custom executor #18770

Merged
merged 1 commit into from
Oct 20, 2022

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Oct 19, 2022

Contribution description

I sometimes find it more convenient to use pytest to execute and debug my more complex tests (it shows output in order of test execution, in color, you can filter tests and has flags to step in with pdb, ...). However, for that I either need to define all the RIOT environment in my shell, or touch makefile/tests/tests.mk to execute the test with pytest. Since I do not want to enforce pytest on everyone and the CI, this amends that file with two optional macros TEST_EXECUTOR and TEST_EXECUTOR_FLAGS, so the executor for the tests can be selected from the environment.

Testing procedure

Sadly, not all tests are able to be run this way: when the test... function has an argument, pytest thinks that argument is a fixture and gets confused (another reason why I made pytest optional). However, all tests that are based on unittest classes (so either unittests.TestCase or testrunner.unittest.PexpectTestCase (e.g. tests/turo can now be executed this way):

$ TEST_EXECUTOR=pytest TEST_EXECUTOR_FLAGS="-v -s" QUIETER=1 make -C tests/turo/ --no-print-directory -j flash test
Building application "tests_turo" for "native" with MCU "native".

/usr/bin/ld: warning: /home/mlenders/Repositories/RIOT-OS/RIOT/tests/turo/bin/native/tests_turo.elf has a LOAD segment with RWX permissions
   text	   data	    bss	    dec	    hex	filename
  39098	    704	  47800	  87602	  15632	/home/mlenders/Repositories/RIOT-OS/RIOT/tests/turo/bin/native/tests_turo.elf
============================= test session starts ==============================
platform linux -- Python 3.10.8, pytest-7.1.3, pluggy-1.0.0 -- /usr/bin/python
cachedir: .pytest_cache
rootdir: /home/mlenders/Repositories/RIOT-OS/RIOT/tests/turo
plugins: cov-4.0.0, anyio-3.6.1
collected 13 items                                                             

tests/01-run.py::TestTuro::test_test_multi_element_dict PASSED
tests/01-run.py::TestTuro::test_test_netif PASSED
tests/01-run.py::TestTuro::test_turo_simple_array_s32 PASSED
tests/01-run.py::TestTuro::test_turo_simple_array_s32_fail PASSED
tests/01-run.py::TestTuro::test_turo_simple_array_u8 PASSED
tests/01-run.py::TestTuro::test_turo_simple_array_u8_fail PASSED
tests/01-run.py::TestTuro::test_turo_simple_dict_s32 PASSED
tests/01-run.py::TestTuro::test_turo_simple_dict_s32_fail PASSED
tests/01-run.py::TestTuro::test_turo_simple_dict_string PASSED
tests/01-run.py::TestTuro::test_turo_simple_dict_string_fail PASSED
tests/01-run.py::TestTuro::test_turo_simple_exit_status PASSED
tests/01-run.py::TestTuro::test_turo_simple_s32 PASSED
tests/01-run.py::TestTuro::test_turo_simple_s32_fail PASSED

============================== 13 passed in 4.52s ==============================

Of course, the normal approach should also still work:

$ QUIETER=1 make -C tests/turo/ --no-print-directory -j flash test
Building application "tests_turo" for "native" with MCU "native".

/usr/bin/ld: warning: /home/mlenders/Repositories/RIOT-OS/RIOT/tests/turo/bin/native/tests_turo.elf has a LOAD segment with RWX permissions
   text	   data	    bss	    dec	    hex	filename
  39098	    704	  47800	  87602	  15632	/home/mlenders/Repositories/RIOT-OS/RIOT/tests/turo/bin/native/tests_turo.elf
.............
----------------------------------------------------------------------
Ran 13 tests in 4.453s

OK

Issues/PRs references

None, but got the idea while debugging #18769.

@miri64 miri64 added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label Oct 19, 2022
@github-actions github-actions bot added Area: build system Area: Build system Area: tests Area: tests and testing framework labels Oct 19, 2022
@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 19, 2022
@riot-ci
Copy link

riot-ci commented Oct 19, 2022

Murdock results

✔️ PASSED

14b7abd build-system: add capability to execute scripts with custom executor

Success Failures Total Runtime
1991 0 1991 06m:23s

Artifacts

This only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now.

@miri64 miri64 merged commit a535e44 into RIOT-OS:master Oct 20, 2022
@miri64 miri64 deleted the makefiles/enh/test-executor branch October 20, 2022 06:07
@kaspar030 kaspar030 added this to the Release 2023.01 milestone Jan 19, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Area: build system Area: Build system Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants