Start the demo by running Trace, one of Aprobe's Predefined Probes. If you have any problems, e-mail support@ocsystems.com or call us at +1 703 359 8160.
The program being probed is Demo.c, which just does a few memory allocations and sleeps the rest of the time. There is nothing special about Demo.c; it could be any program. We have compiled it for you as a convenience into Demo.exe, and the Aprobe Workspace file is pointing to it.
Try this next: use Profile to see why Demo.exe takes so long. After closing the "Running Demo" window, the formatted output shows that we're spending 99% of our time in "DoSleep"! Exercise for the reader: Edit the Application Options to pass a 0 (zero) command-line argument to Demo.exe to eliminate the sleeping.
The above should have taken less than fifteen minutes. If you ran into any problems, please contact support@ocsystems.com (or call us at +1 703 359 8160).
The above can also be accomplished from the command-line. It's just as easy, so next we'll discuss how.
The predefined probes are:
The above steps led through all of these except for Coverage, which we show below, where we will run a small "custom" probe in combination with the predefined line coverage probe to get 100% test coverage.
Each predefined probe has a similar interface. Where substantial configuration is available, the user can request a Java GUI with which to specify the configuration. The configuration is defined in a readable file with an extension of ".cfg", and you can directly edit that file to change options if you decide not to use the GUI. However, each probe has a good set of defaults to allow you to use it "out-of-the-box", as we did above.
To run the above probes from the command-line, you would enter:
aprobe -u trace Demo.exe apformat Demo.apd aprobe -u memwatch -p -g Demo.exe apformat Demo.apd aprobe -u profile Demo.exe apformat Demo.apd
These predefined probes are just the beginning. You can write your own custom probes, as described in the next section.
Examine the file "Demo.apc", reproduced below.
//
// This apc file will force the malloc call to return a NULL value
// (indicating no more memory available) after malloc is called five
// times from within AllocateOne.
//
int count = 0;
probe thread
{
probe extern:"AllocateOne()"
{
probe extern:"malloc()"
{
on_entry
count++;
on_exit
if (count > 5)
$return = NULL;
}
}
}
The aprobe patching language is C, with a few extra keywords added (probe, on_entry, on_exit and on_line). The "patches", or probes, that are defined in Demo.apc have already been compiled for you as a convenience, producing Demo.dll. These probes cause malloc to return a zero (null pointer) after it is called the fifth time from within the routine AllocateOne. In the demo, this will cause a different path to be executed, so we can test that path.
Run the demo with this probe: right click on Demo.exe again and select the first option, "Run Demo.exe with Aprobe". A window should appear and it should contain the output produced by the Demo.exe being run under Aprobe with the patches specified in Demo.apc.
Note that the patches cause malloc to return NULL as expected and the demo program to print out that it is out of memory. To run this from the command line:
aprobe -u Demo Demo.exe
Percent of lines executed: 85
The following probed lines were not executed:
Lines: 31 .. 32 (demo.c)
Now let's run it again for the "Out of memory" case.
To do this we run the line coverage probe again, but this time,
we will add the Demo UAL, so both the Demo and coverage probes are
applied (one can use many different probes at one time!)
aprobe -u coverage Demo.exe apformat Demo aprobe -u coverage -u Demo -d Demo2 Demo.exe apformat Demo2There should now be a "Demo2-0.apd" window within Aprobe, which contains the results of this second run with both coverage and demo together. Looking near the bottom of this second report, we see that this time a different span of lines was not executed.
The results of these two runs can be merged into a summary report using the atcmerge tool as shown in the Aprobe\Advanced\Test_Coverage example.
Of course, custom probes can do much more than this demo shows. If you want to get an idea of what they can do, we suggest that you try the Example Workspaces found in the File menu and described in Aprobe\Examples.
For other information, including white papers, visit www.aprobe.com or contact sales@ocsystems.com.