|This article is a stub. You can help the wiki by|
Regression Testing in FlightGear
While introducing unit tests and regression tests into the FlightGear project has been repeatedly brought up by several long-term contributors  and core developers , it isn't yet in wide or regular use in FlightGear, even though it is generally understood to be a worthwhile addition to FlightGear in order to to automated testing of individual features, for example while prepare releases .
And while there are indeed some minor build tests provided by both, the SimGear and FlightGear projects, such test cases aren't really commonly provided our updated by developers when introducing modified or new code. Also, these are just low level tests for specific APIs - and do not lend themselves to be used for testing high level features.
FlightGear in its current form is an application that was primarily designed as an interactive graphical simulator, in other words, it is meant to be used by a user sitting in front of one or multiple screens, controlled by means such as a keyboard, mouse and other optional hardware such as joysticks/yokes and possibly also rudder/yaw pedals.
While confining FlightGear's design and use cases to this standard use scenario was of course very valid and feasible (as this is definitely the primary use) this restriction isn't necessarily ideal or even appropriate for the project to eventually be able to leverage itself for increasingly important purposes such as automated unit testing or automated benchmarking of individual FlightGear components in order to do regression testing.
This RFC is meant to discuss the possible merits and approaches of allowing FlightGear to be used non-interactively, i.e. in an automated fashion such as for example by invoking it via shell scripts, so that FlightGear doesn't necessarily have to rely on user input or even a graphical output window in order to do a certain, well-defined and limited job.
While there are certainly various thinkable scenarios for employing such facilities in other interesting contexts, this RFC will merely focus on the benefits for FlightGear itself.
Introducing Regression Tests to FlightGear
The task of introducing regression tests isn't that easily achieved in FlightGear's case:
FlightGear has largely become an independent system and platform, so while it would be fairly straightforward (but still very tedious) to introduce individual unit tests in order to validate the correct behavior of low level C++ components, such as the SimGear APIs, it wouldn't really be that easy to properly test the various abstract, high level features that are provided by FlightGear as a functionality provider and simulation framework/platform with all its various subsystems providing support for abstract features.
In fact, conventional regression tests would inevitably fail when it comes to supporting base package resources, simply because FlightGear is the sole target platform for these resources.
While base package resources do generally make use of well-understood and established technologies or standards (i.e. textures, XML, scripts, 3D models, text files etc), it is only the specific combination of these resources inside FlightGear, that define a real purpose and use.
So, doing proper regression testing for such high level features would be very difficult without writing lots of redundant test code, which would probably end up being a maintenance burden in the long term - probably resulting in a situation similar to the current one, where tests simply end up being neglected and ignored at some point.
Thus, this discussion of bringing regression testing to FlightGear favors an approach where FlightGear itself is used as the regression testing framework.
So this isn't about doing low-level unit testing for individual FlightGear C++ code, but much more abstractly do regression testing by making use of the FlightGear platform to test abstract FlightGear features by making use of FlightGear's native support for technologies such as XML, scripting and networking.
Leverage FlightGear as its own regression testing framework, for purposes such as for example:
- debugging (running FlightGear non-interactively, without requiring user input)
- unit tests (e.g. to facilitate refactoring efforts)
- automated release preparations (e.g. to test individual subsystems but also complete aircraft)
- benchmarking the whole system or individual subsystems
Due to FlightGear's extensive support for flexible software interfaces (such as e.g. networking, scripting and XML), FlightGear can in many scenarios theoretically already be used for serving as its own test platform.
In fact, the major obstacle really limiting FlightGear to be used by automated/scripted tests is its reliance on having a graphical output window available and opened.
If FlightGear provided an option to be run in non-interactive/headless mode, so that it wouldn't necessarily create an output window but could just run silently in a shell environment, it could already be easily used by shell scripts to do simple things such as for example profiling the fgfs process while running a specific Nasal script non-interactively and automatically terminating afterwards.
It's worth pointing out that this is indeed already possible: Nasal scripts can terminate the simulator by invoking an fgcommand, so this really isn't that much off the table and would facilitate scenarios where Nasal scripts may run certain test suites and automatically report status back to the caller (shell script). So, this would be just one scenario for running fgfs non-interactively in order to profile the Nasal interpreter.
Also, FlightGear's reliance on user input via means such as the mouse/keyboard and other hardware peripherals doesn't really pose a real problem, because all of these inputs are already internally handled by a combination of XML and scripting, so that emulating arbitrary user input by making use of scripts or by automatically writing to the property tree via network sockets is fairly straightforward and could also be accomplished by running shell scripts, that may for example invoke "netcat" specifically for this purpose.
- allow FlightGear to be run without creating a GUI window, i.e. in "headless" mode
- allow FlightGear to be optionally compiled and run without any sound support/dependencies (OpenAL)
- allow replay buffers to be saved to a file in order to be replayed for automated test/demo flights
- allow arbitrary user inputs to be simulated via property tree modifications (pretty much possible already)
- allow individual subsystems to be enabled/disabled dynamically (via properties), so that profiling and debugging can be restricted to specific usage scenarios and components