Search |
||||||||||||||
Java ME Testing - Debugging Test FailuresPosted by alexeyp on February 22, 2007 at 11:44 PM PST
What to do when tests of JavaTM ME implementation test suite fail ? This article offers some suggestions for debugging test failures - with a special focus on the JT harness and ME Framework features that support debugging. My initial motivation for writing this article was to announce improvements in the Test Export feature, however the topic is just so entertaining that I couldn't stop there. :-) Debugging
in
Java Micro Edition (ME) has number of challenges. Issues related to
debugging problems in Java ME implementation can include any of the
following items:
Problems, specific to automated Java ME test suites, have the
following roots:
Debugging TipsThe goal of this section is to provide you with a list of practical steps that could be taken by the ME Framework and JT harness user in the process of analyzing test failures. These debugging tips range from know-how to very natural and evident.Tip 1 - Browse the code, test specification, test output.If tests are written well, atomic, documented, provided with good trace information, if type of failure allows this trace to be viewed at the console or in the test result, stored by the test harness. If all these 'ifs' are there, it is enough to look at test spec, sources and output to identify the problem. It is not rare case, btw. Example of JT harness test result file contains all information, that test harness could provide to help with debugging, has sections for:
Tip 2 - Turn on logging
In the ME Framework, you can configure the logging level in the
following places:
|
||||||||||||||
|
you must execute the following command:
export sampleValue=<find
'sampleValue' variable in the test environment>
java -classpath $TEST_HOME/classes^
com.sun.tck.satsa.tests.api.java.security.KeyFactory.generatePublicTests^
-envValue $sampleValue
Or even simpler - JT harness result file contains the exact command and values of parameters that must be executed. See section messages:(1/693) in the example.
Unfortunately this works well only in CDC and Java SE
execution
modes. This approach will not work for CLDC/MIDP, where you
need the application to be packaged and deployed before you can execute
it.
The ME Framework is a quite complex set of interacting components involved in test execution. When a test is reported as failed by the JT Harness it's not always evident where the bug is and how to track it down. Most often, when users are trying to track down a bug, they want to run the failed test standalone on the device under test. This is where the Test Export feature can help. Test Export converts an individual test into a small standalone Java ME application containing the test, which can be executed, debugged, or used in any way convenient for the user.
A very simple, partial implementation of the test export was available in the ME Framework from the beginning. It was a hack of a standard CLDC/MIDP execution mechanism., described by the following scheme.
FIGURE X. Autotest mode.
In order to turn test into CLDC/MIDP application that executes separately from the harness, one must replace all these arrows, representing some message exchanges, with static data.
For the initial ME Framework implementation of the test export feature, test packages where supplied with all information necessary for test execution (that replaced links 3 and 4). The execution server was packaging test bundles without waiting for any requests from AMS (links 1 and 2). For the test harness, test status indicated success of packaging and not actual test execution (link 5). When executed, tests did not send result to the execution server but just printed them on the console (link 5). Tests were packaged with all test data but not automatically downloaded to the device and test packages not removed after execution cycle completed.
Even this simple and limited approach allowed to solve some troubleshooting-related tasks. For example, a QA engineer responsible for TCK execution on the development build of the implementation could use these exported test packages as attachments to bug reports. A development engineer not familiar with TCK execution could use it to reproduce the problem and verify the fix.
The previous implementation of the Test Export was not complete. Evident limitations were that only simple non-distributed tests were exported and not test sources. For the user, this meant that a created application could not be modified and rebuilt. The previous implementation also exported only .jar files and not .jad files.
Implementing the full Test Export feature for all types of tests is a challenging task requiring very accurate tracking of all test dependencies. The following are examples of such dependencies:
Identifying all test sources associated with a distributed network test is not a simple task. To make this feature really user-friendly, one should provide parts of the test execution infrastructure, such as the provisioning server for MIDP.
Many of these problems are addressed in the new Test Export implementation that was recently integrated into the ME Framework by Dmitry Trounine.To initiate Test Export for a ME Framework 1.2-based test suite, the user should first open the Configuration Editor and, in the interview, set test export mode on. Then the user should specify the export directory (the location where exported test will be saved) and maybe some additional parameters, such as the 'Prefix of URLs to JAR files' parameter specific for the MIDP platform. See the following screen-shot of the JT harness Configuration Editor: Configuring Test Export.
Finally, the user should select the test or tests to export and run them just as in a regular test run. In test export mode, instead of executing tests on a device, the selected test or tests are saved in the specified test export directory.
When the test export is done, the following content is created in the export directory:
Just as with any other Java application, these applications can be uploaded on any suitable device and launched. The exported tests are executed in the same way that they are executed by ME Framework but in standalone mode, printing the diagnostics and test result on the device screen.
These descriptors are properly configured:
- They contain the same attributes as in regular test runs.
- They are signed and include certificates if the test suite was configured for trusted MIDP security mode.
- They contain proper links to the exported JAR files.
You can use the generated JAD files for OTA provisioning of exported tests by putting them on any suitable HTTP server or by using the special provisioning server included with the ME Framework.
These source files can be used for debugging or rebuilding the exported tests.
Class files in classes subdirectory.
Yeah! Users can change the exported tests by modifying its sources and rebuilding them with this build script. It contains all necessary targets for compiling sources, updating JAR files from classes, and signing JAD files. In addition, build.properties is also generated in the export directory. It defines properties used by the build script and can be used to configure the build. For example, property trusted, if defined, triggers signing JAD files when updating exported tests.
These are not part of exported tests and are not required for using them, but can be also helpful. For example, exportSigner.jar is a tool for updating signatures and certificates of MIDlet suites with tests in those cases where the tests contained in it have been modified and its JAR file has changed.
Let's look at this new feature from the point of view of a Sun Java Wireless Toolkit (Wireless Toolkit) user. Before the test export feature was introduced, users could execute tests on the emulator by using its autotest mode:
$WTK_HOME/bin/emulator -Xautotest
http://localhost:8080/test/getNextApp.jad
This command launches the emulator and specifies an URL at which the emulator should look for tests to download. At this URL resides the execution server of ME Framework. The execution server responds to 'getNextApp.jad' requests by sending new and new tests from a large test suite. The emulator fails in a loop repeating three steps (install, execute, remove) for each downloaded test until the execution server has no more tests to send. There was no way to get just one test (corresponding JAD and JAR files) for standalone execution. In addition, users of the Wireless Toolkit know that autotest mode doesn't allow debugging!
Now, with the test export feature, a user can select the test to debug and export it to any appropriate location. JAR and JAD files are generated and can be executed on emulator. The following is a typical command for launching the exported test on the Wireless Toolkit emulator:
$WTK_HOME/bin/emulator -Xdescriptor $EXPORT_DIR/test3.jad
During its execution, the test prints the output to stdout. Click here to view an example.
This time, debugging the test during its execution is easy.
Just add the -Xdebug argument to last command
with all necessary parameters. You can then use your preferred debugger
with the IDE of your choice to debug the test with its sources which
are also exported.
The next planned improvement for debugging support will come from the integration of Skavas's GUI Agent. This will allow you to use GUI and RMS in addition to console output for execution of exported tests. Watch for more information about this in the future - it's a topic for another post.
The Test Export feature is under development right now and you can improve it by posting on ME Framework forums. Propose your improvement or new feature and you may see it in one of the next releases.
|
|