VM Unit Testing

VM Unit Testing
SchemeStation documentation

1 Purpose

This document describes the unit testing of the SCHEMESTATION Virtual Machine. The purpose of the unit testing is to show that the basic functionality of the virtual machine functions is implemented and that there are sufficient amount of checks for illegal instructions and other malicious use of this unit - the testing should assure that there are not direct possibilities to harm the VM from outside the module.

2 Test environment

The unit tests do not require any particular environment apart from the general SCHEMESTATION develoment environment (Development environment of the SchemeStation project: makefiles and related).

3 Instruction testing

Each instruction function is tested separately. For each function the following is tested:

The first two tests are actually carried out against the instruction decoder, not the individual instruction functions. Overall, this testing is much like black-box or grey-box testing, to be sure that the external behaviour is well defined.

4 Other tests

The VM unit interface is tested as follows:

Besides public unit interface, there are interfaces for instruction encoding and decoding; all these functions are cross-checked so that encodings and decodings correspond each other.

For further information not present here, see the actual test file.

5 Test cases

All test cases for the virtual machine can be found in the schemestation source distribution, from file ./src/libsrc/vm/vm_tester.c, except make_instruction(), which is tested in the file ./src/libsrc/vm/mkinstr.c.

5.1 Instruction decoders

All instruction decoders are tested with the following criteria:

Test cases (first part: (D)one, (U)ndone, (I)ncomplete, second part: (S)uccess, (U)nsuccess, (I)ncomplete):
#DecoderInvalid argumentsFunctionality
1decoder_reg1D/SD/S
2decoder_reg1constD/SD/S
3decoder_reg12D/SD/S
4decoder_reg12constD/SD/S
5decoder_reg123D/SD/S
6decoder_reg1234D/SD/S
7decoder_nopD/SD/S
8make_instructionD/SD/S
Done88
Success88
Total result100%100%

5.2 Instructions (and exceptions)

For each instruction, there are tests for the basic functionality of the instruction (semantics). In addition, possible invalid arguments are monitored.

Test cases (first part: (D)one, (U)ndone, (I)ncomplete, second part: (S)uccess, (U)nsuccess, (I)ncomplete):
#InstructionArgumentsInvalid argumentsFunctionality
0NOPD/SD/S
1HALTD/SD/S
2JUMPREG D/SD/S
3JUMP_IMMEDIATELABEL D/SD/S
4BRANCHREG REG D/SD/S
5BRANCH_IMMEDIATEREG LABEL D/SD/S
6PUSHREG REG D/SD/S
7POPREG REG D/SD/S
8SET_EXCEPTION_HANDLERREG D/SD/S
11SEND_MESSAGEREG REG D/SD/S
14CREATE_PROCEDUREREG REG REG D/SD/S
15GET_PROCEDURE_ENVREG REG D/SD/S
16GET_PROCEDURE_ADDRESSREG REG D/SD/S
17IS_OF_BOOLEANREG REG D/SD/S
18IS_OF_INTEGERREG REG D/SD/S
19IS_OF_FLOATREG REG D/SD/S
20IS_OF_PAIRREG REG D/SD/S
21IS_OF_PAIR_TAGGEDREG REG REG D/SD/S
22IS_OF_VECTORREG REG D/SD/S
23IS_OF_VECTOR_TAGGEDREG REG REG D/SD/S
24IS_OF_PRIVATE_BIT_STRINGREG REG D/SD/S
25IS_OF_PRIVATE_BIT_STRING_TAGGEDREG REG REG D/SD/S
26IS_OF_SHARED_BIT_STRINGREG REG D/SD/S
27IS_OF_SHARED_BIT_STRING_TAGGEDREG REG REG D/SD/S
28IS_OF_PROCEDUREREG REG D/SD/S
31MOVEREG REG D/SD/S
32LOADREG LITERAL D/SD/S
33LOAD_NULLREG D/SD/S
34INT_ADDREG REG REG D/SD/S
35INT_SUBREG REG REG D/SD/S
36INT_MULREG REG REG D/SD/S
37INT_DIVREG REG REG D/SD/S
38INT_MODREG REG REG D/SD/S
39INT_REMREG REG REG D/SD/S
40FLOAT_ADDREG REG REG D/SD/S
41FLOAT_SUBREG REG REG D/SD/S
42FLOAT_MULREG REG REG D/SD/S
43FLOAT_DIVREG REG REG D/SD/S
44FLOAT_MODREG REG REG D/SD/S
45FLOAT_REMREG REG REG D/SD/S
46FLOAT_LOGREG REG D/SD/S
47FLOAT_LOG10REG REG D/SD/S
48FLOAT_EXPREG REG D/SD/S
49FLOAT_SQRTREG REG D/SD/S
50SHRREG REG REG D/SD/S
51SHLREG REG REG D/SD/S
52ANDREG REG REG D/SD/S
53ORREG REG REG D/SD/S
54XORREG REG REG D/SD/S
55NEGREG REG D/SD/S
56RORREG REG REG D/SD/S
57ROLREG REG REG D/SD/S
58LANDREG REG REG D/SD/S
59LORREG REG REG D/SD/S
60NOTREG REG D/SD/S
61BOOLEAN_NOTREG REG D/SD/S
62INT_TO_FLOATREG REG D/SD/S
63FLOAT_TO_INTREG REG D/SD/S
64INT_TO_BIT_STRINGREG REG REG D/SD/S
65BIT_STRING_TO_INTREG REG REG D/SD/S
66EQREG REG REG D/SD/S
67INT_CMPREG REG REG D/SD/S
68FLOAT_CMPREG REG REG D/SD/S
69INT_GEREG REG REG D/SD/S
70FLOAT_GEREG REG REG D/SD/S
71GET_SUBSTRINGREG REG REG REG D/SD/S
72SET_SUBSTRINGREG REG REG D/SD/S
73ALLOC_PAIRREG D/SD/S
74ALLOC_PAIR_TAGGEDREG REG D/SD/S
75ALLOC_VECTORREG REG D/SD/S
76ALLOC_VECTOR_TAGGEDREG REG REG D/SD/S
77ALLOC_SHARED_BIT_STRINGREG REG D/SD/S
78ALLOC_SHARED_BIT_STRING_TAGGEDREG REG REG D/SD/S
79ALLOC_PRIVATE_BIT_STRINGREG REG D/SD/S
80ALLOC_PRIVATE_BIT_STRING_TAGGEDREG REG REG D/SD/S
81PAIR_SET_CARREG REG D/SD/S
82PAIR_SET_CDRREG REG D/SD/S
83PAIR_GET_CARREG REG D/SD/S
84PAIR_GET_CDRREG REG D/SD/S
85VECTOR_SETREG REG REG D/SD/S
86VECTOR_GETREG REG REG D/SD/S
87VECTOR_SET_INDEXREG REG LITERAL D/SD/S
88VECTOR_GET_INDEXREG REG LITERAL D/SD/S
89VECTOR_LENREG REG D/SD/S
90BIT_STRING_LENREG REG D/SD/S
91COPY_PAIRREG REG D/SD/S
92COPY_VECTORREG REG D/SD/S
93COPY_BIT_STRINGREG REG D/SD/S
94CONSREG REG REG D/SD/S
95SAVEREG REG D/SD/S
96RESTOREREG REG D/SD/S
97ALLOC_INTEGERREG D/SD/S
98ALLOC_FLOATREG D/SD/S
99ALLOC_BOOLEANREG D/SD/S
100INTEGER_SETREG REG D/SD/S
101FLOAT_SETREG REG D/SD/S
102BOOLEAN_SETREG REG D/SD/S
103INTEGER_GETREG REG D/SD/S
104FLOAT_GETREG REG D/SD/S
105BOOLEAN_GETREG REG D/SD/S
106PAIR_GET_CAR_OR_BLOCKREG REG D/SD/S
107ALLOC_VECTOR_IMMEDIATEREG LITERAL D/SD/S
108CREATE_PROCEDURE_IMMEDIATEREG REG LABEL D/SD/S
109SAVE_IMMEDIATEREG LITERAL D/SD/S
110RESTORE_IMMEDIATEREG LITERAL D/SD/S
111BIT_STRING_CMPREG REG REG D/SD/S
112BIT_STRING_GEREG REG REG D/SD/S
113TAG_CMPREG REG LITERAL D/SD/S
114IMM_EXTEND[special]D/SD/S
Done110110
Undone00
Incomplete00
Success110110
Unsuccess00
Incomplete00
Total result100%100%

5.3 Messages

The message delivery and reception is verified separately. The incoming message handling has to block any further messages until the current message has been handled. The message testing is implicitly part of both the integration and the system testing.

5.4 VM Unit Interface

SCHEMESTATION Virtual Machine Unit Interface consists of the following functions:

vm_execute()
vm_message()
make_instruction()
reverse_map_instruction()

All these functions are tested with illegal parameters. The actual testing of this interface is carried out in the integration testing (except make_instruction(), which is tested in the file ./src/libsrc/vm/mkinstr.c), due to the fact that they represent the functionality and semantics of the whole SSVM unit.