Jvmtest
From JopWiki
Contents |
[edit] jvmtest - Project
The intention was to create a flexible, easy to use and expandable test suite framework and the corresponding test cases to check and test an implementation of a Java Virtual Machine.
[edit] Features of the framework
- should run on much vms as possible with little effort
- support to run a test case multiple times im multiple threads
- hash function of a test case, to compare the result to a reference vm
- the ability to make special test suites which only cover a view special test cases with "TestCaseList"
[edit] jvmtest on JOP
The jvmtest project is not yet a part of the JOP project, but is prepared to be integrated in the "jop/java/target/src/test" directory for easy compilation with "make P1=test P2=jvmtest P2=JopTestSuite".
[edit] Problems Framework/test suite
During the implementation I have come across a view problems, which are:
- To generate a hash value of a test case, serialization should be used to easily stream the object and genrate some crc over the stream. But the "jdk" classes from the jop project do not cover serialization. At least with "jdk11" (not sure how to use jdk14).
- The class "Thread" is not yet implemented in the jop project and the real time thread class is not intended for this kind of usage. But threaded test suites run fine on Sun J2SE 6.
- The jop library does not fully support autoboxing, because there are some missing functions, e.g.: "Object AObj = 1"; -> "Integer.valueOf(int)" is missing. Covered during the compilation of the project
- Other missing features are: generic ArrayLists and Class.getName()
[edit] Problems test cases
- size of methods <=1024 (256 4 byte slots), therefore test cases have to be split up into multiple methods.
- how to test the instruction
- nop
- swap
- pop
- pop2
- wide prefix (need more than 255 local var slots)
- goto_w
- jsr_w
- max. number of local variables (number of 4 byte slots) are 31
- arrays with more than 2 dims are not supportet
- during a test case with the "*store/*load" instructions an execption was raised in JopSim
- "iinc" with big constants are not supportet (widened iinc)
[edit] Future work
- a lot of test cases
- _load/_store instruction with different/mixed types
- check that the jvm throws the right (run-time) exceptions
- still more test cases
- better hash function
- configuration of some test cases and maybe some auto-generated test cases, to support different vm configurations (e.g. number of local variables to test in a method)
[edit] Class overview
[edit] How to write your own test case
Add a new class which extends TestCase and implement at least the:
- long serialVersionUID; need for interface Serializable
- String getTestCaseName(); need for the test suite
- void writeToStream(ByteArrayOutputStreamEx os); can be empty if serialization works, otherwise write all class fields into the output stream
- TestCaseResult run(); the test case itself
If the class is not thread safe implement the method
- boolean allowMultipleInstances() and return "false";
Then add an instance of your test case class to the test suite (and the TestCaseList). E.g. in the class "TestSuite" add a new entry in the constructor call to "SingleThreadTestCaseList(...... new MyOwnTestCase(), ..... );
If you want to create a test suite an run each test case in multiple threads then replace the "SingleThreadTestCaseList" with the "MultipleThreadTestCaseList".

