Skip to main content

Conditional Processing in Japex

Posted by spericas on August 11, 2006 at 1:30 PM PDT

It has been a while since my last blog about Japex. I'm currently working on a couple of improvements: the first involves cleaning up and simplifying the Japex trend reporting tool (but more on this on a later installment) and the second is about conditional processing in configuration files, the topic I would like to talk about today.

Readers not familiar with Japex and the structure of its configuration files are referred to the Japex manual. Using groups (parameter, driver or test case groups) and XInclude, it is possible to modularize configuration files. The following example shows how to assemble a config file from 3 driver groups and 2 test case groups:

 <testSuite name="Sample" xmlns="http://www.sun.com/japex/testSuite"
     xmlns:xi="http://www.w3.org/2001/XInclude">
   
    ...

    <xi:include href="drivers/driver-group1.xml"/>   
    <xi:include href="drivers/driver-group2.xml"/>   
    <xi:include href="drivers/driver-group3.xml"/>   
   
    <xi:include href="drivers/testcase-group1.xml"/>   
    <xi:include href="drivers/testcase-group2.xml"/>   
 
</testSuite>

This was a great improvement over earlier versions in which only monolithic configuration files were support (of course, you could use XML parsed entities, but these are less intuitive and don't feel like bona-fide modules). Now, what if you are interested in running the same benchmark but with a limited set of test cases, say only test case group 1? Well, in that case, you'd need to write another configuration file in which test case group 2 is omitted. Similarly, what if only driver groups 1 and 3 should be tested next? You guessed it, another config file would be needed.

Obviously, the solution to this problem is to have a form of conditional processing in Japex. It should be simple enough so that it is easy to remember and should not require a whole new expression language in order to evaluate conditions.

Japex 1.0.19 now has support for two new attributes japex:if and japex:unless. These attributes can be associated with any element in a configuration file, although typically they would be used for conditional inclusion, a feature not supported by XInclude. The value of these attributes must be a Java system property which, depending on whether it is defined or not, will determine if the associated element would be processed or not. For example, let us assume that we want a single configuration file that would run in three modes: tall, grande and venti (hmm, where did I hear that before?), where tall runs driver group 1 and test case group 1, grande runs what tall runs plus test case group 2 and venti runs all groups. A possible config file for such a benchmark would be:

 <testSuite name="Sample" xmlns="http://www.sun.com/japex/testSuite"
     xmlns:xi="http://www.w3.org/2001/XInclude"
     xmlns:japex="http://www.sun.com/japex/testSuite">
   
    ...

    <xi:include href="drivers/driver-group1.xml"/>   
    <xi:include href="drivers/driver-group2.xml" japex:unless="tall"/>   
    <xi:include href="drivers/driver-group3.xml" japex:if="venti"/>   
   
    <xi:include href="drivers/testcase-group1.xml"/>   
    <xi:include href="drivers/testcase-group2.xml" japex:unless="tall"/>   
   
</testSuite>

The benchmark's mode would be specified from the command line using the -D option of the java command. A simple pre-processor in Japex inspects each element and omits it from the test suite if its condition fails; if no condition is associated with an element, then it is always preserved.

Paul has been trying to clean up a large benchmark using conditional processing. He also has some ideas on how to tackle this problem using a config file assembler, i.e. a pre-processor that would accept a list of groups and produce a configuration file suitable to be processed by Japex. As we gain more experience using Japex, we'll find out which solution (or combination of solutions) works best in practice. So, send us your feedback and, as always, happy benchmarking!

Related Topics >>