Using PureCoverage with Scripts

Related Topics

You can modify existing batch files and Perl scripts to check code coverage as they execute. The following examples show some ways that you can use PureCoverage command-line options to control data collection from a script.

For Java code generated by the Sun Microsystems JDK:

§          Add the following line to monitor a Java applet using filters contained in the coverage filter file (.cft) Test_jharness.cft, and then to save the data to an ASCII text file:

coverage /SaveTextData /FilterFiles=test_jharness.cft /java <path>/appletviewer.exe example1.html

§          Add the following line to monitor a Java class file:

coverage /SaveTextData /FilterFiles=test_jharness.cft /java <path>/java.exe MyClassName

§          To monitor a JAR file, use the Sun Java viewer and the name of the JAR file, including the extension.

For Java code generated by other compilers, click images\shortcut.gif

For .NET managed code and Visual Basic p-code programs, add the following line to have a test script monitor a .NET managed program or a p-code program using filters contained in the filter file Test_vbharness.cft, and then to save the data to an ASCII text file:

coverage /SaveTextData /FilterFiles=test_vbharness.cft /net pcode_app.exe

For native-compiled (unmanaged) Visual C++ and Visual Basic programs, if you have a test script that runs a native-compiled (unmanaged) program, you can easily modify the script to instrument and run the program. To do this, change the line that runs <exename>.exe to:

coverage <exename>.exe

Alternatively, to run the instrumented version of <exename>.exe consistently throughout your tests, add the following line to the beginning of your test script:

coverage /Run=no /Replace=yes <exename>.exe

This line instructs PureCoverage to instrument the program but not to run the instrumented program. PureCoverage saves the original program to <exename>.exe.original and replaces it with the instrumented version, <exename>.exe. Now, whenever your test script runs <exename>.exe, the instrumented version of your program runs, providing code coverage information.

To run the instrumented version, filter data using filters contained in the PureCoverage filter file (.cft) Test_harness.cft, and save the coverage data to an ASCII text file (.txt) so the script can work with it, add the following line:

coverage /SaveTextData /FilterFiles=test_harness.cft <exename>.exe

Notes:

§                  To run programs from the command line, you must have the RationalPurifyPlus/common directory in your PATH environment variable.

§                  If you run your test script continuously, make sure each run of the script starts with the uninstrumented version of the program.

§                  To use a script to analyze coverage data, modify the script to search the collected data for records that meet specific criteria. For example, a script can raise a failure condition if a function's coverage is below a specified number or percentage.

§                  If you are using Microsoft Windows 2000 or higher, the Windows File Protection feature (WFP) may cause problems when you use PureCoverage's /replace command line option. For a workaround to this problem, click images\shortcut.gif.

(C) Copyright IBM Corporation 1993, 2010.