Skip to content

Commit d961c65

Browse files
daniel-rafflerbaierd
authored andcommitted
Added tests to narrow down bug #339. So far no luck, but we did stumble upon bug #310 for CVC5.
1 parent 0f28dc8 commit d961c65

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* JavaSMT is an API wrapper for a collection of SMT solvers.
3+
* This file is part of JavaSMT.
4+
*
5+
* Copyright (C) 2007-2016 Dirk Beyer
6+
* All rights reserved.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
package org.sosy_lab.java_smt.test;
22+
23+
import static com.google.common.truth.TruthJUnit.assume;
24+
import static org.sosy_lab.java_smt.test.ProverEnvironmentSubject.assertThat;
25+
26+
import java.util.concurrent.ExecutionException;
27+
import java.util.concurrent.ExecutorService;
28+
import java.util.concurrent.Executors;
29+
import java.util.concurrent.Future;
30+
import org.junit.Test;
31+
import org.sosy_lab.common.ShutdownManager;
32+
import org.sosy_lab.common.ShutdownNotifier;
33+
import org.sosy_lab.common.configuration.Configuration;
34+
import org.sosy_lab.common.configuration.InvalidConfigurationException;
35+
import org.sosy_lab.common.log.LogManager;
36+
import org.sosy_lab.java_smt.SolverContextFactory;
37+
import org.sosy_lab.java_smt.SolverContextFactory.Solvers;
38+
import org.sosy_lab.java_smt.api.BasicProverEnvironment;
39+
import org.sosy_lab.java_smt.api.BooleanFormula;
40+
import org.sosy_lab.java_smt.api.BooleanFormulaManager;
41+
import org.sosy_lab.java_smt.api.FormulaManager;
42+
import org.sosy_lab.java_smt.api.IntegerFormulaManager;
43+
import org.sosy_lab.java_smt.api.SolverContext;
44+
import org.sosy_lab.java_smt.api.SolverException;
45+
46+
public class SolverThreadLocalTest extends SolverBasedTest0.ParameterizedSolverBasedTest0 {
47+
@Test
48+
public void allLocalTest() throws InterruptedException, SolverException {
49+
requireIntegers();
50+
51+
HardIntegerFormulaGenerator gen = new HardIntegerFormulaGenerator(imgr, bmgr);
52+
BooleanFormula formula = gen.generate(8);
53+
54+
try (BasicProverEnvironment<?> prover = context.newProverEnvironment()) {
55+
prover.push(formula);
56+
assertThat(prover).isUnsatisfiable();
57+
}
58+
}
59+
60+
@Test public void nonlocalContext() throws ExecutionException, InterruptedException,
61+
SolverException {
62+
requireIntegers();
63+
64+
/* FIXME: Exception for CVC5 (related to #310?)
65+
io.github.cvc5.CVC5ApiException:
66+
Invalid call to 'cvc5::SortKind cvc5::Sort::getKind() const', expected non-null object
67+
*/
68+
assume().that(solverToUse()).isNotEqualTo(Solvers.CVC5);
69+
70+
ExecutorService executor = Executors.newSingleThreadExecutor();
71+
Future<SolverContext> result = executor.submit(() -> {
72+
try {
73+
Configuration config = Configuration.builder()
74+
.setOption("solver.solver", solverToUse().toString())
75+
.build();
76+
} catch (InvalidConfigurationException e) {
77+
throw new RuntimeException(e);
78+
}
79+
LogManager logger = LogManager.createTestLogManager();
80+
ShutdownNotifier shutdownNotifier = ShutdownManager.create().getNotifier();
81+
82+
SolverContextFactory factory = new SolverContextFactory(config, logger, shutdownNotifier);
83+
return factory.generateContext();
84+
});
85+
86+
executor.shutdownNow();
87+
88+
SolverContext context = result.get();
89+
FormulaManager mgr = context.getFormulaManager();
90+
91+
BooleanFormulaManager bmgr = mgr.getBooleanFormulaManager();
92+
IntegerFormulaManager imgr = mgr.getIntegerFormulaManager();
93+
94+
HardIntegerFormulaGenerator gen = new HardIntegerFormulaGenerator(imgr, bmgr);
95+
BooleanFormula formula = gen.generate(8); // CVC5 throws an exception here
96+
97+
try (BasicProverEnvironment<?> prover = context.newProverEnvironment()) {
98+
prover.push(formula);
99+
assertThat(prover).isUnsatisfiable();
100+
}
101+
}
102+
103+
@Test
104+
public void nonlocalFormulaTest() throws InterruptedException, SolverException,
105+
ExecutionException {
106+
requireIntegers();
107+
108+
/* FIXME: Exception for CVC5 (related to #310?)
109+
Invalid call to 'cvc5::SortKind cvc5::Sort::getKind() const', expected non-null object
110+
*/
111+
assume().that(solverToUse()).isNotEqualTo(Solvers.CVC5);
112+
113+
ExecutorService executor = Executors.newSingleThreadExecutor();
114+
Future<BooleanFormula> result = executor.submit(() -> {
115+
HardIntegerFormulaGenerator gen = new HardIntegerFormulaGenerator(imgr, bmgr);
116+
return gen.generate(8);
117+
});
118+
119+
BooleanFormula formula = result.get();
120+
executor.shutdownNow();
121+
122+
try (BasicProverEnvironment<?> prover = context.newProverEnvironment()) {
123+
prover.push(formula);
124+
assertThat(prover).isUnsatisfiable();
125+
}
126+
}
127+
128+
@Test
129+
public void nonlocalProverTest() throws InterruptedException, ExecutionException {
130+
requireIntegers();
131+
132+
/* FIXME: Exception for CVC5
133+
io.github.cvc5.CVC5ApiException:
134+
Given term is not associated with the node manager of this solver
135+
*/
136+
assume().that(solverToUse()).isNotEqualTo(Solvers.CVC5);
137+
138+
HardIntegerFormulaGenerator gen = new HardIntegerFormulaGenerator(imgr, bmgr);
139+
BooleanFormula formula = gen.generate(8);
140+
141+
ExecutorService executor = Executors.newSingleThreadExecutor();
142+
Future<Boolean> result = executor.submit(
143+
() -> {
144+
try (BasicProverEnvironment<?> prover = context.newProverEnvironment()) {
145+
prover.push(formula); // CVC5 throws an exception here
146+
return prover.isUnsat();
147+
}
148+
});
149+
150+
Boolean isUnsat = result.get();
151+
executor.shutdownNow();
152+
153+
assert(isUnsat).equals(true);
154+
}
155+
}

0 commit comments

Comments
 (0)