FlightGear Headless
This article describes content/features that may not yet be available in the latest stable version of FlightGear (2020.3). You may need to install some extra components, use the latest development (Git) version or even rebuild FlightGear from source, possibly from a custom topic branch using special build settings: .This feature is scheduled for FlightGear 2018.x. ![]() If you'd like to learn more about getting your own ideas into FlightGear, check out Implementing new features for FlightGear. |
Portability & Compatibility |
---|
Performance |
Efforts |
FlightGear Headless
The original FG scene graph design is based on rigid assumptions of the ordering of the sequence of events for start up and shut down. Branch management is highly inconsistent, and is scattered all over the flightgear and simgear codebases. But it worked perfectly due to the fixed event sequences. The new subsystem design however brings in a much more flexible design, whereby systems can be dynamically turned on, turned off, restarted, initialised, reinitialised, etc. This is essential for enabling rebooting, and allows for custom FlightGear usage of only a small subset of systems and for a headless mode. The OSG+subsystem breakage occurred once the scene manager subsystem was fully converted to the new design. The OSG scene graph root is created at the start of FGScenery::init(). With the subsystem design, the scene graph root may not be present when other flightgear/simgear code paths are called to create, manage, or destroy the various scene graph branches.[1]
Another option is to make FGRenderer the optional piece - James Turner started doing some work in this direction in December 2015. I.e without FGRenderer there is no rendering at all, and hence no scene-graph.[2]
we should really do with with subclassing, making an SGDisplaySubsystem with:
- virtual void initVisuals();
- virtual void updateVisuals();
- virtual void shutdownVisuals();
With the expectation that the manager layer (FGScenery or FGRenderer) calls initVisuals / updateVisuals / shutdownVisuals if it exists. This also forces the implementation of each subsystem to distinguish simulation pieces (modifies properties) from display pieces (reads but hopefully does not modify properties, modifies OSG/rendering state, i.e. visuals) [3]
- ↑ Edward d'Auvergne (Apr 28th, 2016). [Flightgear-devel] Integration of the new subsystem design and the OSG scene graph management..
- ↑ James Turner (May 4th, 2016). Re: [Flightgear-devel] Integration of the new subsystem design and the OSG scene graph management..
- ↑ James Turner (May 4th, 2016). Re: [Flightgear-devel] Integration of the new subsystem design and the OSG scene graph management..
Motivation
![]() |
these are exactly the same types of changes I was thinking of for fully decoupling all the various parts of FlightGear for use in a CppUnit-based test suite — bugman (Feb 23rd, 2016). Re: FGPython an propose for Python as an nasal alternative.
(powered by Instant-Cquotes) |
![]() |
![]() |
what remains true is the that overwhelming majority of the FlightGear main loop time is spent rendering the graphics. — Curtis Olson (Feb 1st, 2016). Re: [Flightgear-devel] Designing a thread-safe property tree API.
(powered by Instant-Cquotes) |
![]() |
![]() |
That's not to say there aren't some bottlenecks in our rendering pipeline that need to eventually be dealt with, but these are more tied to our use of properties and nasal in graphics system call backs (much of this we inherited from the original design which was build around plib's SG (scene graph) library.) — Curtis Olson (Feb 1st, 2016). Re: [Flightgear-devel] Designing a thread-safe property tree API.
(powered by Instant-Cquotes) |
![]() |
![](/w/images/thumb/5/5b/Patching-fg-3.2-to-make-more-subsystems-optional.png/450px-Patching-fg-3.2-to-make-more-subsystems-optional.png)
Note Also see Testing |
![]() |
If we want to remove an subsystem from the flight gear source code, without leaving any trace of it.. What are the essential steps ?(for example, if the sound update has to be removed, what are steps to be followed). — Divi (Aug 31st, 2015). Steps for Removing subsystems in flightgear source code.
(powered by Instant-Cquotes) |
![]() |
![]() |
the route manager has a fairly nasty bug that results in memory consumption increasing throughout a flight. The rate at which it increases appears to increase with the number of waypoints, with a flight of 20 waypoints experiencing an increase of over 2GB per hour in my tests. The longer the flight, the more waypoints it tends to have and the more unsustainable the growth becomes.
— Richard Senior (2015-02-25 22:00:53). Memory leak most likely from route manager in 3.4.0 and next.
(powered by Instant-Cquotes) |
![]() |
![]() |
I am wishing I could easily add tests for the route-path / GPS code, but anything that needs ‘globals’ is hard to test in isolation.
— James Turner (2015-01-12). Re: [Flightgear-devel] ATIS and negative temperatures (+ very fast
speech).
(powered by Instant-Cquotes) |
![]() |
![]() |
I appreciate that would require us to have a unit-testing infrastructure, and way to bring up a subset of globals and the nav-cache, in a test environment. I have made a few abortive attempts at exactly that but the sprawling nature of FGGlobals keeps defeating me.
— James Turner (2015-05-14). Re: [Flightgear-devel] Major problems with the AI traffic system.
(powered by Instant-Cquotes) |
![]() |
![]() |
The primary goals are:
Obviously supporting a standalone 'fgcanvas' would be quite a small extension from those. I'm not worrying about dynamic dependencies or automatic subsystem creation for the moment - I expect the user / defaults to have defined a set of subsystems that work without crashing You're correct of course that Nasal has many assumptions about subsystems, but I think that can be improved incrementally on the Nasal side. For the test mode, I really want to start Nasal-the-langauge very early, without loading all the modules in Nasal/ immediately. (Or maybe load a 'safe' subset). That's going to take some thought and I didn't get that far yet![1]— James Turner
|
![]() |
![]() |
I'm working on a prototype of this - with no X11 / VLC required at all. It will load scenery tiles (for ground-intersections) but no views or rendering. But don't be in a rush for something to appear in Git, it's just an experiment.[2] — James Turner
|
![]() |
Proof of concept (patch)
Note This will not actually disable rendering, but merely hide the window by rendering to a pbuffer (FBO) |
The main camera is created in CameraGroup::buildCamera and a pbuffer is allocated when you set osg::GraphicContext::Traits.pbuffer to true. These traits are available in buildCamera because we set width and height there. For debugging purpose, you can add a line like
window->gc->getTraits()->pbuffer=true;
at the end of this function.[3]
diff --git a/src/Main/options.cxx b/src/Main/options.cxx
index db5d84d..fb63dd1 100644
--- a/src/Main/options.cxx
+++ b/src/Main/options.cxx
@@ -1797,6 +1797,7 @@ struct OptionDesc {
{"prop", true, OPTION_FUNC | OPTION_MULTI, "", false, "", fgOptSetProperty},
{"load-tape", true, OPTION_FUNC, "", false, "", fgOptLoadTape },
{"developer", true, OPTION_IGNORE | OPTION_BOOL, "", false, "", nullptr },
+ {"enable-headless", false, OPTION_BOOL, "/sim/startup/headless-mode", true, "",0 },
{0}
};
diff --git a/src/Viewer/WindowBuilder.cxx b/src/Viewer/WindowBuilder.cxx
index f4d3c33..a1ffb84 100644
--- a/src/Viewer/WindowBuilder.cxx
+++ b/src/Viewer/WindowBuilder.cxx
@@ -149,6 +149,12 @@ void WindowBuilder::makeDefaultTraits(bool stencil)
SG_LOG(SG_VIEW,SG_DEBUG,"Using initial window size: " << w << " x " << h);
}
}
+bool headless = fgGetBool("/sim/startup/headless-mode", false);
+if (headless) {
+ SG_LOG(SG_VIEW, SG_ALERT, "Headless view required: rendering window to pbuffer");
+ traits->pbuffer = true;
+} // enable headless
+
}
} // of namespace flightgear
For reference, to disable the window. It's the last thing before the return statement in WindowBuilder::makeDefaultTraits(bool stencil):
char* fg_gui = getenv("FG_GUI");
if (fg_gui != NULL && strcmp(fg_gui, "disabled") == 0) {
printf ("danna_fg_gui: %s\n", fg_gui);
traits->pbuffer = true;
}
just set an environment variable in my shell called FG_GUI and then this little hack works.[4]
export FG_GUI=disabled
Status (07/2014)
Note As of mid 2014, this is being worked on via Initializing Nasal early, in part, this effort is also overlapping with the Reset & re-init and FlightGear Run Levels efforts. |
![]() |
One could write automatic tests for FlightGear using the scripting and scenario support. — Tim Moore (Jul 17th, 2007). Re: [Flightgear-devel] development process.
(powered by Instant-Cquotes) |
![]() |
![]() |
I'm writing some automated testing code for pieces of FG, so that I can experiment with changes to various internal bits of code with more confidence that I haven't broken anything. These aren't quite unit-tests (they test multiple areas of the code at once) and they're pretty crude, but any testing is better than none (and quicker than manual testing).[5] — James Turner
|
![]() |
![]() |
I only need the graphical output for the real aircraft and want to disable the unnecessary graphical outputs (to reduce work load).[6] — Rahlf, Jonas (ext.)
|
![]() |
![]() |
I'm interested in the capability of doing multiple builds with different versions, branches and options and in doing some kind of automated testing on the resulting builds[7] — Pat
|
![]() |
![]() |
Make subsystems create-able and removable from commands. Only some subsystems are supported so far, since many have non-default constructors or other complexities.
With this, change, it's possible to dynamically add and remove the traffic-manager at runtime, for example: fgcommand("add-subsystem", props.Node.new({ "subsystem": "traffic-manager", "name":"traffic-manager", "do-bind-init":1})); — James Turner
|
![]() |
![]() |
could some thought be given to producing a benchmark suite for Flightgear. It would need to take in all of the, by now well known, variables - making it by no means a simple beast to manage.
If this could be automated in some way it would be much easier to capture, and then submit, consistent data. [9] — Alan Teeder
|
![]() |
![]() |
A scripted run would be an EXCELLENT tool.[10] — geneb
|
![]() |
![]() |
Is there a way to do that "headless", without any graphic output? I wasn't being clear - I wanted to run *FlightGear* in a "headless" mode,
not the browser.[11] — geneb
|
![]() |
![]() |
I don't think you can run FlightGear without a window. There used to be some property "draw-otw" that - if set - stops fg from rendering anything to
the screen, but it still needs an opengl screen.[12] — TorstenD
|
![]() |
![]() |
I regularly test a rather small subset of FG features, i.e. never use MP or the replay system, no multi-monitor setup, no flights beyond ~90 minutes, no Rembrandt, no Basic Weather, rarely life weather,... so what we need to worry about most are use cases not covered by us — Thorsten Renk (Nov 19th, 2015). Re: [Flightgear-devel] Some thoughts about the release process.
(powered by Instant-Cquotes) |
![]() |
Also see, FlightGear Benchmark
- ↑ James Turner (Oct 01, 2012). incremental initialization of SGSubsystems.
- ↑ James Turner (Sep 26, 2012). Issues 882 (Improved CI / regression testing support by providing options to disable interactive features (sound/window)).
- ↑ FredB (Sun Mar 24). Re: run without osg.
- ↑ alexklibisz (Aug 1st, 2016). Re: Headless mode with access to property tree .
- ↑ James Turner (Sun, 24 Aug 2008 13:53:58 -0700). Startup position offsets (fg_init).
- ↑ Rahlf, Jonas (ext.) (Wed, 31 Jul 2013 04:42:48 -0700). [Flightgear-devel] Disable grahpical output in flightgear / interface flightgear server instead of flightgear.
- ↑ Pat (Wed, 03 Jul 2013 17:24:19 -0700). Re: [Flightgear-devel] FG 2.12 RC Broken ?.
- ↑ James Turner (Oct 01, 2012). Initial work on dynamic subsystem creation..
- ↑ Alan Teeder (Thu, 20 Jun 2013 10:15:42 -0700). [Flightgear-devel] Benchmark matrix.
- ↑ geneb (Thu, 20 Jun 2013 10:20:41 -0700). Re: [Flightgear-devel] Benchmark matrix.
- ↑ geneb (2014-04-23 14:22:57). Property documentation....
- ↑ TorstenD (2014-04-23 14:22:57). Property documentation....
Regression Testing in FlightGear
![]() |
the intel driver is more strict on these and throws errors when others are happily moving along, so that got me into thinking whether we could somehow wire the shader compiler into Jenkins to have these checked right away? Just like it's useful in catching compilation errors on windows and mac, that are less common architectures among the developers. — Tuomas Kuosmanen (Feb 17th, 2016). Re: [Flightgear-devel] To Release or not?.
(powered by Instant-Cquotes) |
![]() |
While introducing unit tests and regression tests into the FlightGear project has been repeatedly brought up by several long-term contributors [2] and core developers [3], 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 do automated testing of individual features, for example when preparing releases [4].
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.
Increasingly, FlightGear users are facing issues that are highly specific to their usage of FlightGear so that it isn't directly or easily possible to reproduce certain issues without exactly reproducing possibly an entire flight including identical startup and runtime settings, a fact that is also frequently acknowledged by FlightGear core developers [5].
This is however not only a tedious and long-winded process, but also a process that may require certain usage patterns and background information or a specific set of skills (such as for example landing a specific aircraft on an aircraft carrier).
In fact, the corresponding bug reports are often fairly long winded and complicated in that they try to provide all information necessary in order to allow developers to redo a certain flight segment that resulted in an error (see for example [6] or [7], [8]).
These obstacles in debugging such highly specific issues are also highlighted by core developers to severely limit the troubleshooting process [9].
For a more recent discussion of regression testing and benchmarking, see FlightGear Benchmark.
Background
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 is an approach that is already used by the jsbsim project to some extent [10].
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, such as for example running certain subsystems for benchmarking purposes or by running scripted flights to fly standard patterns in order to generally help test aircraft that are considered for inclusion in upcoming FlightGear releases.
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
![]() |
I am working on a comprehensive test suite for the flightgear codebase (simgear already has its own). I will present this later on, but only once I have fully functional Windows support. The design of this test suite will allow individual subsystems to be initialised in full isolation. It will allow for the standard subsystem methods (init, reinit, bind, unbind, update, etc.) to be called in any order in a highly repetitive manner. It is a little like Hooray's segfault paradise - the reinit.nas reset/re-init control panel [1] - in that it is great for fishing out a tonne of segfaults. I have used this for stabilising the FGPythonSys experiment [2]. This would really help with implementing the above design and making the OSG heavy subsystems fully independent. — Edward d'Auvergne (Apr 28th, 2016). [Flightgear-devel] Integration of the new subsystem design and the
OSG scene graph management..
(powered by Instant-Cquotes) |
![]() |
![]() |
Actually my thinking is along these lines - these are exactly the same types of changes I was thinking of for fully decoupling all the various parts of FlightGear for use in a CppUnit-based test suite ;) Something for the future though. — bugman (Feb 23rd, 2016). Re: FGPython an propose for Python as an nasal alternative.
(powered by Instant-Cquotes) |
![]() |
![]() |
Personally I would be reluctant to add a framework dependency (CppUnit / Google Test) unless the benefits are large and thus far I wasn’t convinced. The nasty macro-based tests are my hack and could / should be improved. Boost is a bit of a debating point in the project, I’d suggest to avoid it for tests again unless there is some massive benefit. Reflecting on this have written the above, if there was a common framework which could replace my hacks, but also avoid Boost, I’d personally be okay with that providing it’s an optional compile time requirement. Whatever the solution, it should be runnable via CTest, and if it generates output that Jenkins can parse, that would be fantastic. Non-Ctest compatible solutions would be possible but mean some build infrastructure changes. — James Turner (Mar 23rd, 2015). Re: [Flightgear-devel] SimGear/FlightGear Portability Patches.
(powered by Instant-Cquotes) |
![]() |
![]() |
Unit-testing for the FlightGear classes would be fantastic, but in general the ‘FGGlobals’ structure makes it hard. To unit-test most areas will mean a standard test harness which starts up a skeletal subsystem manager, the NavCache (for some classes, e.g. radio testing), and somehow makes an FGGlobals which works (maybe a mock one) but doesn’t require linking in 80% of the codebase. Any maintainable, not-too-intrusive idea on doing that is welcome!
— James Turner (2015-03-23). Re: [Flightgear-devel] SimGear/FlightGear Portability Patches.
(powered by Instant-Cquotes) |
![]() |
![]() |
I've done some initial measurement to identify potential memory leaks in SimGear.
Detection was limited to execution of code covered by unit tests. |
![]() |
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.
Goals
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, or even flights/flight plans)
- benchmarking the whole system or individual subsystems
- feature-scaling by making some subsystems optional or better configurable
Approach
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 a visible 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. Another possible use might be scripted flights to have aircraft fly standard patterns or instrument approaches, while using a network interface such as the telnet facility to monitor the state of the flight during all phases of the flight.
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.
The recent additions to the Autopilot and Route Manager systems in FlightGear also make it increasingly feasible to create completely scripted test flights for automatically doing certain portions of a flight without relying on user input.
![]() |
the most flexible approach would be using scripting - FligthGear has a built-in scripting language (called "Nasal"), that can be used to control aircraft, and even to instantiate multiple AI aircraft, one of the most straightforward examples is the "tanker.nas" script, which creates a fully scripted AI tanker - that could be easily extended to create dozens of tankers, and obviously you could also change the 3D model if you wanted to. In fact, we have a separate addon, named "bombable" that adds "AI bots" to the simulator, for dogfighting purposes - none of that required C++ changes, it's all done in scripting space. Another users implemented a fully scripted missile (fox2.nas) that tracks aircraft
— Hooray (Wed Aug 28). Re: Suitability of this software to run a swarm simulation.
(powered by Instant-Cquotes) |
![]() |
![]() |
Curt did that a while back for the f14b, which did a fully automated carrier approach using just Nasal scripting:
— Hooray (Mon Feb 04). Re: Possibility to run a fully automatized mission ?.
(powered by Instant-Cquotes) |
![]() |
Milestones
- allow FlightGear to be run without creating a visible GUI window, i.e. in "headless" mode, using a --headless parameter
Pending
- allow FlightGear to be optionally compiled and run without any sound support/dependencies (OpenAL)
Done
- allow replay buffers to be saved to a file in order to be replayed for automated test/demo flights, so that users can share saved replay buffers when reporting a bug
Done (supported via the flight recorder subsystem)
- allow arbitrary user inputs to be simulated via property tree modifications (pretty much possible already)
Done
- allow individual subsystems to be enabled/disabled dynamically (via properties), so that profiling and debugging can be restricted to specific usage scenarios and components
- extend the Nasal API in order to facilitate "remote controlling" the simulator largely using scripts
Related
- http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg02181.html
- http://forum.flightgear.org/viewtopic.php?f=18&t=19502&p=179978&hilit=#p179968
- https://code.google.com/p/flightgear-bugs/issues/detail?id=882
- FlightGear commit af6611d7f61a6d993ce94fa6efade0b4485eb7a5
Devel List
- http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40521.html
- http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg29510.html
- http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg29907.html
- http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg02028.html
References
References
|