A Game Changer for Windows Driver Development?
“This is really cool … at the risk of gushing – this is a game-changer!”
Unusual words to hear about part of a source tree! To explain them we need a bit of background:
It started out as a “what-if” project one Thanksgiving; the Fort Lauderdale office had shut down for the break and I knew I wouldn’t be getting any calls for a while, creating a little pocket of time where I could explore one of the challenges we faced, “How do you test a Windows Kernel device driver?”.
By their very nature, Operating Systems are an unforgiving environment. Short of hooking up a debugger from another machine and interrupting execution, there is very little you can do to see what is happening. Much of our Kernel code had been developed in this way, combined with print statements to log activity. It works, but there has to be a more rigorous way to prove that the code is correct!
Ideally, you want to run specific tests showing that when you control the input conditions you get the expected output. These are called Unit Tests; they don’t demonstrate that the engine as a whole works, but instead, that every gear is the right shape and moves as expected. If you know the components are right, you can be a lot more confident that the system as a whole will work!
For historical reasons, one of our drivers was written in User Space and then ported into the kernel. Combined with careful design choices, this means it's a body of code that can run in either environment, making Unit Testing possible. This has proven to be a really fruitful learning experience; User Space development tends to be quicker and there are many more tools available, including profilers and test frameworks.
Recommended by LinkedIn
So, back to the Thanksgiving project! What could we do to build on this work and apply the lessons to the whole code base? Could we find a way of executing fragments of driver code in User Space? Could we use Microsoft’s C++ Unit Test framework in Visual Studio to drive this? It turns out, the answer is “yes”! We’ve been able to build a framework that not only supports testing our Kernel code but goes further and allows entire drivers to be loaded, verifying the specific binary that we intend to ship to customers. As far as I am aware, this is still miles in advance of anything else that is around.
“Really cool … at the risk of gushing – this is a game-changer” is starting to sound about right!
The Unit Test Framework is a large body of code which simulates much of the Windows Kernel, implementing many of the foundational support routines and objects. So how do we know it’s correct? By Unit Testing it, of course! … just like driver code should be Unit Tested! The framework is fully integrated into the Visual Studio environment. Engineers can easily write, run and debug Unit Tests and have them become a permanent part of the QA process.
Unit Testing is an important component in ensuring code quality. The Windows Driver Unit Test Framework enables you to develop Unit Tests alongside a driver and to run them easily on-demand.
It's still a work in progress and at the moment portions of Kernel functionality are stubbed out, but the framework is sufficient to allow credible tests to be performed. The project is being contributed to the Windows Platform Development Kit to enable others to benefit from it. It currently supports the kernel features used by our own driver stack, but it's being made available to the community as a resource that can be developed and further extended.
DataCore has announced that it is contributing the Windows Driver Unit Test Framework to further extend the open-source Windows Platform Development Kit.