Testing Generated Code

Writing Unit Tests For Generated Code

An example of unit testing generated code without running all of Drill is the priorityQueueOrderingTest() test in TopNBatchTest. That test tests the PriorityQueueTemplate class separately from the rest of Drill.

The testing of PriorityQueueTemplate is mainly accomplished by creating instances of the following classes:

Creating A FunctionLookupContext

new FunctionImplementationRegistry(drillConfig)

Creating A CodeCompiler

  1. Create an OperatorFixture.
  2. Retrieve the SystemOptionManager from the OperatorFixture.
    operatorFixture.getOptionManager();
    
  3. Create an instance of CodeCompiler.
    new CodeCompiler(drillConfig, optionManager)
    

Debugging Generated Code

It is possible to set break points in generated code.

Instructions For IntelliJ

  1. File→Project structure…→Modules→distribution→Sources → Add content root
  2. Chose /tmp/drill/codegen
  3. Mark it as Sources directory.
  4. Set saveCodeForDebugging(true) for the code generator of interest
  5. Run the unit test of interest
  6. Now some generated classes should appear in Intellij under the distribution module
  7. Set a break point in a generated class and run the unit test in debug mode

Instructions For Eclipse

  1. To step into the generated code, set a breakpoint just before we call into the setup method.
  2. Step into that method which will step into doSetup. This opens the generated code file.