Project

General

Profile

База данных ограничений » History » Version 35

Andrei Tatarnikov, 12/21/2011 03:44 PM

1 3 Andrei Tatarnikov
h1. Constraint Solver
2 1 Alexander Kamkin
3 11 Andrei Tatarnikov
The constraint solver subsystem is aimed to provide the possibility to automatically generate test cases based on specified constraints. A constraint is represented by a set of limitations for input values. The solver finds values of input variables which will violate the limitations if there are any such values.
4 6 Andrei Tatarnikov
5 8 Andrei Tatarnikov
The subsystem uses a third-party SMT solver as an engine (in the current version, we use the Z3 solver by Microsoft Research). SMT solvers use a special functional language to specify constraints. The subsystem generates constructions in the SMT language and uses the engine to process them and produce the results (find values of unknown input variables).
6 3 Andrei Tatarnikov
7 35 Andrei Tatarnikov
h2.
8
9
<pre>
10
;Finds an integer  
11
;Expected output:
12
;sat ((x #x00000080))
13
14
(declare-const x (_ BitVec 32))
15
(assert (bvugt x (_ bv100 32)))
16
(assert (bvult x (_ bv200 32)))
17
(assert (= (bvand x (bvsub x (_ bv1 32))) (_ bv0 32)))
18
(check-sat)
19
(get-value (x))
20
(exit)
21
</pre>
22
23 18 Andrei Tatarnikov
h2. Syntax trees
24
25 9 Andrei Tatarnikov
We use language-independent syntax trees to represent constraints. These trees then are processed to generate a representation that can be understood by a particular SMT solver. The syntax tree contains the following node types:
26 13 Andrei Tatarnikov
# Constraint. This is the root node of the tree. It holds the list of unknown variables and the list of limitations for these variables.
27 21 Andrei Tatarnikov
# Formula. Represents a limitation expression. Can be combined with other limitations to build a more complex limitation (by applying a logic OR, AND or NOT to it). The underlying expression must be a logic expression that can be solved to true or false.
28 13 Andrei Tatarnikov
# Operation. Represents an unary or binary operation with some unknown variable, some value or some expression as parameters.
29 14 Andrei Tatarnikov
# Variable.Represents an input variable. It can have an assigned value and, in such case, will be treated as a value. Otherwise, it is an unknown variable. A variable includes a type as an attribute.
30
# Value. Specifies some known value of the specified type which can be accessed as an attribute.
31 17 Andrei Tatarnikov
32 16 Andrei Tatarnikov
Note: Operation, Variables and Value can be treated polymorphically as syntax elements (SyntaxElement). This allows combining them to build complex expressions.
33 1 Alexander Kamkin
34 24 Andrei Tatarnikov
The current implementation supports operations with the following data types:
35 26 Andrei Tatarnikov
# Bit vectors
36
# Booleans
37 16 Andrei Tatarnikov
38 22 Andrei Tatarnikov
h2. Constraint Solver Java Library
39 3 Andrei Tatarnikov
40 28 Andrei Tatarnikov
The source code files of the Constraint Solver subsystem are located in the "microtesk++/constraint-solver" folder. The java classes are organized in the following packages:
41 32 Andrei Tatarnikov
# ru.ispras.microtesk.constraints - contains SMT representation generation logic and solver implementations.
42
# ru.ispras.microtesk.constraints.syntax - contains classes implementing syntax tree nodes.
43
# ru.ispras.microtesk.constraints.syntax.types - contains code that specifies particular data types and operation types.
44 29 Andrei Tatarnikov
# ru.ispras.microtesk.constraints.tests - contains JUnit test cases.
45 28 Andrei Tatarnikov
46 34 Andrei Tatarnikov
<pre>
47 33 Andrei Tatarnikov
@
48
;Finds an integer  
49
;Expected output:
50
;sat ((x #x00000080))
51
52
(declare-const x (_ BitVec 32))
53
(assert (bvugt x (_ bv100 32)))
54
(assert (bvult x (_ bv200 32)))
55
(assert (= (bvand x (bvsub x (_ bv1 32))) (_ bv0 32)))
56
(check-sat)
57
(get-value (x))
58 1 Alexander Kamkin
(exit)
59 33 Andrei Tatarnikov
@
60 34 Andrei Tatarnikov
</pre>
61 3 Andrei Tatarnikov
62
h1. База данных ограничений
63
64
База данных ограничений строится автоматически в результате анализа формализованных спецификаций системы команд микропроцессора, выполненной на одном из ADL-языков (например, nML). Некоторые ситуации могут описываться вручную и добавляться в базу данных ограничений.