FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-smt/src/org/sosy_lab/java_smt/test/DebugModeTest.java at master · sosy-lab/java-smt · GitHub
sosy-lab
java-smt
Repository navigation
Code
Issues
114
(114)
Pull requests
43
(43)
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
java-smt
/
src
/
org
/
sosy_lab
/
java_smt
/
test
/
DebugModeTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
206 lines (180 loc) · 7.71 KB
Breadcrumbs
java-smt
/
src
/
org
/
sosy_lab
/
java_smt
/
test
/
DebugModeTest.java
Copy path
File metadata and controls
206 lines (180 loc) · 7.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// This file is part of JavaSMT,
// an API wrapper for a collection of SMT solvers:
// https://github.com/sosy-lab/java-smt
//
// SPDX-FileCopyrightText: 2023 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
package
org
.
sosy_lab
.
java_smt
.
test
;
import
static
org
.
junit
.
Assert
.
assertThrows
;
import
static
org
.
sosy_lab
.
java_smt
.
test
.
ProverEnvironmentSubject
.
assertThat
;
import
com
.
google
.
common
.
base
.
Throwables
;
import
com
.
google
.
common
.
collect
.
ImmutableList
;
import
java
.
util
.
List
;
import
java
.
util
.
concurrent
.
ExecutionException
;
import
java
.
util
.
concurrent
.
ExecutorService
;
import
java
.
util
.
concurrent
.
Executors
;
import
java
.
util
.
concurrent
.
Future
;
import
org
.
junit
.
After
;
import
org
.
junit
.
Before
;
import
org
.
junit
.
Test
;
import
org
.
sosy_lab
.
common
.
configuration
.
Configuration
;
import
org
.
sosy_lab
.
common
.
configuration
.
InvalidConfigurationException
;
import
org
.
sosy_lab
.
java_smt
.
SolverContextFactory
;
import
org
.
sosy_lab
.
java_smt
.
SolverContextFactory
.
Solvers
;
import
org
.
sosy_lab
.
java_smt
.
api
.
BasicProverEnvironment
;
import
org
.
sosy_lab
.
java_smt
.
api
.
BooleanFormula
;
import
org
.
sosy_lab
.
java_smt
.
api
.
BooleanFormulaManager
;
import
org
.
sosy_lab
.
java_smt
.
api
.
FormulaManager
;
import
org
.
sosy_lab
.
java_smt
.
api
.
FormulaType
;
import
org
.
sosy_lab
.
java_smt
.
api
.
FunctionDeclaration
;
import
org
.
sosy_lab
.
java_smt
.
api
.
IntegerFormulaManager
;
import
org
.
sosy_lab
.
java_smt
.
api
.
NumeralFormula
.
IntegerFormula
;
import
org
.
sosy_lab
.
java_smt
.
api
.
SolverContext
;
import
org
.
sosy_lab
.
java_smt
.
api
.
SolverException
;
import
org
.
sosy_lab
.
java_smt
.
api
.
UFManager
;
public
class
DebugModeTest
extends
SolverBasedTest0
.
ParameterizedSolverBasedTest0
{
private
SolverContextFactory
debugFactory
;
private
SolverContext
debugContext
;
private
UFManager
debugFmgr
;
private
BooleanFormulaManager
debugBmgr
;
private
IntegerFormulaManager
debugImgr
;
private
static
final
int
DEFAULT_PROBLEM_SIZE
=
8
;
@
Before
public
void
init
()
throws
InvalidConfigurationException
{
Configuration
debugConfig
=
Configuration
.
builder
()
.
setOption
(
"solver.solver"
,
solverToUse
().
toString
())
.
setOption
(
"solver.useDebugMode"
,
String
.
valueOf
(
true
))
.
build
();
debugFactory
=
new
SolverContextFactory
(
debugConfig
,
logger
,
shutdownNotifierToUse
());
debugContext
=
debugFactory
.
generateContext
();
FormulaManager
debugMgr
=
debugContext
.
getFormulaManager
();
try
{
debugFmgr
=
debugMgr
.
getUFManager
();
debugBmgr
=
debugMgr
.
getBooleanFormulaManager
();
debugImgr
=
debugMgr
.
getIntegerFormulaManager
();
}
catch
(
UnsupportedOperationException
e
) {
// Boolector does not support integer theory. We just leave debugImgr set to null.
}
}
@
After
public
void
cleanup
() {
if
(
debugContext
!=
null
) {
debugContext
.
close
();
}
}
/**
* Helper method for threadLocalTest(). Will rethrow any exception that occurred on the other
* thread.
*/
private
void
checkForExceptions
(
Future
<?>
task
) {
try
{
// Accessing the future will rethrow the exception on the main thread
assert
task
.
get
() ==
null
;
}
catch
(
ExecutionException
e
) {
Throwables
.
throwIfInstanceOf
(
e
.
getCause
(),
IllegalStateException
.
class
);
Throwables
.
throwIfUnchecked
(
e
.
getCause
());
}
catch
(
InterruptedException
e
) {
Thread
.
currentThread
().
interrupt
();
}
}
/** Try to use the context from a different thread. */
@
SuppressWarnings
(
"resource"
)
@
Test
public
void
nonLocalThreadTest
() {
requireVisitor
();
ExecutorService
exec
=
Executors
.
newSingleThreadExecutor
();
Future
<?>
result
=
exec
.
submit
(
() -> {
// Generate a non-trivial problem for our tests
BooleanFormula
varA
=
debugBmgr
.
makeVariable
(
"a"
);
BooleanFormula
formula
=
debugBmgr
.
and
(
varA
,
debugBmgr
.
not
(
varA
));
try
(
BasicProverEnvironment
<?>
prover
=
debugContext
.
newProverEnvironment
()) {
prover
.
push
(
formula
);
assertThat
(
prover
).
isUnsatisfiable
();
}
return
null
;
});
// We expect debug mode to throw an exception only on CVC5
if
(
solverToUse
() ==
Solvers
.
CVC5
) {
assertThrows
(
IllegalStateException
.
class
, () ->
checkForExceptions
(
result
));
}
else
{
checkForExceptions
(
result
);
}
exec
.
shutdownNow
();
}
/**
* Helper method for noSharedFormulasTest(). Will use the debug context to check the formula for
* satisfiability.
*
* @param pFormula This formula should come from a different context
*/
private
void
checkFormulaInDebugContext
(
BooleanFormula
pFormula
)
throws
InterruptedException
,
SolverException
{
try
(
BasicProverEnvironment
<?>
prover
=
debugContext
.
newProverEnvironment
()) {
prover
.
push
(
pFormula
);
assertThat
(
prover
).
isUnsatisfiable
();
}
}
/** Create a formula then try using it from a different context. */
@
Test
public
void
noSharedFormulasTest
()
throws
InterruptedException
,
SolverException
,
InvalidConfigurationException
{
requireIntegers
();
requireVisitor
();
try
(
SolverContext
newContext
=
debugFactory
.
generateContext
()) {
BooleanFormulaManager
newBmgr
=
newContext
.
getFormulaManager
().
getBooleanFormulaManager
();
IntegerFormulaManager
newImgr
=
newContext
.
getFormulaManager
().
getIntegerFormulaManager
();
HardIntegerFormulaGenerator
hardProblem
=
new
HardIntegerFormulaGenerator
(
newImgr
,
newBmgr
);
BooleanFormula
formula
=
hardProblem
.
generate
(
DEFAULT_PROBLEM_SIZE
);
// We expect debug mode to throw an exception for all solvers, except CVC4, CVC5 and Yices
if
(!
ImmutableList
.
of
(
Solvers
.
CVC4
,
Solvers
.
YICES2
).
contains
(
solverToUse
())) {
assertThrows
(
IllegalArgumentException
.
class
, () ->
checkFormulaInDebugContext
(
formula
));
}
else
{
checkFormulaInDebugContext
(
formula
);
}
}
}
/**
* Helper method for noSharedDeclarationsTest(). Uses the function declaration in debug context.
*
* @param pDeclaration A function declaration from a different context.
*/
@
SuppressWarnings
(
"ResultOfMethodCallIgnored"
)
public
void
checkDeclarationInDebugContext
(
FunctionDeclaration
<
IntegerFormula
>
pDeclaration
) {
debugFmgr
.
callUF
(
pDeclaration
,
debugImgr
.
makeNumber
(
0
));
}
/** Declare a function, then try calling it from a different context. */
@
Test
public
void
noSharedDeclarationsTest
()
throws
InvalidConfigurationException
{
requireIntegers
();
requireVisitor
();
try
(
SolverContext
newContext
=
debugFactory
.
generateContext
()) {
UFManager
newFmgr
=
newContext
.
getFormulaManager
().
getUFManager
();
FunctionDeclaration
<
IntegerFormula
>
id
=
newFmgr
.
declareUF
(
"id"
,
FormulaType
.
IntegerType
,
ImmutableList
.
of
(
FormulaType
.
IntegerType
));
// We expect debug mode to throw an exception for all solvers, except Princess, CVC4 and Yices
if
(!
List
.
of
(
Solvers
.
PRINCESS
,
Solvers
.
YICES2
).
contains
(
solverToUse
())) {
assertThrows
(
IllegalArgumentException
.
class
, () ->
checkDeclarationInDebugContext
(
id
));
}
else
{
checkDeclarationInDebugContext
(
id
);
}
}
}
/** Try to add a formula from a different solver to our solver context. */
@
Test
public
void
noSharingBetweenSolversTest
()
throws
InvalidConfigurationException
{
Solvers
otherSolver
=
solverToUse
() ==
Solvers
.
SMTINTERPOL
?
Solvers
.
PRINCESS
:
Solvers
.
SMTINTERPOL
;
try
(
SolverContext
otherContext
=
debugFactory
.
generateContext
(
otherSolver
)) {
BooleanFormulaManager
otherBmgr
=
otherContext
.
getFormulaManager
().
getBooleanFormulaManager
();
BooleanFormula
formula
=
otherBmgr
.
makeFalse
();
try
(
BasicProverEnvironment
<?>
prover
=
debugContext
.
newProverEnvironment
()) {
assertThrows
(
IllegalArgumentException
.
class
, () ->
prover
.
push
(
formula
));
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL