New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Twister v2 – a general rework of the testing framework #42458
Comments
Random thoughts: we could consider re-using pytest ecosystem, see for example https://github.com/pytest-dev/pytest-cpp (not tested, though) |
After having several discussions I started to be convinced that pytest might be a good framework to wrap twister around. I've heard several times: "Why do you want to reinvent the wheel and not to take an existing framework, where your requirements are already supported, and which is in a common usage? Why not pytest?". From my initial prestudy, using pytest looks really tempting. We will collect and present more information about it and its benefits. We will also present a Proof Of Concept for the pytest-based twister. Below is my idea for the requirements for the PoC. I also added them to the RFC text. Of course, they are a subject to be discussed: PoCGoal
|
I just wanted to chime in and mention IDE support. VS Code introduced a test runner API a couple of months ago that allows listing and running tests through a UI in the sidebar. Microsoft's Python extension already supports this API, and will populate the test list with tests discovered using pytest: https://code.visualstudio.com/docs/python/testing. They're also working on a similar API for code coverage, but that's still not in the public release. If pytest is a viable solution, Twister will essentially get a VS Code UI for free. I'm not sure how debugging would work for Twister tests, but it's likely possible to implement this through Zephyr side python code. I haven't tried it myself, but CLion also appears to support this. Regardless, we'd like to create a Twister user experience with Nordic's VS Code extensions - either as a new standalone Twister extension, or as part of the main extension. For this to work out, we'll need to be able to:
|
I'd like to add a minor point about junit. I suggest that for Twister v2, the output xml should be adjusted such that tests/samples in Jenkins ends up being browsable in a similar layout to the actual filesystem layout. So the above image (which shows samples in
This will make it less noisy in the UI and more obvious where to locate tests. I believe this should be as simple as rearranging the components of the test names. |
For this, at least from a mcumgr standpoint, it's vital that there is also support for being able to use and interact with an external utility (likely python based, but any type of external script/application would be preferred) so that it can send/receive commands to/from real devices (qemu devices could also be considered) and to also use the return code of the process when exiting to influence if a test is successful or not. |
@lairdjm Could you rephrase this a bit? Not sure if I follow. What would be a use case? I understand it now as to be able to use twister as a middleman between external unity and hardware/emulator. Is it the case? |
So for testing mcumgr, it will have the code on the module and it will need to communicate with an external utility either via serial, bluetooth, UDP or another transport method and as part of that the test will need to set the tool up and run it. Example would be for getting a file from the filesystem of a device, zephyr application gets loaded to the target board and runs, an application/script runs on the test PC which then communicates with the device to download the file and checks the commands work and that the received file is what was expected. |
Similar as to what you can do using the |
@PerMac is there an update on pytest PoC? We need to decide very soon if this is going to be the way to go or if we have to implement things differently. |
The status is that me and my colleague will work on a prototype for the pytest-based runner. Some initial work was already done, but it is too early to show anything meaningful yet. We had to get internally a green light for the commitment and its scope and it was granted recently. |
can we close this please? |
This RFC is closed since twister v2 won't be introduced. The strategy to improve the existing framework instead was adapted. Working on v2 brought an understanding on how to integrate pytest with twister allowing introduction of more complex tests, which were postulated in this PR. Such tests are now possibile to be executed within the current framework. https://docs.zephyrproject.org/latest/develop/test/pytest.html. More context: |
Why?
Twister was developed and evolved in a more “reactive” manner, adding new features when they were needed. In its current state Twister lacks a coherent overall architecture. A lot of parts are done in a procedural way, where a single function is responsible for too many operations (e.g. handle() method which: locks a device where a test will be run, creates a command for a runner, flashes, counts execution time, sets test statuses, unlocks the device). This makes the framework hard to maintain and expand.
Several places in the code have a similar responsibility (e.g. different report formats have their own decision trees handling test statuses) which makes maintenance very error-prone and requires high vigilance on all other parts that have to be synced when a change is made in one of them.
In addition, transparency, reliability, and traceability of test specifications/results are hard to obtain due to the current design . This is a major concern of test managers.
The current state of Twister makes many developers reluctant towards contributing to the source code, which is harmful to an open-source project. Our goal is to make the software more transparent and modularized, flattening the learning curve and making the code more approachable for potential contributors.
Having Quality Assurance at heart it seems we are at a point where a general rework of Twister is a necessary path to follow.
How?
Twister will get a grand rework. We will follow ISTQB (International Software Testing Qualifications Board) standards for test architecture design. The idea is to start with a generic Test Automation Architecture (from ISTQB test automation engineer syllabus, section 3.1) and adapt it to our needs. The core principles to follow when designing Twister v2 are:
The new design will also enforce higher QA standards at its core. New components will be designed according to the requirements and will be developed alongside corresponding tests verifying the correctness of components’ performance.
Overall requirements:
The above requirements were gathered during testing wg meetings and discussions with colleagues involved in testing (at various levels). Just to stress this out, nothing is set in stone. I would really appreciate all the suggestions and/or additional requirements.
The process for developing Twister v2 will be transparent and contributors will be encourage to take part in it. I volunteer to create and maintain a GitHub "project" for this process. I will split the framework into major modules (e.g. test configuration, reporting, execution etc.) and gather/provide a separate high-level description and requirements for each of them. The idea is to be able to implement them in parallel. I also hope that having modules, components and corresponding tasks divided into smaller chunks and easily visible on a kanban-style table will attract contributors to fulfilling them. I would also like to try using
good first issue
andhelp wanted
labels on easier and smaller tasks.PoC (pytest)
Goal
Show the concept behind pytest and its major benefits. Show that the framework can be compatible with zephyr and its tests.
Requirements:
Show how plugins/fixtures/hooks works and how a framework can be built from blocks -> benefits from standardized apis and specs:
ETA:
Hard to estimate yet.
I will keep editing this entry, by adding more graphs, requirements, and details.
The text was updated successfully, but these errors were encountered: